private void upsertMeasurementAlias()

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


  private void upsertMeasurementAlias(SessionPool sessionPool, String timeseries, String alias)
      throws BaseException {
    if (alias == null || "null".equals(alias) || StringUtils.isBlank(alias)) {
      return;
    }
    if (alias.matches("^as$") || alias.matches("^\\d+$") || alias.matches("^like$")) {
      throw new BaseException(ErrorCode.NO_SUP_ALIAS_WORD, ErrorCode.NO_SUP_ALIAS_WORD_MSG);
    }
    String existAlias = executeQueryOneLine(sessionPool, "show timeseries " + timeseries, "alias");
    if (alias.equals(existAlias)) {
      return;
    }
    try {
      String sql = "alter timeseries " + timeseries + " upsert alias=" + alias;
      sessionPool.executeNonQueryStatement(sql);
    } catch (StatementExecutionException e) {
      logger.error(e.getMessage());
      if (e.getMessage().contains("No permissions")) {
        throw new BaseException(
            ErrorCode.NO_PRI_ALTER_MEASUREMENT, ErrorCode.NO_PRI_ALTER_MEASUREMENT_MSG);
      }
      throw new BaseException(ErrorCode.UPSERT_ALIAS_FAIL, ErrorCode.UPSERT_ALIAS_FAIL_MSG);
    } catch (IoTDBConnectionException e) {
      logger.error(e.getMessage());
      throw new BaseException(ErrorCode.GET_SESSION_FAIL, ErrorCode.GET_SESSION_FAIL_MSG);
    }
  }