Young-Leo commented on code in PR #17027:
URL: https://github.com/apache/iotdb/pull/17027#discussion_r2754796243
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/impl/ClientRPCServiceImpl.java:
##########
@@ -1488,6 +1505,174 @@ 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();
+
+ 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));
+ }
+
+ int parameterCount = ParameterExtractor.getParameterCount(statement);
+
+ 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.PREPARE_STATEMENT.getName(),
TSStatusCode.INTERNAL_SERVER_ERROR));
+ }
+ }
+
+ @Override
+ public TSExecuteStatementResp executePreparedStatement(TSExecutePreparedReq
req) {
+ boolean finished = false;
+ long queryId = Long.MIN_VALUE;
+ IClientSession clientSession =
SESSION_MANAGER.getCurrSessionAndUpdateIdleTime();
+
+ if (!SESSION_MANAGER.checkLogin(clientSession)) {
+ return RpcUtils.getTSExecuteStatementResp(getNotLoggedInStatus());
+ }
+
+ long startTime = System.nanoTime();
+ Throwable t = null;
+ try {
+ String statementName = req.getStatementName();
+
+ List<DeserializedParam> rawParams =
+
PreparedParameterSerializer.deserialize(ByteBuffer.wrap(req.getParameters()));
+ List<Literal> parameters = new ArrayList<>(rawParams.size());
+ for (DeserializedParam param : rawParams) {
+ parameters.add(convertToLiteral(param));
+ }
+
+ Execute executeStatement = new Execute(new Identifier(statementName),
parameters);
+
+ queryId = SESSION_MANAGER.requestQueryId(clientSession,
req.getStatementId());
+
+ long timeout = req.isSetTimeout() ? req.getTimeout() :
config.getQueryTimeoutThreshold();
+ ExecutionResult result =
+ COORDINATOR.executeForTableModel(
+ executeStatement,
+ relationSqlParser,
+ clientSession,
+ queryId,
+ SESSION_MANAGER.getSessionInfo(clientSession),
+ "EXECUTE " + statementName,
Review Comment:
Added.
--
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]