xuzifu666 commented on code in PR #4983:
URL: https://github.com/apache/calcite/pull/4983#discussion_r3345654043
##########
core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableAggregateBase.java:
##########
@@ -145,6 +146,32 @@ protected void implementLambdaFactory(BlockBuilder builder,
requireNonNull(agg.accumulatorAdder,
"agg.accumulatorAdder")))));
continue;
}
+ // Check if all collation field indices are within the input row type
bounds.
+ // When using LISTAGG(DISTINCT col1) WITHIN GROUP (ORDER BY col2)
where col2 is not
+ // a GROUP BY column, col2's index may exceed the re-grouped input row
type bounds.
+ // In such cases, we fall back to non-sorted aggregation instead of
crashing.
+ boolean validCollation = true;
+ for (final RelFieldCollation fieldCollation :
agg.call.collation.getFieldCollations()) {
+ if (fieldCollation.getFieldIndex() >=
inputPhysType.getRowType().getFieldCount()) {
+ validCollation = false;
+ break;
+ }
+ }
+
+ if (!validCollation) {
Review Comment:
This is a compromise solution to avoid crashes by downgrading the handling
of such special statements (removing the `order by` clause). The main issue is
that a thorough fix involves many aspects, with less consideration for ROI. If
it becomes clear that a completely accurate `order by` result is required, I
will attempt a fix with the lowest possible cost in the future.
--
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]