Search in sources :

Example 11 with SortSpec

use of org.apache.flink.table.planner.plan.nodes.exec.spec.SortSpec in project flink by apache.

the class CodeSplitTest method testRecordComparator.

@Test
public void testRecordComparator() {
    int numFields = 600;
    RowType rowType = getIntRowType(numFields);
    SortSpec.SortSpecBuilder builder = SortSpec.builder();
    for (int i = 0; i < numFields; i++) {
        builder.addField(i, true, true);
    }
    SortSpec sortSpec = builder.build();
    GenericRowData rowData1 = new GenericRowData(numFields);
    GenericRowData rowData2 = new GenericRowData(numFields);
    Random random = new Random();
    for (int i = 0; i < numFields; i++) {
        int x = random.nextInt(100);
        rowData1.setField(i, x);
        rowData2.setField(i, x);
    }
    int result = random.nextInt(3) - 1;
    if (result == -1) {
        rowData1.setField(random.nextInt(numFields), -1);
    } else if (result == 1) {
        rowData1.setField(random.nextInt(numFields), 100);
    }
    Consumer<TableConfig> consumer = tableConfig -> {
        RecordComparator instance = ComparatorCodeGenerator.gen(tableConfig, "", rowType, sortSpec).newInstance(classLoader);
        for (int i = 0; i < 100; i++) {
            Assert.assertEquals(result, instance.compare(rowData1, rowData2));
        }
    };
    runTest(consumer);
}
Also used : Arrays(java.util.Arrays) FlinkMatchers(org.apache.flink.core.testutils.FlinkMatchers) IntType(org.apache.flink.table.types.logical.IntType) Random(java.util.Random) FlinkTypeFactory(org.apache.flink.table.planner.calcite.FlinkTypeFactory) RowType(org.apache.flink.table.types.logical.RowType) ArrayList(java.util.ArrayList) HashFunction(org.apache.flink.table.runtime.generated.HashFunction) TableConfigOptions(org.apache.flink.table.api.config.TableConfigOptions) BinaryRowWriter(org.apache.flink.table.data.writer.BinaryRowWriter) GenericRowData(org.apache.flink.table.data.GenericRowData) RexNode(org.apache.calcite.rex.RexNode) OutputStream(java.io.OutputStream) PrintStream(java.io.PrintStream) RelDataType(org.apache.calcite.rel.type.RelDataType) TableConfig(org.apache.flink.table.api.TableConfig) RecordComparator(org.apache.flink.table.runtime.generated.RecordComparator) RexBuilder(org.apache.calcite.rex.RexBuilder) Test(org.junit.Test) IOException(java.io.IOException) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) ComparatorCodeGenerator(org.apache.flink.table.planner.codegen.sort.ComparatorCodeGenerator) RexInputRef(org.apache.calcite.rex.RexInputRef) Consumer(java.util.function.Consumer) JoinUtil(org.apache.flink.table.planner.plan.utils.JoinUtil) JoinCondition(org.apache.flink.table.runtime.generated.JoinCondition) List(java.util.List) MatcherAssert(org.hamcrest.MatcherAssert) LogicalType(org.apache.flink.table.types.logical.LogicalType) SqlStdOperatorTable(org.apache.calcite.sql.fun.SqlStdOperatorTable) Assert(org.junit.Assert) Collections(java.util.Collections) SortSpec(org.apache.flink.table.planner.plan.nodes.exec.spec.SortSpec) Projection(org.apache.flink.table.runtime.generated.Projection) Random(java.util.Random) RowType(org.apache.flink.table.types.logical.RowType) GenericRowData(org.apache.flink.table.data.GenericRowData) TableConfig(org.apache.flink.table.api.TableConfig) SortSpec(org.apache.flink.table.planner.plan.nodes.exec.spec.SortSpec) RecordComparator(org.apache.flink.table.runtime.generated.RecordComparator) Test(org.junit.Test)

Aggregations

SortSpec (org.apache.flink.table.planner.plan.nodes.exec.spec.SortSpec)11 RowData (org.apache.flink.table.data.RowData)6 GeneratedRecordComparator (org.apache.flink.table.runtime.generated.GeneratedRecordComparator)5 LogicalType (org.apache.flink.table.types.logical.LogicalType)5 RowType (org.apache.flink.table.types.logical.RowType)5 Transformation (org.apache.flink.api.dag.Transformation)4 TableException (org.apache.flink.table.api.TableException)4 ExecEdge (org.apache.flink.table.planner.plan.nodes.exec.ExecEdge)4 Random (java.util.Random)3 OneInputTransformation (org.apache.flink.streaming.api.transformations.OneInputTransformation)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)2 BinaryRowData (org.apache.flink.table.data.binary.BinaryRowData)2 CodeGeneratorContext (org.apache.flink.table.planner.codegen.CodeGeneratorContext)2 EmptyRowDataKeySelector (org.apache.flink.table.runtime.keyselector.EmptyRowDataKeySelector)2 RowDataKeySelector (org.apache.flink.table.runtime.keyselector.RowDataKeySelector)2 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1