You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "cecemei (via GitHub)" <gi...@apache.org> on 2025/09/16 21:38:45 UTC
[PR] Remove ordering direction requirement on projection match (druid)
cecemei opened a new pull request, #18539:
URL: https://github.com/apache/druid/pull/18539
### Description
Remove ordering direction requirement on projection match. Also updated `CursorFactoryProjectionTest`:
- use `groupingEngine.mergeRunners` to enable result sorting, since segment sorting push down is not enabled in `groupingEngine.process`.
- update all ArrayResultSet to use List<Object[]> instead.
- prefer `Map.of` over `ImmutableMap.of`.
<hr>
<!-- Check the items by putting "x" in the brackets for the done things. Not all of these items apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items from the checklist below are strictly necessary, but it would be very helpful if you at least self-review the PR. -->
This PR has:
- [ ] been self-reviewed.
- [ ] using the [concurrency checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md) (Remove this item if the PR doesn't have any relation to concurrency.)
- [ ] added documentation for new or modified features or behaviors.
- [ ] a release note entry in the PR description.
- [ ] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
- [ ] added or updated version, license, or notice information in [licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
- [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
- [ ] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for [code coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met.
- [ ] added integration tests.
- [ ] been tested in a test Druid cluster.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Update ordering direction requirement on projection match (druid)
Posted by "cecemei (via GitHub)" <gi...@apache.org>.
cecemei merged PR #18539:
URL: https://github.com/apache/druid/pull/18539
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Remove ordering direction requirement on projection match (druid)
Posted by "clintropolis (via GitHub)" <gi...@apache.org>.
clintropolis commented on code in PR #18539:
URL: https://github.com/apache/druid/pull/18539#discussion_r2361223998
##########
processing/src/test/java/org/apache/druid/segment/CursorFactoryProjectionTest.java:
##########
@@ -1898,75 +1909,40 @@ private void testGroupBy(
List<Object[]> expectedResults
)
{
- final Sequence<ResultRow> resultRows = groupingEngine.process(
+ resourcesReservationPool.reserve(
+ new QueryResourceId(RESOURCE_ID),
query,
- cursorFactory,
- timeBoundaryInspector,
- nonBlockingPool,
- queryMetrics
- );
-
- queryMetrics.assertProjection();
-
- final List<ResultRow> results = resultRows.toList();
- assertGroupByResults(expectedResults, results);
-
- final Sequence<ResultRow> resultRowsNoProjection = groupingEngine.process(
- query.withOverriddenContext(Map.of(QueryContexts.NO_PROJECTIONS, true)),
- cursorFactory,
- timeBoundaryInspector,
- nonBlockingPool,
- null
+ true,
+ new GroupByStatsProvider.PerQueryStats()
);
-
- final List<ResultRow> resultsNoProjection = resultRowsNoProjection.toList();
- assertGroupByResults(expectedResults, resultsNoProjection);
- }
-
- private void testGroupBy(GroupByQuery query, ExpectedProjectionGroupBy queryMetrics, Set<Object[]> expectedResults)
- {
- testGroupBy(projectionsCursorFactory, projectionsTimeBoundaryInspector, query, queryMetrics, expectedResults);
- }
-
- private void testGroupBy(
- CursorFactory cursorFactory,
- TimeBoundaryInspector timeBoundaryInspector,
- GroupByQuery query,
- ExpectedProjectionGroupBy queryMetrics,
- Set<Object[]> expectedResults
- )
- {
- final Sequence<ResultRow> resultRows = groupingEngine.process(
+ QueryRunner<ResultRow> runner = (unused1, unused2) -> groupingEngine.process(
query,
cursorFactory,
timeBoundaryInspector,
nonBlockingPool,
queryMetrics
);
+ final List<ResultRow> results = groupingEngine
+ .mergeRunners(DirectQueryProcessingPool.INSTANCE, List.of(runner))
+ .run(QueryPlus.wrap(query))
+ .toList();
queryMetrics.assertProjection();
+ assertGroupByResults(expectedResults, results);
- final Object[] results = resultRows.toList().stream().map(ResultRow::getArray).map(Arrays::toString).toArray();
- Arrays.sort(results);
-
- final Object[] expectedResultsArray = expectedResults.stream().map(Arrays::toString).toArray();
- Arrays.sort(expectedResultsArray);
- // print a full diff of all differing elements.
- Assertions.assertEquals(Arrays.toString(expectedResultsArray), Arrays.toString(results));
-
- final Sequence<ResultRow> resultRowsNoProjection = groupingEngine.process(
- query.withOverriddenContext(Map.of(QueryContexts.NO_PROJECTIONS, true)),
- cursorFactory,
- timeBoundaryInspector,
- nonBlockingPool,
- null
- );
-
- final Object[] resultsNoProjection = resultRowsNoProjection.toList().stream().map(ResultRow::getArray).map(Arrays::toString).toArray();
- Arrays.sort(resultsNoProjection);
- // print a full diff of all differing elements.
- Assertions.assertEquals(Arrays.toString(expectedResultsArray), Arrays.toString(resultsNoProjection));
-
+ runner = (unused1, unused2) ->
+ groupingEngine.process(
+ query.withOverriddenContext(Map.of(QueryContexts.NO_PROJECTIONS, true)),
+ cursorFactory,
+ timeBoundaryInspector,
+ nonBlockingPool,
+ null
+ );
+ final List<ResultRow> resultsNoProjection = groupingEngine
+ .mergeRunners(DirectQueryProcessingPool.INSTANCE, List.of(runner))
Review Comment:
it doesn't seem that important that these tests use `mergeRunners` since they are focused on testing cursors of the per segment processing, but i guess it isn't that harmful either...
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Remove ordering direction requirement on projection match (druid)
Posted by "cecemei (via GitHub)" <gi...@apache.org>.
cecemei commented on code in PR #18539:
URL: https://github.com/apache/druid/pull/18539#discussion_r2361421186
##########
processing/src/test/java/org/apache/druid/segment/CursorFactoryProjectionTest.java:
##########
@@ -1898,75 +1909,40 @@ private void testGroupBy(
List<Object[]> expectedResults
)
{
- final Sequence<ResultRow> resultRows = groupingEngine.process(
+ resourcesReservationPool.reserve(
+ new QueryResourceId(RESOURCE_ID),
query,
- cursorFactory,
- timeBoundaryInspector,
- nonBlockingPool,
- queryMetrics
- );
-
- queryMetrics.assertProjection();
-
- final List<ResultRow> results = resultRows.toList();
- assertGroupByResults(expectedResults, results);
-
- final Sequence<ResultRow> resultRowsNoProjection = groupingEngine.process(
- query.withOverriddenContext(Map.of(QueryContexts.NO_PROJECTIONS, true)),
- cursorFactory,
- timeBoundaryInspector,
- nonBlockingPool,
- null
+ true,
+ new GroupByStatsProvider.PerQueryStats()
);
-
- final List<ResultRow> resultsNoProjection = resultRowsNoProjection.toList();
- assertGroupByResults(expectedResults, resultsNoProjection);
- }
-
- private void testGroupBy(GroupByQuery query, ExpectedProjectionGroupBy queryMetrics, Set<Object[]> expectedResults)
- {
- testGroupBy(projectionsCursorFactory, projectionsTimeBoundaryInspector, query, queryMetrics, expectedResults);
- }
-
- private void testGroupBy(
- CursorFactory cursorFactory,
- TimeBoundaryInspector timeBoundaryInspector,
- GroupByQuery query,
- ExpectedProjectionGroupBy queryMetrics,
- Set<Object[]> expectedResults
- )
- {
- final Sequence<ResultRow> resultRows = groupingEngine.process(
+ QueryRunner<ResultRow> runner = (unused1, unused2) -> groupingEngine.process(
query,
cursorFactory,
timeBoundaryInspector,
nonBlockingPool,
queryMetrics
);
+ final List<ResultRow> results = groupingEngine
+ .mergeRunners(DirectQueryProcessingPool.INSTANCE, List.of(runner))
+ .run(QueryPlus.wrap(query))
+ .toList();
queryMetrics.assertProjection();
+ assertGroupByResults(expectedResults, results);
- final Object[] results = resultRows.toList().stream().map(ResultRow::getArray).map(Arrays::toString).toArray();
- Arrays.sort(results);
-
- final Object[] expectedResultsArray = expectedResults.stream().map(Arrays::toString).toArray();
- Arrays.sort(expectedResultsArray);
- // print a full diff of all differing elements.
- Assertions.assertEquals(Arrays.toString(expectedResultsArray), Arrays.toString(results));
-
- final Sequence<ResultRow> resultRowsNoProjection = groupingEngine.process(
- query.withOverriddenContext(Map.of(QueryContexts.NO_PROJECTIONS, true)),
- cursorFactory,
- timeBoundaryInspector,
- nonBlockingPool,
- null
- );
-
- final Object[] resultsNoProjection = resultRowsNoProjection.toList().stream().map(ResultRow::getArray).map(Arrays::toString).toArray();
- Arrays.sort(resultsNoProjection);
- // print a full diff of all differing elements.
- Assertions.assertEquals(Arrays.toString(expectedResultsArray), Arrays.toString(resultsNoProjection));
-
+ runner = (unused1, unused2) ->
+ groupingEngine.process(
+ query.withOverriddenContext(Map.of(QueryContexts.NO_PROJECTIONS, true)),
+ cursorFactory,
+ timeBoundaryInspector,
+ nonBlockingPool,
+ null
+ );
+ final List<ResultRow> resultsNoProjection = groupingEngine
+ .mergeRunners(DirectQueryProcessingPool.INSTANCE, List.of(runner))
Review Comment:
It needs mergeRunners because `GroupByMergingQueryRunner` used `RowBasedGrouperHelper.makeGrouperIterator`, which returns sorted result. `GroupByQueryEngine.GroupByEngineIterator` returns unsorted result.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Update ordering direction requirement on projection match (druid)
Posted by "cecemei (via GitHub)" <gi...@apache.org>.
cecemei commented on code in PR #18539:
URL: https://github.com/apache/druid/pull/18539#discussion_r2373243123
##########
processing/src/main/java/org/apache/druid/segment/CursorBuildSpec.java:
##########
@@ -234,8 +237,18 @@ public boolean isCompatibleOrdering(List<OrderBy> ordering)
if (ordering.size() < preferredOrdering.size()) {
return false;
}
- for (int i = 0; i < preferredOrdering.size(); i++) {
- if (!ordering.get(i).equals(preferredOrdering.get(i))) {
+
+ boolean exactMatch = ordering.get(0).equals(preferredOrdering.get(0));
+ if (!exactMatch && !ordering.get(0).equals(preferredOrdering.get(0).reverse())) {
Review Comment:
updated to a `isExactReverse` method instead of creating additional objects
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Update ordering direction requirement on projection match (druid)
Posted by "cecemei (via GitHub)" <gi...@apache.org>.
cecemei commented on code in PR #18539:
URL: https://github.com/apache/druid/pull/18539#discussion_r2369088422
##########
processing/src/test/java/org/apache/druid/segment/CursorFactoryProjectionTest.java:
##########
@@ -1898,75 +1909,40 @@ private void testGroupBy(
List<Object[]> expectedResults
)
{
- final Sequence<ResultRow> resultRows = groupingEngine.process(
+ resourcesReservationPool.reserve(
+ new QueryResourceId(RESOURCE_ID),
query,
- cursorFactory,
- timeBoundaryInspector,
- nonBlockingPool,
- queryMetrics
- );
-
- queryMetrics.assertProjection();
-
- final List<ResultRow> results = resultRows.toList();
- assertGroupByResults(expectedResults, results);
-
- final Sequence<ResultRow> resultRowsNoProjection = groupingEngine.process(
- query.withOverriddenContext(Map.of(QueryContexts.NO_PROJECTIONS, true)),
- cursorFactory,
- timeBoundaryInspector,
- nonBlockingPool,
- null
+ true,
+ new GroupByStatsProvider.PerQueryStats()
);
-
- final List<ResultRow> resultsNoProjection = resultRowsNoProjection.toList();
- assertGroupByResults(expectedResults, resultsNoProjection);
- }
-
- private void testGroupBy(GroupByQuery query, ExpectedProjectionGroupBy queryMetrics, Set<Object[]> expectedResults)
- {
- testGroupBy(projectionsCursorFactory, projectionsTimeBoundaryInspector, query, queryMetrics, expectedResults);
- }
-
- private void testGroupBy(
- CursorFactory cursorFactory,
- TimeBoundaryInspector timeBoundaryInspector,
- GroupByQuery query,
- ExpectedProjectionGroupBy queryMetrics,
- Set<Object[]> expectedResults
- )
- {
- final Sequence<ResultRow> resultRows = groupingEngine.process(
+ QueryRunner<ResultRow> runner = (unused1, unused2) -> groupingEngine.process(
query,
cursorFactory,
timeBoundaryInspector,
nonBlockingPool,
queryMetrics
);
+ final List<ResultRow> results = groupingEngine
+ .mergeRunners(DirectQueryProcessingPool.INSTANCE, List.of(runner))
+ .run(QueryPlus.wrap(query))
+ .toList();
queryMetrics.assertProjection();
+ assertGroupByResults(expectedResults, results);
- final Object[] results = resultRows.toList().stream().map(ResultRow::getArray).map(Arrays::toString).toArray();
- Arrays.sort(results);
-
- final Object[] expectedResultsArray = expectedResults.stream().map(Arrays::toString).toArray();
- Arrays.sort(expectedResultsArray);
- // print a full diff of all differing elements.
- Assertions.assertEquals(Arrays.toString(expectedResultsArray), Arrays.toString(results));
-
- final Sequence<ResultRow> resultRowsNoProjection = groupingEngine.process(
- query.withOverriddenContext(Map.of(QueryContexts.NO_PROJECTIONS, true)),
- cursorFactory,
- timeBoundaryInspector,
- nonBlockingPool,
- null
- );
-
- final Object[] resultsNoProjection = resultRowsNoProjection.toList().stream().map(ResultRow::getArray).map(Arrays::toString).toArray();
- Arrays.sort(resultsNoProjection);
- // print a full diff of all differing elements.
- Assertions.assertEquals(Arrays.toString(expectedResultsArray), Arrays.toString(resultsNoProjection));
-
+ runner = (unused1, unused2) ->
+ groupingEngine.process(
+ query.withOverriddenContext(Map.of(QueryContexts.NO_PROJECTIONS, true)),
+ cursorFactory,
+ timeBoundaryInspector,
+ nonBlockingPool,
+ null
+ );
+ final List<ResultRow> resultsNoProjection = groupingEngine
+ .mergeRunners(DirectQueryProcessingPool.INSTANCE, List.of(runner))
Review Comment:
updated to make merging/sorting controllable.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Remove ordering direction requirement on projection match (druid)
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #18539:
URL: https://github.com/apache/druid/pull/18539#discussion_r2353970023
##########
processing/src/test/java/org/apache/druid/segment/CursorFactoryProjectionTest.java:
##########
@@ -1649,23 +1644,19 @@ public void testProjectionFilteredProjectionMatch()
.setInterval(Intervals.ETERNITY)
.setDimFilter(new EqualityFilter("a", ColumnType.STRING, "a", null))
.addDimension("a")
+ .setContext(Map.of(QueryContexts.QUERY_RESOURCE_ID, RESOURCE_ID))
.build();
final boolean isRealtime = projectionsCursorFactory instanceof IncrementalIndexCursorFactory;
// realtime projections don't have row count, so abfoo is chosen because of how projection sorting happens
- final ExpectedProjectionGroupBy queryMetrics = new ExpectedProjectionGroupBy(isRealtime ? "abfoo" : "a_hourly_c_sum_filter_a_to_a");
+ final ExpectedProjectionGroupBy queryMetrics =
+ new ExpectedProjectionGroupBy(isRealtime ? "abfoo" : "a_hourly_c_sum_filter_a_to_a");
final CursorBuildSpec buildSpec = GroupingEngine.makeCursorBuildSpec(query, queryMetrics);
assertCursorProjection(buildSpec, queryMetrics, isRealtime ? 4 : 2);
-
- testGroupBy(
- query,
- queryMetrics,
- makeArrayResultSet(
- new Object[]{"a"}
- )
- );
+ // List.of auto unpack Object[] to Object, so use ImmutableList.of
+ testGroupBy(query, queryMetrics, ImmutableList.of(new Object[]{"a"}));
Review Comment:
The comment contains a grammatical error. It should be 'List.of auto unpacks Object[] to Object' or 'List.of automatically unpacks Object[] to Object'.
##########
processing/src/test/java/org/apache/druid/segment/CursorFactoryProjectionTest.java:
##########
@@ -1707,19 +1694,19 @@ public void testProjectionFilteredToEmpty()
.setDimFilter(new EqualityFilter("a", ColumnType.STRING, "nomatch", null))
.setContext(Map.of("useProjection", "a_hourly_c_sum_filter_a_to_empty"))
.addDimension("a")
+ .setContext(Map.of(QueryContexts.QUERY_RESOURCE_ID, RESOURCE_ID))
Review Comment:
The second setContext call overwrites the first one. These should be merged into a single call with both keys.
```suggestion
.setContext(Map.of(
"useProjection", "a_hourly_c_sum_filter_a_to_empty",
QueryContexts.QUERY_RESOURCE_ID, RESOURCE_ID))
.addDimension("a")
```
##########
processing/src/test/java/org/apache/druid/segment/CursorFactoryProjectionTest.java:
##########
@@ -1678,22 +1669,18 @@ public void testProjectionFilteredNoFilteredProjectionMatch()
.setInterval(Intervals.ETERNITY)
.setDimFilter(new EqualityFilter("a", ColumnType.STRING, "b", null))
.addDimension("a")
+ .setContext(Map.of(QueryContexts.QUERY_RESOURCE_ID, RESOURCE_ID))
.build();
final boolean isRealtime = projectionsCursorFactory instanceof IncrementalIndexCursorFactory;
- final ExpectedProjectionGroupBy queryMetrics = new ExpectedProjectionGroupBy(isRealtime ? "abfoo" : "a_hourly_c_sum_with_count_latest");
+ final ExpectedProjectionGroupBy queryMetrics =
+ new ExpectedProjectionGroupBy(isRealtime ? "abfoo" : "a_hourly_c_sum_with_count_latest");
final CursorBuildSpec buildSpec = GroupingEngine.makeCursorBuildSpec(query, queryMetrics);
assertCursorProjection(buildSpec, queryMetrics, isRealtime ? 2 : 1);
-
- testGroupBy(
- query,
- queryMetrics,
- makeArrayResultSet(
- new Object[]{"b"}
- )
- );
+ // List.of auto unpack Object[] to Object, so use ImmutableList.of
Review Comment:
The comment contains a grammatical error. It should be 'List.of auto unpacks Object[] to Object' or 'List.of automatically unpacks Object[] to Object'.
```suggestion
// List.of automatically unpacks Object[] to Object, so use ImmutableList.of
```
##########
processing/src/test/java/org/apache/druid/segment/CursorFactoryProjectionTest.java:
##########
@@ -1707,19 +1694,19 @@ public void testProjectionFilteredToEmpty()
.setDimFilter(new EqualityFilter("a", ColumnType.STRING, "nomatch", null))
.setContext(Map.of("useProjection", "a_hourly_c_sum_filter_a_to_empty"))
.addDimension("a")
+ .setContext(Map.of(QueryContexts.QUERY_RESOURCE_ID, RESOURCE_ID))
Review Comment:
The second setContext call overwrites the first one. These should be merged into a single call with both keys.
```suggestion
.setContext(Map.of(
"useProjection", "a_hourly_c_sum_filter_a_to_empty",
QueryContexts.QUERY_RESOURCE_ID, RESOURCE_ID
))
.addDimension("a")
```
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Remove ordering direction requirement on projection match (druid)
Posted by "clintropolis (via GitHub)" <gi...@apache.org>.
clintropolis commented on code in PR #18539:
URL: https://github.com/apache/druid/pull/18539#discussion_r2361509821
##########
processing/src/test/java/org/apache/druid/segment/CursorFactoryProjectionTest.java:
##########
@@ -1898,75 +1909,40 @@ private void testGroupBy(
List<Object[]> expectedResults
)
{
- final Sequence<ResultRow> resultRows = groupingEngine.process(
+ resourcesReservationPool.reserve(
+ new QueryResourceId(RESOURCE_ID),
query,
- cursorFactory,
- timeBoundaryInspector,
- nonBlockingPool,
- queryMetrics
- );
-
- queryMetrics.assertProjection();
-
- final List<ResultRow> results = resultRows.toList();
- assertGroupByResults(expectedResults, results);
-
- final Sequence<ResultRow> resultRowsNoProjection = groupingEngine.process(
- query.withOverriddenContext(Map.of(QueryContexts.NO_PROJECTIONS, true)),
- cursorFactory,
- timeBoundaryInspector,
- nonBlockingPool,
- null
+ true,
+ new GroupByStatsProvider.PerQueryStats()
);
-
- final List<ResultRow> resultsNoProjection = resultRowsNoProjection.toList();
- assertGroupByResults(expectedResults, resultsNoProjection);
- }
-
- private void testGroupBy(GroupByQuery query, ExpectedProjectionGroupBy queryMetrics, Set<Object[]> expectedResults)
- {
- testGroupBy(projectionsCursorFactory, projectionsTimeBoundaryInspector, query, queryMetrics, expectedResults);
- }
-
- private void testGroupBy(
- CursorFactory cursorFactory,
- TimeBoundaryInspector timeBoundaryInspector,
- GroupByQuery query,
- ExpectedProjectionGroupBy queryMetrics,
- Set<Object[]> expectedResults
- )
- {
- final Sequence<ResultRow> resultRows = groupingEngine.process(
+ QueryRunner<ResultRow> runner = (unused1, unused2) -> groupingEngine.process(
query,
cursorFactory,
timeBoundaryInspector,
nonBlockingPool,
queryMetrics
);
+ final List<ResultRow> results = groupingEngine
+ .mergeRunners(DirectQueryProcessingPool.INSTANCE, List.of(runner))
+ .run(QueryPlus.wrap(query))
+ .toList();
queryMetrics.assertProjection();
+ assertGroupByResults(expectedResults, results);
- final Object[] results = resultRows.toList().stream().map(ResultRow::getArray).map(Arrays::toString).toArray();
- Arrays.sort(results);
-
- final Object[] expectedResultsArray = expectedResults.stream().map(Arrays::toString).toArray();
- Arrays.sort(expectedResultsArray);
- // print a full diff of all differing elements.
- Assertions.assertEquals(Arrays.toString(expectedResultsArray), Arrays.toString(results));
-
- final Sequence<ResultRow> resultRowsNoProjection = groupingEngine.process(
- query.withOverriddenContext(Map.of(QueryContexts.NO_PROJECTIONS, true)),
- cursorFactory,
- timeBoundaryInspector,
- nonBlockingPool,
- null
- );
-
- final Object[] resultsNoProjection = resultRowsNoProjection.toList().stream().map(ResultRow::getArray).map(Arrays::toString).toArray();
- Arrays.sort(resultsNoProjection);
- // print a full diff of all differing elements.
- Assertions.assertEquals(Arrays.toString(expectedResultsArray), Arrays.toString(resultsNoProjection));
-
+ runner = (unused1, unused2) ->
+ groupingEngine.process(
+ query.withOverriddenContext(Map.of(QueryContexts.NO_PROJECTIONS, true)),
+ cursorFactory,
+ timeBoundaryInspector,
+ nonBlockingPool,
+ null
+ );
+ final List<ResultRow> resultsNoProjection = groupingEngine
+ .mergeRunners(DirectQueryProcessingPool.INSTANCE, List.of(runner))
Review Comment:
why do we need a sorted result? (other than making it a bit easier to write tests since otherwise sometimes it is inconsistent between runs)
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Update ordering direction requirement on projection match (druid)
Posted by "cecemei (via GitHub)" <gi...@apache.org>.
cecemei commented on code in PR #18539:
URL: https://github.com/apache/druid/pull/18539#discussion_r2369084913
##########
processing/src/main/java/org/apache/druid/segment/CursorBuildSpec.java:
##########
@@ -235,7 +235,7 @@ public boolean isCompatibleOrdering(List<OrderBy> ordering)
return false;
}
for (int i = 0; i < preferredOrdering.size(); i++) {
- if (!ordering.get(i).equals(preferredOrdering.get(i))) {
+ if (!ordering.get(i).getColumnName().equals(preferredOrdering.get(i).getColumnName())) {
Review Comment:
Synced offline, this has been updated
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Remove ordering direction requirement on projection match (druid)
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #18539:
URL: https://github.com/apache/druid/pull/18539#discussion_r2357218664
##########
processing/src/main/java/org/apache/druid/segment/CursorBuildSpec.java:
##########
@@ -235,7 +235,7 @@ public boolean isCompatibleOrdering(List<OrderBy> ordering)
return false;
}
for (int i = 0; i < preferredOrdering.size(); i++) {
- if (!ordering.get(i).equals(preferredOrdering.get(i))) {
+ if (!ordering.get(i).getColumnName().equals(preferredOrdering.get(i).getColumnName())) {
Review Comment:
This change relaxes the ordering direction requirement for projection matching. Consider adding a comment explaining why direction comparison was removed and that only column names need to match for projection compatibility.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Update ordering direction requirement on projection match (druid)
Posted by "clintropolis (via GitHub)" <gi...@apache.org>.
clintropolis commented on code in PR #18539:
URL: https://github.com/apache/druid/pull/18539#discussion_r2371379697
##########
processing/src/main/java/org/apache/druid/segment/CursorBuildSpec.java:
##########
@@ -234,8 +237,18 @@ public boolean isCompatibleOrdering(List<OrderBy> ordering)
if (ordering.size() < preferredOrdering.size()) {
return false;
}
- for (int i = 0; i < preferredOrdering.size(); i++) {
- if (!ordering.get(i).equals(preferredOrdering.get(i))) {
+
+ boolean exactMatch = ordering.get(0).equals(preferredOrdering.get(0));
+ if (!exactMatch && !ordering.get(0).equals(preferredOrdering.get(0).reverse())) {
Review Comment:
it might be nicer to do this without making additional `OrderBy` objects that `reverse` is going to be making since this is going to happen for every projection match of every segment being processed (to keep the garbage collector from having to do work); i think we could just check inline if the direction is same or reversed, and just keep counters and make sure either the same direction counter or reverse counter are the same as the total length (and bail early if neither count matches the processed count)
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Update ordering direction requirement on projection match (druid)
Posted by "cecemei (via GitHub)" <gi...@apache.org>.
cecemei commented on code in PR #18539:
URL: https://github.com/apache/druid/pull/18539#discussion_r2369083976
##########
processing/src/test/java/org/apache/druid/segment/CursorFactoryProjectionTest.java:
##########
@@ -605,6 +590,10 @@ public void testProjectionSelectionTwoDims()
.setInterval(Intervals.ETERNITY)
.addDimension("a")
.addDimension("b")
+ .addOrderByColumn("a", Direction.DESCENDING)
+ .addOrderByColumn("b", Direction.DESCENDING)
+ .setLimit(10)
+ .setContext(Map.of(QueryContexts.QUERY_RESOURCE_ID, RESOURCE_ID))
Review Comment:
this is moved to testGroupBy based on merging is needed or not
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Remove ordering direction requirement on projection match (druid)
Posted by "clintropolis (via GitHub)" <gi...@apache.org>.
clintropolis commented on code in PR #18539:
URL: https://github.com/apache/druid/pull/18539#discussion_r2361213594
##########
processing/src/main/java/org/apache/druid/segment/CursorBuildSpec.java:
##########
@@ -235,7 +235,7 @@ public boolean isCompatibleOrdering(List<OrderBy> ordering)
return false;
}
for (int i = 0; i < preferredOrdering.size(); i++) {
- if (!ordering.get(i).equals(preferredOrdering.get(i))) {
+ if (!ordering.get(i).getColumnName().equals(preferredOrdering.get(i).getColumnName())) {
Review Comment:
I don't think we want to change this method since i think some callers do need to check that the directions are the same.
More importantly though, this needs to be more strict than just matching name, the check that projections needs is that the ordering is either same direction, or every column is exactly the opposite direction of the preferred ordering. So like `ORDER BY X ASC, Y DESC` can match `X ASC, Y DESC` or `X DESC, Y ASC`, but cannot match `X ASC Y ASC`.
This functionality is not really used much yet since today mainly the only thing callers care about is ordered by __time first, but we want stuff to be correct in the future as we expand
##########
processing/src/test/java/org/apache/druid/segment/CursorFactoryProjectionTest.java:
##########
@@ -605,6 +590,10 @@ public void testProjectionSelectionTwoDims()
.setInterval(Intervals.ETERNITY)
.addDimension("a")
.addDimension("b")
+ .addOrderByColumn("a", Direction.DESCENDING)
+ .addOrderByColumn("b", Direction.DESCENDING)
+ .setLimit(10)
+ .setContext(Map.of(QueryContexts.QUERY_RESOURCE_ID, RESOURCE_ID))
Review Comment:
if this is required for something, it should maybe be set by `testGroupBy` or something instead of needing each test to set it specifically
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Remove ordering direction requirement on projection match (druid)
Posted by "clintropolis (via GitHub)" <gi...@apache.org>.
clintropolis commented on code in PR #18539:
URL: https://github.com/apache/druid/pull/18539#discussion_r2361223998
##########
processing/src/test/java/org/apache/druid/segment/CursorFactoryProjectionTest.java:
##########
@@ -1898,75 +1909,40 @@ private void testGroupBy(
List<Object[]> expectedResults
)
{
- final Sequence<ResultRow> resultRows = groupingEngine.process(
+ resourcesReservationPool.reserve(
+ new QueryResourceId(RESOURCE_ID),
query,
- cursorFactory,
- timeBoundaryInspector,
- nonBlockingPool,
- queryMetrics
- );
-
- queryMetrics.assertProjection();
-
- final List<ResultRow> results = resultRows.toList();
- assertGroupByResults(expectedResults, results);
-
- final Sequence<ResultRow> resultRowsNoProjection = groupingEngine.process(
- query.withOverriddenContext(Map.of(QueryContexts.NO_PROJECTIONS, true)),
- cursorFactory,
- timeBoundaryInspector,
- nonBlockingPool,
- null
+ true,
+ new GroupByStatsProvider.PerQueryStats()
);
-
- final List<ResultRow> resultsNoProjection = resultRowsNoProjection.toList();
- assertGroupByResults(expectedResults, resultsNoProjection);
- }
-
- private void testGroupBy(GroupByQuery query, ExpectedProjectionGroupBy queryMetrics, Set<Object[]> expectedResults)
- {
- testGroupBy(projectionsCursorFactory, projectionsTimeBoundaryInspector, query, queryMetrics, expectedResults);
- }
-
- private void testGroupBy(
- CursorFactory cursorFactory,
- TimeBoundaryInspector timeBoundaryInspector,
- GroupByQuery query,
- ExpectedProjectionGroupBy queryMetrics,
- Set<Object[]> expectedResults
- )
- {
- final Sequence<ResultRow> resultRows = groupingEngine.process(
+ QueryRunner<ResultRow> runner = (unused1, unused2) -> groupingEngine.process(
query,
cursorFactory,
timeBoundaryInspector,
nonBlockingPool,
queryMetrics
);
+ final List<ResultRow> results = groupingEngine
+ .mergeRunners(DirectQueryProcessingPool.INSTANCE, List.of(runner))
+ .run(QueryPlus.wrap(query))
+ .toList();
queryMetrics.assertProjection();
+ assertGroupByResults(expectedResults, results);
- final Object[] results = resultRows.toList().stream().map(ResultRow::getArray).map(Arrays::toString).toArray();
- Arrays.sort(results);
-
- final Object[] expectedResultsArray = expectedResults.stream().map(Arrays::toString).toArray();
- Arrays.sort(expectedResultsArray);
- // print a full diff of all differing elements.
- Assertions.assertEquals(Arrays.toString(expectedResultsArray), Arrays.toString(results));
-
- final Sequence<ResultRow> resultRowsNoProjection = groupingEngine.process(
- query.withOverriddenContext(Map.of(QueryContexts.NO_PROJECTIONS, true)),
- cursorFactory,
- timeBoundaryInspector,
- nonBlockingPool,
- null
- );
-
- final Object[] resultsNoProjection = resultRowsNoProjection.toList().stream().map(ResultRow::getArray).map(Arrays::toString).toArray();
- Arrays.sort(resultsNoProjection);
- // print a full diff of all differing elements.
- Assertions.assertEquals(Arrays.toString(expectedResultsArray), Arrays.toString(resultsNoProjection));
-
+ runner = (unused1, unused2) ->
+ groupingEngine.process(
+ query.withOverriddenContext(Map.of(QueryContexts.NO_PROJECTIONS, true)),
+ cursorFactory,
+ timeBoundaryInspector,
+ nonBlockingPool,
+ null
+ );
+ final List<ResultRow> resultsNoProjection = groupingEngine
+ .mergeRunners(DirectQueryProcessingPool.INSTANCE, List.of(runner))
Review Comment:
it doesn't seem that important that these tests use `mergeRunners` since they are focused on the per segment processing, but i guess it isn't that harmful either...
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org