class_docstr: Simplify queries by eliminating sub-queries when possible by rewriting expressions.
  
   Expressions in the SELECT, GROUP BY, and WHERE are can be rewritten.
  
  e.g. from
  
  SELECT b.col0 AS foo
  FROM (
    SELECT SUM(a.col0) AS bar
    FROM table0 a
  ) b
  GROUP BY b.col0
  
  to
  
  SELECT SUM(a.col0) AS foo
  FROM table0 a
  GROUP BY foo
code: def optimize(
      self, node: SqlQueryPlanNode
  ) -> SqlQueryPlanNode:  # noqa: D
      result = node.accept(SqlRewritingSubQueryReducerVisitor())
      if self._use_column_alias_in_group_bys:
          return result.accept(SqlGroupByRewritingVisitor())
      return result
  
imports: from __future__ import annotations
  import logging
  from dataclasses import dataclass
  from typing import List, Optional, Sequence, Tuple
  from metricflow.sql.optimizer.sql_query_plan_optimizer import SqlQueryPlanOptimizer
  from metricflow.sql.sql_exprs import SqlColumnAliasReferenceExpression, SqlColumnReference, SqlColumnReplacements, SqlExpressionNode, SqlExpressionTreeLineage, SqlLogicalExpression, SqlLogicalOperator
  from metricflow.sql.sql_plan import SqlJoinDescription, SqlOrderByDescription, SqlQueryPlanNode, SqlQueryPlanNodeVisitor, SqlSelectColumn, SqlSelectQueryFromClauseNode, SqlSelectStatementNode, SqlTableFromClauseNode
label_desc: Use image node_id 2 for calling the SqlRewritingSubQueryReducer obj's underlying member method code with example usage: obj.optimize(node) and returns: result, result