Search in sources :

Example 1 with HashFunction

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

the class CodeSplitTest method testHashFunction.

@Test
public void testHashFunction() {
    int numFields = 1000;
    RowType rowType = getIntRowType(numFields);
    int[] hashFields = new int[numFields];
    for (int i = 0; i < numFields; i++) {
        hashFields[i] = i;
    }
    GenericRowData rowData = new GenericRowData(numFields);
    for (int i = 0; i < numFields; i++) {
        rowData.setField(i, i);
    }
    Consumer<TableConfig> consumer = tableConfig -> {
        HashFunction instance = HashCodeGenerator.generateRowHash(new CodeGeneratorContext(tableConfig), rowType, "", hashFields).newInstance(classLoader);
        for (int i = 0; i < 100; i++) {
            Assert.assertEquals(-1433414860, instance.hashCode(rowData));
        }
    };
    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) HashFunction(org.apache.flink.table.runtime.generated.HashFunction) RowType(org.apache.flink.table.types.logical.RowType) 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