itiels commented on code in PR #2868:
URL: https://github.com/apache/calcite/pull/2868#discussion_r985604527
##########
core/src/main/java/org/apache/calcite/sql/SqlWithinGroupOperator.java:
##########
@@ -79,7 +81,56 @@ public SqlWithinGroupOperator() {
SqlValidator validator,
SqlValidatorScope scope,
SqlCall call) {
- // Validate type of the inner aggregate call
- return validateOperands(validator, scope, call);
+
+ SqlCall inner = call.operand(0);
+ throwIfNotAggregate(call, validator, inner.getOperator());
+ if (inner.getOperator().getKind() == SqlKind.PERCENTILE_DISC) {
+ // We first check the percentile call operands, and then derive the
correct type using
+ // PercentileDiscCallBinding (See CALCITE-5230).
+ SqlCallBinding opBinding =
+ new PercentileDiscCallBinding(validator, scope, inner,
getCollationColumn(call));
+ inner.getOperator().checkOperandTypes(opBinding, true);
+ RelDataType ret = inner.getOperator().inferReturnType(opBinding);
+ validator.setValidatedNodeType(inner, ret);
+ return ret;
+ } else {
+ return validateOperands(validator, scope, call);
+ }
+ }
Review Comment:
I don't think we can, because the validation/derivation is needed to be done
in terms of the `inner` operator. even if we supply the correct
`SqlCallBinding` to `validateOperands`, it will still be done in the context of
the outer operator(`SqlWithinGroupOperator`)
--
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]