Search in sources :

Example 1 with AsyncTableFunctionProvider

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());
}
Also used : HBaseDynamicTableSource(org.apache.flink.connector.hbase2.source.HBaseDynamicTableSource) HBaseRowDataAsyncLookupFunction(org.apache.flink.connector.hbase2.source.HBaseRowDataAsyncLookupFunction) LookupRuntimeProviderContext(org.apache.flink.table.runtime.connector.source.LookupRuntimeProviderContext) AsyncTableFunctionProvider(org.apache.flink.table.connector.source.AsyncTableFunctionProvider) LookupTableSource(org.apache.flink.table.connector.source.LookupTableSource) ResolvedSchema(org.apache.flink.table.catalog.ResolvedSchema) AsyncTableFunction(org.apache.flink.table.functions.AsyncTableFunction) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) HBaseDynamicTableSource(org.apache.flink.connector.hbase2.source.HBaseDynamicTableSource) Test(org.junit.Test)

Example 2 with AsyncTableFunctionProvider

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()));
}
Also used : IntStream(java.util.stream.IntStream) AsyncTableFunctionProvider(org.apache.flink.table.connector.source.AsyncTableFunctionProvider) JsonCreator(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator) LegacyTableSourceTable(org.apache.flink.table.planner.plan.schema.LegacyTableSourceTable) JsonSubTypes(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonSubTypes) RexLiteral(org.apache.calcite.rex.RexLiteral) Collection(java.util.Collection) TableException(org.apache.flink.table.api.TableException) UserDefinedFunction(org.apache.flink.table.functions.UserDefinedFunction) TableSourceTable(org.apache.flink.table.planner.plan.schema.TableSourceTable) LookupableTableSource(org.apache.flink.table.sources.LookupableTableSource) JsonProperty(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty) RelOptTable(org.apache.calcite.plan.RelOptTable) ArrayList(java.util.ArrayList) Objects(java.util.Objects) List(java.util.List) LookupTableSource(org.apache.flink.table.connector.source.LookupTableSource) LogicalType(org.apache.flink.table.types.logical.LogicalType) JsonTypeInfo(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonTypeInfo) Internal(org.apache.flink.annotation.Internal) TableFunctionProvider(org.apache.flink.table.connector.source.TableFunctionProvider) JsonIgnoreProperties(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonIgnoreProperties) LookupRuntimeProviderContext(org.apache.flink.table.runtime.connector.source.LookupRuntimeProviderContext) JsonTypeName(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonTypeName) TableException(org.apache.flink.table.api.TableException) LegacyTableSourceTable(org.apache.flink.table.planner.plan.schema.LegacyTableSourceTable) AsyncTableFunctionProvider(org.apache.flink.table.connector.source.AsyncTableFunctionProvider) AsyncTableFunctionProvider(org.apache.flink.table.connector.source.AsyncTableFunctionProvider) TableFunctionProvider(org.apache.flink.table.connector.source.TableFunctionProvider) LookupableTableSource(org.apache.flink.table.sources.LookupableTableSource) LookupRuntimeProviderContext(org.apache.flink.table.runtime.connector.source.LookupRuntimeProviderContext) LookupTableSource(org.apache.flink.table.connector.source.LookupTableSource) LegacyTableSourceTable(org.apache.flink.table.planner.plan.schema.LegacyTableSourceTable) TableSourceTable(org.apache.flink.table.planner.plan.schema.TableSourceTable)

Aggregations

AsyncTableFunctionProvider (org.apache.flink.table.connector.source.AsyncTableFunctionProvider)2 LookupTableSource (org.apache.flink.table.connector.source.LookupTableSource)2 LookupRuntimeProviderContext (org.apache.flink.table.runtime.connector.source.LookupRuntimeProviderContext)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Objects (java.util.Objects)1 IntStream (java.util.stream.IntStream)1 RelOptTable (org.apache.calcite.plan.RelOptTable)1 RexLiteral (org.apache.calcite.rex.RexLiteral)1 Internal (org.apache.flink.annotation.Internal)1 HBaseDynamicTableSource (org.apache.flink.connector.hbase2.source.HBaseDynamicTableSource)1 HBaseRowDataAsyncLookupFunction (org.apache.flink.connector.hbase2.source.HBaseRowDataAsyncLookupFunction)1 JsonCreator (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator)1 JsonIgnoreProperties (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonIgnoreProperties)1 JsonProperty (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty)1 JsonSubTypes (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonSubTypes)1 JsonTypeInfo (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonTypeInfo)1 JsonTypeName (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonTypeName)1 TableException (org.apache.flink.table.api.TableException)1