use of org.apache.flink.table.types.logical.BigIntType in project flink by apache.
the class WindowOperatorTest method testSlidingCountWindow.
@Test
public void testSlidingCountWindow() throws Exception {
if (!UTC_ZONE_ID.equals(shiftTimeZone)) {
return;
}
closeCalled.set(0);
final int windowSize = 5;
final int windowSlide = 3;
LogicalType[] windowTypes = new LogicalType[] { new BigIntType() };
WindowOperator operator = WindowOperatorBuilder.builder().withInputFields(inputFieldTypes).withShiftTimezone(shiftTimeZone).countWindow(windowSize, windowSlide).aggregateAndBuild(getCountWindowAggFunction(), equaliser, accTypes, aggResultTypes, windowTypes);
OneInputStreamOperatorTestHarness<RowData, RowData> testHarness = createTestHarness(operator);
ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>();
testHarness.open();
testHarness.processElement(insertRecord("key2", 1, 0L));
testHarness.processElement(insertRecord("key2", 2, 1000L));
testHarness.processElement(insertRecord("key2", 3, 2500L));
testHarness.processElement(insertRecord("key2", 4, 2500L));
testHarness.processElement(insertRecord("key2", 5, 2500L));
testHarness.processElement(insertRecord("key1", 1, 10L));
testHarness.processElement(insertRecord("key1", 2, 1000L));
testHarness.processWatermark(new Watermark(12000));
testHarness.setProcessingTime(12000L);
expectedOutput.addAll(doubleRecord(isTableAggregate, insertRecord("key2", 15L, 5L, 0L)));
expectedOutput.add(new Watermark(12000));
assertor.assertOutputEqualsSorted("Output was not correct.", expectedOutput, testHarness.getOutput());
// do a snapshot, close and restore again
OperatorSubtaskState snapshotV2 = testHarness.snapshot(0L, 0);
testHarness.close();
expectedOutput.clear();
testHarness = createTestHarness(operator);
testHarness.setup();
testHarness.initializeState(snapshotV2);
testHarness.open();
testHarness.processElement(insertRecord("key1", 3, 2500L));
testHarness.processElement(insertRecord("key1", 4, 2500L));
testHarness.processElement(insertRecord("key1", 5, 2500L));
expectedOutput.addAll(doubleRecord(isTableAggregate, insertRecord("key1", 15L, 5L, 0L)));
assertor.assertOutputEqualsSorted("Output was not correct.", expectedOutput, testHarness.getOutput());
testHarness.processElement(insertRecord("key2", 6, 6000L));
testHarness.processElement(insertRecord("key2", 7, 6000L));
testHarness.processElement(insertRecord("key2", 8, 6050L));
testHarness.processElement(insertRecord("key2", 9, 6050L));
expectedOutput.addAll(doubleRecord(isTableAggregate, insertRecord("key2", 30L, 5L, 1L)));
assertor.assertOutputEqualsSorted("Output was not correct.", expectedOutput, testHarness.getOutput());
testHarness.processElement(insertRecord("key1", 6, 4000L));
testHarness.processElement(insertRecord("key1", 7, 4000L));
testHarness.processElement(insertRecord("key1", 8, 4000L));
testHarness.processElement(insertRecord("key2", 10, 15000L));
testHarness.processElement(insertRecord("key2", 11, 15000L));
expectedOutput.addAll(doubleRecord(isTableAggregate, insertRecord("key1", 30L, 5L, 1L)));
expectedOutput.addAll(doubleRecord(isTableAggregate, insertRecord("key2", 45L, 5L, 2L)));
assertor.assertOutputEqualsSorted("Output was not correct.", expectedOutput, testHarness.getOutput());
testHarness.close();
// we close once in the rest...
assertEquals("Close was not called.", 2, closeCalled.get());
}
use of org.apache.flink.table.types.logical.BigIntType in project flink by apache.
the class RowTimeSortOperatorTest method testOnlySortOnRowTime.
@Test
public void testOnlySortOnRowTime() throws Exception {
InternalTypeInfo<RowData> inputRowType = InternalTypeInfo.ofFields(new BigIntType(), new BigIntType(), VarCharType.STRING_TYPE, new IntType());
int rowTimeIdx = 0;
RowDataHarnessAssertor assertor = new RowDataHarnessAssertor(inputRowType.toRowFieldTypes());
RowTimeSortOperator operator = createSortOperator(inputRowType, rowTimeIdx, null);
OneInputStreamOperatorTestHarness<RowData, RowData> testHarness = createTestHarness(operator);
testHarness.open();
testHarness.processElement(insertRecord(3L, 2L, "Hello world", 3));
testHarness.processElement(insertRecord(2L, 2L, "Hello", 2));
testHarness.processElement(insertRecord(6L, 3L, "Luke Skywalker", 6));
testHarness.processElement(insertRecord(5L, 3L, "I am fine.", 5));
testHarness.processElement(insertRecord(7L, 4L, "Comment#1", 7));
testHarness.processElement(insertRecord(9L, 4L, "Comment#3", 9));
testHarness.processElement(insertRecord(10L, 4L, "Comment#4", 10));
testHarness.processElement(insertRecord(8L, 4L, "Comment#2", 8));
testHarness.processElement(insertRecord(1L, 1L, "Hi", 2));
testHarness.processElement(insertRecord(1L, 1L, "Hi", 1));
testHarness.processElement(insertRecord(4L, 3L, "Helloworld, how are you?", 4));
testHarness.processWatermark(new Watermark(9L));
List<Object> expectedOutput = new ArrayList<>();
expectedOutput.add(insertRecord(1L, 1L, "Hi", 2));
expectedOutput.add(insertRecord(1L, 1L, "Hi", 1));
expectedOutput.add(insertRecord(2L, 2L, "Hello", 2));
expectedOutput.add(insertRecord(3L, 2L, "Hello world", 3));
expectedOutput.add(insertRecord(4L, 3L, "Helloworld, how are you?", 4));
expectedOutput.add(insertRecord(5L, 3L, "I am fine.", 5));
expectedOutput.add(insertRecord(6L, 3L, "Luke Skywalker", 6));
expectedOutput.add(insertRecord(7L, 4L, "Comment#1", 7));
expectedOutput.add(insertRecord(8L, 4L, "Comment#2", 8));
expectedOutput.add(insertRecord(9L, 4L, "Comment#3", 9));
expectedOutput.add(new Watermark(9L));
// do a snapshot, data could be recovered from state
OperatorSubtaskState snapshot = testHarness.snapshot(0L, 0);
assertor.assertOutputEquals("output wrong.", expectedOutput, testHarness.getOutput());
testHarness.close();
expectedOutput.clear();
operator = createSortOperator(inputRowType, rowTimeIdx, null);
testHarness = createTestHarness(operator);
testHarness.initializeState(snapshot);
testHarness.open();
// late data will be dropped
testHarness.processElement(insertRecord(5L, 3L, "I am fine.", 6));
testHarness.processWatermark(new Watermark(10L));
expectedOutput.add(insertRecord(10L, 4L, "Comment#4", 10));
expectedOutput.add(new Watermark(10L));
assertor.assertOutputEquals("output wrong.", expectedOutput, testHarness.getOutput());
// those watermark has no effect
testHarness.processWatermark(new Watermark(11L));
testHarness.processWatermark(new Watermark(12L));
expectedOutput.add(new Watermark(11L));
expectedOutput.add(new Watermark(12L));
assertor.assertOutputEquals("output wrong.", expectedOutput, testHarness.getOutput());
}
Aggregations