com.facebook.presto.spi.type.DateType Java Examples
The following examples show how to use
com.facebook.presto.spi.type.DateType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TypeHelper.java From presto-kudu with Apache License 2.0 | 5 votes |
public static org.apache.kudu.Type toKuduClientType(Type type) { if (type instanceof VarcharType) { return org.apache.kudu.Type.STRING; } else if (type == TimestampType.TIMESTAMP) { return org.apache.kudu.Type.UNIXTIME_MICROS; } else if (type == BigintType.BIGINT) { return org.apache.kudu.Type.INT64; } else if (type == IntegerType.INTEGER) { return org.apache.kudu.Type.INT32; } else if (type == SmallintType.SMALLINT) { return org.apache.kudu.Type.INT16; } else if (type == TinyintType.TINYINT) { return org.apache.kudu.Type.INT8; } else if (type == RealType.REAL) { return org.apache.kudu.Type.FLOAT; } else if (type == DoubleType.DOUBLE) { return org.apache.kudu.Type.DOUBLE; } else if (type == BooleanType.BOOLEAN) { return org.apache.kudu.Type.BOOL; } else if (type instanceof VarbinaryType) { return org.apache.kudu.Type.BINARY; } else if (type instanceof DecimalType) { return org.apache.kudu.Type.DECIMAL; } else if (type == DateType.DATE) { return org.apache.kudu.Type.STRING; } else if (type instanceof CharType) { return org.apache.kudu.Type.STRING; } else { throw new IllegalStateException("Type mapping implemented for Presto type: " + type); } }
Example #2
Source File: TypeHelper.java From presto-kudu with Apache License 2.0 | 5 votes |
public static Type mappedType(Type sourceType) { if (sourceType == DateType.DATE) { return VarcharType.VARCHAR; } else { return sourceType; } }
Example #3
Source File: Elasticsearch2Client.java From presto-connectors with Apache License 2.0 | 4 votes |
private static XContentBuilder buildFieldType(XContentBuilder fieldBuilder, Type type) throws IOException { final String dateTimeFormat = "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"; //Type mapping // see:https://www.elastic.co/guide/en/elasticsearch/reference/6.3/mapping-types.html if (type.equals(BooleanType.BOOLEAN)) { return fieldBuilder.field("type", "boolean"); } if (type.equals(BigintType.BIGINT)) { return fieldBuilder.field("type", "long"); } if (type.equals(IntegerType.INTEGER)) { return fieldBuilder.field("type", "integer"); } if (type.equals(SmallintType.SMALLINT)) { return fieldBuilder.field("type", "short"); } if (type.equals(TinyintType.TINYINT)) { return fieldBuilder.field("type", "byte"); } if (type.equals(DoubleType.DOUBLE)) { return fieldBuilder.field("type", "double"); } if (type.equals(DateType.DATE)) { return fieldBuilder.field("type", "date") .field("format", dateTimeFormat); } if (type.equals(TimeType.TIME)) { return fieldBuilder.field("type", "date") .field("format", dateTimeFormat); } if (type.equals(TimestampType.TIMESTAMP)) { return fieldBuilder.field("type", "date") .field("format", dateTimeFormat); } if (type.equals(TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE)) { //TODO: TIMESTAMP_WITH_TIME_ZONE return fieldBuilder.field("type", "date") .field("format", "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"); } if (type instanceof DecimalType) { return fieldBuilder.field("type", "double"); } if (isVarcharType(type)) { //es 2.4.x // .field("index", "not_analyzed") return fieldBuilder.field("type", "string"); } if (type.equals(VarbinaryType.VARBINARY)) { return fieldBuilder.field("type", "binary"); } if (isArrayType(type)) { Type elementType = type.getTypeParameters().get(0); if (isArrayType(elementType) || isMapType(elementType) || isRowType(elementType)) { throw new PrestoException(NOT_SUPPORTED, "sorry unsupported type: " + type); } return buildFieldType(fieldBuilder, elementType); } if (isMapType(type)) { throw new PrestoException(NOT_SUPPORTED, "sorry unsupported type: " + type); } if (isRowType(type)) { throw new PrestoException(NOT_SUPPORTED, "sorry unsupported type: " + type); } throw new PrestoException(NOT_SUPPORTED, "unsupported type: " + type); }
Example #4
Source File: Elasticsearch6Client.java From presto-connectors with Apache License 2.0 | 4 votes |
private static XContentBuilder buildFieldType(XContentBuilder fieldBuilder, Type type) throws IOException { final String dateTimeFormat = "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"; //Type mapping // see:https://www.elastic.co/guide/en/elasticsearch/reference/6.3/mapping-types.html if (type.equals(BooleanType.BOOLEAN)) { return fieldBuilder.field("type", "boolean"); } if (type.equals(BigintType.BIGINT)) { return fieldBuilder.field("type", "long"); } if (type.equals(IntegerType.INTEGER)) { return fieldBuilder.field("type", "integer"); } if (type.equals(SmallintType.SMALLINT)) { return fieldBuilder.field("type", "short"); } if (type.equals(TinyintType.TINYINT)) { return fieldBuilder.field("type", "byte"); } if (type.equals(DoubleType.DOUBLE)) { return fieldBuilder.field("type", "double"); } if (type.equals(DateType.DATE)) { return fieldBuilder.field("type", "date") .field("format", dateTimeFormat); } if (type.equals(TimeType.TIME)) { return fieldBuilder.field("type", "date") .field("format", dateTimeFormat); } if (type.equals(TimestampType.TIMESTAMP)) { return fieldBuilder.field("type", "date") .field("format", dateTimeFormat); } if (type.equals(TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE)) { //TODO: TIMESTAMP_WITH_TIME_ZONE return fieldBuilder.field("type", "date") .field("format", "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"); } if (type instanceof DecimalType) { return fieldBuilder.field("type", "double"); } if (isVarcharType(type)) { //TODO: text or keyword ? return fieldBuilder.field("type", "text"); } if (type.equals(VarbinaryType.VARBINARY)) { return fieldBuilder.field("type", "binary"); } if (isArrayType(type)) { Type elementType = type.getTypeParameters().get(0); if (isArrayType(elementType) || isMapType(elementType) || isRowType(elementType)) { throw new PrestoException(NOT_SUPPORTED, "sorry unsupported type: " + type); } return buildFieldType(fieldBuilder, elementType); } if (isMapType(type)) { throw new PrestoException(NOT_SUPPORTED, "sorry unsupported type: " + type); } if (isRowType(type)) { throw new PrestoException(NOT_SUPPORTED, "sorry unsupported type: " + type); } throw new PrestoException(NOT_SUPPORTED, "unsupported type: " + type); }
Example #5
Source File: Elasticsearch5Client.java From presto-connectors with Apache License 2.0 | 4 votes |
private static XContentBuilder buildFieldType(XContentBuilder fieldBuilder, Type type) throws IOException { final String dateTimeFormat = "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"; //Type mapping // see:https://www.elastic.co/guide/en/elasticsearch/reference/6.3/mapping-types.html if (type.equals(BooleanType.BOOLEAN)) { return fieldBuilder.field("type", "boolean"); } if (type.equals(BigintType.BIGINT)) { return fieldBuilder.field("type", "long"); } if (type.equals(IntegerType.INTEGER)) { return fieldBuilder.field("type", "integer"); } if (type.equals(SmallintType.SMALLINT)) { return fieldBuilder.field("type", "short"); } if (type.equals(TinyintType.TINYINT)) { return fieldBuilder.field("type", "byte"); } if (type.equals(DoubleType.DOUBLE)) { return fieldBuilder.field("type", "double"); } if (type.equals(DateType.DATE)) { return fieldBuilder.field("type", "date") .field("format", dateTimeFormat); } if (type.equals(TimeType.TIME)) { return fieldBuilder.field("type", "date") .field("format", dateTimeFormat); } if (type.equals(TimestampType.TIMESTAMP)) { return fieldBuilder.field("type", "date") .field("format", dateTimeFormat); } if (type.equals(TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE)) { //TODO: TIMESTAMP_WITH_TIME_ZONE return fieldBuilder.field("type", "date") .field("format", "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"); } if (type instanceof DecimalType) { return fieldBuilder.field("type", "double"); } if (isVarcharType(type)) { //TODO: text or keyword ? return fieldBuilder.field("type", "text"); } if (type.equals(VarbinaryType.VARBINARY)) { return fieldBuilder.field("type", "binary"); } if (isArrayType(type)) { Type elementType = type.getTypeParameters().get(0); if (isArrayType(elementType) || isMapType(elementType) || isRowType(elementType)) { throw new PrestoException(NOT_SUPPORTED, "sorry unsupported type: " + type); } return buildFieldType(fieldBuilder, elementType); } if (isMapType(type)) { throw new PrestoException(NOT_SUPPORTED, "sorry unsupported type: " + type); } if (isRowType(type)) { throw new PrestoException(NOT_SUPPORTED, "sorry unsupported type: " + type); } throw new PrestoException(NOT_SUPPORTED, "unsupported type: " + type); }
Example #6
Source File: ParaflowMetaDataReader.java From paraflow with Apache License 2.0 | 4 votes |
private Type getType(String typeName) { log.debug("Get type " + typeName); typeName = typeName.toLowerCase(); // check if type is varchar(xx) Pattern vcpattern = Pattern.compile("varchar\\(\\s*(\\d+)\\s*\\)"); Matcher vcmatcher = vcpattern.matcher(typeName); if (vcmatcher.find()) { String vlen = vcmatcher.group(1); if (!vlen.isEmpty()) { return VarcharType.createVarcharType(Integer.parseInt(vlen)); } return UnknownType.UNKNOWN; } // check if type is char(xx) Pattern cpattern = Pattern.compile("char\\(\\s*(\\d+)\\s*\\)"); Matcher cmatcher = cpattern.matcher(typeName); if (cmatcher.find()) { String clen = cmatcher.group(1); if (!clen.isEmpty()) { return CharType.createCharType(Integer.parseInt(clen)); } return UnknownType.UNKNOWN; } // check if type is decimal(precision, scale) Pattern dpattern = Pattern.compile("decimal\\((\\d+)\\s*,?\\s*(\\d*)\\)"); Matcher dmatcher = dpattern.matcher(typeName); if (dmatcher.find()) { String dprecision = dmatcher.group(1); String dscale = dmatcher.group(2); if (dprecision.isEmpty()) { return UnknownType.UNKNOWN; } if (dscale.isEmpty()) { return DecimalType.createDecimalType(Integer.parseInt(dprecision)); } return DecimalType.createDecimalType(Integer.parseInt(dprecision), Integer.parseInt(dscale)); } switch (typeName) { case "boolean": return BooleanType.BOOLEAN; case "tinyint": return TinyintType.TINYINT; case "smallint": return SmallintType.SMALLINT; case "integer": return IntegerType.INTEGER; case "bigint": return BigintType.BIGINT; case "real": return RealType.REAL; case "double": return DoubleType.DOUBLE; case "date": return DateType.DATE; case "time": return TimeType.TIME; case "timestamp": return TimestampType.TIMESTAMP; default: return UnknownType.UNKNOWN; } }