Search in sources :

Example 6 with TableSource

use of org.apache.flink.table.sources.TableSource in project flink by apache.

the class CatalogSchemaTable method findAndCreateTableSource.

private Optional<TableSource<?>> findAndCreateTableSource() {
    Optional<TableSource<?>> tableSource = Optional.empty();
    try {
        if (contextResolvedTable.getTable() instanceof CatalogTable) {
            // Use an empty config for TableSourceFactoryContextImpl since we can't fetch the
            // actual TableConfig here. And currently the empty config do not affect the logic.
            ReadableConfig config = new Configuration();
            TableSourceFactory.Context context = new TableSourceFactoryContextImpl(contextResolvedTable.getIdentifier(), contextResolvedTable.getTable(), config, contextResolvedTable.isTemporary());
            TableSource<?> source = TableFactoryUtil.findAndCreateTableSource(context);
            if (source instanceof StreamTableSource) {
                if (!isStreamingMode && !((StreamTableSource<?>) source).isBounded()) {
                    throw new ValidationException("Cannot query on an unbounded source in batch mode, but " + contextResolvedTable.getIdentifier().asSummaryString() + " is unbounded.");
                }
                tableSource = Optional.of(source);
            } else {
                throw new ValidationException("Catalog tables only support " + "StreamTableSource and InputFormatTableSource.");
            }
        }
    } catch (Exception e) {
        tableSource = Optional.empty();
    }
    return tableSource;
}
Also used : TableSourceFactory(org.apache.flink.table.factories.TableSourceFactory) ReadableConfig(org.apache.flink.configuration.ReadableConfig) TableSource(org.apache.flink.table.sources.TableSource) StreamTableSource(org.apache.flink.table.sources.StreamTableSource) ValidationException(org.apache.flink.table.api.ValidationException) Configuration(org.apache.flink.configuration.Configuration) ConnectorCatalogTable(org.apache.flink.table.catalog.ConnectorCatalogTable) CatalogTable(org.apache.flink.table.catalog.CatalogTable) StreamTableSource(org.apache.flink.table.sources.StreamTableSource) ValidationException(org.apache.flink.table.api.ValidationException) TableSourceFactoryContextImpl(org.apache.flink.table.factories.TableSourceFactoryContextImpl)

Aggregations

TableSource (org.apache.flink.table.sources.TableSource)6 StreamTableSource (org.apache.flink.table.sources.StreamTableSource)4 RelDataType (org.apache.calcite.rel.type.RelDataType)2 Configuration (org.apache.flink.configuration.Configuration)2 TableSchema (org.apache.flink.table.api.TableSchema)2 CatalogTable (org.apache.flink.table.catalog.CatalogTable)2 DescriptorProperties (org.apache.flink.table.descriptors.DescriptorProperties)2 TableSourceFactoryContextImpl (org.apache.flink.table.factories.TableSourceFactoryContextImpl)2 FlinkTypeFactory (org.apache.flink.table.planner.calcite.FlinkTypeFactory)2 CsvTableSource (org.apache.flink.table.sources.CsvTableSource)2 DataType (org.apache.flink.table.types.DataType)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Optional (java.util.Optional)1 Nullable (javax.annotation.Nullable)1 RexNode (org.apache.calcite.rex.RexNode)1 InputFormat (org.apache.flink.api.common.io.InputFormat)1 TypeInformation (org.apache.flink.api.common.typeinfo.TypeInformation)1 Transformation (org.apache.flink.api.dag.Transformation)1