use of org.apache.flink.table.expressions.ResolvedFieldReference in project flink by apache.
the class TimestampExtractorUtils method getAccessedFields.
/**
* Retrieves all field accesses needed for the given {@link TimestampExtractor}.
*
* @param timestampExtractor Extractor for which to construct array of field accesses.
* @param physicalInputType Physical input type that the timestamp extractor accesses.
* @param nameRemapping Additional remapping of a logical to a physical field name.
* TimestampExtractor works with logical names, but accesses physical fields
* @return Array of physical field references.
*/
public static ResolvedFieldReference[] getAccessedFields(TimestampExtractor timestampExtractor, DataType physicalInputType, Function<String, String> nameRemapping) {
final Function<String, ResolvedFieldReference> fieldMapping;
if (LogicalTypeChecks.isCompositeType(physicalInputType.getLogicalType())) {
ResolvedSchema schema = DataTypeUtils.expandCompositeTypeToSchema(physicalInputType);
fieldMapping = (arg) -> mapToResolvedField(nameRemapping, schema, arg);
} else {
fieldMapping = (arg) -> new ResolvedFieldReference(arg, TypeConversions.fromDataTypeToLegacyInfo(physicalInputType), 0);
}
return getAccessedFields(timestampExtractor, fieldMapping);
}
use of org.apache.flink.table.expressions.ResolvedFieldReference in project flink by apache.
the class TimestampExtractorUtils method mapToResolvedField.
private static ResolvedFieldReference mapToResolvedField(Function<String, String> nameRemapping, ResolvedSchema schema, String arg) {
String remappedName = nameRemapping.apply(arg);
int idx = IntStream.range(0, schema.getColumnCount()).filter(i -> schema.getColumnNames().get(i).equals(remappedName)).findFirst().orElseThrow(() -> new ValidationException(String.format("Field %s does not exist", remappedName)));
TypeInformation<?> dataType = TypeConversions.fromDataTypeToLegacyInfo(schema.getColumnDataTypes().get(idx));
return new ResolvedFieldReference(remappedName, dataType, idx);
}
use of org.apache.flink.table.expressions.ResolvedFieldReference in project flink by apache.
the class ExistingField method getExpression.
/**
* Returns an {@link Expression} that casts a {@link Long}, {@link Timestamp}, or timestamp
* formatted {@link String} field (e.g., "2018-05-28 12:34:56.000") into a rowtime attribute.
*/
@Override
public Expression getExpression(ResolvedFieldReference[] fieldAccesses) {
ResolvedFieldReference fieldAccess = fieldAccesses[0];
DataType type = fromLegacyInfoToDataType(fieldAccess.resultType());
FieldReferenceExpression fieldReferenceExpr = new FieldReferenceExpression(fieldAccess.name(), type, 0, fieldAccess.fieldIndex());
switch(type.getLogicalType().getTypeRoot()) {
case BIGINT:
case TIMESTAMP_WITHOUT_TIME_ZONE:
return fieldReferenceExpr;
case VARCHAR:
DataType outputType = TIMESTAMP(3).bridgedTo(Timestamp.class);
return CallExpression.permanent(CAST, Arrays.asList(fieldReferenceExpr, typeLiteral(outputType)), outputType);
default:
throw new RuntimeException("Unsupport type: " + type);
}
}
Aggregations