Search in sources :

Example 1 with Projection

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

the class CodeSplitTest method testProjection.

@SuppressWarnings("unchecked")
@Test
public void testProjection() {
    int numFields = 1000;
    RowType rowType = getIntRowType(numFields);
    List<Integer> order = new ArrayList<>();
    for (int i = 0; i < numFields; i++) {
        order.add(i);
    }
    Collections.shuffle(order);
    GenericRowData input = new GenericRowData(numFields);
    for (int i = 0; i < numFields; i++) {
        input.setField(i, i);
    }
    BinaryRowData output = new BinaryRowData(numFields);
    BinaryRowWriter outputWriter = new BinaryRowWriter(output);
    for (int i = 0; i < numFields; i++) {
        outputWriter.writeInt(i, order.get(i));
    }
    outputWriter.complete();
    Consumer<TableConfig> consumer = tableConfig -> {
        Projection instance = ProjectionCodeGenerator.generateProjection(new CodeGeneratorContext(tableConfig), "", rowType, rowType, order.stream().mapToInt(i -> i).toArray()).newInstance(classLoader);
        for (int i = 0; i < 100; i++) {
            Assert.assertEquals(output, instance.apply(input));
        }
    };
    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) ArrayList(java.util.ArrayList) RowType(org.apache.flink.table.types.logical.RowType) Projection(org.apache.flink.table.runtime.generated.Projection) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) BinaryRowWriter(org.apache.flink.table.data.writer.BinaryRowWriter) GenericRowData(org.apache.flink.table.data.GenericRowData) TableConfig(org.apache.flink.table.api.TableConfig) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Random (java.util.Random)1 Consumer (java.util.function.Consumer)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 RexBuilder (org.apache.calcite.rex.RexBuilder)1 RexInputRef (org.apache.calcite.rex.RexInputRef)1 RexNode (org.apache.calcite.rex.RexNode)1 SqlStdOperatorTable (org.apache.calcite.sql.fun.SqlStdOperatorTable)1 FlinkMatchers (org.apache.flink.core.testutils.FlinkMatchers)1 TableConfig (org.apache.flink.table.api.TableConfig)1 TableConfigOptions (org.apache.flink.table.api.config.TableConfigOptions)1 GenericRowData (org.apache.flink.table.data.GenericRowData)1 BinaryRowData (org.apache.flink.table.data.binary.BinaryRowData)1 BinaryRowWriter (org.apache.flink.table.data.writer.BinaryRowWriter)1