|
46 | 46 | import org.apache.doris.nereids.trees.plans.PlaceholderId; |
47 | 47 | import org.apache.doris.nereids.trees.plans.commands.ExecuteCommand; |
48 | 48 | import org.apache.doris.nereids.trees.plans.commands.PrepareCommand; |
| 49 | +import org.apache.doris.thrift.TUniqueId; |
49 | 50 |
|
50 | 51 | import com.google.common.base.Preconditions; |
51 | 52 | import com.google.common.base.Strings; |
@@ -170,14 +171,31 @@ private void handleExecute(PrepareStmt prepareStmt, long stmtId) { |
170 | 171 | } |
171 | 172 | } |
172 | 173 |
|
173 | | - private void handleExecute(PrepareCommand prepareCommand, long stmtId, PreparedStatementContext prepCtx) { |
| 174 | + private String getHexStr(ByteBuffer packetBuf) { |
| 175 | + byte[] bytes = packetBuf.array(); |
| 176 | + StringBuilder hex = new StringBuilder(); |
| 177 | + for (int i = packetBuf.position(); i < packetBuf.limit(); ++i) { |
| 178 | + hex.append(String.format("%02X ", bytes[i])); |
| 179 | + } |
| 180 | + return hex.toString(); |
| 181 | + } |
| 182 | + |
| 183 | + @Override |
| 184 | + protected void handleExecute(PrepareCommand prepareCommand, long stmtId, PreparedStatementContext prepCtx, |
| 185 | + ByteBuffer packetBuf, TUniqueId queryId) { |
174 | 186 | int paramCount = prepareCommand.placeholderCount(); |
175 | 187 | LOG.debug("execute prepared statement {}, paramCount {}", stmtId, paramCount); |
176 | 188 | // null bitmap |
177 | 189 | String stmtStr = ""; |
178 | 190 | try { |
179 | 191 | StatementContext statementContext = prepCtx.statementContext; |
180 | 192 | if (paramCount > 0) { |
| 193 | + if (LOG.isDebugEnabled()) { |
| 194 | + LOG.debug("execute param buf: {}, array: {}", packetBuf, getHexStr(packetBuf)); |
| 195 | + } |
| 196 | + if (!ctx.isProxy()) { |
| 197 | + ctx.setPrepareExecuteBuffer(packetBuf.duplicate()); |
| 198 | + } |
181 | 199 | byte[] nullbitmapData = new byte[(paramCount + 7) / 8]; |
182 | 200 | packetBuf.get(nullbitmapData); |
183 | 201 | // new_params_bind_flag |
@@ -218,7 +236,11 @@ private void handleExecute(PrepareCommand prepareCommand, long stmtId, PreparedS |
218 | 236 | stmt.setOrigStmt(prepareCommand.getOriginalStmt()); |
219 | 237 | executor = new StmtExecutor(ctx, stmt); |
220 | 238 | ctx.setExecutor(executor); |
221 | | - executor.execute(); |
| 239 | + if (null != queryId) { |
| 240 | + executor.execute(queryId); |
| 241 | + } else { |
| 242 | + executor.execute(); |
| 243 | + } |
222 | 244 | if (ctx.getSessionVariable().isEnablePreparedStmtAuditLog()) { |
223 | 245 | stmtStr = executeStmt.toSql(); |
224 | 246 | stmtStr = stmtStr + " /*originalSql = " + prepareCommand.getOriginalStmt().originStmt + "*/"; |
@@ -266,7 +288,7 @@ private void handleExecute() { |
266 | 288 | "msg: Not supported such prepared statement"); |
267 | 289 | return; |
268 | 290 | } |
269 | | - handleExecute(preparedStatementContext.command, stmtId, preparedStatementContext); |
| 291 | + handleExecute(preparedStatementContext.command, stmtId, preparedStatementContext, packetBuf, null); |
270 | 292 | } |
271 | 293 | } |
272 | 294 |
|
|
0 commit comments