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 7d1e08eafa [Fix](Nereids) rand() and uuid() should not fold constant 
(#22492)
7d1e08eafa is described below

commit 7d1e08eafabcd04aca80c8d6c5827b86ef9795e0
Author: mch_ucchi <41606806+sohardforan...@users.noreply.github.com>
AuthorDate: Fri Aug 4 15:36:03 2023 +0800

    [Fix](Nereids) rand() and uuid() should not fold constant (#22492)
    
    rand() and uuid() should not fold constant and we change the default value 
of fold constant for non-deterministic function to false.
---
 .../functions/executable/ExecutableFunctions.java      | 18 ------------------
 .../trees/expressions/functions/scalar/Random.java     |  3 ++-
 .../main/java/org/apache/doris/qe/SessionVariable.java |  2 +-
 .../java/org/apache/doris/planner/QueryPlanTest.java   |  2 +-
 .../nereids_p0/datatype/test_date_acquire.groovy       |  1 +
 .../fold_constant/fold_constant_by_fe.groovy           |  4 ++++
 6 files changed, 9 insertions(+), 21 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/ExecutableFunctions.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/ExecutableFunctions.java
index d50a314222..abed55a1ff 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/ExecutableFunctions.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/ExecutableFunctions.java
@@ -31,15 +31,12 @@ import 
org.apache.doris.nereids.trees.expressions.literal.TinyIntLiteral;
 import org.apache.doris.nereids.trees.expressions.literal.VarcharLiteral;
 
 import java.math.BigInteger;
-import java.util.Random;
-import java.util.UUID;
 
 /**
  * functions that can be executed in FE.
  */
 public class ExecutableFunctions {
     public static final ExecutableFunctions INSTANCE = new 
ExecutableFunctions();
-    private static final Random RANDOM = new Random();
 
     /**
      * other scalar function
@@ -112,19 +109,4 @@ public class ExecutableFunctions {
     public static Expression pi() {
         return new DoubleLiteral(Math.PI);
     }
-
-    @ExecFunction(name = "uuid", argTypes = {}, returnType = "VARCHAR")
-    public static Expression uuid() {
-        return new VarcharLiteral(UUID.randomUUID().toString());
-    }
-
-    @ExecFunction(name = "rand", argTypes = {}, returnType = "DOUBLE")
-    public static Expression rand() {
-        return new DoubleLiteral(RANDOM.nextDouble());
-    }
-
-    @ExecFunction(name = "random", argTypes = {}, returnType = "DOUBLE")
-    public static Expression random() {
-        return new DoubleLiteral(RANDOM.nextDouble());
-    }
 }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Random.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Random.java
index 17d40baf98..04b669d843 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Random.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Random.java
@@ -20,6 +20,7 @@ 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.ExplicitlyCastableSignature;
+import org.apache.doris.nereids.trees.expressions.functions.Nondeterministic;
 import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
 import org.apache.doris.nereids.types.BigIntType;
 import org.apache.doris.nereids.types.DoubleType;
@@ -33,7 +34,7 @@ import java.util.List;
  * ScalarFunction 'random'. This class is generated by GenerateFunction.
  */
 public class Random extends ScalarFunction
-        implements ExplicitlyCastableSignature {
+        implements ExplicitlyCastableSignature, Nondeterministic {
 
     public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
             FunctionSignature.ret(DoubleType.INSTANCE).args(),
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
index 18e8333ea6..151b570478 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
@@ -1000,7 +1000,7 @@ public class SessionVariable implements Serializable, 
Writable {
     public boolean enableMinidump = false;
 
     @VariableMgr.VarAttr(name = ENABLE_FOLD_NONDETERMINISTIC_FN)
-    public boolean enableFoldNondeterministicFn = true;
+    public boolean enableFoldNondeterministicFn = false;
 
     @VariableMgr.VarAttr(name = MINIDUMP_PATH)
     public String minidumpPath = "";
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java
index 4b00fa303b..93b6c5b407 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java
@@ -856,7 +856,7 @@ public class QueryPlanTest extends TestWithFeService {
                 + "from test.test1 "
                 + "where time_col = case when date_format(now(),'%H%i')  < 123 
then date_format(date_sub("
                 + "now(),2),'%Y%m%d') else 
date_format(date_sub(now(),1),'%Y%m%d') end";
-        
Assert.assertFalse(StringUtils.containsIgnoreCase(getSQLPlanOrErrorMsg("explain 
" + caseWhenSql),
+        
Assert.assertTrue(StringUtils.containsIgnoreCase(getSQLPlanOrErrorMsg("explain 
" + caseWhenSql),
                 "CASE WHEN"));
 
         // test 1: case when then
diff --git 
a/regression-test/suites/nereids_p0/datatype/test_date_acquire.groovy 
b/regression-test/suites/nereids_p0/datatype/test_date_acquire.groovy
index f78752a33f..b6afad759d 100644
--- a/regression-test/suites/nereids_p0/datatype/test_date_acquire.groovy
+++ b/regression-test/suites/nereids_p0/datatype/test_date_acquire.groovy
@@ -18,6 +18,7 @@
 suite("test_date_acquire") {
     sql 'set enable_nereids_planner=true'
     sql 'set enable_fallback_to_original_planner=false'
+    sql 'set enable_fold_nondeterministic_fn=true'
 
     String res = sql 'explain select now(), now(3), curdate(), current_date(), 
curtime(), current_time(), current_timestamp(), current_timestamp(3)'
     res = res.split('VUNION')[1]
diff --git 
a/regression-test/suites/nereids_p0/fold_constant/fold_constant_by_fe.groovy 
b/regression-test/suites/nereids_p0/fold_constant/fold_constant_by_fe.groovy
index 10f1931372..fbd4d1a326 100644
--- a/regression-test/suites/nereids_p0/fold_constant/fold_constant_by_fe.groovy
+++ b/regression-test/suites/nereids_p0/fold_constant/fold_constant_by_fe.groovy
@@ -18,6 +18,10 @@
 suite("test_fold_constant_by_fe") {
     sql 'set enable_nereids_planner=true'
     sql 'set enable_fallback_to_original_planner=false'
+    sql 'set enable_fold_nondeterministic_fn=true'
+
+    def results = sql 'select uuid(), uuid()'
+    assertFalse(Objects.equals(results[0][0], results[0][1]))
 
     def test_date = [
             "2021-04-12", "1969-12-31", "1356-12-12", "0001-01-01", 
"9998-12-31",


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

Reply via email to