Search in sources :

Example 6 with GeneratedJoinCondition

use of org.apache.flink.table.runtime.generated.GeneratedJoinCondition in project flink by apache.

the class StreamExecJoin method translateToPlanInternal.

@Override
@SuppressWarnings("unchecked")
protected Transformation<RowData> translateToPlanInternal(PlannerBase planner, ExecNodeConfig config) {
    final ExecEdge leftInputEdge = getInputEdges().get(0);
    final ExecEdge rightInputEdge = getInputEdges().get(1);
    final Transformation<RowData> leftTransform = (Transformation<RowData>) leftInputEdge.translateToPlan(planner);
    final Transformation<RowData> rightTransform = (Transformation<RowData>) rightInputEdge.translateToPlan(planner);
    final RowType leftType = (RowType) leftInputEdge.getOutputType();
    final RowType rightType = (RowType) rightInputEdge.getOutputType();
    JoinUtil.validateJoinSpec(joinSpec, leftType, rightType, true);
    final int[] leftJoinKey = joinSpec.getLeftKeys();
    final int[] rightJoinKey = joinSpec.getRightKeys();
    final InternalTypeInfo<RowData> leftTypeInfo = InternalTypeInfo.of(leftType);
    final JoinInputSideSpec leftInputSpec = JoinUtil.analyzeJoinInput(leftTypeInfo, leftJoinKey, leftUniqueKeys);
    final InternalTypeInfo<RowData> rightTypeInfo = InternalTypeInfo.of(rightType);
    final JoinInputSideSpec rightInputSpec = JoinUtil.analyzeJoinInput(rightTypeInfo, rightJoinKey, rightUniqueKeys);
    GeneratedJoinCondition generatedCondition = JoinUtil.generateConditionFunction(config.getTableConfig(), joinSpec, leftType, rightType);
    long minRetentionTime = config.getStateRetentionTime();
    AbstractStreamingJoinOperator operator;
    FlinkJoinType joinType = joinSpec.getJoinType();
    if (joinType == FlinkJoinType.ANTI || joinType == FlinkJoinType.SEMI) {
        operator = new StreamingSemiAntiJoinOperator(joinType == FlinkJoinType.ANTI, leftTypeInfo, rightTypeInfo, generatedCondition, leftInputSpec, rightInputSpec, joinSpec.getFilterNulls(), minRetentionTime);
    } else {
        boolean leftIsOuter = joinType == FlinkJoinType.LEFT || joinType == FlinkJoinType.FULL;
        boolean rightIsOuter = joinType == FlinkJoinType.RIGHT || joinType == FlinkJoinType.FULL;
        operator = new StreamingJoinOperator(leftTypeInfo, rightTypeInfo, generatedCondition, leftInputSpec, rightInputSpec, leftIsOuter, rightIsOuter, joinSpec.getFilterNulls(), minRetentionTime);
    }
    final RowType returnType = (RowType) getOutputType();
    final TwoInputTransformation<RowData, RowData, RowData> transform = ExecNodeUtil.createTwoInputTransformation(leftTransform, rightTransform, createTransformationMeta(JOIN_TRANSFORMATION, config), operator, InternalTypeInfo.of(returnType), leftTransform.getParallelism());
    // set KeyType and Selector for state
    RowDataKeySelector leftSelect = KeySelectorUtil.getRowDataSelector(leftJoinKey, leftTypeInfo);
    RowDataKeySelector rightSelect = KeySelectorUtil.getRowDataSelector(rightJoinKey, rightTypeInfo);
    transform.setStateKeySelectors(leftSelect, rightSelect);
    transform.setStateKeyType(leftSelect.getProducedType());
    return transform;
}
Also used : TwoInputTransformation(org.apache.flink.streaming.api.transformations.TwoInputTransformation) Transformation(org.apache.flink.api.dag.Transformation) ExecEdge(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge) RowType(org.apache.flink.table.types.logical.RowType) FlinkJoinType(org.apache.flink.table.runtime.operators.join.FlinkJoinType) JoinInputSideSpec(org.apache.flink.table.runtime.operators.join.stream.state.JoinInputSideSpec) RowData(org.apache.flink.table.data.RowData) GeneratedJoinCondition(org.apache.flink.table.runtime.generated.GeneratedJoinCondition) AbstractStreamingJoinOperator(org.apache.flink.table.runtime.operators.join.stream.AbstractStreamingJoinOperator) StreamingJoinOperator(org.apache.flink.table.runtime.operators.join.stream.StreamingJoinOperator) RowDataKeySelector(org.apache.flink.table.runtime.keyselector.RowDataKeySelector) AbstractStreamingJoinOperator(org.apache.flink.table.runtime.operators.join.stream.AbstractStreamingJoinOperator) StreamingSemiAntiJoinOperator(org.apache.flink.table.runtime.operators.join.stream.StreamingSemiAntiJoinOperator)

Example 7 with GeneratedJoinCondition

