This is an automated email from the ASF dual-hosted git repository.

morrysnow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 18c1081659 [fix](nereids) fix some nereids bugs (#19711)
18c1081659 is described below

commit 18c1081659992a6be16f0ab4c12b29da9eb33b93
Author: starocean999 <[email protected]>
AuthorDate: Thu May 18 11:33:56 2023 +0800

    [fix](nereids) fix some nereids bugs (#19711)
    
    1. add json_unquote and json_extract functions
    2. remove mv releated code in visitPhysicalOlapScan
    3. forbid bitmap and hll type for topn node's sort exprs
    4. HashDistributionInfo of olap scan node should use the slots from output 
not the full schema
    5. SelectMaterializedIndexWithoutAggregate should use the filter node's 
output together with the predicate to get the correct mv
    6. forbid SimplifyArithmeticRule for decimal type
    7. make DecimalLiteral's type and value consistent with each other if the 
value is decimalv2
    8. json_array need support empty argument
---
 .../doris/catalog/BuiltinScalarFunctions.java      |  4 +++
 .../glue/translator/PhysicalPlanTranslator.java    | 25 -------------------
 .../nereids/rules/analysis/CheckAfterRewrite.java  |  7 ++++++
 .../expression/rules/SimplifyArithmeticRule.java   |  4 +--
 .../LogicalOlapScanToPhysicalOlapScan.java         | 11 +++++---
 .../SelectMaterializedIndexWithoutAggregate.java   |  2 +-
 .../expressions/functions/scalar/JsonArray.java    | 11 +++-----
 .../scalar/{JsonArray.java => JsonExtract.java}    | 29 +++++++++++-----------
 .../expressions/functions/scalar/JsonObject.java   | 11 +++-----
 .../scalar/{JsonArray.java => JsonUnQuote.java}    | 27 ++++++++++----------
 .../trees/expressions/literal/DecimalLiteral.java  |  3 +--
 .../expressions/visitor/ScalarFunctionVisitor.java | 10 ++++++++
 .../doris/nereids/util/TypeCoercionUtils.java      | 11 +++++---
 .../nereids_tpch_shape_sf1000_p0/shape/q17.out     |  2 +-
 .../data/nereids_tpch_shape_sf1_p0/shape/q17.out   |  2 +-
 .../data/nereids_tpch_shape_sf500_p0/shape/q17.out |  2 +-
 16 files changed, 78 insertions(+), 83 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinScalarFunctions.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinScalarFunctions.java
index e933b0fdd8..974f958779 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinScalarFunctions.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinScalarFunctions.java
@@ -159,8 +159,10 @@ import 
org.apache.doris.nereids.trees.expressions.functions.scalar.If;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.Initcap;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.Instr;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.JsonArray;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.JsonExtract;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.JsonObject;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.JsonQuote;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.JsonUnQuote;
 import 
org.apache.doris.nereids.trees.expressions.functions.scalar.JsonbExistsPath;
 import 
org.apache.doris.nereids.trees.expressions.functions.scalar.JsonbExtract;
 import 
org.apache.doris.nereids.trees.expressions.functions.scalar.JsonbExtractBigint;
@@ -492,6 +494,8 @@ public class BuiltinScalarFunctions implements 
FunctionHelper {
             scalar(JsonArray.class, "json_array"),
             scalar(JsonObject.class, "json_object"),
             scalar(JsonQuote.class, "json_quote"),
+            scalar(JsonUnQuote.class, "json_unquote"),
+            scalar(JsonExtract.class, "json_extract"),
             scalar(JsonbExistsPath.class, "jsonb_exists_path"),
             scalar(JsonbExtract.class, "jsonb_extract"),
             scalar(JsonbExtractBigint.class, "jsonb_extract_bigint"),
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java
index 1b151131db..c995e2b78d 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java
@@ -172,7 +172,6 @@ import java.util.Map;
 import java.util.Objects;
 import java.util.Optional;
 import java.util.Set;
-import java.util.function.Function;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
@@ -548,7 +547,6 @@ public class PhysicalPlanTranslator extends 
DefaultPlanVisitor<PlanFragment, Pla
         // Create OlapScanNode
         List<Slot> slotList = new ImmutableList.Builder<Slot>()
                 .addAll(olapScan.getOutput())
-                
.addAll(filterSlotsOfSelectedIndex(olapScan.getNonUserVisibleOutput(), 
olapScan))
                 .build();
         Set<ExprId> deferredMaterializedExprIds = Collections.emptySet();
         if 
(olapScan.getMutableState(PhysicalOlapScan.DEFERRED_MATERIALIZED_SLOTS).isPresent())
 {
@@ -560,20 +558,6 @@ public class PhysicalPlanTranslator extends 
DefaultPlanVisitor<PlanFragment, Pla
         if 
(olapScan.getMutableState(PhysicalOlapScan.DEFERRED_MATERIALIZED_SLOTS).isPresent())
 {
             injectRowIdColumnSlot(tupleDescriptor);
         }
-
-        // Use column with the same name in selected materialized index meta 
for slot desc,
-        // to get the correct col unique id.
-        if (olapScan.getSelectedIndexId() != olapTable.getBaseIndexId()) {
-            Map<String, Column> indexCols = 
olapTable.getSchemaByIndexId(olapScan.getSelectedIndexId())
-                    .stream()
-                    .collect(Collectors.toMap(Column::getName, 
Function.identity()));
-            tupleDescriptor.getSlots().forEach(slotDesc -> {
-                Column column = slotDesc.getColumn();
-                if (column != null && indexCols.containsKey(column.getName())) 
{
-                    slotDesc.setColumn(indexCols.get(column.getName()));
-                }
-            });
-        }
         tupleDescriptor.setTable(olapTable);
 
         OlapScanNode olapScanNode = new OlapScanNode(context.nextPlanNodeId(), 
tupleDescriptor, "OlapScanNode");
@@ -2301,15 +2285,6 @@ public class PhysicalPlanTranslator extends 
DefaultPlanVisitor<PlanFragment, Pla
         }
     }
 
-    private List<Slot> filterSlotsOfSelectedIndex(List<Slot> slots, 
PhysicalOlapScan olapScan) {
-        ImmutableSet<Column> selectIndexColumns = 
ImmutableSet.copyOf(olapScan.getTable()
-                
.getIndexIdToMeta().get(olapScan.getSelectedIndexId()).getSchema());
-        return slots.stream()
-                .filter(slot -> ((SlotReference) slot).getColumn().isPresent()
-                        && selectIndexColumns.contains(((SlotReference) 
slot).getColumn().get()))
-                .collect(ImmutableList.toImmutableList());
-    }
-
     private PlanFragment createPlanFragment(PlanNode planNode, DataPartition 
dataPartition, AbstractPlan physicalPlan) {
         PlanFragment planFragment = new PlanFragment(context.nextFragmentId(), 
planNode, dataPartition);
         updateLegacyPlanIdToPhysicalPlan(planNode, physicalPlan);
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/CheckAfterRewrite.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/CheckAfterRewrite.java
index 13426b9710..cc864990fb 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/CheckAfterRewrite.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/CheckAfterRewrite.java
@@ -31,6 +31,7 @@ import 
org.apache.doris.nereids.trees.expressions.functions.ExpressionTrait;
 import org.apache.doris.nereids.trees.plans.Plan;
 import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
 import org.apache.doris.nereids.trees.plans.logical.LogicalSort;
+import org.apache.doris.nereids.trees.plans.logical.LogicalTopN;
 
 import org.apache.commons.lang3.StringUtils;
 
@@ -104,6 +105,12 @@ public class CheckAfterRewrite extends 
OneAnalysisRuleFactory {
                             .isOnlyMetricType()))) {
                 throw new AnalysisException(Type.OnlyMetricTypeErrorMsg);
             }
+        } else if (plan instanceof LogicalTopN) {
+            if (((LogicalTopN<?>) plan).getOrderKeys().stream().anyMatch((
+                    orderKey -> orderKey.getExpr().getDataType()
+                            .isOnlyMetricType()))) {
+                throw new AnalysisException(Type.OnlyMetricTypeErrorMsg);
+            }
         }
     }
 }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyArithmeticRule.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyArithmeticRule.java
