Search in sources :

Example 1 with AsyncTableFunction

use of org.apache.flink.table.functions.AsyncTableFunction 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 AsyncTableFunction

use of org.apache.flink.table.functions.AsyncTableFunction in project flink by apache.

the class CommonExecLookupJoin method translateToPlanInternal.

@Override
@SuppressWarnings("unchecked")
public Transformation<RowData> translateToPlanInternal(PlannerBase planner, ExecNodeConfig config) {
    RelOptTable temporalTable = temporalTableSourceSpec.getTemporalTable(planner.getFlinkContext());
    // validate whether the node is valid and supported.
    validate(temporalTable);
    final ExecEdge inputEdge = getInputEdges().get(0);
    RowType inputRowType = (RowType) inputEdge.getOutputType();
    RowType tableSourceRowType = FlinkTypeFactory.toLogicalRowType(temporalTable.getRowType());
    RowType resultRowType = (RowType) getOutputType();
    validateLookupKeyType(lookupKeys, inputRowType, tableSourceRowType);
    boolean isAsyncEnabled = false;
    UserDefinedFunction userDefinedFunction = LookupJoinUtil.getLookupFunction(temporalTable, lookupKeys.keySet());
    UserDefinedFunctionHelper.prepareInstance(config, userDefinedFunction);
    if (userDefinedFunction instanceof AsyncTableFunction) {
        isAsyncEnabled = true;
    }
    boolean isLeftOuterJoin = joinType == FlinkJoinType.LEFT;
    StreamOperatorFactory<RowData> operatorFactory;
    if (isAsyncEnabled) {
        operatorFactory = createAsyncLookupJoin(temporalTable, config, lookupKeys, (AsyncTableFunction<Object>) userDefinedFunction, planner.getRelBuilder(), inputRowType, tableSourceRowType, resultRowType, isLeftOuterJoin);
    } else {
        operatorFactory = createSyncLookupJoin(temporalTable, config, lookupKeys, (TableFunction<Object>) userDefinedFunction, planner.getRelBuilder(), inputRowType, tableSourceRowType, resultRowType, isLeftOuterJoin, planner.getExecEnv().getConfig().isObjectReuseEnabled());
    }
    Transformation<RowData> inputTransformation = (Transformation<RowData>) inputEdge.translateToPlan(planner);
    return ExecNodeUtil.createOneInputTransformation(inputTransformation, createTransformationMeta(LOOKUP_JOIN_TRANSFORMATION, config), operatorFactory, InternalTypeInfo.of(resultRowType), inputTransformation.getParallelism());
}
Also used : RowData(org.apache.flink.table.data.RowData) Transformation(org.apache.flink.api.dag.Transformation) ExecEdge(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge) UserDefinedFunction(org.apache.flink.table.functions.UserDefinedFunction) RowType(org.apache.flink.table.types.logical.RowType) AsyncTableFunction(org.apache.flink.table.functions.AsyncTableFunction) TableFunction(org.apache.flink.table.functions.TableFunction) RelOptTable(org.apache.calcite.plan.RelOptTable) AsyncTableFunction(org.apache.flink.table.functions.AsyncTableFunction)

Aggregations

AsyncTableFunction (org.apache.flink.table.functions.AsyncTableFunction)2 RelOptTable (org.apache.calcite.plan.RelOptTable)1 Transformation (org.apache.flink.api.dag.Transformation)1 HBaseDynamicTableSource (org.apache.flink.connector.hbase2.source.HBaseDynamicTableSource)1 HBaseRowDataAsyncLookupFunction (org.apache.flink.connector.hbase2.source.HBaseRowDataAsyncLookupFunction)1 ResolvedSchema (org.apache.flink.table.catalog.ResolvedSchema)1 AsyncTableFunctionProvider (org.apache.flink.table.connector.source.AsyncTableFunctionProvider)1 DynamicTableSource (org.apache.flink.table.connector.source.DynamicTableSource)1 LookupTableSource (org.apache.flink.table.connector.source.LookupTableSource)1 RowData (org.apache.flink.table.data.RowData)1 TableFunction (org.apache.flink.table.functions.TableFunction)1 UserDefinedFunction (org.apache.flink.table.functions.UserDefinedFunction)1 ExecEdge (org.apache.flink.table.planner.plan.nodes.exec.ExecEdge)1 LookupRuntimeProviderContext (org.apache.flink.table.runtime.connector.source.LookupRuntimeProviderContext)1 RowType (org.apache.flink.table.types.logical.RowType)1 Test (org.junit.Test)1