morrySnow commented on code in PR #38680:
URL: https://github.com/apache/doris/pull/38680#discussion_r1699544183


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java:
##########
@@ -633,7 +639,31 @@ private Plan 
bindProject(MatchingContext<LogicalProject<Plan>> ctx) {
                 if (!excepts.isEmpty()) {
                     slots = Utils.filterImmutableList(slots, slot -> 
!boundExcepts.get().contains(slot));
                 }
-                boundProjections.addAll(slots);
+                if (!replaces.isEmpty()) {
+                    final Map<String, NamedExpression> replaceMap = new 
HashMap<>();
+                    final Set<String> replaced = new HashSet<>();
+                    for (NamedExpression replace : boundReplaces.get()) {
+                        Preconditions.checkArgument(replace instanceof Alias);
+                        Alias alias = (Alias) replace;
+                        replaceMap.put(alias.getName(), alias);
+                    }
+
+                    for (Slot slot : slots) {
+                        if (replaceMap.containsKey(slot.getName())) {

Review Comment:
   what will happen if query like `select * replace ('123' as c1) from t, t t2` 
when t has columns `c1`?
   i think we should thrown exception same as `select c1 from t, t t2`;
   
   so the better way to do it may be we should use alias name as UnboundSlot, 
and use them to bind with project's child's output. and then we use 
`org.apache.doris.nereids.util.ExpressionUtils#replace` to replace project list.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -3009,10 +3012,23 @@ protected LogicalPlan withSelectQuerySpecification(
                         throw new ParseException("only column name is 
supported in except clause", selectColumnCtx);
                     }
                     UnboundStar star = new UnboundStar(ImmutableList.of());
-                    project = new LogicalProject<>(ImmutableList.of(star), 
expressions, isDistinct, aggregate);
+                    project = new LogicalProject<>(
+                            ImmutableList.of(star), expressions, 
ImmutableList.of(), isDistinct, aggregate);
+                } else if (selectColumnCtx.REPLACE() != null) {

Review Comment:
   `else if` not a good way. if we support use expect + replace, we should use 
`if`. if we do not support use them togather, we should throw exception.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalProject.java:
##########


Review Comment:
   update hashCode, equals and toString



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to