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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/util/Utils.java:
##########
@@ -128,6 +128,21 @@ public static String qualifiedName(List<String> qualifier, 
String name) {
         return StringUtils.join(qualifiedNameParts(qualifier, name), ".");
     }
 
+    /** get qualified name with Backtick */
+    public static String qualifiedNameWithBacktick(List<String> qualifiers, 
String name) {
+        List<String> fullName = new ArrayList<>(qualifiers);
+        fullName.add(name);
+        return qualifiedNameWithBacktick(fullName);
+    }
+
+    public static String qualifiedNameWithBacktick(List<String> qualifiers) {
+        List<String> qualifierWithBacktick = 
Lists.newArrayListWithCapacity(qualifiers.size());
+        for (String qualifier : qualifiers) {
+            qualifierWithBacktick.add('`' + qualifier + '`');

Review Comment:
   do we need do escape? think about name with back quote
   ```
   `ab``c`
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/RuleType.java:
##########
@@ -421,7 +421,6 @@ public enum RuleType {
     LOGICAL_GENERATE_TO_PHYSICAL_GENERATE(RuleTypeClass.IMPLEMENTATION),
     LOGICAL_WINDOW_TO_PHYSICAL_WINDOW_RULE(RuleTypeClass.IMPLEMENTATION),
     IMPLEMENTATION_SENTINEL(RuleTypeClass.IMPLEMENTATION),
-

Review Comment:
   revert this change



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundRelation.java:
##########
@@ -55,35 +56,44 @@ public class UnboundRelation extends LogicalRelation 
implements Unbound, BlockFu
     private final Optional<TableSample> tableSample;
     private final Optional<String> indexName;
     private TableScanParams scanParams;
+    // the start and end position of the sql substring(e.g. "t1", "db1.t1", 
"ctl1.db1.t1")
+    private Pair<Integer, Integer> indexInSqlString;

Review Comment:
   still need this mutable variable? could make it unmutable?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java:
##########
@@ -581,6 +583,10 @@ private Plan 
bindProject(MatchingContext<LogicalProject<Plan>> ctx) {
                     slots = Utils.filterImmutableList(slots, slot -> 
!boundExcepts.get().contains(slot));
                 }
                 boundProjections.addAll(slots);
+                UnboundStar unboundStar = (UnboundStar) expression;
+                if (unboundStar.getIndexInSqlString() != null) {

Review Comment:
   maybe it is better to make `IndexInSqlString` in `UnboundStar` as 
`Optional<...>` and use `Optional#map` here



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java:
##########
@@ -239,6 +241,11 @@ private LogicalPlan makeOlapScan(TableIf table, 
UnboundRelation unboundRelation,
 
     private LogicalPlan getLogicalPlan(TableIf table, UnboundRelation 
unboundRelation,
                                                List<String> tableQualifier, 
CascadesContext cascadesContext) {
+        if (unboundRelation.getIndexInSqlString() != null) {

Review Comment:
   maybe it is better to use Optional#map
   BTW: add some comment to explain what this if for?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/util/Utils.java:
##########
@@ -128,6 +128,21 @@ public static String qualifiedName(List<String> qualifier, 
String name) {
         return StringUtils.join(qualifiedNameParts(qualifier, name), ".");
     }
 
+    /** get qualified name with Backtick */
+    public static String qualifiedNameWithBacktick(List<String> qualifiers, 
String name) {
+        List<String> fullName = new ArrayList<>(qualifiers);
+        fullName.add(name);
+        return qualifiedNameWithBacktick(fullName);
+    }
+
+    public static String qualifiedNameWithBacktick(List<String> qualifiers) {

Review Comment:
   backtick -> back quote



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateViewInfo.java:
##########
@@ -0,0 +1,327 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.trees.plans.commands.info;
+
+import org.apache.doris.analysis.ColWithComment;
+import org.apache.doris.analysis.CreateViewStmt;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.common.ErrorCode;
+import org.apache.doris.common.ErrorReport;
+import org.apache.doris.common.FeNameFormat;
+import org.apache.doris.common.Pair;
+import org.apache.doris.common.UserException;
+import org.apache.doris.common.util.Util;
+import org.apache.doris.mysql.privilege.PrivPredicate;
+import org.apache.doris.nereids.CascadesContext;
+import org.apache.doris.nereids.DorisParser;
+import org.apache.doris.nereids.DorisParser.NamedExpressionContext;
+import org.apache.doris.nereids.DorisParser.NamedExpressionSeqContext;
+import org.apache.doris.nereids.DorisParserBaseVisitor;
+import org.apache.doris.nereids.NereidsPlanner;
+import org.apache.doris.nereids.StatementContext;
+import org.apache.doris.nereids.analyzer.UnboundResultSink;
+import org.apache.doris.nereids.exceptions.AnalysisException;
+import org.apache.doris.nereids.jobs.executor.AbstractBatchJobExecutor;
+import org.apache.doris.nereids.jobs.rewrite.RewriteJob;
+import org.apache.doris.nereids.parser.NereidsParser;
+import org.apache.doris.nereids.properties.PhysicalProperties;
+import org.apache.doris.nereids.rules.analysis.AnalyzeCTE;
+import org.apache.doris.nereids.rules.analysis.BindExpression;
+import org.apache.doris.nereids.rules.analysis.BindRelation;
+import org.apache.doris.nereids.rules.analysis.CheckPolicy;
+import org.apache.doris.nereids.rules.analysis.EliminateLogicalSelectHint;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.plans.Plan;
+import 
org.apache.doris.nereids.trees.plans.commands.ExplainCommand.ExplainLevel;
+import org.apache.doris.nereids.trees.plans.logical.LogicalCTEAnchor;
+import org.apache.doris.nereids.trees.plans.logical.LogicalCTEProducer;
+import org.apache.doris.nereids.trees.plans.logical.LogicalFileSink;
+import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
+import org.apache.doris.nereids.trees.plans.visitor.DefaultPlanVisitor;
+import org.apache.doris.qe.ConnectContext;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+import org.antlr.v4.runtime.ParserRuleContext;
+import org.antlr.v4.runtime.tree.ParseTree;
+import org.antlr.v4.runtime.tree.RuleNode;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * CreateViewInfo
+ */
+public class CreateViewInfo {
+    private final boolean ifNotExists;
+    private final TableNameInfo viewName;
+    private final String comment;
+    private final LogicalPlan logicalQuery;
+    private final String querySql;
+    private final List<SimpleColumnDefinition> simpleColumnDefinitions;
+    private final List<Column> finalCols = Lists.newArrayList();
+    private final List<Slot> outputs = Lists.newArrayList();

Review Comment:
   outputs could be a local var?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundStar.java:
##########
@@ -33,14 +34,21 @@
  * Star expression.
  */
 public class UnboundStar extends NamedExpression implements LeafExpression, 
Unbound, PropagateNullable {
-
     private final List<String> qualifier;
+    // the start and end position of the sql substring(e.g. "*", "table.*")
+    private Pair<Integer, Integer> indexInSqlString;

Review Comment:
   ditto



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateViewInfo.java:
##########
@@ -0,0 +1,327 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.trees.plans.commands.info;
+
+import org.apache.doris.analysis.ColWithComment;
+import org.apache.doris.analysis.CreateViewStmt;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.common.ErrorCode;
+import org.apache.doris.common.ErrorReport;
+import org.apache.doris.common.FeNameFormat;
+import org.apache.doris.common.Pair;
+import org.apache.doris.common.UserException;
+import org.apache.doris.common.util.Util;
+import org.apache.doris.mysql.privilege.PrivPredicate;
+import org.apache.doris.nereids.CascadesContext;
+import org.apache.doris.nereids.DorisParser;
+import org.apache.doris.nereids.DorisParser.NamedExpressionContext;
+import org.apache.doris.nereids.DorisParser.NamedExpressionSeqContext;
+import org.apache.doris.nereids.DorisParserBaseVisitor;
+import org.apache.doris.nereids.NereidsPlanner;
+import org.apache.doris.nereids.StatementContext;
+import org.apache.doris.nereids.analyzer.UnboundResultSink;
+import org.apache.doris.nereids.exceptions.AnalysisException;
+import org.apache.doris.nereids.jobs.executor.AbstractBatchJobExecutor;
+import org.apache.doris.nereids.jobs.rewrite.RewriteJob;
+import org.apache.doris.nereids.parser.NereidsParser;
+import org.apache.doris.nereids.properties.PhysicalProperties;
+import org.apache.doris.nereids.rules.analysis.AnalyzeCTE;
+import org.apache.doris.nereids.rules.analysis.BindExpression;
+import org.apache.doris.nereids.rules.analysis.BindRelation;
+import org.apache.doris.nereids.rules.analysis.CheckPolicy;
+import org.apache.doris.nereids.rules.analysis.EliminateLogicalSelectHint;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.plans.Plan;
+import 
org.apache.doris.nereids.trees.plans.commands.ExplainCommand.ExplainLevel;
+import org.apache.doris.nereids.trees.plans.logical.LogicalCTEAnchor;
+import org.apache.doris.nereids.trees.plans.logical.LogicalCTEProducer;
+import org.apache.doris.nereids.trees.plans.logical.LogicalFileSink;
+import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
+import org.apache.doris.nereids.trees.plans.visitor.DefaultPlanVisitor;
+import org.apache.doris.qe.ConnectContext;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+import org.antlr.v4.runtime.ParserRuleContext;
+import org.antlr.v4.runtime.tree.ParseTree;
+import org.antlr.v4.runtime.tree.RuleNode;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * CreateViewInfo
+ */
+public class CreateViewInfo {
+    private final boolean ifNotExists;
+    private final TableNameInfo viewName;
+    private final String comment;
+    private final LogicalPlan logicalQuery;
+    private final String querySql;
+    private final List<SimpleColumnDefinition> simpleColumnDefinitions;
+    private final List<Column> finalCols = Lists.newArrayList();
+    private final List<Slot> outputs = Lists.newArrayList();
+    private Plan analyzedPlan;
+
+    /** constructor*/
+    public CreateViewInfo(boolean ifNotExists, TableNameInfo viewName, String 
comment, LogicalPlan logicalQuery,
+            String querySql, List<SimpleColumnDefinition> 
simpleColumnDefinitions) {
+        this.ifNotExists = ifNotExists;
+        this.viewName = viewName;
+        this.comment = comment;
+        if (logicalQuery instanceof LogicalFileSink) {
+            throw new AnalysisException("Not support OUTFILE clause in CREATE 
VIEW statement");
+        }
+        this.logicalQuery = logicalQuery;
+        this.querySql = querySql;
+        this.simpleColumnDefinitions = simpleColumnDefinitions;
+    }
+
+    /** init */
+    public void init(ConnectContext ctx) throws UserException {
+        analyzeAndFillRewriteSqlMap(querySql, ctx);
+        OutermostPlanFinder outermostPlanFinder = new OutermostPlanFinder();

Review Comment:
   could we use Singleton instance?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/SimpleColumnDefinition.java:
##########
@@ -39,4 +41,8 @@ public String getName() {
     public String getComment() {
         return comment;
     }
+
+    public ColWithComment transferToColWithComment() {

Review Comment:
   translateTo?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to