Search in sources :

Example 1 with SortCodeGenerator

use of org.apache.flink.table.planner.codegen.sort.SortCodeGenerator in project flink by apache.

the class BatchExecSortMergeJoin method translateToPlanInternal.

@Override
@SuppressWarnings("unchecked")
protected Transformation<RowData> translateToPlanInternal(PlannerBase planner, ExecNodeConfig config) {
    ExecEdge leftInputEdge = getInputEdges().get(0);
    ExecEdge rightInputEdge = getInputEdges().get(1);
    // get input types
    RowType leftType = (RowType) leftInputEdge.getOutputType();
    RowType rightType = (RowType) rightInputEdge.getOutputType();
    LogicalType[] keyFieldTypes = IntStream.of(leftKeys).mapToObj(leftType::getTypeAt).toArray(LogicalType[]::new);
    RowType keyType = RowType.of(keyFieldTypes);
    GeneratedJoinCondition condFunc = JoinUtil.generateConditionFunction(config.getTableConfig(), nonEquiCondition, leftType, rightType);
    long externalBufferMemory = config.get(ExecutionConfigOptions.TABLE_EXEC_RESOURCE_EXTERNAL_BUFFER_MEMORY).getBytes();
    long sortMemory = config.get(ExecutionConfigOptions.TABLE_EXEC_RESOURCE_SORT_MEMORY).getBytes();
    int externalBufferNum = 1;
    if (joinType == FlinkJoinType.FULL) {
        externalBufferNum = 2;
    }
    long managedMemory = externalBufferMemory * externalBufferNum + sortMemory * 2;
    SortCodeGenerator leftSortGen = newSortGen(config, leftKeys, leftType);
    SortCodeGenerator rightSortGen = newSortGen(config, rightKeys, rightType);
    int[] keyPositions = IntStream.range(0, leftKeys.length).toArray();
    SortMergeJoinOperator operator = new SortMergeJoinOperator(1.0 * externalBufferMemory / managedMemory, joinType, leftIsSmaller, condFunc, ProjectionCodeGenerator.generateProjection(new CodeGeneratorContext(config.getTableConfig()), "SMJProjection", leftType, keyType, leftKeys), ProjectionCodeGenerator.generateProjection(new CodeGeneratorContext(config.getTableConfig()), "SMJProjection", rightType, keyType, rightKeys), leftSortGen.generateNormalizedKeyComputer("LeftComputer"), leftSortGen.generateRecordComparator("LeftComparator"), rightSortGen.generateNormalizedKeyComputer("RightComputer"), rightSortGen.generateRecordComparator("RightComparator"), newSortGen(config, keyPositions, keyType).generateRecordComparator("KeyComparator"), filterNulls);
    Transformation<RowData> leftInputTransform = (Transformation<RowData>) leftInputEdge.translateToPlan(planner);
    Transformation<RowData> rightInputTransform = (Transformation<RowData>) rightInputEdge.translateToPlan(planner);
    return ExecNodeUtil.createTwoInputTransformation(leftInputTransform, rightInputTransform, createTransformationName(config), createTransformationDescription(config), SimpleOperatorFactory.of(operator), InternalTypeInfo.of(getOutputType()), rightInputTransform.getParallelism(), managedMemory);
}
Also used : Transformation(org.apache.flink.api.dag.Transformation) ExecEdge(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge) CodeGeneratorContext(org.apache.flink.table.planner.codegen.CodeGeneratorContext) RowType(org.apache.flink.table.types.logical.RowType) LogicalType(org.apache.flink.table.types.logical.LogicalType) GeneratedJoinCondition(org.apache.flink.table.runtime.generated.GeneratedJoinCondition) RowData(org.apache.flink.table.data.RowData) SortMergeJoinOperator(org.apache.flink.table.runtime.operators.join.SortMergeJoinOperator) SortCodeGenerator(org.apache.flink.table.planner.codegen.sort.SortCodeGenerator)

Example 2 with SortCodeGenerator

