rohangarg commented on code in PR #16742: URL: https://github.com/apache/druid/pull/16742#discussion_r1687991446
########## sql/src/main/java/org/apache/druid/sql/calcite/planner/DruidSqlValidator.java: ########## @@ -857,4 +861,50 @@ private SqlNode getSqlNodeFor(SqlInsert insert, int idx) } return src; } + + @Override + protected void validateHavingClause(SqlSelect select) + { + super.validateHavingClause(select); + SqlNode having = select.getHaving(); + if (containsOver(having)) { + throw buildCalciteContextException("Window functions are not allowed in HAVING", having); + } + } + + private boolean containsOver(SqlNode having) + { + if (having == null) { + return false; + } + final Predicate<SqlCall> callPredicate = call -> call.getOperator() instanceof SqlOverOperator; + return containsCall(having, callPredicate); + } + + // copy of SqlUtil#containsCall + /** Returns whether an AST tree contains a call that matches a given + * predicate. */ + private static boolean containsCall(SqlNode node, + Predicate<SqlCall> callPredicate) + { + try { + SqlVisitor<Void> visitor = Review Comment: is it not possible to make this a boolean visitor? `true` indicates presence, and `false` and `null` indicating non-presence? ########## sql/src/main/java/org/apache/druid/sql/calcite/expression/Expressions.java: ########## @@ -238,6 +241,10 @@ public static DruidExpression toDruidExpressionWithPostAggOperands( final SqlKind kind = rexNode.getKind(); if (kind == SqlKind.INPUT_REF) { return inputRefToDruidExpression(rowSignature, rexNode); + } else if (rexNode instanceof RexOver) { + throw new CannotBuildQueryException( + StringUtils.format("Encountered an OVER during Filter translation [%s].", rexNode) Review Comment: I am not sure whether this code gets exercised only in during filter translation. Seems to be used for other things as well. -- 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-unsubscr...@druid.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org