[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.
This commit is contained in:
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@ -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(),
|
||||
|
||||
@ -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 = "";
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user