use of org.apache.flink.table.planner.codegen.sort.SortCodeGenerator in project flink by apache.

the class BatchExecSort method translateToPlanInternal.

@SuppressWarnings("unchecked")
@Override
protected Transformation<RowData> translateToPlanInternal(PlannerBase planner, ExecNodeConfig config) {
    ExecEdge inputEdge = getInputEdges().get(0);
    Transformation<RowData> inputTransform = (Transformation<RowData>) inputEdge.translateToPlan(planner);
    RowType inputType = (RowType) inputEdge.getOutputType();
    SortCodeGenerator codeGen = new SortCodeGenerator(config.getTableConfig(), inputType, sortSpec);
    SortOperator operator = new SortOperator(codeGen.generateNormalizedKeyComputer("BatchExecSortComputer"), codeGen.generateRecordComparator("BatchExecSortComparator"));
    long sortMemory = config.get(ExecutionConfigOptions.TABLE_EXEC_RESOURCE_SORT_MEMORY).getBytes();
    return ExecNodeUtil.createOneInputTransformation(inputTransform, createTransformationName(config), createTransformationDescription(config), SimpleOperatorFactory.of(operator), InternalTypeInfo.of((RowType) getOutputType()), inputTransform.getParallelism(), sortMemory);
}
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) RowType(org.apache.flink.table.types.logical.RowType) SortCodeGenerator(org.apache.flink.table.planner.codegen.sort.SortCodeGenerator) SortOperator(org.apache.flink.table.runtime.operators.sort.SortOperator)

Example 3 with SortCodeGenerator

use of org.apache.flink.table.planner.codegen.sort.SortCodeGenerator in project flink by apache.

the class SortCodeGeneratorTest method getSortBaseWithNulls.

public static Tuple2<NormalizedKeyComputer, RecordComparator> getSortBaseWithNulls(String namePrefix, RowType inputType, SortSpec sortSpec) {
    SortCodeGenerator generator = new SortCodeGenerator(new TableConfig(), inputType, sortSpec);
    GeneratedNormalizedKeyComputer computer = generator.generateNormalizedKeyComputer(namePrefix + "Computer");
    GeneratedRecordComparator comparator = generator.generateRecordComparator(namePrefix + "Comparator");
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    return new Tuple2<>(computer.newInstance(cl), comparator.newInstance(cl));
}
Also used : GeneratedNormalizedKeyComputer(org.apache.flink.table.runtime.generated.GeneratedNormalizedKeyComputer) Tuple2(org.apache.flink.api.java.tuple.Tuple2) TableConfig(org.apache.flink.table.api.TableConfig) SortCodeGenerator(org.apache.flink.table.planner.codegen.sort.SortCodeGenerator) GeneratedRecordComparator(org.apache.flink.table.runtime.generated.GeneratedRecordComparator)

Aggregations

SortCodeGenerator (org.apache.flink.table.planner.codegen.sort.SortCodeGenerator)3 Transformation (org.apache.flink.api.dag.Transformation)2 RowData (org.apache.flink.table.data.RowData)2 ExecEdge (org.apache.flink.table.planner.plan.nodes.exec.ExecEdge)2 RowType (org.apache.flink.table.types.logical.RowType)2 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 TableConfig (org.apache.flink.table.api.TableConfig)1 CodeGeneratorContext (org.apache.flink.table.planner.codegen.CodeGeneratorContext)1 GeneratedJoinCondition (org.apache.flink.table.runtime.generated.GeneratedJoinCondition)1 GeneratedNormalizedKeyComputer (org.apache.flink.table.runtime.generated.GeneratedNormalizedKeyComputer)1 GeneratedRecordComparator (org.apache.flink.table.runtime.generated.GeneratedRecordComparator)1 SortMergeJoinOperator (org.apache.flink.table.runtime.operators.join.SortMergeJoinOperator)1 SortOperator (org.apache.flink.table.runtime.operators.sort.SortOperator)1 LogicalType (org.apache.flink.table.types.logical.LogicalType)1