Skip to content

Commit

Permalink
[BugFix] Fix forward statement miss policy rewrite bug (backport #46195
Browse files Browse the repository at this point in the history
…) (#46241)

Co-authored-by: HangyuanLiu <[email protected]>
  • Loading branch information
mergify[bot] and HangyuanLiu authored May 24, 2024
1 parent 80a6a6c commit 44058fe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
21 changes: 17 additions & 4 deletions fe/fe-core/src/main/java/com/starrocks/qe/ConnectProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import com.starrocks.sql.ast.UserIdentity;
import com.starrocks.sql.common.SqlDigestBuilder;
import com.starrocks.sql.parser.ParsingException;
import com.starrocks.sql.parser.SqlParser;
import com.starrocks.thrift.TMasterOpRequest;
import com.starrocks.thrift.TMasterOpResult;
import com.starrocks.thrift.TQueryOptions;
Expand Down Expand Up @@ -106,7 +107,6 @@ public class ConnectProcessor {

protected StmtExecutor executor = null;


public ConnectProcessor(ConnectContext context) {
this.ctx = context;
}
Expand Down Expand Up @@ -528,7 +528,7 @@ private void handleExecute() {
packetBuf.get(nullBitmap);
try {
ctx.setQueryId(UUIDUtil.genUUID());

// new_params_bind_flag
if (packetBuf.hasRemaining() && (int) packetBuf.get() != 0) {
// parse params types
Expand Down Expand Up @@ -560,7 +560,7 @@ private void handleExecute() {
if (enableAudit) {
auditAfterExec(originStmt, executor.getParsedStmt(), executor.getQueryStatisticsForAuditLog());
}
} catch (Throwable e) {
} catch (Throwable e) {
// Catch all throwable.
// If reach here, maybe palo bug.
LOG.warn("Process one query failed because unknown reason: ", e);
Expand Down Expand Up @@ -828,7 +828,20 @@ public TMasterOpResult proxyExecute(TMasterOpRequest request) {
}
// 0 for compatibility.
int idx = request.isSetStmtIdx() ? request.getStmtIdx() : 0;
executor = new StmtExecutor(ctx, new OriginStatement(request.getSql(), idx), true);

List<StatementBase> stmts = SqlParser.parse(request.getSql(), ctx.getSessionVariable());
StatementBase statement = stmts.get(idx);
//Build View SQL without Policy Rewrite
new AstTraverser<Void, Void>() {
@Override
public Void visitRelation(Relation relation, Void context) {
relation.setNeedRewrittenByPolicy(true);
return null;
}
}.visit(statement);

executor = new StmtExecutor(ctx, statement);
executor.setProxy();
executor.execute();
} catch (IOException e) {
// Client failed.
Expand Down
6 changes: 5 additions & 1 deletion fe/fe-core/src/main/java/com/starrocks/qe/StmtExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public class StmtExecutor {
private Coordinator coord = null;
private LeaderOpExecutor leaderOpExecutor = null;
private RedirectStatus redirectStatus = null;
private final boolean isProxy;
private boolean isProxy;
private List<ByteBuffer> proxyResultBuffer = null;
private ShowResultSet proxyResultSet = null;
private PQueryStatistics statisticsForAuditLog;
Expand Down Expand Up @@ -275,6 +275,10 @@ public StmtExecutor(ConnectContext ctx, StatementBase parsedStmt) {
this.isProxy = false;
}

public void setProxy() {
isProxy = true;
}

public Coordinator getCoordinator() {
return this.coord;
}
Expand Down

0 comments on commit 44058fe

Please sign in to comment.