use of org.apache.flink.table.connector.source.LookupTableSource in project flink by apache.
the class TemporalTableSourceSpec method getTemporalTable.
@JsonIgnore
public RelOptTable getTemporalTable(FlinkContext flinkContext) {
if (null != temporalTable) {
return temporalTable;
}
if (null != tableSourceSpec && null != outputType) {
LookupTableSource lookupTableSource = tableSourceSpec.getLookupTableSource(flinkContext);
SourceAbilitySpec[] sourceAbilitySpecs = null;
if (null != tableSourceSpec.getSourceAbilities()) {
sourceAbilitySpecs = tableSourceSpec.getSourceAbilities().toArray(new SourceAbilitySpec[0]);
}
return new TableSourceTable(null, outputType, FlinkStatistic.UNKNOWN(), lookupTableSource, true, tableSourceSpec.getContextResolvedTable(), flinkContext, sourceAbilitySpecs);
}
throw new TableException("Can not obtain temporalTable correctly!");
}
use of org.apache.flink.table.connector.source.LookupTableSource in project flink by apache.
the class TemporalTableSourceSpecSerdeTest method testTemporalTableSourceSpecSerde.
public static Stream<TemporalTableSourceSpec> testTemporalTableSourceSpecSerde() {
Map<String, String> options1 = new HashMap<>();
options1.put("connector", "filesystem");
options1.put("format", "testcsv");
options1.put("path", "/tmp");
final ResolvedSchema resolvedSchema1 = new ResolvedSchema(Collections.singletonList(Column.physical("a", DataTypes.BIGINT())), Collections.emptyList(), null);
final CatalogTable catalogTable1 = CatalogTable.of(Schema.newBuilder().fromResolvedSchema(resolvedSchema1).build(), null, Collections.emptyList(), options1);
ResolvedCatalogTable resolvedCatalogTable = new ResolvedCatalogTable(catalogTable1, resolvedSchema1);
RelDataType relDataType1 = FACTORY.createSqlType(SqlTypeName.BIGINT);
LookupTableSource lookupTableSource = new TestValuesTableFactory.MockedLookupTableSource();
TableSourceTable tableSourceTable1 = new TableSourceTable(null, relDataType1, FlinkStatistic.UNKNOWN(), lookupTableSource, true, ContextResolvedTable.temporary(ObjectIdentifier.of("default_catalog", "default_db", "MyTable"), resolvedCatalogTable), FLINK_CONTEXT, new SourceAbilitySpec[] { new LimitPushDownSpec(100) });
TemporalTableSourceSpec temporalTableSourceSpec1 = new TemporalTableSourceSpec(tableSourceTable1);
return Stream.of(temporalTableSourceSpec1);
}
use of org.apache.flink.table.connector.source.LookupTableSource in project flink by apache.
the class LookupJoinUtil method getLookupFunction.
/**
* Gets LookupFunction from temporal table according to the given lookup keys.
*/
public static UserDefinedFunction getLookupFunction(RelOptTable temporalTable, Collection<Integer> lookupKeys) {
int[] lookupKeyIndicesInOrder = getOrderedLookupKeys(lookupKeys);
if (temporalTable instanceof TableSourceTable) {
// TODO: support nested lookup keys in the future,
// currently we only support top-level lookup keys
int[][] indices = IntStream.of(lookupKeyIndicesInOrder).mapToObj(i -> new int[] { i }).toArray(int[][]::new);
LookupTableSource tableSource = (LookupTableSource) ((TableSourceTable) temporalTable).tableSource();
LookupRuntimeProviderContext providerContext = new LookupRuntimeProviderContext(indices);
LookupTableSource.LookupRuntimeProvider provider = tableSource.getLookupRuntimeProvider(providerContext);
if (provider instanceof TableFunctionProvider) {
return ((TableFunctionProvider<?>) provider).createTableFunction();
} else if (provider instanceof AsyncTableFunctionProvider) {
return ((AsyncTableFunctionProvider<?>) provider).createAsyncTableFunction();
}
}
if (temporalTable instanceof LegacyTableSourceTable) {
String[] lookupFieldNamesInOrder = IntStream.of(lookupKeyIndicesInOrder).mapToObj(temporalTable.getRowType().getFieldNames()::get).toArray(String[]::new);
LegacyTableSourceTable<?> legacyTableSourceTable = (LegacyTableSourceTable<?>) temporalTable;
LookupableTableSource<?> tableSource = (LookupableTableSource<?>) legacyTableSourceTable.tableSource();
if (tableSource.isAsyncEnabled()) {
return tableSource.getAsyncLookupFunction(lookupFieldNamesInOrder);
} else {
return tableSource.getLookupFunction(lookupFieldNamesInOrder);
}
}
throw new TableException(String.format("table %s is neither TableSourceTable not LegacyTableSourceTable", temporalTable.getQualifiedName()));
}
Aggregations