From ec9457728e4a22e20f8d4f0a87b97d1ba3256fa9 Mon Sep 17 00:00:00 2001 From: XuYi Date: Mon, 15 Jan 2018 12:00:46 +0800 Subject: [PATCH] add exception in batch execute statement (#299) --- .../tsinghua/iotdb/service/TSServiceImpl.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/cn/edu/tsinghua/iotdb/service/TSServiceImpl.java b/src/main/java/cn/edu/tsinghua/iotdb/service/TSServiceImpl.java index fe920342509..2d693395b56 100644 --- a/src/main/java/cn/edu/tsinghua/iotdb/service/TSServiceImpl.java +++ b/src/main/java/cn/edu/tsinghua/iotdb/service/TSServiceImpl.java @@ -2,6 +2,7 @@ package cn.edu.tsinghua.iotdb.service; import java.io.IOException; import java.nio.ByteBuffer; +import java.sql.Statement; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -271,6 +272,9 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext { } List statements = req.getStatements(); List result = new ArrayList<>(); + boolean isAllSuccessful = true; + String batchErrorMessage = ""; + for (String statement : statements) { try { PhysicalPlan physicalPlan = processor.parseSQLToPhysicalPlan(statement, timeZone.get()); @@ -280,17 +284,26 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext { } TSExecuteStatementResp resp = ExecuteUpdateStatement(physicalPlan); if(resp.getStatus().getStatusCode().equals(TS_StatusCode.SUCCESS_STATUS)){ - result.add(1); + result.add(Statement.SUCCESS_NO_INFO); } else{ - result.add(-1); + result.add(Statement.EXECUTE_FAILED); + isAllSuccessful = false; + batchErrorMessage = resp.getStatus().getErrorMessage(); } } catch (Exception e) { - LOGGER.error("Fail to generate physcial plan and execute for statement {}", statement); - result.add(-1); + String errMessage = String.format("Fail to generate physcial plan and execute for statement %s beacuse %s", statement, e.getMessage()); + LOGGER.error(errMessage); + result.add(Statement.EXECUTE_FAILED); + isAllSuccessful = false; + batchErrorMessage = errMessage; } } - return getTSBathExecuteStatementResp(TS_StatusCode.SUCCESS_STATUS, "Execute batch statements successfully", result); + if(isAllSuccessful) { + return getTSBathExecuteStatementResp(TS_StatusCode.SUCCESS_STATUS, "Execute batch statements successfully", result); + } else { + return getTSBathExecuteStatementResp(TS_StatusCode.ERROR_STATUS, batchErrorMessage, result); + } } catch (Exception e) { LOGGER.error("{}: error occurs when executing statements",TsFileDBConstant.GLOBAL_DB_NAME, e); return getTSBathExecuteStatementResp(TS_StatusCode.ERROR_STATUS, e.getMessage(), null);