index 80b2ff4026..24f96e9105 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyArithmeticRule.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyArithmeticRule.java
@@ -81,8 +81,8 @@ public class SimplifyArithmeticRule extends 
AbstractExpressionRewriteRule {
         List<Operand> variables = Lists.newArrayList();
         List<Operand> constants = Lists.newArrayList();
 
-        // TODO currently we don't process decimalV3 for simplicity.
-        if (flattedExpressions.stream().anyMatch(operand -> 
operand.expression.getDataType().isDecimalV3Type())) {
+        // TODO currently we don't process decimal for simplicity.
+        if (flattedExpressions.stream().anyMatch(operand -> 
operand.expression.getDataType().isDecimalLikeType())) {
             return arithmetic;
         }
         // 2. move variables to left side and move constants to right sid.
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/LogicalOlapScanToPhysicalOlapScan.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/LogicalOlapScanToPhysicalOlapScan.java
index ea3e4c0530..1829e7734b 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/LogicalOlapScanToPhysicalOlapScan.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/LogicalOlapScanToPhysicalOlapScan.java
@@ -32,6 +32,7 @@ import org.apache.doris.nereids.rules.Rule;
 import org.apache.doris.nereids.rules.RuleType;
 import org.apache.doris.nereids.trees.expressions.ExprId;
 import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.expressions.SlotReference;
 import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
 import org.apache.doris.nereids.trees.plans.physical.PhysicalOlapScan;
 
@@ -74,16 +75,18 @@ public class LogicalOlapScanToPhysicalOlapScan extends 
OneImplementationRuleFact
         boolean isSelectUnpartition = olapTable.getPartitionInfo().getType() 
== PartitionType.UNPARTITIONED
                 || olapScan.getSelectedPartitionIds().size() == 1;
         if (isBelongStableCG || isSelectUnpartition) {
-            if (!(distributionInfo instanceof HashDistributionInfo)) {
+            if (!(distributionInfo instanceof HashDistributionInfo)
+                    || olapScan.getSelectedIndexId() != 
olapScan.getTable().getBaseIndexId()) {
+                // TODO if a mv is selected, we ignore base table's 
distributionInfo for now
+                // need improve this to handle the case if mv's 
distributionInfo is the same as base table
                 return DistributionSpecAny.INSTANCE;
             }
             HashDistributionInfo hashDistributionInfo = (HashDistributionInfo) 
distributionInfo;
             List<Slot> output = olapScan.getOutput();
             List<ExprId> hashColumns = Lists.newArrayList();
-            List<Column> schemaColumns = olapScan.getTable().getFullSchema();
-            for (int i = 0; i < schemaColumns.size(); i++) {
+            for (int i = 0; i < output.size(); i++) {
                 for (Column column : 
hashDistributionInfo.getDistributionColumns()) {
-                    if (schemaColumns.get(i).equals(column)) {
+                    if (((SlotReference) 
output.get(i)).getColumn().get().equals(column)) {
                         hashColumns.add(output.get(i).getExprId());
                     }
                 }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/mv/SelectMaterializedIndexWithoutAggregate.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/mv/SelectMaterializedIndexWithoutAggregate.java
index 41bf87c09d..012fb01534 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/mv/SelectMaterializedIndexWithoutAggregate.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/mv/SelectMaterializedIndexWithoutAggregate.java
@@ -86,7 +86,7 @@ public class SelectMaterializedIndexWithoutAggregate extends 
AbstractSelectMater
                 logicalFilter(logicalOlapScan().when(this::shouldSelectIndex))
                         .then(filter -> {
                             LogicalOlapScan scan = filter.child();
-                            return filter.withChildren(select(scan, 
ImmutableSet::of, filter::getConjuncts));
+                            return filter.withChildren(select(scan, 
filter::getOutputSet, filter::getConjuncts));
                         })
                         .toRule(RuleType.MATERIALIZED_INDEX_FILTER_SCAN),
 
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/JsonArray.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/JsonArray.java
index d4cb92d206..51d8d4f4e6 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/JsonArray.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/JsonArray.java
@@ -25,7 +25,6 @@ import 
org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
 import org.apache.doris.nereids.types.VarcharType;
 import org.apache.doris.nereids.util.ExpressionUtils;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 
 import java.util.List;
@@ -41,10 +40,10 @@ public class JsonArray extends ScalarFunction
     );
 
     /**
-     * constructor with 1 or more arguments.
+     * constructor with 0 or more arguments.
      */
-    public JsonArray(Expression arg, Expression... varArgs) {
-        super("json_array", ExpressionUtils.mergeArguments(arg, varArgs));
+    public JsonArray(Expression... varArgs) {
+        super("json_array", ExpressionUtils.mergeArguments(varArgs));
     }
 
     /**
@@ -52,9 +51,7 @@ public class JsonArray extends ScalarFunction
      */
     @Override
     public JsonArray withChildren(List<Expression> children) {
-        Preconditions.checkArgument(children.size() >= 1);
-        return new JsonArray(children.get(0),
-                children.subList(1, children.size()).toArray(new 
Expression[0]));
+        return new JsonArray(children.toArray(new Expression[0]));
     }
 
     @Override
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/JsonArray.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/JsonExtract.java
similarity index 64%
copy from 
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/JsonArray.java
copy to 
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/JsonExtract.java
index d4cb92d206..12d1c22a13 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/JsonArray.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/JsonExtract.java
@@ -19,8 +19,8 @@ package 
org.apache.doris.nereids.trees.expressions.functions.scalar;
 
 import org.apache.doris.catalog.FunctionSignature;
 import org.apache.doris.nereids.trees.expressions.Expression;
-import org.apache.doris.nereids.trees.expressions.functions.AlwaysNotNullable;
 import 
org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
+import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable;
 import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
 import org.apache.doris.nereids.types.VarcharType;
 import org.apache.doris.nereids.util.ExpressionUtils;
@@ -31,30 +31,30 @@ import com.google.common.collect.ImmutableList;
 import java.util.List;
 
 /**
- * ScalarFunction 'json_array'. This class is generated by GenerateFunction.
+ * ScalarFunction 'json_object'. This class is generated by GenerateFunction.
  */
-public class JsonArray extends ScalarFunction
-        implements ExplicitlyCastableSignature, AlwaysNotNullable {
+public class JsonExtract extends ScalarFunction
+        implements ExplicitlyCastableSignature, PropagateNullable {
 
-    public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
-            
FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT).varArgs(VarcharType.SYSTEM_DEFAULT)
-    );
+    public static final List<FunctionSignature> SIGNATURES =
+            ImmutableList.of(FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT)
+                    .varArgs(VarcharType.SYSTEM_DEFAULT, 
VarcharType.SYSTEM_DEFAULT));
 
     /**
      * constructor with 1 or more arguments.
      */
-    public JsonArray(Expression arg, Expression... varArgs) {
-        super("json_array", ExpressionUtils.mergeArguments(arg, varArgs));
+    public JsonExtract(Expression arg0, Expression arg1, Expression... 
varArgs) {
+        super("json_extract", ExpressionUtils.mergeArguments(arg0, arg1, 
varArgs));
     }
 
     /**
      * withChildren.
      */
     @Override
-    public JsonArray withChildren(List<Expression> children) {
-        Preconditions.checkArgument(children.size() >= 1);
-        return new JsonArray(children.get(0),
-                children.subList(1, children.size()).toArray(new 
Expression[0]));
+    public JsonExtract withChildren(List<Expression> children) {
+        Preconditions.checkArgument(children.size() >= 2);
+        return new JsonExtract(children.get(0), children.get(1),
+                children.subList(2, children.size()).toArray(new 
Expression[0]));
     }
 
     @Override
@@ -64,6 +64,7 @@ public class JsonArray extends ScalarFunction
 
     @Override
     public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
-        return visitor.visitJsonArray(this, context);
+        return visitor.visitJsonExtract(this, context);
     }
 }
+
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/JsonObject.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/JsonObject.java
index 9e54c98386..e1e2c961ef 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/JsonObject.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/JsonObject.java
@@ -26,7 +26,6 @@ import 
org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
 import org.apache.doris.nereids.types.VarcharType;
 import org.apache.doris.nereids.util.ExpressionUtils;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 
 import java.util.List;
@@ -42,10 +41,10 @@ public class JsonObject extends ScalarFunction
     );
 
     /**
-     * constructor with 1 or more arguments.
+     * constructor with 0 or more arguments.
      */
-    public JsonObject(Expression arg, Expression... varArgs) {
-        super("json_object", ExpressionUtils.mergeArguments(arg, varArgs));
+    public JsonObject(Expression... varArgs) {
+        super("json_object", ExpressionUtils.mergeArguments(varArgs));
     }
 
     @Override
@@ -62,9 +61,7 @@ public class JsonObject extends ScalarFunction
      */
     @Override
     public JsonObject withChildren(List<Expression> children) {
-        Preconditions.checkArgument(children.size() >= 1);
-        return new JsonObject(children.get(0),
-                children.subList(1, children.size()).toArray(new 
Expression[0]));
+        return new JsonObject(children.toArray(new Expression[0]));
     }
 
     @Override
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/JsonArray.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/JsonUnQuote.java
similarity index 67%
copy from 
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/JsonArray.java
copy to 
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/JsonUnQuote.java
index d4cb92d206..a169c6f540 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/JsonArray.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/JsonUnQuote.java
@@ -19,11 +19,11 @@ package 
org.apache.doris.nereids.trees.expressions.functions.scalar;
 
 import org.apache.doris.catalog.FunctionSignature;
 import org.apache.doris.nereids.trees.expressions.Expression;
-import org.apache.doris.nereids.trees.expressions.functions.AlwaysNotNullable;
+import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable;
 import 
org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
+import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression;
 import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
 import org.apache.doris.nereids.types.VarcharType;
-import org.apache.doris.nereids.util.ExpressionUtils;
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
@@ -31,30 +31,29 @@ import com.google.common.collect.ImmutableList;
 import java.util.List;
 
 /**
- * ScalarFunction 'json_array'. This class is generated by GenerateFunction.
+ * ScalarFunction 'json_unquote'. This class is generated by GenerateFunction.
  */
-public class JsonArray extends ScalarFunction
-        implements ExplicitlyCastableSignature, AlwaysNotNullable {
+public class JsonUnQuote extends ScalarFunction
+        implements UnaryExpression, ExplicitlyCastableSignature, 
AlwaysNullable {
 
     public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
-            
FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT).varArgs(VarcharType.SYSTEM_DEFAULT)
+            
FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT).args(VarcharType.SYSTEM_DEFAULT)
     );
 
     /**
-     * constructor with 1 or more arguments.
+     * constructor with 1 argument.
      */
-    public JsonArray(Expression arg, Expression... varArgs) {
-        super("json_array", ExpressionUtils.mergeArguments(arg, varArgs));
+    public JsonUnQuote(Expression arg) {
+        super("json_unquote", arg);
     }
 
     /**
      * withChildren.
      */
     @Override
-    public JsonArray withChildren(List<Expression> children) {
-        Preconditions.checkArgument(children.size() >= 1);
-        return new JsonArray(children.get(0),
-                children.subList(1, children.size()).toArray(new 
Expression[0]));
+    public JsonUnQuote withChildren(List<Expression> children) {
+        Preconditions.checkArgument(children.size() == 1);
+        return new JsonUnQuote(children.get(0));
     }
 
     @Override
@@ -64,6 +63,6 @@ public class JsonArray extends ScalarFunction
 
     @Override
     public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
-        return visitor.visitJsonArray(this, context);
+        return visitor.visitJsonUnQuote(this, context);
     }
 }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DecimalLiteral.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DecimalLiteral.java
index 43ab839fad..10a97a71ed 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DecimalLiteral.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DecimalLiteral.java
@@ -33,8 +33,7 @@ public class DecimalLiteral extends Literal {
     private final BigDecimal value;
 
     public DecimalLiteral(BigDecimal value) {
-        super(DecimalV2Type.createDecimalV2Type(value));
-        this.value = Objects.requireNonNull(value);
+        this(DecimalV2Type.createDecimalV2Type(value), value);
     }
 
     public DecimalLiteral(DecimalV2Type dataType, BigDecimal value) {
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/ScalarFunctionVisitor.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/ScalarFunctionVisitor.java
index 7eb28b1e08..4b48fdc5c5 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/ScalarFunctionVisitor.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/ScalarFunctionVisitor.java
@@ -160,8 +160,10 @@ import 
org.apache.doris.nereids.trees.expressions.functions.scalar.If;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.Initcap;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.Instr;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.JsonArray;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.JsonExtract;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.JsonObject;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.JsonQuote;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.JsonUnQuote;
 import 
org.apache.doris.nereids.trees.expressions.functions.scalar.JsonbExistsPath;
 import 
org.apache.doris.nereids.trees.expressions.functions.scalar.JsonbExtract;
 import 
org.apache.doris.nereids.trees.expressions.functions.scalar.JsonbExtractBigint;
@@ -943,10 +945,18 @@ public interface ScalarFunctionVisitor<R, C> {
         return visitScalarFunction(jsonObject, context);
     }
 
+    default R visitJsonExtract(JsonExtract jsonExtract, C context) {
+        return visitScalarFunction(jsonExtract, context);
+    }
+
     default R visitJsonQuote(JsonQuote jsonQuote, C context) {
         return visitScalarFunction(jsonQuote, context);
     }
 
+    default R visitJsonUnQuote(JsonUnQuote jsonUnQuote, C context) {
+        return visitScalarFunction(jsonUnQuote, context);
+    }
+
     default R visitJsonbExistsPath(JsonbExistsPath jsonbExistsPath, C context) 
{
         return visitScalarFunction(jsonbExistsPath, context);
     }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java
index 2d8ca9475b..c919d7116b 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java
@@ -1169,14 +1169,17 @@ public class TypeCoercionUtils {
                         throw new AnalysisException(function.getName() + " key 
can't be NULL: " + function.toSql());
                     }
                     // Not to return NULL directly, so save string, but flag 
is '0'
-                    newArguments.add(new 
org.apache.doris.nereids.trees.expressions.literal.StringLiteral("NULL"));
+                    newArguments.add(new StringLiteral("NULL"));
                 } else {
                     newArguments.add(argument);
                 }
             }
-            // add json type string to the last
-            newArguments.add(new 
org.apache.doris.nereids.trees.expressions.literal.StringLiteral(
-                    jsonTypeStr.toString()));
+            if (arguments.isEmpty()) {
+                newArguments.add(new StringLiteral(""));
+            } else {
+                // add json type string to the last
+                newArguments.add(new StringLiteral(jsonTypeStr.toString()));
+            }
             return (BoundFunction) function.withChildren(newArguments);
         } catch (Throwable t) {
             throw new AnalysisException(t.getMessage());
diff --git a/regression-test/data/nereids_tpch_shape_sf1000_p0/shape/q17.out 
b/regression-test/data/nereids_tpch_shape_sf1000_p0/shape/q17.out
index 833dd1a625..7bab135966 100644
--- a/regression-test/data/nereids_tpch_shape_sf1000_p0/shape/q17.out
+++ b/regression-test/data/nereids_tpch_shape_sf1000_p0/shape/q17.out
@@ -5,7 +5,7 @@ PhysicalProject
 ----PhysicalDistribute
 ------hashAgg[LOCAL]
 --------PhysicalProject
-----------filter((cast(l_quantity as DECIMAL(27, 9)) < (avg(l_quantity) 
OVER(PARTITION BY p_partkey) * 0.200000000)))
+----------filter((cast(l_quantity as DECIMAL(27, 9)) < (0.200000000 * 
avg(l_quantity) OVER(PARTITION BY p_partkey))))
 ------------PhysicalWindow
 --------------PhysicalQuickSort
 ----------------PhysicalDistribute
diff --git a/regression-test/data/nereids_tpch_shape_sf1_p0/shape/q17.out 
b/regression-test/data/nereids_tpch_shape_sf1_p0/shape/q17.out
index 833dd1a625..7bab135966 100644
--- a/regression-test/data/nereids_tpch_shape_sf1_p0/shape/q17.out
+++ b/regression-test/data/nereids_tpch_shape_sf1_p0/shape/q17.out
@@ -5,7 +5,7 @@ PhysicalProject
 ----PhysicalDistribute
 ------hashAgg[LOCAL]
 --------PhysicalProject
-----------filter((cast(l_quantity as DECIMAL(27, 9)) < (avg(l_quantity) 
OVER(PARTITION BY p_partkey) * 0.200000000)))
+----------filter((cast(l_quantity as DECIMAL(27, 9)) < (0.200000000 * 
avg(l_quantity) OVER(PARTITION BY p_partkey))))
 ------------PhysicalWindow
 --------------PhysicalQuickSort
 ----------------PhysicalDistribute
diff --git a/regression-test/data/nereids_tpch_shape_sf500_p0/shape/q17.out 
b/regression-test/data/nereids_tpch_shape_sf500_p0/shape/q17.out
index 833dd1a625..7bab135966 100644
--- a/regression-test/data/nereids_tpch_shape_sf500_p0/shape/q17.out
+++ b/regression-test/data/nereids_tpch_shape_sf500_p0/shape/q17.out
@@ -5,7 +5,7 @@ PhysicalProject
 ----PhysicalDistribute
 ------hashAgg[LOCAL]
 --------PhysicalProject
-----------filter((cast(l_quantity as DECIMAL(27, 9)) < (avg(l_quantity) 
OVER(PARTITION BY p_partkey) * 0.200000000)))
+----------filter((cast(l_quantity as DECIMAL(27, 9)) < (0.200000000 * 
avg(l_quantity) OVER(PARTITION BY p_partkey))))
 ------------PhysicalWindow
 --------------PhysicalQuickSort
 ----------------PhysicalDistribute


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

Reply via email to