public RecordVO getRecords()

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


  public RecordVO getRecords(
      Connection connection, String deviceName, String timeseriesName, String dataType)
      throws BaseException {
    SessionPool sessionPool = null;
    SessionDataSetWrapper sessionDataSetWrapper = null;
    RecordVO recordVO = new RecordVO();
    List<Date> timeList = new ArrayList<>();
    List<String> valueList = new ArrayList<>();
    Map<String, Integer> textCount = new HashMap<>();
    String sql =
        "select "
            + StringUtils.removeStart(timeseriesName, deviceName + ".")
            + " from "
            + deviceName
            + " order by time desc limit 200 offset 0";
    try {
      sessionPool = getSessionPool(connection);
      sessionDataSetWrapper = sessionPool.executeQueryStatement(sql);
      while (sessionDataSetWrapper.hasNext()) {
        if ("TEXT".equals(dataType)) {
          RowRecord next = sessionDataSetWrapper.next();
          String text = next.getFields().get(0).toString();
          if (textCount.containsKey(text)) {
            textCount.put(text, textCount.get(text) + 1);
          } else {
            textCount.put(text, 1);
          }
        } else if (StringUtils.equalsAny(
            dataType, "INT32", "INT64", "BOOLEAN", "FLOAT", "DOUBLE")) {
          RowRecord next = sessionDataSetWrapper.next();
          Date date = new Date(next.getTimestamp());
          timeList.add(date);
          List<org.apache.iotdb.tsfile.read.common.Field> fields = next.getFields();
          valueList.add(fields.get(0).toString());
        } else {
          throw new BaseException(ErrorCode.DB_DATATYPE_WRONG, ErrorCode.DB_DATATYPE_WRONG_MSG);
        }
      }
      recordVO.setTimeList(timeList);
      recordVO.setValueList(valueList);
      recordVO.setTextCount(textCount);
      return recordVO;
    } catch (IoTDBConnectionException e) {
      logger.error(e.getMessage());
      throw new BaseException(ErrorCode.GET_RECORD_FAIL, ErrorCode.GET_RECORD_FAIL_MSG);
    } catch (StatementExecutionException e) {
      logger.error(e.getMessage());
      throw new BaseException(ErrorCode.GET_RECORD_FAIL, ErrorCode.GET_RECORD_FAIL_MSG);
    } finally {
      closeResultSet(sessionDataSetWrapper);
      closeSessionPool(sessionPool);
    }
  }