Skip to content

Commit

Permalink
[opt](Nereids) remove Nondeterministic trait from date related functi…
Browse files Browse the repository at this point in the history
…ons (#26444)
  • Loading branch information
morrySnow committed Nov 8, 2023
1 parent 2842d05 commit 88aee9b
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,8 @@ public enum ExpressionFunctions {
private static final Logger LOG = LogManager.getLogger(ExpressionFunctions.class);
private ImmutableMultimap<String, FEFunctionInvoker> functions;
public static final Set<String> unfixedFn = ImmutableSet.of(
"now",
"current_time",
"current_date",
"utc_timestamp",
"uuid",
"random",
"unix_timestamp"
"random"
);

private ExpressionFunctions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,11 @@

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

import org.apache.doris.qe.ConnectContext;

/**
* Nondeterministic functions.
*
* e.g. 'rand()', 'random()'.
*
*/
public interface Nondeterministic extends ExpressionTrait {
@Override
default boolean foldable() {
return ConnectContext.get() == null
|| ConnectContext.get().getSessionVariable() == null
|| ConnectContext.get().getSessionVariable().isEnableFoldNondeterministicFn();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,19 @@ public static Expression currentDate() {
return DateLiteral.fromJavaDateType(LocalDateTime.now(DateUtils.getTimeZone()));
}

/**
* date acquire function: current_time
*/
@ExecFunction(name = "curtime", argTypes = {}, returnType = "DATETIME")
public static Expression curTime() {
return DateTimeLiteral.fromJavaDateType(LocalDateTime.now(DateUtils.getTimeZone()));
}
// comment these function temporally until we support TimeLiteral
// /**
// * date acquire function: current_time
// */
// @ExecFunction(name = "curtime", argTypes = {}, returnType = "TIME")
// public static Expression curTime() {
// return DateTimeLiteral.fromJavaDateType(LocalDateTime.now(DateUtils.getTimeZone()));
// }

@ExecFunction(name = "current_time", argTypes = {}, returnType = "DATETIME")
public static Expression currentTime() {
return DateTimeLiteral.fromJavaDateType(LocalDateTime.now(DateUtils.getTimeZone()));
}
// @ExecFunction(name = "current_time", argTypes = {}, returnType = "TIME")
// public static Expression currentTime() {
// return DateTimeLiteral.fromJavaDateType(LocalDateTime.now(DateUtils.getTimeZone()));
// }

/**
* date transformation function: unix_timestamp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public boolean nullable() {
}
}

@Override
public boolean foldable() {
return false;
}

/**
* withChildren.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* ScalarFunction 'unix_timestamp'. This class is generated by GenerateFunction.
*/
public class UnixTimestamp extends ScalarFunction
implements Nondeterministic, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args {
implements ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Nondeterministic {

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

@Override
public boolean foldable() {
if (children.size() != 0) {
return true;
}
return Nondeterministic.super.foldable();
}

@Override
public List<FunctionSignature> getSignatures() {
return SIGNATURES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public Uuid() {
super("uuid");
}

@Override
public boolean foldable() {
return false;
}

@Override
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
return visitor.visitUuid(this, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public UuidNumeric() {
super("uuid_numeric");
}

@Override
public boolean foldable() {
return false;
}

@Override
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
return visitor.visitUuidNumeric(this, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ suite("test_date_acquire") {
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)'
String res = sql 'explain select now(), now(3), curdate(), current_date(), current_timestamp(), current_timestamp(3)'
res = res.split('VUNION')[1]
assertFalse(res.contains("()") || res.contains("(3)"))

Expand Down

0 comments on commit 88aee9b

Please sign in to comment.