use of org.apache.flink.table.connector.source.AsyncTableFunctionProvider in project flink by apache.
the class HBaseDynamicTableFactoryTest method testLookupAsync.
@Test
public void testLookupAsync() {
Map<String, String> options = getAllOptions();
options.put("lookup.async", "true");
ResolvedSchema schema = ResolvedSchema.of(Column.physical(ROWKEY, STRING()), Column.physical(FAMILY1, ROW(FIELD(COL1, DOUBLE()), FIELD(COL2, INT()))));
DynamicTableSource source = createTableSource(schema, options);
assertTrue(source instanceof HBaseDynamicTableSource);
HBaseDynamicTableSource hbaseSource = (HBaseDynamicTableSource) source;
int[][] lookupKey = { { 0 } };
LookupTableSource.LookupRuntimeProvider lookupProvider = hbaseSource.getLookupRuntimeProvider(new LookupRuntimeProviderContext(lookupKey));
assertTrue(lookupProvider instanceof AsyncTableFunctionProvider);
AsyncTableFunction asyncTableFunction = ((AsyncTableFunctionProvider) lookupProvider).createAsyncTableFunction();
assertTrue(asyncTableFunction instanceof HBaseRowDataAsyncLookupFunction);
assertEquals("testHBastTable", ((HBaseRowDataAsyncLookupFunction) asyncTableFunction).getHTableName());
}
use of org.apache.flink.table.connector.source.AsyncTableFunctionProvider 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