use of org.apache.flink.table.types.logical.TimestampType in project flink by apache.
the class LogicalTypesTest method testRowType.
@Test
public void testRowType() {
assertThat(new RowType(Arrays.asList(new RowType.RowField("a", new VarCharType(), "Someone's desc."), new RowType.RowField("b`", new TimestampType())))).satisfies(baseAssertions("ROW<`a` VARCHAR(1) 'Someone''s desc.', `b``` TIMESTAMP(6)>", "ROW<`a` VARCHAR(1) '...', `b``` TIMESTAMP(6)>", new Class[] { Row.class }, new Class[] { Row.class }, new LogicalType[] { new VarCharType(), new TimestampType() }, new RowType(Arrays.asList(new RowType.RowField("a", new VarCharType(), "Different desc."), new RowType.RowField("b`", new TimestampType())))));
assertThatThrownBy(() -> new RowType(Arrays.asList(new RowType.RowField("b", new VarCharType()), new RowType.RowField("b", new VarCharType()), new RowType.RowField("a", new VarCharType()), new RowType.RowField("a", new TimestampType())))).isInstanceOf(ValidationException.class);
assertThatThrownBy(() -> new RowType(Collections.singletonList(new RowType.RowField("", new VarCharType())))).isInstanceOf(ValidationException.class);
}
use of org.apache.flink.table.types.logical.TimestampType in project flink by apache.
the class LogicalTypesTest method testArrayType.
@Test
public void testArrayType() {
assertThat(new ArrayType(new TimestampType())).satisfies(baseAssertions("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())));
assertThat(new ArrayType(new ArrayType(new TimestampType()))).satisfies(baseAssertions("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()));
assertThat(nestedArray).doesNotSupportInputConversion(java.sql.Timestamp[].class).doesNotSupportOutputConversion(java.sql.Timestamp[].class);
}
use of org.apache.flink.table.types.logical.TimestampType in project flink by apache.
the class LogicalTypesTest method testMultisetType.
@Test
public void testMultisetType() {
assertThat(new MultisetType(new TimestampType())).satisfies(baseAssertions("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())));
assertThat(new MultisetType(new MultisetType(new TimestampType()))).satisfies(baseAssertions("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()))));
}
use of org.apache.flink.table.types.logical.TimestampType in project flink by apache.
the class DefaultSchemaResolver method adjustRowtimeAttribute.
private Column adjustRowtimeAttribute(List<WatermarkSpec> watermarkSpecs, Column column) {
final String name = column.getName();
final DataType dataType = column.getDataType();
final boolean hasWatermarkSpec = watermarkSpecs.stream().anyMatch(s -> s.getRowtimeAttribute().equals(name));
if (hasWatermarkSpec && isStreamingMode) {
switch(dataType.getLogicalType().getTypeRoot()) {
case TIMESTAMP_WITHOUT_TIME_ZONE:
final TimestampType originalType = (TimestampType) dataType.getLogicalType();
final LogicalType rowtimeType = new TimestampType(originalType.isNullable(), TimestampKind.ROWTIME, originalType.getPrecision());
return column.copy(replaceLogicalType(dataType, rowtimeType));
case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
final LocalZonedTimestampType timestampLtzType = (LocalZonedTimestampType) dataType.getLogicalType();
final LogicalType rowtimeLtzType = new LocalZonedTimestampType(timestampLtzType.isNullable(), TimestampKind.ROWTIME, timestampLtzType.getPrecision());
return column.copy(replaceLogicalType(dataType, rowtimeLtzType));
default:
throw new ValidationException("Invalid data type of expression for rowtime definition. " + "The field must be of type TIMESTAMP(p) or TIMESTAMP_LTZ(p)," + " the supported precision 'p' is from 0 to 3.");
}
}
return column;
}
use of org.apache.flink.table.types.logical.TimestampType in project flink by apache.
the class TimestampToTimestampCastRule method generateExpression.
@Override
public String generateExpression(CodeGeneratorCastRule.Context context, String inputTerm, LogicalType inputLogicalType, LogicalType targetLogicalType) {
final int inputPrecision = LogicalTypeChecks.getPrecision(inputLogicalType);
int targetPrecision = LogicalTypeChecks.getPrecision(targetLogicalType);
if (inputLogicalType.is(LogicalTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE) && targetLogicalType.is(LogicalTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE)) {
final TimestampKind inputTimestampKind = ((TimestampType) inputLogicalType).getKind();
final TimestampKind targetTimestampKind = ((TimestampType) targetLogicalType).getKind();
if (inputTimestampKind == TimestampKind.ROWTIME || inputTimestampKind == TimestampKind.PROCTIME || targetTimestampKind == TimestampKind.ROWTIME || targetTimestampKind == TimestampKind.PROCTIME) {
targetPrecision = 3;
}
}
final String operand;
if (inputLogicalType.is(LogicalTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE) && targetLogicalType.is(LogicalTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE)) {
operand = staticCall(BuiltInMethods.TIMESTAMP_TO_TIMESTAMP_WITH_LOCAL_ZONE(), inputTerm, context.getSessionTimeZoneTerm());
} else if (inputLogicalType.is(LogicalTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE) && targetLogicalType.is(LogicalTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE)) {
operand = staticCall(BuiltInMethods.TIMESTAMP_WITH_LOCAL_ZONE_TO_TIMESTAMP(), inputTerm, context.getSessionTimeZoneTerm());
} else {
operand = inputTerm;
}
if (inputPrecision <= targetPrecision) {
return operand;
} else {
return staticCall(BuiltInMethods.TRUNCATE_SQL_TIMESTAMP(), operand, targetPrecision);
}
}
Aggregations