Search in sources :

Example 1 with DynamicTableSourceFactory

use of org.apache.flink.table.factories.DynamicTableSourceFactory in project flink by apache.

the class HiveLookupJoinITCase method getLookupFunction.

private FileSystemLookupFunction<HiveTablePartition> getLookupFunction(String tableName) throws Exception {
    TableEnvironmentInternal tableEnvInternal = (TableEnvironmentInternal) tableEnv;
    ObjectIdentifier tableIdentifier = ObjectIdentifier.of(hiveCatalog.getName(), "default", tableName);
    CatalogTable catalogTable = (CatalogTable) hiveCatalog.getTable(tableIdentifier.toObjectPath());
    HiveLookupTableSource hiveTableSource = (HiveLookupTableSource) FactoryUtil.createDynamicTableSource((DynamicTableSourceFactory) hiveCatalog.getFactory().orElseThrow(IllegalStateException::new), tableIdentifier, tableEnvInternal.getCatalogManager().resolveCatalogTable(catalogTable), tableEnv.getConfig().getConfiguration(), Thread.currentThread().getContextClassLoader(), false);
    FileSystemLookupFunction<HiveTablePartition> lookupFunction = (FileSystemLookupFunction<HiveTablePartition>) hiveTableSource.getLookupFunction(new int[][] { { 0 } });
    return lookupFunction;
}
Also used : DynamicTableSourceFactory(org.apache.flink.table.factories.DynamicTableSourceFactory) TableEnvironmentInternal(org.apache.flink.table.api.internal.TableEnvironmentInternal) CatalogTable(org.apache.flink.table.catalog.CatalogTable) ObjectIdentifier(org.apache.flink.table.catalog.ObjectIdentifier)

Example 2 with DynamicTableSourceFactory

use of org.apache.flink.table.factories.DynamicTableSourceFactory in project flink by apache.

the class DynamicTableSourceSpec method getTableSource.

private DynamicTableSource getTableSource(FlinkContext flinkContext) {
    if (tableSource == null) {
        final DynamicTableSourceFactory factory = flinkContext.getModuleManager().getFactory(Module::getTableSourceFactory).orElse(null);
        tableSource = FactoryUtil.createDynamicTableSource(factory, contextResolvedTable.getIdentifier(), contextResolvedTable.getResolvedTable(), loadOptionsFromCatalogTable(contextResolvedTable, flinkContext), flinkContext.getTableConfig().getConfiguration(), flinkContext.getClassLoader(), contextResolvedTable.isTemporary());
        if (sourceAbilities != null) {
            RowType newProducedType = (RowType) contextResolvedTable.getResolvedSchema().toSourceRowDataType().getLogicalType();
            for (SourceAbilitySpec spec : sourceAbilities) {
                SourceAbilityContext context = new SourceAbilityContext(flinkContext, newProducedType);
                spec.apply(tableSource, context);
                if (spec.getProducedType().isPresent()) {
                    newProducedType = spec.getProducedType().get();
                }
            }
        }
    }
    return tableSource;
}
Also used : DynamicTableSourceFactory(org.apache.flink.table.factories.DynamicTableSourceFactory) SourceAbilityContext(org.apache.flink.table.planner.plan.abilities.source.SourceAbilityContext) SourceAbilitySpec(org.apache.flink.table.planner.plan.abilities.source.SourceAbilitySpec) RowType(org.apache.flink.table.types.logical.RowType)

Example 3 with DynamicTableSourceFactory

use of org.apache.flink.table.factories.DynamicTableSourceFactory in project flink by apache.

the class CatalogSourceTable method createDynamicTableSource.

private DynamicTableSource createDynamicTableSource(FlinkContext context, ResolvedCatalogTable catalogTable) {
    final ReadableConfig config = context.getTableConfig().getConfiguration();
    final Optional<DynamicTableSourceFactory> factoryFromCatalog = schemaTable.getContextResolvedTable().getCatalog().flatMap(Catalog::getFactory).map(f -> f instanceof DynamicTableSourceFactory ? (DynamicTableSourceFactory) f : null);
    final Optional<DynamicTableSourceFactory> factoryFromModule = context.getModuleManager().getFactory(Module::getTableSourceFactory);
    // Since the catalog is more specific, we give it precedence over a factory provided by any
    // modules.
    final DynamicTableSourceFactory factory = firstPresent(factoryFromCatalog, factoryFromModule).orElse(null);
    return FactoryUtil.createDynamicTableSource(factory, schemaTable.getContextResolvedTable().getIdentifier(), catalogTable, config, Thread.currentThread().getContextClassLoader(), schemaTable.isTemporary());
}
Also used : ReadableConfig(org.apache.flink.configuration.ReadableConfig) DynamicTableSourceFactory(org.apache.flink.table.factories.DynamicTableSourceFactory) Module(org.apache.flink.table.module.Module)

Aggregations

DynamicTableSourceFactory (org.apache.flink.table.factories.DynamicTableSourceFactory)3 ReadableConfig (org.apache.flink.configuration.ReadableConfig)1 TableEnvironmentInternal (org.apache.flink.table.api.internal.TableEnvironmentInternal)1 CatalogTable (org.apache.flink.table.catalog.CatalogTable)1 ObjectIdentifier (org.apache.flink.table.catalog.ObjectIdentifier)1 Module (org.apache.flink.table.module.Module)1 SourceAbilityContext (org.apache.flink.table.planner.plan.abilities.source.SourceAbilityContext)1 SourceAbilitySpec (org.apache.flink.table.planner.plan.abilities.source.SourceAbilitySpec)1 RowType (org.apache.flink.table.types.logical.RowType)1