Skip to content

Commit

Permalink
[BugFix] fix issue when using placeholder in column position in prepa…
Browse files Browse the repository at this point in the history
…re stmt (#51812)

Signed-off-by: ShaoxunLi <[email protected]>
  • Loading branch information
ShaoxunLi authored Oct 15, 2024
1 parent 51184d0 commit a9b5ce9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
19 changes: 19 additions & 0 deletions fe/fe-core/src/main/java/com/starrocks/analysis/Parameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,23 @@ public Type getOriginType() {
protected String toSqlImpl() {
return "?";
}

@Override
public int hashCode() {
return slotId;
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}

if (obj.getClass() != this.getClass()) {
return false;
}

Parameter parameter = (Parameter) obj;
return this.slotId == parameter.slotId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.HashSet;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
Expand Down Expand Up @@ -97,6 +99,22 @@ public void testPrepareEnable() {
Assert.assertFalse(executor.isForwardToLeader());
}

@Test
public void testPrepareWithSelectConst() throws Exception {
String sql = "PREPARE stmt1 FROM select ?, ?, ?;";
PrepareStmt stmt = (PrepareStmt) UtFrameUtils.parseStmtWithNewParser(sql, ctx);
Assert.assertEquals(3, stmt.getParameters().size());

HashSet<Integer> idSet = new HashSet<Integer>();
for (Expr expr : stmt.getParameters()) {
Assert.assertEquals(true, idSet.add(expr.hashCode()));
}

Assert.assertEquals(false, stmt.getParameters().get(0).equals(stmt.getParameters().get(1)));
Assert.assertEquals(false, stmt.getParameters().get(1).equals(stmt.getParameters().get(2)));
Assert.assertEquals(false, stmt.getParameters().get(0).equals(stmt.getParameters().get(2)));
}

@Test
public void testPrepareStatementParser() {
String sql = "PREPARE stmt1 FROM insert into demo.prepare_stmt values (?, ?, ?, ?);";
Expand Down

0 comments on commit a9b5ce9

Please sign in to comment.