use of org.apache.flink.table.sources.InputFormatTableSource in project flink by apache.
the class CommonExecLegacyTableSourceScan method translateToPlanInternal.
@SuppressWarnings("unchecked")
@Override
protected Transformation<RowData> translateToPlanInternal(PlannerBase planner, ExecNodeConfig config) {
final Transformation<?> sourceTransform;
final StreamExecutionEnvironment env = planner.getExecEnv();
if (tableSource instanceof InputFormatTableSource) {
InputFormatTableSource<Object> inputFormat = (InputFormatTableSource<Object>) tableSource;
TypeInformation<Object> typeInfo = (TypeInformation<Object>) fromDataTypeToTypeInfo(inputFormat.getProducedDataType());
InputFormat<Object, ?> format = inputFormat.getInputFormat();
sourceTransform = createInput(env, format, typeInfo);
} else if (tableSource instanceof StreamTableSource) {
sourceTransform = ((StreamTableSource<?>) tableSource).getDataStream(env).getTransformation();
} else {
throw new UnsupportedOperationException(tableSource.getClass().getSimpleName() + " is unsupported.");
}
final TypeInformation<?> inputType = sourceTransform.getOutputType();
final DataType producedDataType = tableSource.getProducedDataType();
// check that declared and actual type of table source DataStream are identical
if (!inputType.equals(TypeInfoDataTypeConverter.fromDataTypeToTypeInfo(producedDataType))) {
throw new TableException(String.format("TableSource of type %s " + "returned a DataStream of data type %s that does not match with the " + "data type %s declared by the TableSource.getProducedDataType() method. " + "Please validate the implementation of the TableSource.", tableSource.getClass().getCanonicalName(), inputType, producedDataType));
}
final RowType outputType = (RowType) getOutputType();
final RelDataType relDataType = FlinkTypeFactory.INSTANCE().buildRelNodeRowType(outputType);
// get expression to extract rowtime attribute
final Optional<RexNode> rowtimeExpression = JavaScalaConversionUtil.toJava(TableSourceUtil.getRowtimeAttributeDescriptor(tableSource, relDataType)).map(desc -> TableSourceUtil.getRowtimeExtractionExpression(desc.getTimestampExtractor(), producedDataType, planner.getRelBuilder(), getNameRemapping()));
return createConversionTransformationIfNeeded(planner.getExecEnv(), config, sourceTransform, rowtimeExpression.orElse(null));
}
Aggregations