mihaibudiu commented on code in PR #4983:
URL: https://github.com/apache/calcite/pull/4983#discussion_r3336048865
##########
core/src/main/java/org/apache/calcite/adapter/enumerable/PhysTypeImpl.java:
##########
@@ -276,9 +276,15 @@ static PhysType of(
final Expression selector;
if (collations.size() == 1) {
RelFieldCollation collation = collations.get(0);
+ final int index = collation.getFieldIndex();
+ if (index < 0 || index >= rowType.getFieldList().size()) {
Review Comment:
I guess these should never be reachable if the code generator is correct
##########
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:
I am a bit confused: there is a sort order specified, yet it is ignored?
That cannot be right.
--
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]