private SqlResultVO executeQuery()

in backend/src/main/java/org/apache/iotdb/admin/service/impl/IotDBServiceImpl.java [4355:4412]


  private SqlResultVO executeQuery(SessionPool sessionPool, String sql, String notStopKey)
      throws BaseException {
    SqlResultVO sqlResultVO = new SqlResultVO();
    List<List<String>> valuelist = new ArrayList<>();
    SessionDataSetWrapper sessionDataSetWrapper = null;
    boolean timeFlag = false;
    try {
      sessionDataSetWrapper = sessionPool.executeQueryStatement(sql);
      long start = System.currentTimeMillis();
      List<String> columnNames = sessionDataSetWrapper.getColumnNames();
      sqlResultVO.setMetaDataList(columnNames);
      if ("Time".equals(columnNames.get(0))) {
        timeFlag = true;
      }
      int batchSize = sessionDataSetWrapper.getBatchSize();
      long count = 0;
      if (batchSize > 0) {
        while (sessionDataSetWrapper.hasNext() && QUERY_STOP.get(notStopKey)) {
          List<String> strList = new ArrayList<>();
          RowRecord rowRecord = sessionDataSetWrapper.next();
          if (timeFlag) {
            long timestamp = rowRecord.getTimestamp();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");
            Date date = new Date(timestamp);
            String timeStr = simpleDateFormat.format(date);
            strList.add(timeStr);
          }
          count++;
          for (org.apache.iotdb.tsfile.read.common.Field field : rowRecord.getFields()) {
            strList.add(field.toString());
          }
          valuelist.add(strList);
        }
        long end = System.currentTimeMillis();
        long time = end - start;
        String queryTime = time + "ms";
        sqlResultVO.setQueryTime(queryTime);
        sqlResultVO.setLine(count);
      }
    } catch (StatementExecutionException e) {
      logger.error(e.getMessage());
      throw new BaseException(
          ErrorCode.SQL_EP,
          ErrorCode.SQL_EP_MSG
              + ":["
              + sql
              + "]statement execution error, error message:["
              + e.getMessage()
              + "]");
    } catch (IoTDBConnectionException e) {
      logger.error(e.getMessage());
      throw new BaseException(ErrorCode.GET_SESSION_FAIL, ErrorCode.GET_SESSION_FAIL_MSG);
    } finally {
      closeResultSet(sessionDataSetWrapper);
    }
    sqlResultVO.setValueList(valuelist);
    return sqlResultVO;
  }