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;
}
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;
}
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());
}
Aggregations