use of org.apache.flink.table.runtime.generated.GeneratedJoinCondition in project flink by apache.

the class StreamExecTemporalJoin method getJoinOperator.

private TwoInputStreamOperator<RowData, RowData, RowData> getJoinOperator(ExecNodeConfig config, RowType leftInputType, RowType rightInputType) {
    // input must not be nullable, because the runtime join function will make sure
    // the code-generated function won't process null inputs
    final CodeGeneratorContext ctx = new CodeGeneratorContext(config.getTableConfig());
    final ExprCodeGenerator exprGenerator = new ExprCodeGenerator(ctx, false).bindInput(leftInputType, CodeGenUtils.DEFAULT_INPUT1_TERM(), JavaScalaConversionUtil.toScala(Optional.empty())).bindSecondInput(rightInputType, CodeGenUtils.DEFAULT_INPUT2_TERM(), JavaScalaConversionUtil.toScala(Optional.empty()));
    String body = "return true;";
    if (joinSpec.getNonEquiCondition().isPresent()) {
        final GeneratedExpression condition = exprGenerator.generateExpression(joinSpec.getNonEquiCondition().get());
        body = String.format("%s\nreturn %s;", condition.code(), condition.resultTerm());
    }
    GeneratedJoinCondition generatedJoinCondition = FunctionCodeGenerator.generateJoinCondition(ctx, "ConditionFunction", body, CodeGenUtils.DEFAULT_INPUT1_TERM(), CodeGenUtils.DEFAULT_INPUT2_TERM());
    return createJoinOperator(config, leftInputType, rightInputType, generatedJoinCondition);
}
Also used : GeneratedJoinCondition(org.apache.flink.table.runtime.generated.GeneratedJoinCondition) CodeGeneratorContext(org.apache.flink.table.planner.codegen.CodeGeneratorContext) GeneratedExpression(org.apache.flink.table.planner.codegen.GeneratedExpression) ExprCodeGenerator(org.apache.flink.table.planner.codegen.ExprCodeGenerator)

Example 8 with GeneratedJoinCondition

use of org.apache.flink.table.runtime.generated.GeneratedJoinCondition in project flink by apache.

the class LongHashJoinGeneratorTest method newOperator.

@Override
public Object newOperator(long memorySize, HashJoinType type, boolean reverseJoinFunction) {
    RowType keyType = RowType.of(new IntType());
    Assert.assertTrue(LongHashJoinGenerator.support(type, keyType, new boolean[] { true }));
    return LongHashJoinGenerator.gen(new TableConfig(), type, keyType, RowType.of(new IntType(), new IntType()), RowType.of(new IntType(), new IntType()), new int[] { 0 }, new int[] { 0 }, 20, 10000, reverseJoinFunction, new GeneratedJoinCondition(MyJoinCondition.class.getCanonicalName(), "", new Object[0]));
}
Also used : GeneratedJoinCondition(org.apache.flink.table.runtime.generated.GeneratedJoinCondition) RowType(org.apache.flink.table.types.logical.RowType) TableConfig(org.apache.flink.table.api.TableConfig) IntType(org.apache.flink.table.types.logical.IntType)

Aggregations

GeneratedJoinCondition (org.apache.flink.table.runtime.generated.GeneratedJoinCondition)8 RowData (org.apache.flink.table.data.RowData)6 RowType (org.apache.flink.table.types.logical.RowType)6 Transformation (org.apache.flink.api.dag.Transformation)5 ExecEdge (org.apache.flink.table.planner.plan.nodes.exec.ExecEdge)5 RowDataKeySelector (org.apache.flink.table.runtime.keyselector.RowDataKeySelector)4 TwoInputTransformation (org.apache.flink.streaming.api.transformations.TwoInputTransformation)3 CodeGeneratorContext (org.apache.flink.table.planner.codegen.CodeGeneratorContext)3 FlinkJoinType (org.apache.flink.table.runtime.operators.join.FlinkJoinType)2 LogicalType (org.apache.flink.table.types.logical.LogicalType)2 ZoneId (java.time.ZoneId)1 OneInputTransformation (org.apache.flink.streaming.api.transformations.OneInputTransformation)1 UnionTransformation (org.apache.flink.streaming.api.transformations.UnionTransformation)1 KeyedTwoInputStreamOperatorTestHarness (org.apache.flink.streaming.util.KeyedTwoInputStreamOperatorTestHarness)1 TableConfig (org.apache.flink.table.api.TableConfig)1 TableException (org.apache.flink.table.api.TableException)1 ExprCodeGenerator (org.apache.flink.table.planner.codegen.ExprCodeGenerator)1 GeneratedExpression (org.apache.flink.table.planner.codegen.GeneratedExpression)1 SortCodeGenerator (org.apache.flink.table.planner.codegen.sort.SortCodeGenerator)1 WindowAttachedWindowingStrategy (org.apache.flink.table.planner.plan.logical.WindowAttachedWindowingStrategy)1