Young-Leo commented on code in PR #17027:
URL: https://github.com/apache/iotdb/pull/17027#discussion_r2703293186


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/impl/ClientRPCServiceImpl.java:
##########
@@ -1488,6 +1505,179 @@ public TSStatus closeOperation(TSCloseOperationReq req) 
{
         COORDINATOR::cleanupQueryExecution);
   }
 
+  // ========================= PreparedStatement RPC Methods 
=========================
+
+  @Override
+  public TSPrepareResp prepareStatement(TSPrepareReq req) {
+    IClientSession clientSession = 
SESSION_MANAGER.getCurrSessionAndUpdateIdleTime();
+    if (!SESSION_MANAGER.checkLogin(clientSession)) {
+      return new TSPrepareResp(getNotLoggedInStatus());
+    }
+
+    try {
+      String sql = req.getSql();
+      String statementName = req.getStatementName();
+
+      // Parse SQL to get Statement AST
+      org.apache.iotdb.db.queryengine.plan.relational.sql.ast.Statement 
statement =
+          relationSqlParser.createStatement(sql, clientSession.getZoneId(), 
clientSession);
+
+      if (statement == null) {
+        return new TSPrepareResp(
+            RpcUtils.getStatus(TSStatusCode.SQL_PARSE_ERROR, "Failed to parse 
SQL: " + sql));
+      }
+
+      // Get parameter count before registering
+      int parameterCount = ParameterExtractor.getParameterCount(statement);
+
+      // Register the prepared statement using helper
+      PreparedStatementHelper.register(clientSession, statementName, 
statement);
+
+      TSPrepareResp resp = new 
TSPrepareResp(RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS));
+      resp.setParameterCount(parameterCount);
+      return resp;
+    } catch (Exception e) {
+      return new TSPrepareResp(
+          onQueryException(
+              e, OperationType.EXECUTE_STATEMENT.getName(), 
TSStatusCode.INTERNAL_SERVER_ERROR));

Review Comment:
   Done
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to