bchong95 commented on code in PR #2953:
URL: https://github.com/apache/calcite/pull/2953#discussion_r1105229753
##########
core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java:
##########
@@ -4187,6 +4194,82 @@ protected void validateWindowClause(SqlSelect select) {
windowList.validate(this, windowScope);
}
+ protected void validateQualifyClause(SqlSelect select) {
+ SqlNode qualifyNode = select.getQualify();
+ if (qualifyNode == null) {
+ return;
+ }
+
+ SqlValidatorScope qualifyScope = getSelectScope(select);
+
+ qualifyNode = extendedExpand(qualifyNode, qualifyScope, select,
ExpansionClause.QUALIFY);
+ select.setQualify(qualifyNode);
+
+ inferUnknownTypes(
+ booleanType,
+ qualifyScope,
+ qualifyNode);
+
+ qualifyNode.validate(this, qualifyScope);
+
+ final RelDataType type = deriveType(qualifyScope, qualifyNode);
+ if (!SqlTypeUtil.inBooleanFamily(type)) {
+ throw newValidationError(qualifyNode,
RESOURCE.condMustBeBoolean("QUALIFY"));
+ }
+
+ boolean qualifyContainsWindowFunction =
qualifyNode.accept(WindowFunctionDetector.INSTANCE);
+ if (!qualifyContainsWindowFunction) {
+ throw newValidationError(qualifyNode,
+
RESOURCE.qualifyExpressionMustContainWindowFunction(qualifyNode.toString()));
+ }
+ }
+
+ /** Detects OVER. */
Review Comment:
Good point! I didn't know about that API
--
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]