private Map<Symbol, Symbol> mappingFromAssignments(
        Map<Symbol, Expression> assignments, boolean ambiguousSymbolsPresent) {
      Map<Symbol, Symbol> newMapping = new HashMap<>();
      Map<Expression, Symbol> inputsToOutputs = new HashMap<>();
      for (Map.Entry<Symbol, Expression> assignment : assignments.entrySet()) {
        Expression expression = assignment.getValue();
        // 1. for trivial symbol projection, map output symbol to input symbol
        // If the assignment potentially introduces a reused (ambiguous) symbol, do not map output
        // to input
        // to avoid mixing semantics. Input symbols represent semantics as in the source plan,
        // while output symbols represent newly established semantics.
        if (expression instanceof SymbolReference && !ambiguousSymbolsPresent) {
          Symbol value = Symbol.from(expression);
          if (!assignment.getKey().equals(value)) {
            newMapping.put(assignment.getKey(), value);
          }
        }
        // 2. map same deterministic expressions within a projection into the same symbol
        // omit NullLiterals since those have ambiguous types
        else if (DeterminismEvaluator.isDeterministic(expression)
            && !(expression instanceof NullLiteral)) {
          Symbol previous = inputsToOutputs.get(expression);
          if (previous == null) {
            inputsToOutputs.put(expression, assignment.getKey());
          } else {
            newMapping.put(assignment.getKey(), previous);
          }
        }
      }
      return newMapping;
    }
Replace all symbols in the plan with new symbols. The returned plan has different output than
the original plan. Also, the order of symbols might change during symbol replacement. Symbols
in the list `fields` are replaced maintaining the order so they might be used to match original
symbols with their replacements. Replacing symbols helps avoid collisions when symbols or parts
of the plan are reused.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/optimizations/UnaliasSymbolReferences.java