public static Statement createStatement(TSAggregationQueryReq req) throws IllegalPathException {
    final long startTime = System.nanoTime();
    QueryStatement queryStatement = new QueryStatement();

    FromComponent fromComponent = new FromComponent();
    fromComponent.addPrefixPath(new PartialPath("", false));
    queryStatement.setFromComponent(fromComponent);

    SelectComponent selectComponent = new SelectComponent();
    List<PartialPath> selectPaths = new ArrayList<>();
    for (String pathStr : req.getPaths()) {
      if (req.isLegalPathNodes()) {
        selectPaths.add(new PartialPath(pathStr.split("\\.")));
      } else {
        selectPaths.add(new PartialPath(pathStr));
      }
    }
    List<TAggregationType> aggregations = req.getAggregations();
    for (int i = 0; i < aggregations.size(); i++) {
      selectComponent.addResultColumn(
          new ResultColumn(
              new FunctionExpression(
                  aggregations.get(i).toString(),
                  new LinkedHashMap<>(),
                  Collections.singletonList(new TimeSeriesOperand(selectPaths.get(i)))),
              ResultColumn.ColumnType.AGGREGATION));
    }
    queryStatement.setSelectComponent(selectComponent);

    if (req.isSetInterval()) {
      GroupByTimeComponent groupByTimeComponent = new GroupByTimeComponent();
      groupByTimeComponent.setStartTime(req.getStartTime());
      groupByTimeComponent.setEndTime(req.getEndTime());
      groupByTimeComponent.setInterval(new TimeDuration(0, req.getInterval()));
      if (req.isSetSlidingStep()) {
        groupByTimeComponent.setSlidingStep(new TimeDuration(0, req.getSlidingStep()));
      } else {
        groupByTimeComponent.setSlidingStep(groupByTimeComponent.getInterval());
      }
      queryStatement.setGroupByTimeComponent(groupByTimeComponent);
    } else if (req.isSetStartTime()) {
      WhereCondition whereCondition = new WhereCondition();
      GreaterEqualExpression leftPredicate =
          new GreaterEqualExpression(
              new TimestampOperand(),
              new ConstantOperand(TSDataType.INT64, Long.toString(req.getStartTime())));
      LessThanExpression rightPredicate =
          new LessThanExpression(
              new TimestampOperand(),
              new ConstantOperand(TSDataType.INT64, Long.toString(req.getEndTime())));
      LogicAndExpression predicate = new LogicAndExpression(leftPredicate, rightPredicate);
      whereCondition.setPredicate(predicate);
      queryStatement.setWhereCondition(whereCondition);
    }
    PERFORMANCE_OVERVIEW_METRICS.recordParseCost(System.nanoTime() - startTime);
    return queryStatement;
  }
Convert SQL and RPC requests to {@link Statement}.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/StatementGenerator.java