Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BugFix] fix analyzing error in prepare stmt with HAVING clause #50583

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.starrocks.analysis.LiteralExpr;
import com.starrocks.analysis.MatchExpr;
import com.starrocks.analysis.OrderByElement;
import com.starrocks.analysis.Parameter;
import com.starrocks.analysis.ParseNode;
import com.starrocks.analysis.SlotRef;
import com.starrocks.analysis.Subquery;
Expand Down Expand Up @@ -128,6 +129,9 @@ public Boolean visitFieldReference(FieldReference node, Void context) {

@Override
public Boolean visitExpression(Expr node, Void context) {
if (node instanceof Parameter) {
return true;
}
throw new SemanticException(node.toSql() + " must appear in the GROUP BY clause or be used in an aggregate function",
node.getPos());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,23 @@ public void testPrepareStatementParser() {
"prepared statement protocol yet.", e.getMessage());
}

@Test
public void testPrepareStatementParserWithHavingClause() {
String sql = "PREPARE stmt1 FROM SELECT prepare_stmt.c0 from prepare_stmt GROUP BY prepare_stmt.c0 HAVING COUNT(*) = ?";
try {
PrepareStmt stmt = (PrepareStmt) UtFrameUtils.parseStmtWithNewParser(sql, ctx);
} catch (Exception e) {
Assert.fail("should not reach here");
}

sql = "PREPARE stmt1 FROM SELECT prepare_stmt.c0 from prepare_stmt GROUP BY prepare_stmt.c0 HAVING c0 > ?";
try {
PrepareStmt stmt = (PrepareStmt) UtFrameUtils.parseStmtWithNewParser(sql, ctx);
} catch (Exception e) {
Assert.fail("should not reach here");
}
}

@Test
public void testPrepareStmtWithCte() throws Exception {
String sql = "PREPARE stmt FROM with cte as (select * from prepare_stmt where c0 = ?) select * from cte where c1 = ?";
Expand Down
Loading