Skip to content

Commit 8064617

Browse files
authored
[opt](Nereids) remove Nondeterministic trait from date related functions (#26444)
1 parent b7c81bc commit 8064617

9 files changed

Lines changed: 38 additions & 43 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/analysis/ExpressionFunctions.java‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,8 @@ public enum ExpressionFunctions {
5252
private static final Logger LOG = LogManager.getLogger(ExpressionFunctions.class);
5353
private ImmutableMultimap<String, FEFunctionInvoker> functions;
5454
public static final Set<String> unfixedFn = ImmutableSet.of(
55-
"now",
56-
"current_time",
57-
"current_date",
58-
"utc_timestamp",
5955
"uuid",
60-
"random",
61-
"unix_timestamp"
56+
"random"
6257
);
6358

6459
private ExpressionFunctions() {

‎fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/Nondeterministic.java‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,11 @@
1717

1818
package org.apache.doris.nereids.trees.expressions.functions;
1919

20-
import org.apache.doris.qe.ConnectContext;
21-
2220
/**
2321
* Nondeterministic functions.
2422
*
2523
* e.g. 'rand()', 'random()'.
2624
*
2725
*/
2826
public interface Nondeterministic extends ExpressionTrait {
29-
@Override
30-
default boolean foldable() {
31-
return ConnectContext.get() == null
32-
|| ConnectContext.get().getSessionVariable() == null
33-
|| ConnectContext.get().getSessionVariable().isEnableFoldNondeterministicFn();
34-
}
3527
}

‎fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeAcquire.java‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,19 @@ public static Expression currentDate() {
8686
return DateLiteral.fromJavaDateType(LocalDateTime.now(DateUtils.getTimeZone()));
8787
}
8888

89-
/**
90-
* date acquire function: current_time
91-
*/
92-
@ExecFunction(name = "curtime", argTypes = {}, returnType = "DATETIME")
93-
public static Expression curTime() {
94-
return DateTimeLiteral.fromJavaDateType(LocalDateTime.now(DateUtils.getTimeZone()));
95-
}
89+
// comment these function temporally until we support TimeLiteral
90+
// /**
91+
// * date acquire function: current_time
92+
// */
93+
// @ExecFunction(name = "curtime", argTypes = {}, returnType = "TIME")
94+
// public static Expression curTime() {
95+
// return DateTimeLiteral.fromJavaDateType(LocalDateTime.now(DateUtils.getTimeZone()));
96+
// }
9697

97-
@ExecFunction(name = "current_time", argTypes = {}, returnType = "DATETIME")
98-
public static Expression currentTime() {
99-
return DateTimeLiteral.fromJavaDateType(LocalDateTime.now(DateUtils.getTimeZone()));
100-
}
98+
// @ExecFunction(name = "current_time", argTypes = {}, returnType = "TIME")
99+
// public static Expression currentTime() {
100+
// return DateTimeLiteral.fromJavaDateType(LocalDateTime.now(DateUtils.getTimeZone()));
101+
// }
101102

102103
/**
103104
* date transformation function: unix_timestamp

‎fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Random.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ public boolean nullable() {
7070
}
7171
}
7272

73+
@Override
74+
public boolean foldable() {
75+
return false;
76+
}
77+
7378
/**
7479
* withChildren.
7580
*/

‎fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/UnixTimestamp.java‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
* ScalarFunction 'unix_timestamp'. This class is generated by GenerateFunction.
4141
*/
4242
public class UnixTimestamp extends ScalarFunction
43-
implements Nondeterministic, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args {
43+
implements ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Nondeterministic {
4444

4545
private static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
4646
FunctionSignature.ret(IntegerType.INSTANCE).args(),
@@ -101,14 +101,6 @@ public UnixTimestamp withChildren(List<Expression> children) {
101101
}
102102
}
103103

104-
@Override
105-
public boolean foldable() {
106-
if (children.size() != 0) {
107-
return true;
108-
}
109-
return Nondeterministic.super.foldable();
110-
}
111-
112104
@Override
113105
public List<FunctionSignature> getSignatures() {
114106
return SIGNATURES;

‎fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Uuid.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ public Uuid() {
4646
super("uuid");
4747
}
4848

49+
@Override
50+
public boolean foldable() {
51+
return false;
52+
}
53+
4954
@Override
5055
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
5156
return visitor.visitUuid(this, context);

‎fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/UuidNumeric.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ public UuidNumeric() {
4646
super("uuid_numeric");
4747
}
4848

49+
@Override
50+
public boolean foldable() {
51+
return false;
52+
}
53+
4954
@Override
5055
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
5156
return visitor.visitUuidNumeric(this, context);

‎fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/PlanVisitorTest.java‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import org.apache.doris.catalog.TableIf.TableType;
2222
import org.apache.doris.nereids.trees.TreeNode;
2323
import org.apache.doris.nereids.trees.expressions.Expression;
24-
import org.apache.doris.nereids.trees.expressions.functions.scalar.CurrentDate;
25-
import org.apache.doris.nereids.trees.expressions.functions.scalar.Now;
24+
import org.apache.doris.nereids.trees.expressions.functions.scalar.Random;
25+
import org.apache.doris.nereids.trees.expressions.functions.scalar.Uuid;
2626
import org.apache.doris.nereids.trees.plans.physical.PhysicalPlan;
2727
import org.apache.doris.nereids.trees.plans.visitor.NondeterministicFunctionCollector;
2828
import org.apache.doris.nereids.trees.plans.visitor.TableCollector;
@@ -76,15 +76,15 @@ protected void runBeforeAll() throws Exception {
7676
+ "\"replication_num\" = \"1\"\n"
7777
+ ");");
7878

79-
createView("CREATE VIEW `view1` AS SELECT t1.*, current_date() FROM\n"
79+
createView("CREATE VIEW `view1` AS SELECT t1.*, random() FROM\n"
8080
+ "`table1` t1 LEFT JOIN\n"
8181
+ "`table2` t2 ON t1.c1 = t2.c1;");
8282
}
8383

8484
@Test
8585
public void test1() {
8686
PlanChecker.from(connectContext)
87-
.checkPlannerResult("SELECT *, now() FROM table1 "
87+
.checkPlannerResult("SELECT *, random() FROM table1 "
8888
+ "LEFT SEMI JOIN table2 ON table1.c1 = table2.c1 "
8989
+ "WHERE table1.c1 IN (SELECT c1 FROM table2) OR table1.c1 < 10",
9090
nereidsPlanner -> {
@@ -93,7 +93,7 @@ public void test1() {
9393
// Check nondeterministic collect
9494
physicalPlan.accept(NondeterministicFunctionCollector.INSTANCE, collectResult);
9595
Assertions.assertEquals(1, collectResult.size());
96-
Assertions.assertTrue(collectResult.get(0) instanceof Now);
96+
Assertions.assertTrue(collectResult.get(0) instanceof Random);
9797
// Check get tables
9898
TableCollectorContext collectorContext =
9999
new TableCollector.TableCollectorContext(Sets.newHashSet(TableType.OLAP));
@@ -114,7 +114,7 @@ public void test1() {
114114
@Test
115115
public void test2() {
116116
PlanChecker.from(connectContext)
117-
.checkPlannerResult("SELECT view1.*, now() FROM view1 "
117+
.checkPlannerResult("SELECT view1.*, uuid() FROM view1 "
118118
+ "LEFT SEMI JOIN table2 ON view1.c1 = table2.c1 "
119119
+ "WHERE view1.c1 IN (SELECT c1 FROM table2) OR view1.c1 < 10",
120120
nereidsPlanner -> {
@@ -123,8 +123,8 @@ public void test2() {
123123
// Check nondeterministic collect
124124
physicalPlan.accept(NondeterministicFunctionCollector.INSTANCE, collectResult);
125125
Assertions.assertEquals(2, collectResult.size());
126-
Assertions.assertTrue(collectResult.get(0) instanceof Now);
127-
Assertions.assertTrue(collectResult.get(1) instanceof CurrentDate);
126+
Assertions.assertTrue(collectResult.get(0) instanceof Uuid);
127+
Assertions.assertTrue(collectResult.get(1) instanceof Random);
128128
// Check get tables
129129
TableCollectorContext collectorContext =
130130
new TableCollector.TableCollectorContext(Sets.newHashSet(TableType.OLAP));

‎regression-test/suites/nereids_p0/datatype/test_date_acquire.groovy‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ suite("test_date_acquire") {
2020
sql 'set enable_fallback_to_original_planner=false'
2121
sql 'set enable_fold_nondeterministic_fn=true'
2222

23-
String res = sql 'explain select now(), now(3), curdate(), current_date(), curtime(), current_time(), current_timestamp(), current_timestamp(3)'
23+
String res = sql 'explain select now(), now(3), curdate(), current_date(), current_timestamp(), current_timestamp(3)'
2424
res = res.split('VUNION')[1]
2525
assertFalse(res.contains("()") || res.contains("(3)"))
2626

0 commit comments

Comments
 (0)