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);
}
Aggregations