xiaokang commented on code in PR #30348:
URL: https://github.com/apache/doris/pull/30348#discussion_r1467200195


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/types/VariantType.java:
##########
@@ -0,0 +1,83 @@
+// 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.types;
+
+import org.apache.doris.catalog.Type;
+import org.apache.doris.nereids.annotation.Developing;
+import org.apache.doris.nereids.types.coercion.PrimitiveType;
+
+import java.util.Objects;
+
+/**
+ * Variant type in Nereids.
+ * Why Variant is not complex type? Since it's nested structure is not 
pre-defined, then using
+ * primitive type will be easy to handle meta info in FE.
+ */
+@Developing
+public class VariantType extends PrimitiveType {
+
+    public static final VariantType INSTANCE = new VariantType();
+
+    public static final int WIDTH = 24;
+
+    @Override
+    public Type toCatalogDataType() {
+        return Type.VARIANT;
+    }
+
+    @Override
+    public boolean acceptsType(DataType other) {
+        return other instanceof VariantType;
+    }
+
+    @Override
+    public String simpleString() {
+        return "map";

Review Comment:
   variant



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/types/VariantType.java:
##########
@@ -0,0 +1,83 @@
+// 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.types;
+
+import org.apache.doris.catalog.Type;
+import org.apache.doris.nereids.annotation.Developing;
+import org.apache.doris.nereids.types.coercion.PrimitiveType;
+
+import java.util.Objects;
+
+/**
+ * Variant type in Nereids.
+ * Why Variant is not complex type? Since it's nested structure is not 
pre-defined, then using
+ * primitive type will be easy to handle meta info in FE.
+ */
+@Developing
+public class VariantType extends PrimitiveType {
+
+    public static final VariantType INSTANCE = new VariantType();
+
+    public static final int WIDTH = 24;

Review Comment:
   add comment for 24



##########
regression-test/suites/variant_p0/load.groovy:
##########
@@ -15,7 +15,7 @@
 // specific language governing permissions and limitations
 // under the License.
 
-suite("regression_test_variant", "variant_type"){
+suite("regression_test_variant", "nonConcurrent"){

Review Comment:
   why nonConcurrent



##########
regression-test/suites/variant_p0/column_name.groovy:
##########
@@ -28,19 +28,21 @@ suite("regression_test_variant_column_name", 
"variant_type"){
         properties("replication_num" = "1", "disable_auto_compaction" = 
"true");
     """ 
 
+    // sql "set experimental_enable_nereids_planner = false"
+
     sql """insert into ${table_name} values (1, '{"中文" : "中文", 
"\\\u4E2C\\\u6587": "unicode"}')"""
     qt_sql """select v:中文, v:`\\\u4E2C\\\u6587` from ${table_name}"""

Review Comment:
   change all v:



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/ExpressionTranslator.java:
##########
@@ -194,12 +197,29 @@ private OlapTable getOlapTableDirectly(SlotRef left) {
         return null;
     }
 
+    @Override
+    public Expr visitElementAt(ElementAt elementAt, PlanTranslatorContext 
context) {
+        if (PushDownToProjectionFunction.validToPushDown(elementAt)) {
+            if (ConnectContext.get() != null
+                    && ConnectContext.get().getSessionVariable() != null
+                    && 
!ConnectContext.get().getSessionVariable().isEnableRewriteElementAtToSlot()) {
+                throw new AnalysisException(
+                        "set enable_rewrite_element_at_to_slot=true when using 
element_at function for variant type");
+            }
+            SlotReference rewrittenSlot = (SlotReference) 
context.getConnectContext()
+                    
.getStatementContext().getRewrittenSlotRefByOriginalExpr(elementAt);
+            Preconditions.checkNotNull(rewrittenSlot);
+            return context.findSlotRef(rewrittenSlot.getExprId());
+        }
+        return visitScalarFunction(elementAt, context);
+    }
+
     @Override
     public Expr visitMatch(Match match, PlanTranslatorContext context) {
         String invertedIndexParser = 
InvertedIndexUtil.INVERTED_INDEX_PARSER_UNKNOWN;
         String invertedIndexParserMode = 
InvertedIndexUtil.INVERTED_INDEX_PARSER_COARSE_GRANULARITY;
         Map<String, String> invertedIndexCharFilter = new HashMap<>();
-        SlotRef left = (SlotRef) match.left().accept(this, context);
+        SlotRef left = (SlotRef) 
match.left().getInputSlots().stream().findFirst().get().accept(this, context);

Review Comment:
   add comment



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/StatementContext.java:
##########
@@ -149,6 +166,62 @@ public int getMaxContinuousJoin() {
         return joinCount;
     }
 
+    public Set<SlotReference> getAllPathsSlots() {
+        Set<SlotReference> allSlotReferences = Sets.newHashSet();
+        for (Map<List<String>, SlotReference> slotReferenceMap : 
subColumnSlotRefMap.values()) {
+            allSlotReferences.addAll(slotReferenceMap.values());
+        }
+        return allSlotReferences;
+    }
+
+    public Expression getOriginalExpr(SlotReference rewriteSlot) {
+        return subColumnOriginalExprMap.getOrDefault(rewriteSlot, null);
+    }
+
+    public Slot getRewrittenSlotRefByOriginalExpr(Expression originalExpr) {
+        return originalExprToRewrittenSubColumn.getOrDefault(originalExpr, 
null);
+    }
+
+    /**
+     * Add a slot ref attached with paths in context to avoid duplicated slot
+     */
+    public void addPathSlotRef(Slot root, List<String> paths, SlotReference 
slotRef, Expression originalExpr) {
+        Comparator<List<String>> pathsComparator = new 
Comparator<List<String>>() {

Review Comment:
   do not new Comparator every time.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/RuleType.java:
##########
@@ -49,8 +49,11 @@ public enum RuleType {
     BINDING_UNBOUND_TVF_RELATION_FUNCTION(RuleTypeClass.REWRITE),
     BINDING_SET_OPERATION_SLOT(RuleTypeClass.REWRITE),
     BINDING_INLINE_TABLE_SLOT(RuleTypeClass.REWRITE),
-
     COUNT_LITERAL_REWRITE(RuleTypeClass.REWRITE),
+    BINDING_SLOT_WITH_PATHS_PROJECT(RuleTypeClass.REWRITE),

Review Comment:
   why not place them just after other BINDING_*



-- 
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