github-advanced-security[bot] commented on code in PR #20655:
URL: https://github.com/apache/druid/pull/20655#discussion_r4332077400
##########
processing/src/test/java/org/apache/druid/query/scan/ScanQueryRunnerFactoryTest.java:
##########
@@ -373,5 +381,223 @@
ex.getMessage()
);
}
+
+ @Test
+ public void testPriorityQueueDescendingSkipsOlderIntervals()
+ {
+ final RecordingRunner hour0 = new RecordingRunner(HOUR_0, 10, 20, 30);
+ final RecordingRunner hour1 = new RecordingRunner(HOUR_1, 10, 20, 30);
+ final RecordingRunner hour2Partition0 = new RecordingRunner(HOUR_2, 10,
20, 30);
+ final RecordingRunner hour2Partition1 = new RecordingRunner(HOUR_2, 15,
25, 35);
+
+ Assertions.assertEquals(
+ List.of(minute(HOUR_2, 35), minute(HOUR_2, 30), minute(HOUR_2, 25)),
+ runMerged(
+ Order.DESCENDING,
+ 3,
+ List.of(HOUR_0, HOUR_1, HOUR_2, HOUR_2),
+ List.of(hour0, hour1, hour2Partition0, hour2Partition1)
+ )
+ );
+ Assertions.assertEquals(
+ List.of(false, false, true, true),
+ ranFlags(hour0, hour1, hour2Partition0, hour2Partition1)
+ );
+ }
+
+ @Test
+ public void testPriorityQueueDescendingRunsIntervalsUntilLimitReached()
+ {
+ final RecordingRunner hour0 = new RecordingRunner(HOUR_0, 10, 20, 30);
+ final RecordingRunner hour1 = new RecordingRunner(HOUR_1, 10, 20, 30);
+ final RecordingRunner hour2 = new RecordingRunner(HOUR_2, 10, 20);
+
+ Assertions.assertEquals(
+ List.of(minute(HOUR_2, 20), minute(HOUR_2, 10), minute(HOUR_1, 30),
minute(HOUR_1, 20)),
+ runMerged(Order.DESCENDING, 4, List.of(HOUR_0, HOUR_1, HOUR_2),
List.of(hour0, hour1, hour2))
+ );
+ Assertions.assertEquals(List.of(false, true, true), ranFlags(hour0,
hour1, hour2));
+ }
+
+ @Test
+ public void testPriorityQueueAscendingSkipsLaterIntervals()
+ {
+ final RecordingRunner hour0Partition0 = new RecordingRunner(HOUR_0, 10,
20, 30);
+ final RecordingRunner hour0Partition1 = new RecordingRunner(HOUR_0, 15,
25, 35);
+ final RecordingRunner hour1 = new RecordingRunner(HOUR_1, 10, 20, 30);
+ final RecordingRunner hour2 = new RecordingRunner(HOUR_2, 10, 20, 30);
+
+ Assertions.assertEquals(
+ List.of(minute(HOUR_0, 10), minute(HOUR_0, 15), minute(HOUR_0, 20)),
+ runMerged(
+ Order.ASCENDING,
+ 3,
+ List.of(HOUR_0, HOUR_0, HOUR_1, HOUR_2),
+ List.of(hour0Partition0, hour0Partition1, hour1, hour2)
+ )
+ );
+ Assertions.assertEquals(
+ List.of(true, true, false, false),
+ ranFlags(hour0Partition0, hour0Partition1, hour1, hour2)
+ );
+ }
+
+ @Test
+ public void testRunnersThatDoNotMatchDescriptors()
+ {
+ // One fewer runner than descriptors, so runners cannot be matched to
intervals.
+ final List<QueryRunner<ScanResultValue>> runners = List.of(
+ new RecordingRunner(HOUR_0, 10, 20, 30),
+ new RecordingRunner(HOUR_2, 10, 20, 30)
+ );
+ final List<Interval> descriptorIntervals = List.of(HOUR_0, HOUR_1,
HOUR_2);
+
+ // Priority queue strategy.
+ Assertions.assertThrows(
+ DruidException.class,
+ () -> runMerged(Order.DESCENDING, 2, descriptorIntervals, runners)
+ );
+
+ // N-way merge strategy.
+ Assertions.assertThrows(
+ DruidException.class,
+ () -> runMerged(Order.DESCENDING,
CONFIG.getMaxRowsQueuedForOrdering() + 1, descriptorIntervals, runners)
+ );
+ }
+
+ @Test
+ public void
testPriorityQueueDescendingSinkQueryRunnersSkipsOlderIntervals()
+ {
+ final RecordingRunner hour0Hydrant0 = new RecordingRunner(HOUR_0, 10,
20);
+ final RecordingRunner hour0Hydrant1 = new RecordingRunner(HOUR_0, 30);
+ final RecordingRunner hour1Hydrant0 = new RecordingRunner(HOUR_1, 10,
30);
+ final RecordingRunner hour1Hydrant1 = new RecordingRunner(HOUR_1, 20);
+
+ Assertions.assertEquals(
+ List.of(minute(HOUR_1, 30), minute(HOUR_1, 20)),
+ runMerged(
+ Order.DESCENDING,
+ 2,
+ List.of(HOUR_0, HOUR_1),
+ new SinkQueryRunners<>(
+ List.of(
+ Pair.of(HOUR_0, hour0Hydrant0),
+ Pair.of(HOUR_0, hour0Hydrant1),
+ Pair.of(HOUR_1, hour1Hydrant0),
+ Pair.of(HOUR_1, hour1Hydrant1)
+ )
+ )
+ )
+ );
+ Assertions.assertEquals(
+ List.of(false, false, true, true),
+ ranFlags(hour0Hydrant0, hour0Hydrant1, hour1Hydrant0, hour1Hydrant1)
+ );
+ }
+
+ @Test
+ public void testNWayMergeDescendingSinkQueryRunners()
+ {
+ Assertions.assertEquals(
+ List.of(
+ minute(HOUR_1, 30),
+ minute(HOUR_1, 20),
+ minute(HOUR_1, 10),
+ minute(HOUR_0, 30),
+ minute(HOUR_0, 20),
+ minute(HOUR_0, 10)
+ ),
+ runMerged(
+ Order.DESCENDING,
+ CONFIG.getMaxRowsQueuedForOrdering() + 1,
+ List.of(HOUR_0, HOUR_1),
+ new SinkQueryRunners<>(
+ List.of(
+ Pair.of(HOUR_0, new RecordingRunner(HOUR_0, 10, 20)),
+ Pair.of(HOUR_0, new RecordingRunner(HOUR_0, 30)),
+ Pair.of(HOUR_1, new RecordingRunner(HOUR_1, 10, 30)),
+ Pair.of(HOUR_1, new RecordingRunner(HOUR_1, 20))
+ )
+ )
+ )
+ );
+ }
+
+ private static List<Long> runMerged(
+ final Order order,
+ final long limit,
+ final List<Interval> descriptorIntervals,
+ final Iterable<QueryRunner<ScanResultValue>> runners
+ )
+ {
+ final ScanQuery query =
+ Druids.newScanQueryBuilder()
+ .dataSource("foo")
+ .intervals(
+ new MultipleSpecificSegmentSpec(
+ IntStream.range(0, descriptorIntervals.size())
+ .mapToObj(i -> new
SegmentDescriptor(descriptorIntervals.get(i), "v0", i))
+ .collect(Collectors.toList())
+ )
+ )
+ .resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_LIST)
+ .order(order)
+ .limit(limit)
+ .build();
+
+ return FACTORY.mergeRunners(Execs.directExecutor(), runners)
Review Comment:
## CodeQL / Deprecated method or constructor invocation
Invoking [QueryRunnerFactory.mergeRunners](1) should be avoided because it
has been deprecated.
[Show more
details](https://github.com/apache/druid/security/code-scanning/12112)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]