org.apache.flink.table.types.logical.TimestampType Java Examples
The following examples show how to use
org.apache.flink.table.types.logical.TimestampType.
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: BinaryRowData.java From flink with Apache License 2.0 | 6 votes |
/** * If it is a fixed-length field, we can call this BinaryRowData's setXX method for in-place updates. * If it is variable-length field, can't use this method, because the underlying data is stored continuously. */ public static boolean isInFixedLengthPart(LogicalType type) { switch (type.getTypeRoot()) { case BOOLEAN: case TINYINT: case SMALLINT: case INTEGER: case DATE: case TIME_WITHOUT_TIME_ZONE: case INTERVAL_YEAR_MONTH: case BIGINT: case INTERVAL_DAY_TIME: case FLOAT: case DOUBLE: return true; case DECIMAL: return DecimalData.isCompact(((DecimalType) type).getPrecision()); case TIMESTAMP_WITHOUT_TIME_ZONE: return TimestampData.isCompact(((TimestampType) type).getPrecision()); case TIMESTAMP_WITH_LOCAL_TIME_ZONE: return TimestampData.isCompact(((LocalZonedTimestampType) type).getPrecision()); default: return false; } }
Example #2
Source File: LogicalTypesTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testMultisetType() { testAll( new MultisetType(new TimestampType()), "MULTISET<TIMESTAMP(6)>", "MULTISET<TIMESTAMP(6)>", new Class[]{Map.class}, new Class[]{Map.class}, new LogicalType[]{new TimestampType()}, new MultisetType(new SmallIntType()) ); testAll( new MultisetType(new MultisetType(new TimestampType())), "MULTISET<MULTISET<TIMESTAMP(6)>>", "MULTISET<MULTISET<TIMESTAMP(6)>>", new Class[]{Map.class}, new Class[]{Map.class}, new LogicalType[]{new MultisetType(new TimestampType())}, new MultisetType(new MultisetType(new SmallIntType())) ); }
Example #3
Source File: SelectTableSinkSchemaConverter.java From flink with Apache License 2.0 | 6 votes |
/** * Convert time attributes (proc time / event time) to regular timestamp * and build a new {@link TableSchema}. */ public static TableSchema convertTimeAttributeToRegularTimestamp(TableSchema tableSchema) { DataType[] dataTypes = tableSchema.getFieldDataTypes(); String[] oldNames = tableSchema.getFieldNames(); TableSchema.Builder builder = TableSchema.builder(); for (int i = 0; i < tableSchema.getFieldCount(); i++) { DataType fieldType = dataTypes[i]; String fieldName = oldNames[i]; if (fieldType.getLogicalType() instanceof TimestampType) { TimestampType timestampType = (TimestampType) fieldType.getLogicalType(); if (!timestampType.getKind().equals(TimestampKind.REGULAR)) { // converts `TIME ATTRIBUTE(ROWTIME)`/`TIME ATTRIBUTE(PROCTIME)` to `TIMESTAMP(3)` builder.field(fieldName, DataTypes.TIMESTAMP(3)); continue; } } builder.field(fieldName, fieldType); } return builder.build(); }
Example #4
Source File: ExecutionContextTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testTemporalTables() throws Exception { final ExecutionContext<?> context = createStreamingExecutionContext(); final StreamTableEnvironment tableEnv = (StreamTableEnvironment) context.getTableEnvironment(); assertArrayEquals( new String[]{"EnrichmentSource", "HistorySource", "HistoryView", "TemporalTableUsage"}, tableEnv.listTables()); assertArrayEquals( new String[]{"sourcetemporaltable", "viewtemporaltable"}, tableEnv.listUserDefinedFunctions()); assertArrayEquals( new String[]{"integerField", "stringField", "rowtimeField", "integerField0", "stringField0", "rowtimeField0"}, tableEnv.from("TemporalTableUsage").getSchema().getFieldNames()); // Please delete this test after removing registerTableSourceInternal in SQL-CLI. TableSchema tableSchema = tableEnv.from("EnrichmentSource").getSchema(); LogicalType timestampType = tableSchema.getFieldDataTypes()[2].getLogicalType(); assertTrue(timestampType instanceof TimestampType); assertEquals(TimestampKind.ROWTIME, ((TimestampType) timestampType).getKind()); }
Example #5
Source File: EqualiserCodeGeneratorTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testTimestamp() { RecordEqualiser equaliser = new EqualiserCodeGenerator( new LogicalType[]{new TimestampType()}) .generateRecordEqualiser("TIMESTAMP") .newInstance(Thread.currentThread().getContextClassLoader()); Function<TimestampData, BinaryRowData> func = o -> { BinaryRowData row = new BinaryRowData(1); BinaryRowWriter writer = new BinaryRowWriter(row); writer.writeTimestamp(0, o, 9); writer.complete(); return row; }; assertBoolean(equaliser, func, fromEpochMillis(1024), fromEpochMillis(1024), true); assertBoolean(equaliser, func, fromEpochMillis(1024), fromEpochMillis(1025), false); }
Example #6
Source File: SelectTableSinkSchemaConverter.java From flink with Apache License 2.0 | 6 votes |
/** * Convert time attributes (proc time / event time) to normal timestamps, * and return a new {@link TableSchema}. */ static TableSchema convertTimeAttributeToRegularTimestamp(TableSchema tableSchema) { DataType[] oldTypes = tableSchema.getFieldDataTypes(); String[] oldNames = tableSchema.getFieldNames(); TableSchema.Builder builder = TableSchema.builder(); for (int i = 0; i < tableSchema.getFieldCount(); i++) { DataType fieldType = oldTypes[i]; String fieldName = oldNames[i]; if (fieldType.getLogicalType() instanceof TimestampType) { TimestampType timestampType = (TimestampType) fieldType.getLogicalType(); if (!timestampType.getKind().equals(TimestampKind.REGULAR)) { // converts `TIME ATTRIBUTE(ROWTIME)`/`TIME ATTRIBUTE(PROCTIME)` to `TIMESTAMP` builder.field(fieldName, Types.SQL_TIMESTAMP); continue; } } builder.field(fieldName, fieldType); } return builder.build(); }
Example #7
Source File: ConnectorCatalogTable.java From flink with Apache License 2.0 | 6 votes |
private static void updateRowtimeIndicators( DefinedRowtimeAttributes source, String[] fieldNames, DataType[] types) { List<String> rowtimeAttributes = source.getRowtimeAttributeDescriptors() .stream() .map(RowtimeAttributeDescriptor::getAttributeName) .collect(Collectors.toList()); for (int i = 0; i < fieldNames.length; i++) { if (rowtimeAttributes.contains(fieldNames[i])) { // bridged to timestamp for compatible flink-planner types[i] = new AtomicDataType(new TimestampType(true, TimestampKind.ROWTIME, 3)) .bridgedTo(java.sql.Timestamp.class); } } }
Example #8
Source File: ConnectorCatalogTable.java From flink with Apache License 2.0 | 6 votes |
private static void updateRowtimeIndicators( DefinedRowtimeAttributes source, String[] fieldNames, DataType[] types) { List<String> rowtimeAttributes = source.getRowtimeAttributeDescriptors() .stream() .map(RowtimeAttributeDescriptor::getAttributeName) .collect(Collectors.toList()); for (int i = 0; i < fieldNames.length; i++) { if (rowtimeAttributes.contains(fieldNames[i])) { // bridged to timestamp for compatible flink-planner types[i] = new AtomicDataType(new TimestampType(true, TimestampKind.ROWTIME, 3)) .bridgedTo(java.sql.Timestamp.class); } } }
Example #9
Source File: LogicalTypesTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testArrayType() { testAll( new ArrayType(new TimestampType()), "ARRAY<TIMESTAMP(6)>", "ARRAY<TIMESTAMP(6)>", new Class[]{java.sql.Timestamp[].class, java.time.LocalDateTime[].class, List.class, ArrayList.class}, new Class[]{java.sql.Timestamp[].class, java.time.LocalDateTime[].class, List.class}, new LogicalType[]{new TimestampType()}, new ArrayType(new SmallIntType()) ); testAll( new ArrayType(new ArrayType(new TimestampType())), "ARRAY<ARRAY<TIMESTAMP(6)>>", "ARRAY<ARRAY<TIMESTAMP(6)>>", new Class[]{java.sql.Timestamp[][].class, java.time.LocalDateTime[][].class}, new Class[]{java.sql.Timestamp[][].class, java.time.LocalDateTime[][].class}, new LogicalType[]{new ArrayType(new TimestampType())}, new ArrayType(new ArrayType(new SmallIntType())) ); final LogicalType nestedArray = new ArrayType(new ArrayType(new TimestampType())); assertFalse(nestedArray.supportsInputConversion(java.sql.Timestamp[].class)); assertFalse(nestedArray.supportsOutputConversion(java.sql.Timestamp[].class)); }
Example #10
Source File: LogicalTypesTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testMultisetType() { testAll( new MultisetType(new TimestampType()), "MULTISET<TIMESTAMP(6)>", "MULTISET<TIMESTAMP(6)>", new Class[]{Map.class, HashMap.class, TreeMap.class}, new Class[]{Map.class}, new LogicalType[]{new TimestampType()}, new MultisetType(new SmallIntType()) ); testAll( new MultisetType(new MultisetType(new TimestampType())), "MULTISET<MULTISET<TIMESTAMP(6)>>", "MULTISET<MULTISET<TIMESTAMP(6)>>", new Class[]{Map.class, HashMap.class, TreeMap.class}, new Class[]{Map.class}, new LogicalType[]{new MultisetType(new TimestampType())}, new MultisetType(new MultisetType(new SmallIntType())) ); }
Example #11
Source File: DataFormatConverters.java From flink with Apache License 2.0 | 6 votes |
private static int getDateTimePrecision(LogicalType logicalType) { if (logicalType instanceof LocalZonedTimestampType) { return ((LocalZonedTimestampType) logicalType).getPrecision(); } else if (logicalType instanceof TimestampType) { return ((TimestampType) logicalType).getPrecision(); } else { TypeInformation typeInfo = ((LegacyTypeInformationType) logicalType).getTypeInformation(); if (typeInfo instanceof LegacyInstantTypeInfo) { return ((LegacyInstantTypeInfo) typeInfo).getPrecision(); } else if (typeInfo instanceof LegacyLocalDateTimeTypeInfo) { return ((LegacyLocalDateTimeTypeInfo) typeInfo).getPrecision(); } else { // TimestampType.DEFAULT_PRECISION == LocalZonedTimestampType.DEFAULT_PRECISION == 6 return TimestampType.DEFAULT_PRECISION; } } }
Example #12
Source File: LogicalTypeParser.java From flink with Apache License 2.0 | 6 votes |
private LogicalType parseTimestampType() { int precision = parseOptionalPrecision(TimestampType.DEFAULT_PRECISION); if (hasNextToken(Keyword.WITHOUT)) { nextToken(Keyword.WITHOUT); nextToken(Keyword.TIME); nextToken(Keyword.ZONE); } else if (hasNextToken(Keyword.WITH)) { nextToken(Keyword.WITH); if (hasNextToken(Keyword.LOCAL)) { nextToken(Keyword.LOCAL); nextToken(Keyword.TIME); nextToken(Keyword.ZONE); return new LocalZonedTimestampType(precision); } else { nextToken(Keyword.TIME); nextToken(Keyword.ZONE); return new ZonedTimestampType(precision); } } return new TimestampType(precision); }
Example #13
Source File: FlinkTypeToType.java From iceberg with Apache License 2.0 | 5 votes |
@SuppressWarnings("checkstyle:CyclomaticComplexity") @Override public Type atomic(AtomicDataType type) { LogicalType inner = type.getLogicalType(); if (inner instanceof VarCharType || inner instanceof CharType) { return Types.StringType.get(); } else if (inner instanceof BooleanType) { return Types.BooleanType.get(); } else if (inner instanceof IntType || inner instanceof SmallIntType || inner instanceof TinyIntType) { return Types.IntegerType.get(); } else if (inner instanceof BigIntType) { return Types.LongType.get(); } else if (inner instanceof VarBinaryType) { return Types.BinaryType.get(); } else if (inner instanceof BinaryType) { BinaryType binaryType = (BinaryType) inner; return Types.FixedType.ofLength(binaryType.getLength()); } else if (inner instanceof FloatType) { return Types.FloatType.get(); } else if (inner instanceof DoubleType) { return Types.DoubleType.get(); } else if (inner instanceof DateType) { return Types.DateType.get(); } else if (inner instanceof TimeType) { return Types.TimeType.get(); } else if (inner instanceof TimestampType) { return Types.TimestampType.withoutZone(); } else if (inner instanceof LocalZonedTimestampType) { return Types.TimestampType.withZone(); } else if (inner instanceof DecimalType) { DecimalType decimalType = (DecimalType) inner; return Types.DecimalType.of(decimalType.getPrecision(), decimalType.getScale()); } else { throw new UnsupportedOperationException("Not a supported type: " + type.toString()); } }
Example #14
Source File: HiveTypeUtil.java From flink with Apache License 2.0 | 5 votes |
@Override public TypeInfo visit(TimestampType timestampType) { if (checkPrecision && timestampType.getPrecision() != 9) { throw new CatalogException("HiveCatalog currently only supports timestamp of precision 9"); } return TypeInfoFactory.timestampTypeInfo; }
Example #15
Source File: LogicalTypesTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testMapType() { testAll( new MapType(new VarCharType(20), new TimestampType()), "MAP<VARCHAR(20), TIMESTAMP(6)>", "MAP<VARCHAR(20), TIMESTAMP(6)>", new Class[]{Map.class}, new Class[]{Map.class}, new LogicalType[]{new VarCharType(20), new TimestampType()}, new MapType(new VarCharType(99), new TimestampType()) ); }
Example #16
Source File: ArrowUtils.java From flink with Apache License 2.0 | 5 votes |
@Override public ArrowType visit(TimestampType timestampType) { if (timestampType.getPrecision() == 0) { return new ArrowType.Timestamp(TimeUnit.SECOND, null); } else if (timestampType.getPrecision() >= 1 && timestampType.getPrecision() <= 3) { return new ArrowType.Timestamp(TimeUnit.MILLISECOND, null); } else if (timestampType.getPrecision() >= 4 && timestampType.getPrecision() <= 6) { return new ArrowType.Timestamp(TimeUnit.MICROSECOND, null); } else { return new ArrowType.Timestamp(TimeUnit.NANOSECOND, null); } }
Example #17
Source File: LegacyTypeInfoDataTypeConverter.java From flink with Apache License 2.0 | 5 votes |
private static DataType convertToTimeAttributeType(TimeIndicatorTypeInfo timeIndicatorTypeInfo) { final TimestampKind kind; if (timeIndicatorTypeInfo.isEventTime()) { kind = TimestampKind.ROWTIME; } else { kind = TimestampKind.PROCTIME; } return new AtomicDataType(new TimestampType(true, kind, 3)) .bridgedTo(java.sql.Timestamp.class); }
Example #18
Source File: LegacyTypeInfoDataTypeConverter.java From flink with Apache License 2.0 | 5 votes |
private static TypeInformation<?> convertToTimeAttributeTypeInfo(TimestampType timestampType) { if (isRowtimeAttribute(timestampType)) { return TimeIndicatorTypeInfo.ROWTIME_INDICATOR; } else { return TimeIndicatorTypeInfo.PROCTIME_INDICATOR; } }
Example #19
Source File: LogicalTypeGeneralization.java From flink with Apache License 2.0 | 5 votes |
private static LogicalType createTimestampType(LogicalTypeRoot typeRoot, int precision) { switch (typeRoot) { case TIMESTAMP_WITHOUT_TIME_ZONE: return new TimestampType(precision); case TIMESTAMP_WITH_TIME_ZONE: return new ZonedTimestampType(precision); case TIMESTAMP_WITH_LOCAL_TIME_ZONE: return new LocalZonedTimestampType(precision); default: throw new IllegalArgumentException(); } }
Example #20
Source File: LogicalTypesTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testTimestampTypeWithTimeAttribute() { testAll( new TimestampType(true, TimestampKind.ROWTIME, 9), "TIMESTAMP(9)", "TIMESTAMP(9) *ROWTIME*", new Class[]{java.sql.Timestamp.class, java.time.LocalDateTime.class}, new Class[]{java.time.LocalDateTime.class}, new LogicalType[]{}, new TimestampType(3) ); }
Example #21
Source File: KuduTableUtils.java From bahir-flink with Apache License 2.0 | 5 votes |
public static TableSchema getSchemaWithSqlTimestamp(TableSchema schema) { TableSchema.Builder builder = new TableSchema.Builder(); TableSchemaUtils.getPhysicalSchema(schema).getTableColumns().forEach( tableColumn -> { if (tableColumn.getType().getLogicalType() instanceof TimestampType) { builder.field(tableColumn.getName(), tableColumn.getType().bridgedTo(Timestamp.class)); } else { builder.field(tableColumn.getName(), tableColumn.getType()); } }); return builder.build(); }
Example #22
Source File: KuduTypeUtils.java From bahir-flink with Apache License 2.0 | 5 votes |
public static DataType toFlinkType(Type type, ColumnTypeAttributes typeAttributes) { switch (type) { case STRING: return DataTypes.STRING(); case FLOAT: return DataTypes.FLOAT(); case INT8: return DataTypes.TINYINT(); case INT16: return DataTypes.SMALLINT(); case INT32: return DataTypes.INT(); case INT64: return DataTypes.BIGINT(); case DOUBLE: return DataTypes.DOUBLE(); case DECIMAL: return DataTypes.DECIMAL(typeAttributes.getPrecision(), typeAttributes.getScale()); case BOOL: return DataTypes.BOOLEAN(); case BINARY: return DataTypes.BYTES(); case UNIXTIME_MICROS: return new AtomicDataType(new TimestampType(3), Timestamp.class); default: throw new IllegalArgumentException("Illegal var type: " + type); } }
Example #23
Source File: PythonTypeUtils.java From flink with Apache License 2.0 | 5 votes |
@Override public FlinkFnApi.Schema.FieldType visit(TimestampType timestampType) { FlinkFnApi.Schema.FieldType.Builder builder = FlinkFnApi.Schema.FieldType.newBuilder() .setTypeName(FlinkFnApi.Schema.TypeName.TIMESTAMP) .setNullable(timestampType.isNullable()); FlinkFnApi.Schema.TimestampInfo.Builder timestampInfoBuilder = FlinkFnApi.Schema.TimestampInfo.newBuilder() .setPrecision(timestampType.getPrecision()); builder.setTimestampInfo(timestampInfoBuilder); return builder.build(); }
Example #24
Source File: LegacyTypeInfoDataTypeConverter.java From flink with Apache License 2.0 | 5 votes |
private static TypeInformation<?> convertToTimeAttributeTypeInfo(TimestampType timestampType) { if (isRowtimeAttribute(timestampType)) { return TimeIndicatorTypeInfo.ROWTIME_INDICATOR; } else { return TimeIndicatorTypeInfo.PROCTIME_INDICATOR; } }
Example #25
Source File: LogicalTypesTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testMapType() { testAll( new MapType(new VarCharType(20), new TimestampType()), "MAP<VARCHAR(20), TIMESTAMP(6)>", "MAP<VARCHAR(20), TIMESTAMP(6)>", new Class[]{Map.class, HashMap.class, TreeMap.class}, new Class[]{Map.class}, new LogicalType[]{new VarCharType(20), new TimestampType()}, new MapType(new VarCharType(99), new TimestampType()) ); }
Example #26
Source File: ArrayFieldReader.java From flink with Apache License 2.0 | 5 votes |
private Class<?> getElementClass(LogicalType elementType) { DataType dataType = TypeConversions.fromLogicalToDataType(elementType); if (elementType instanceof TimestampType) { // the default conversion class is java.time.LocalDateTime dataType = dataType.bridgedTo(Timestamp.class); } else if (elementType instanceof DateType) { // the default conversion class is java.time.LocalDate dataType = dataType.bridgedTo(Date.class); } else if (elementType instanceof TimeType) { // the default conversion class is java.time.LocalTime dataType = dataType.bridgedTo(Time.class); } return dataType.getConversionClass(); }
Example #27
Source File: LogicalTypesTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testTimestampTypeWithTimeAttribute() { testAll( new TimestampType(true, TimestampKind.ROWTIME, 9), "TIMESTAMP(9)", "TIMESTAMP(9) *ROWTIME*", new Class[]{java.sql.Timestamp.class, java.time.LocalDateTime.class}, new Class[]{java.time.LocalDateTime.class}, new LogicalType[]{}, new TimestampType(3) ); }
Example #28
Source File: LogicalTypesTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testTimestampType() { testAll( new TimestampType(9), "TIMESTAMP(9)", "TIMESTAMP(9)", new Class[]{java.sql.Timestamp.class, java.time.LocalDateTime.class}, new Class[]{java.time.LocalDateTime.class}, new LogicalType[]{}, new TimestampType(3) ); }
Example #29
Source File: LogicalTypeMerging.java From flink with Apache License 2.0 | 5 votes |
private static LogicalType createTimestampType(LogicalTypeRoot typeRoot, int precision) { switch (typeRoot) { case TIMESTAMP_WITHOUT_TIME_ZONE: return new TimestampType(precision); case TIMESTAMP_WITH_TIME_ZONE: return new ZonedTimestampType(precision); case TIMESTAMP_WITH_LOCAL_TIME_ZONE: return new LocalZonedTimestampType(precision); default: throw new IllegalArgumentException(); } }
Example #30
Source File: LegacyTypeInfoDataTypeConverter.java From flink with Apache License 2.0 | 5 votes |
private static DataType convertToTimeAttributeType(TimeIndicatorTypeInfo timeIndicatorTypeInfo) { final TimestampKind kind; if (timeIndicatorTypeInfo.isEventTime()) { kind = TimestampKind.ROWTIME; } else { kind = TimestampKind.PROCTIME; } return new AtomicDataType(new TimestampType(true, kind, 3)) .bridgedTo(java.sql.Timestamp.class); }