public Statement rewrite(
      Statement statement, PathPatternTree patternTree, MPPQueryContext queryContext)
      throws StatementAnalyzeException {
    QueryStatement queryStatement = (QueryStatement) statement;
    this.patternTree = patternTree;
    // prefix paths in the FROM clause
    List<PartialPath> prefixPaths = queryStatement.getFromComponent().getPrefixPaths();

    if (queryStatement.isAlignByDevice()) {
      for (ResultColumn resultColumn : queryStatement.getSelectComponent().getResultColumns()) {
        ExpressionAnalyzer.constructPatternTreeFromExpression(
            resultColumn.getExpression(), prefixPaths, patternTree);
      }
      if (queryStatement.hasGroupByExpression()) {
        ExpressionAnalyzer.constructPatternTreeFromExpression(
            queryStatement.getGroupByComponent().getControlColumnExpression(),
            prefixPaths,
            patternTree);
      }
      if (queryStatement.hasOrderByExpression()) {
        for (Expression sortItemExpression : queryStatement.getExpressionSortItemList()) {
          ExpressionAnalyzer.constructPatternTreeFromExpression(
              sortItemExpression, prefixPaths, patternTree);
        }
      }
    } else {
      // concat SELECT with FROM
      List<ResultColumn> resultColumns =
          concatSelectWithFrom(queryStatement.getSelectComponent(), prefixPaths, queryContext);
      queryStatement.getSelectComponent().setResultColumns(resultColumns);

      // concat GROUP BY with FROM
      if (queryStatement.hasGroupByExpression()) {
        queryStatement
            .getGroupByComponent()
            .setControlColumnExpression(
                contactGroupByWithFrom(
                    queryStatement.getGroupByComponent().getControlColumnExpression(),
                    prefixPaths,
                    queryContext));
      }
      if (queryStatement.hasOrderByExpression()) {
        List<Expression> sortItemExpressions = queryStatement.getExpressionSortItemList();
        sortItemExpressions.replaceAll(
            expression -> contactOrderByWithFrom(expression, prefixPaths, queryContext));
      }
    }

    // concat WHERE with FROM
    if (queryStatement.getWhereCondition() != null) {
      ExpressionAnalyzer.constructPatternTreeFromExpression(
          queryStatement.getWhereCondition().getPredicate(), prefixPaths, patternTree);
    }

    // concat HAVING with FROM
    if (queryStatement.getHavingCondition() != null) {
      ExpressionAnalyzer.constructPatternTreeFromExpression(
          queryStatement.getHavingCondition().getPredicate(), prefixPaths, patternTree);
    }

    // only authorized paths are visible for user
    patternTree.constructTree();
    this.patternTree =
        PathPatternTreeUtils.intersectWithFullPathPrefixTree(
            patternTree, queryStatement.getAuthorityScope());
    return queryStatement;
  }
This rewriter:

<p>1. Concat prefix path in SELECT, WHERE, and WITHOUT NULL clause with the suffix path in the
FROM clause.

<p>2. Construct a {@link PathPatternTree}.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/ConcatPathRewriter.java