From c1bd5b26a842dddc03c9c87735b6677cde74ffdc Mon Sep 17 00:00:00 2001 From: morrySnow <101034200+morrySnow@users.noreply.github.com> Date: Thu, 23 Mar 2023 23:05:15 +0800 Subject: [PATCH] [refactor](Nereids) expression translate no long rely on legacy planner code (#17671) --- .../apache/doris/analysis/AnalyticExpr.java | 4 - .../apache/doris/analysis/ArithmeticExpr.java | 5 - .../doris/analysis/BetweenPredicate.java | 5 - .../doris/analysis/BinaryPredicate.java | 19 +- .../org/apache/doris/analysis/CaseExpr.java | 17 +- .../org/apache/doris/analysis/CastExpr.java | 20 +- .../doris/analysis/CompoundPredicate.java | 5 - .../doris/analysis/DefaultValueExpr.java | 5 - .../java/org/apache/doris/analysis/Expr.java | 15 - .../doris/analysis/FunctionCallExpr.java | 20 - .../apache/doris/analysis/InPredicate.java | 52 +- .../doris/analysis/IsNullPredicate.java | 26 +- .../apache/doris/analysis/LiteralExpr.java | 5 - .../org/apache/doris/analysis/Predicate.java | 5 - .../org/apache/doris/analysis/SlotRef.java | 5 - .../analysis/TimestampArithmeticExpr.java | 52 +- .../doris/analysis/TupleIsNullPredicate.java | 5 - .../glue/translator/ExpressionTranslator.java | 77 +- .../translator/PhysicalPlanTranslator.java | 9 +- .../translator/RuntimeFilterTranslator.java | 11 +- .../trees/expressions/InPredicate.java | 12 +- .../nereids/trees/expressions/IsNull.java | 8 +- .../trees/expressions/NullSafeEqual.java | 9 +- .../expressions/TimestampArithmetic.java | 4 - .../test_timestamp_arithmetic.out | 703 ++++++++++++++++++ .../test_timestamp_arithmetic.sql | 50 ++ 26 files changed, 887 insertions(+), 261 deletions(-) create mode 100644 regression-test/data/nereids_function_p0/test_timestamp_arithmetic.out create mode 100644 regression-test/suites/nereids_function_p0/test_timestamp_arithmetic.sql diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/AnalyticExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/AnalyticExpr.java index 0796f5deed..e2397cdc83 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AnalyticExpr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AnalyticExpr.java @@ -1002,8 +1002,4 @@ public class AnalyticExpr extends Expr { } return Joiner.on(", ").join(strings); } - - @Override - public void finalizeImplForNereids() throws AnalysisException { - } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/ArithmeticExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/ArithmeticExpr.java index 60a3774401..4b3c252418 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ArithmeticExpr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ArithmeticExpr.java @@ -756,11 +756,6 @@ public class ArithmeticExpr extends Expr { } } - @Override - public void finalizeImplForNereids() throws AnalysisException { - - } - @Override public void write(DataOutput out) throws IOException { Text.writeString(out, op.name()); diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/BetweenPredicate.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/BetweenPredicate.java index 72d2ef6471..4f24e7fdf0 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/BetweenPredicate.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/BetweenPredicate.java @@ -119,9 +119,4 @@ public class BetweenPredicate extends Predicate { public int hashCode() { return 31 * super.hashCode() + Boolean.hashCode(isNotBetween); } - - @Override - public void finalizeImplForNereids() throws AnalysisException { - throw new AnalysisException("analyze between predicate for Nereids do not implementation."); - } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/BinaryPredicate.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/BinaryPredicate.java index c0bff0c759..0d4e4d2d61 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/BinaryPredicate.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/BinaryPredicate.java @@ -21,6 +21,7 @@ package org.apache.doris.analysis; import org.apache.doris.catalog.Function; +import org.apache.doris.catalog.Function.NullableMode; import org.apache.doris.catalog.FunctionSet; import org.apache.doris.catalog.PrimitiveType; import org.apache.doris.catalog.ScalarFunction; @@ -168,6 +169,18 @@ public class BinaryPredicate extends Predicate implements Writable { children.add(e2); } + public BinaryPredicate(Operator op, Expr e1, Expr e2, Type retType, NullableMode nullableMode) { + super(); + this.op = op; + this.opcode = op.opcode; + Preconditions.checkNotNull(e1); + children.add(e1); + Preconditions.checkNotNull(e2); + children.add(e2); + fn = new Function(new FunctionName(op.name), Lists.newArrayList(e1.getType(), e2.getType()), retType, + false, true, nullableMode); + } + protected BinaryPredicate(BinaryPredicate other) { super(other); op = other.op; @@ -779,10 +792,4 @@ public class BinaryPredicate extends Predicate implements Writable { } return hasNullableChild(); } - - @Override - public void finalizeImplForNereids() throws AnalysisException { - super.finalizeImplForNereids(); - fn = getBuiltinFunction(op.name, collectChildReturnTypes(), Function.CompareMode.IS_NONSTRICT_SUPERTYPE_OF); - } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/CaseExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/CaseExpr.java index 80e5d87ed9..fb6414a1e2 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/CaseExpr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CaseExpr.java @@ -88,6 +88,16 @@ public class CaseExpr extends Expr { } } + /** + * use for Nereids ONLY + */ + public CaseExpr(List whenClauses, Expr elseExpr) { + this(null, whenClauses, elseExpr); + // nereids do not have CaseExpr, and nereids will unify the types, + // so just use the first then type + type = children.get(1).getType(); + } + protected CaseExpr(CaseExpr other) { super(other); hasCaseExpr = other.hasCaseExpr; @@ -428,11 +438,4 @@ public class CaseExpr extends Expr { } return false; } - - @Override - public void finalizeImplForNereids() throws AnalysisException { - // nereids do not have CaseExpr, and nereids will unify the types, - // so just use the first then type - type = children.get(1).getType(); - } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java index c6a6073c35..c1b1ee1fa2 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java @@ -114,13 +114,20 @@ public class CastExpr extends Expr { * Just use for nereids, put analyze() in finalizeImplForNereids */ public CastExpr(Type targetType, Expr e, Void v) { - super(); Preconditions.checkArgument(targetType.isValid()); Preconditions.checkNotNull(e); type = targetType; targetTypeDef = null; isImplicit = true; children.add(e); + try { + analyze(); + } catch (AnalysisException ex) { + LOG.warn("Implicit casts fail", ex); + Preconditions.checkState(false, + "Implicit casts should never throw analysis exception."); + } + analysisDone(); } /** @@ -572,17 +579,6 @@ public class CastExpr extends Expr { || (!children.get(0).getType().isDateType() && getType().isDateType()); } - @Override - public void finalizeImplForNereids() throws AnalysisException { - try { - analyze(); - } catch (AnalysisException ex) { - LOG.warn("Implicit casts fail", ex); - Preconditions.checkState(false, - "Implicit casts should never throw analysis exception."); - } - } - @Override public String getStringValueForArray() { return children.get(0).getStringValueForArray(); diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/CompoundPredicate.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/CompoundPredicate.java index eca6aa564b..d711114db4 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/CompoundPredicate.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CompoundPredicate.java @@ -273,11 +273,6 @@ public class CompoundPredicate extends Predicate { return hasNullableChild(); } - @Override - public void finalizeImplForNereids() throws AnalysisException { - - } - @Override public String toString() { return toSqlImpl(); diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/DefaultValueExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/DefaultValueExpr.java index 01ed882a2c..4552e6f84f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/DefaultValueExpr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/DefaultValueExpr.java @@ -40,9 +40,4 @@ public class DefaultValueExpr extends Expr { public Expr clone() { return null; } - - @Override - public void finalizeImplForNereids() throws AnalysisException { - - } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java index 71022ad81e..a28e0cc7f7 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java @@ -2154,21 +2154,6 @@ public abstract class Expr extends TreeNode implements ParseNode, Cloneabl return true; } - public final void finalizeForNereids() throws AnalysisException { - if (isAnalyzed()) { - return; - } - for (Expr child : children) { - child.finalizeForNereids(); - } - finalizeImplForNereids(); - analysisDone(); - } - - public void finalizeImplForNereids() throws AnalysisException { - throw new AnalysisException("analyze for Nereids do not implementation."); - } - public void materializeSrcExpr() { if (this instanceof SlotRef) { SlotRef thisRef = (SlotRef) this; diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java index f538e85cc6..3cd23d5af9 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java @@ -1857,26 +1857,6 @@ public class FunctionCallExpr extends Expr { return result.toString(); } - public void finalizeImplForNereids() throws AnalysisException { - - } - - private List getArgTypesForNereids() { - if (argTypesForNereids.isPresent()) { - return argTypesForNereids.get(); - } else { - return Lists.newArrayList(collectChildReturnTypes()); - } - } - - /** - * NOTICE: This function only used for Nereids, should not call it if u don't - * know what it is mean. - */ - public void setMergeForNereids(boolean isMergeAggFn) { - this.isMergeAggFn = isMergeAggFn; - } - public List getOrderByElements() { return orderByElements; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/InPredicate.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/InPredicate.java index e041549ab7..2608c060d5 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/InPredicate.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/InPredicate.java @@ -21,6 +21,7 @@ package org.apache.doris.analysis; import org.apache.doris.catalog.Function; +import org.apache.doris.catalog.Function.NullableMode; import org.apache.doris.catalog.FunctionSet; import org.apache.doris.catalog.PrimitiveType; import org.apache.doris.catalog.ScalarFunction; @@ -100,6 +101,22 @@ public class InPredicate extends Predicate { this.isNotIn = isNotIn; } + /** + * use for Nereids ONLY + */ + public InPredicate(Expr compareExpr, List inList, boolean isNotIn, boolean allConstant) { + this(compareExpr, inList, isNotIn); + type = Type.BOOLEAN; + if (allConstant) { + opcode = isNotIn ? TExprOpcode.FILTER_NOT_IN : TExprOpcode.FILTER_IN; + } else { + opcode = isNotIn ? TExprOpcode.FILTER_NEW_NOT_IN : TExprOpcode.FILTER_NEW_IN; + fn = new Function(new FunctionName(isNotIn ? NOT_IN_ITERATE : IN_ITERATE), + Lists.newArrayList(getChild(0).getType(), getChild(1).getType()), Type.BOOLEAN, + true, true, NullableMode.DEPEND_ON_ARGUMENT); + } + } + protected InPredicate(InPredicate other) { super(other); isNotIn = other.isNotIn(); @@ -331,39 +348,4 @@ public class InPredicate extends Predicate { public boolean isNullable() { return hasNullableChild(); } - - @Override - public void finalizeImplForNereids() throws AnalysisException { - super.finalizeImplForNereids(); - boolean allConstant = true; - for (int i = 1; i < children.size(); ++i) { - if (!children.get(i).isConstant()) { - allConstant = false; - break; - } - } - // Only lookup fn_ if all subqueries have been rewritten. If the second child is a - // subquery, it will have type ArrayType, which cannot be resolved to a builtin - // function and will fail analysis. - Type[] argTypes = {getChild(0).type, getChild(1).type}; - if (allConstant) { - // fn = getBuiltinFunction(analyzer, isNotIn ? NOT_IN_SET_LOOKUP : IN_SET_LOOKUP, - // argTypes, Function.CompareMode.IS_NONSTRICT_SUPERTYPE_OF); - opcode = isNotIn ? TExprOpcode.FILTER_NOT_IN : TExprOpcode.FILTER_IN; - // Todo: need to implement completely type cast compatibility, like castAllToCompatibleType(); - Type compatibleType = getChild(0).getType(); - for (int i = 1; i < children.size(); ++i) { - compatibleType = Type.getCmpType(compatibleType, getChild(i).getType()); - } - for (int i = 0; i < children.size(); ++i) { - if (!getChild(i).getType().equals(compatibleType)) { - getChild(i).setType(compatibleType); - } - } - } else { - fn = getBuiltinFunction(isNotIn ? NOT_IN_ITERATE : IN_ITERATE, - argTypes, Function.CompareMode.IS_NONSTRICT_SUPERTYPE_OF); - opcode = isNotIn ? TExprOpcode.FILTER_NEW_NOT_IN : TExprOpcode.FILTER_NEW_IN; - } - } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/IsNullPredicate.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/IsNullPredicate.java index 55b732a79c..64367c56ce 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/IsNullPredicate.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/IsNullPredicate.java @@ -33,11 +33,8 @@ import org.apache.doris.thrift.TExprNodeType; import com.google.common.base.Preconditions; import com.google.common.collect.Lists; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; public class IsNullPredicate extends Predicate { - private static final Logger LOG = LogManager.getLogger(IsNullPredicate.class); private static final String IS_NULL = "is_null_pred"; private static final String IS_NOT_NULL = "is_not_null_pred"; @@ -87,10 +84,22 @@ public class IsNullPredicate extends Predicate { private final boolean isNotNull; public IsNullPredicate(Expr e, boolean isNotNull) { + this(e, isNotNull, false); + } + + /** + * use for Nereids ONLY + */ + public IsNullPredicate(Expr e, boolean isNotNull, boolean isNereids) { super(); this.isNotNull = isNotNull; Preconditions.checkNotNull(e); children.add(e); + if (isNereids) { + fn = new Function(new FunctionName(isNotNull ? IS_NOT_NULL : IS_NULL), + Lists.newArrayList(e.getType()), Type.BOOLEAN, false, true, NullableMode.ALWAYS_NOT_NULLABLE); + Preconditions.checkState(fn != null, "tupleisNull fn == NULL"); + } } protected IsNullPredicate(IsNullPredicate other) { @@ -174,15 +183,4 @@ public class IsNullPredicate extends Predicate { } return childValue instanceof NullLiteral ? new BoolLiteral(!isNotNull) : new BoolLiteral(isNotNull); } - - @Override - public void finalizeImplForNereids() throws AnalysisException { - super.finalizeImplForNereids(); - if (isNotNull) { - fn = getBuiltinFunction(IS_NOT_NULL, collectChildReturnTypes(), Function.CompareMode.IS_INDISTINGUISHABLE); - } else { - fn = getBuiltinFunction(IS_NULL, collectChildReturnTypes(), Function.CompareMode.IS_INDISTINGUISHABLE); - } - Preconditions.checkState(fn != null, "tupleisNull fn == NULL"); - } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/LiteralExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/LiteralExpr.java index b4bd824388..1b39cf094f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/LiteralExpr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/LiteralExpr.java @@ -260,11 +260,6 @@ public abstract class LiteralExpr extends Expr implements Comparable getEqSlots() { return null; } - - @Override - public void finalizeImplForNereids() throws AnalysisException { - type = Type.BOOLEAN; - } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotRef.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotRef.java index 95e8c0038e..90cb11f576 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotRef.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotRef.java @@ -526,11 +526,6 @@ public class SlotRef extends Expr { return desc.getIsNullable(); } - @Override - public void finalizeImplForNereids() throws AnalysisException { - - } - @Override public String toString() { StringBuilder builder = new StringBuilder(); diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/TimestampArithmeticExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/TimestampArithmeticExpr.java index 971fa2f762..a36ddb7600 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/TimestampArithmeticExpr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/TimestampArithmeticExpr.java @@ -19,6 +19,7 @@ package org.apache.doris.analysis; import org.apache.doris.analysis.ArithmeticExpr.Operator; import org.apache.doris.catalog.Function; +import org.apache.doris.catalog.Function.NullableMode; import org.apache.doris.catalog.PrimitiveType; import org.apache.doris.catalog.ScalarType; import org.apache.doris.catalog.Type; @@ -31,7 +32,7 @@ import org.apache.doris.thrift.TExprNodeType; import org.apache.doris.thrift.TExprOpcode; import com.google.common.base.Preconditions; -import org.apache.commons.lang3.StringUtils; +import com.google.common.collect.Lists; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -46,7 +47,7 @@ import java.util.Map; */ public class TimestampArithmeticExpr extends Expr { private static final Logger LOG = LogManager.getLogger(TimestampArithmeticExpr.class); - private static Map TIME_UNITS_MAP = new HashMap(); + private static final Map TIME_UNITS_MAP = new HashMap(); static { for (TimeUnit timeUnit : TimeUnit.values()) { @@ -97,40 +98,24 @@ public class TimestampArithmeticExpr extends Expr { * @param timeUnitIdent interval time unit, could be 'year', 'month', 'day', 'hour', 'minute', 'second'. * @param dataType the return data type of this expression. */ - public TimestampArithmeticExpr(String funcName, Expr e1, Expr e2, String timeUnitIdent, Type dataType) { + public TimestampArithmeticExpr(String funcName, ArithmeticExpr.Operator op, + Expr e1, Expr e2, String timeUnitIdent, Type dataType, NullableMode nullableMode) { this.funcName = funcName; this.timeUnitIdent = timeUnitIdent; this.timeUnit = TIME_UNITS_MAP.get(timeUnitIdent.toUpperCase(Locale.ROOT)); + this.op = op; this.intervalFirst = false; children.add(e1); children.add(e2); this.type = dataType; - } + fn = new Function(new FunctionName(funcName.toLowerCase(Locale.ROOT)), + Lists.newArrayList(e1.getType(), e2.getType()), dataType, false, true, nullableMode); + try { + opcode = getOpCode(); + } catch (AnalysisException e) { + throw new RuntimeException(e); + } - /** - * used for Nereids ONLY. - * C'tor for non-function-call like arithmetic, e.g., 'a + interval b year'. - * e1 always refers to the timestamp to be added/subtracted from, and e2 - * to the time value (even in the interval-first case). - * - * @param op operator of this function either ADD or SUBTRACT. - * @param e1 non interval literal child of this function - * @param e2 interval literal child of this function - * @param timeUnitIdent interval time unit, could be 'year', 'month', 'day', 'hour', 'minute', 'second'. - * @param intervalFirst true if the left child is interval literal - * @param dataType the return data type of this expression. - */ - public TimestampArithmeticExpr(ArithmeticExpr.Operator op, Expr e1, Expr e2, - String timeUnitIdent, boolean intervalFirst, Type dataType) { - Preconditions.checkState(op == Operator.ADD || op == Operator.SUBTRACT); - this.funcName = null; - this.op = op; - this.timeUnitIdent = timeUnitIdent; - this.timeUnit = TIME_UNITS_MAP.get(timeUnitIdent.toUpperCase(Locale.ROOT)); - this.intervalFirst = intervalFirst; - children.add(e1); - children.add(e2); - this.type = dataType; } protected TimestampArithmeticExpr(TimestampArithmeticExpr other) { @@ -475,15 +460,4 @@ public class TimestampArithmeticExpr extends Expr { return description; } } - - @Override - public void finalizeImplForNereids() throws AnalysisException { - if (StringUtils.isEmpty(funcName)) { - throw new AnalysisException("function name is null"); - } - timeUnit = TIME_UNITS_MAP.get(timeUnitIdent.toUpperCase()); - opcode = getOpCode(); - fn = getBuiltinFunction(funcName.toLowerCase(), collectChildReturnTypes(), - Function.CompareMode.IS_NONSTRICT_SUPERTYPE_OF); - } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/TupleIsNullPredicate.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/TupleIsNullPredicate.java index 2f6c0955d3..203f0629c8 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/TupleIsNullPredicate.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/TupleIsNullPredicate.java @@ -239,9 +239,4 @@ public class TupleIsNullPredicate extends Predicate { public boolean isNullable() { return false; } - - @Override - public void finalizeImplForNereids() throws AnalysisException { - super.finalizeImplForNereids(); - } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/ExpressionTranslator.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/ExpressionTranslator.java index ac0177486a..e36e30f0b6 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/ExpressionTranslator.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/ExpressionTranslator.java @@ -83,6 +83,7 @@ import org.apache.doris.nereids.trees.expressions.visitor.DefaultExpressionVisit import org.apache.doris.nereids.types.coercion.AbstractDataType; import org.apache.doris.thrift.TFunctionBinaryType; +import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import java.util.ArrayList; @@ -99,8 +100,7 @@ public class ExpressionTranslator extends DefaultExpressionVisitor inList = inPredicate.getOptions().stream() .map(e -> translate(e, context)) .collect(Collectors.toList()); + boolean allConstant = inPredicate.getOptions().stream().allMatch(Expression::isConstant); return new org.apache.doris.analysis.InPredicate( inPredicate.getCompareExpr().accept(this, context), - inList, - true); + inList, true, allConstant); } else if (not.child() instanceof EqualTo) { EqualTo equalTo = (EqualTo) not.child(); return new BinaryPredicate(Operator.NE, equalTo.child(0).accept(this, context), - equalTo.child(1).accept(this, context)); + equalTo.child(1).accept(this, context), + equalTo.getDataType().toCatalogDataType(), + NullableMode.DEPEND_ON_ARGUMENT); } else if (not.child() instanceof InSubquery || not.child() instanceof Exists) { return new BoolLiteral(true); } else if (not.child() instanceof IsNull) { - return new IsNullPredicate(((IsNull) not.child()).child().accept(this, context), true); + return new IsNullPredicate(((IsNull) not.child()).child().accept(this, context), true, true); } else { return new CompoundPredicate(CompoundPredicate.Operator.NOT, not.child(0).accept(this, context), null); @@ -261,7 +267,7 @@ public class ExpressionTranslator extends DefaultExpressionVisitor inList = inPredicate.getOptions().stream() .map(e -> e.accept(this, context)) .collect(Collectors.toList()); - return new org.apache.doris.analysis.InPredicate(inPredicate.getCompareExpr().accept(this, context), - inList, - false); + boolean allConstant = inPredicate.getOptions().stream().allMatch(Expression::isConstant); + return new org.apache.doris.analysis.InPredicate( + inPredicate.getCompareExpr().accept(this, context), + inList, false, allConstant); } @Override @@ -417,15 +424,15 @@ public class ExpressionTranslator extends DefaultExpressionVisitor e.getDataType().isDateV2LikeType())) { + nullableMode = NullableMode.DEPEND_ON_ARGUMENT; } + return new TimestampArithmeticExpr(arithmetic.getFuncName(), arithmetic.getOp(), + arithmetic.left().accept(this, context), arithmetic.right().accept(this, context), + arithmetic.getTimeUnit().toString(), arithmetic.getDataType().toCatalogDataType(), nullableMode); } @Override @@ -435,7 +442,7 @@ public class ExpressionTranslator extends DefaultExpressionVisitor null */ public class InPredicate extends Expression { @@ -54,17 +56,17 @@ public class InPredicate extends Expression { return BooleanType.INSTANCE; } - @Override - public boolean nullable() throws UnboundException { - return children().stream().anyMatch(Expression::nullable); - } - @Override public InPredicate withChildren(List children) { Preconditions.checkArgument(children.size() > 1); return new InPredicate(children.get(0), ImmutableList.copyOf(children).subList(1, children.size())); } + @Override + public boolean nullable() throws UnboundException { + return children().stream().anyMatch(Expression::nullable); + } + @Override public String toString() { return compareExpr + " IN " + options.stream() diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/IsNull.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/IsNull.java index 8e5e9080df..35d3c2da2b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/IsNull.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/IsNull.java @@ -18,6 +18,7 @@ package org.apache.doris.nereids.trees.expressions; import org.apache.doris.nereids.exceptions.UnboundException; +import org.apache.doris.nereids.trees.expressions.functions.AlwaysNotNullable; import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.BooleanType; @@ -31,7 +32,7 @@ import java.util.Objects; /** * expr is null predicate. */ -public class IsNull extends Expression implements UnaryExpression { +public class IsNull extends Expression implements UnaryExpression, AlwaysNotNullable { public IsNull(Expression e) { super(e); @@ -42,11 +43,6 @@ public class IsNull extends Expression implements UnaryExpression { return visitor.visitIsNull(this, context); } - @Override - public boolean nullable() { - return false; - } - @Override public IsNull withChildren(List children) { Preconditions.checkArgument(children.size() == 1); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/NullSafeEqual.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/NullSafeEqual.java index b8a0a50b90..6ed6847b35 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/NullSafeEqual.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/NullSafeEqual.java @@ -17,7 +17,7 @@ package org.apache.doris.nereids.trees.expressions; -import org.apache.doris.nereids.exceptions.UnboundException; +import org.apache.doris.nereids.trees.expressions.functions.AlwaysNotNullable; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import com.google.common.base.Preconditions; @@ -28,7 +28,7 @@ import java.util.List; * Null safe equal expression: a <=> b. * Unlike normal equal to expression, null <=> null is true. */ -public class NullSafeEqual extends ComparisonPredicate { +public class NullSafeEqual extends ComparisonPredicate implements AlwaysNotNullable { /** * Constructor of Null Safe Equal ComparisonPredicate. * @@ -39,11 +39,6 @@ public class NullSafeEqual extends ComparisonPredicate { super(left, right, "<=>"); } - @Override - public boolean nullable() throws UnboundException { - return false; - } - @Override public String toString() { return "(" + left() + " <=> " + right() + ")"; diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/TimestampArithmetic.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/TimestampArithmetic.java index ad4dcfbd44..b586a409b1 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/TimestampArithmetic.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/TimestampArithmetic.java @@ -109,10 +109,6 @@ public class TimestampArithmetic extends Expression implements BinaryExpression, return funcName; } - public boolean isIntervalFirst() { - return intervalFirst; - } - public Operator getOp() { return op; } diff --git a/regression-test/data/nereids_function_p0/test_timestamp_arithmetic.out b/regression-test/data/nereids_function_p0/test_timestamp_arithmetic.out new file mode 100644 index 0000000000..fd5f147877 --- /dev/null +++ b/regression-test/data/nereids_function_p0/test_timestamp_arithmetic.out @@ -0,0 +1,703 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !test_timestamp_arithmetic -- +0 + +-- !test_timestamp_arithmetic_2 -- +0 + +-- !test_timestamp_arithmetic_3 -- +\N +2012-03-02 +2012-03-03 +2012-03-04 +2012-03-05 +2012-03-06 +2012-03-07 +2012-03-08 +2012-03-09 +2012-03-10 +2012-03-11 +2012-03-12 +2012-03-13 + +-- !test_timestamp_arithmetic_4 -- +\N +2012-03-01T00:00:01 +2012-03-02T00:00:01 +2012-03-03T00:00:01 +2012-03-04T00:00:01 +2012-03-05T00:00:01 +2012-03-06T00:00:01 +2012-03-07T00:00:01 +2012-03-08T00:00:01 +2012-03-09T00:00:01 +2012-03-10T00:00:01 +2012-03-11T00:00:01 +2012-03-12T00:00:01 + +-- !test_timestamp_arithmetic_5 -- +\N +2012-02-29 +2012-03-01 +2012-03-02 +2012-03-03 +2012-03-04 +2012-03-05 +2012-03-06 +2012-03-07 +2012-03-08 +2012-03-09 +2012-03-10 +2012-03-11 + +-- !test_timestamp_arithmetic_6 -- +\N +2012-02-29T23:59:59 +2012-03-01T23:59:59 +2012-03-02T23:59:59 +2012-03-03T23:59:59 +2012-03-04T23:59:59 +2012-03-05T23:59:59 +2012-03-06T23:59:59 +2012-03-07T23:59:59 +2012-03-08T23:59:59 +2012-03-09T23:59:59 +2012-03-10T23:59:59 +2012-03-11T23:59:59 + +-- !test_timestamp_arithmetic_7 -- +2012-03-02 +2012-03-03 +2012-03-04 +2012-03-05 +2012-03-06 +2012-03-07 +2012-03-08 +2012-03-09 +2012-03-10 +2012-03-11 +2012-03-12 +2012-03-13 + +-- !test_timestamp_arithmetic_8 -- +2012-03-01T00:00:01 +2012-03-02T00:00:01 +2012-03-03T00:00:01 +2012-03-04T00:00:01 +2012-03-05T00:00:01 +2012-03-06T00:00:01 +2012-03-07T00:00:01 +2012-03-08T00:00:01 +2012-03-09T00:00:01 +2012-03-10T00:00:01 +2012-03-11T00:00:01 +2012-03-12T00:00:01 + +-- !test_timestamp_arithmetic_9 -- +2012-02-29 +2012-03-01 +2012-03-02 +2012-03-03 +2012-03-04 +2012-03-05 +2012-03-06 +2012-03-07 +2012-03-08 +2012-03-09 +2012-03-10 +2012-03-11 + +-- !test_timestamp_arithmetic_10 -- +2012-02-29T23:59:59 +2012-03-01T23:59:59 +2012-03-02T23:59:59 +2012-03-03T23:59:59 +2012-03-04T23:59:59 +2012-03-05T23:59:59 +2012-03-06T23:59:59 +2012-03-07T23:59:59 +2012-03-08T23:59:59 +2012-03-09T23:59:59 +2012-03-10T23:59:59 +2012-03-11T23:59:59 + +-- !test_timestamp_arithmetic_11 -- +\N +2012-03-02 +2012-03-03 +2012-03-04 +2012-03-05 +2012-03-06 +2012-03-07 +2012-03-08 +2012-03-09 +2012-03-10 +2012-03-11 +2012-03-12 +2012-03-13 + +-- !test_timestamp_arithmetic_12 -- +\N +2012-03-01T00:00:01 +2012-03-02T00:00:01 +2012-03-03T00:00:01 +2012-03-04T00:00:01 +2012-03-05T00:00:01 +2012-03-06T00:00:01 +2012-03-07T00:00:01 +2012-03-08T00:00:01 +2012-03-09T00:00:01 +2012-03-10T00:00:01 +2012-03-11T00:00:01 +2012-03-12T00:00:01 + +-- !test_timestamp_arithmetic_13 -- +\N +2012-02-29 +2012-03-01 +2012-03-02 +2012-03-03 +2012-03-04 +2012-03-05 +2012-03-06 +2012-03-07 +2012-03-08 +2012-03-09 +2012-03-10 +2012-03-11 + +-- !test_timestamp_arithmetic_14 -- +\N +2012-02-29T23:59:59 +2012-03-01T23:59:59 +2012-03-02T23:59:59 +2012-03-03T23:59:59 +2012-03-04T23:59:59 +2012-03-05T23:59:59 +2012-03-06T23:59:59 +2012-03-07T23:59:59 +2012-03-08T23:59:59 +2012-03-09T23:59:59 +2012-03-10T23:59:59 +2012-03-11T23:59:59 + +-- !test_timestamp_arithmetic_15 -- +2012-03-02 +2012-03-03 +2012-03-04 +2012-03-05 +2012-03-06 +2012-03-07 +2012-03-08 +2012-03-09 +2012-03-10 +2012-03-11 +2012-03-12 +2012-03-13 + +-- !test_timestamp_arithmetic_16 -- +2012-03-01T00:00:01 +2012-03-02T00:00:01 +2012-03-03T00:00:01 +2012-03-04T00:00:01 +2012-03-05T00:00:01 +2012-03-06T00:00:01 +2012-03-07T00:00:01 +2012-03-08T00:00:01 +2012-03-09T00:00:01 +2012-03-10T00:00:01 +2012-03-11T00:00:01 +2012-03-12T00:00:01 + +-- !test_timestamp_arithmetic_17 -- +2012-02-29 +2012-03-01 +2012-03-02 +2012-03-03 +2012-03-04 +2012-03-05 +2012-03-06 +2012-03-07 +2012-03-08 +2012-03-09 +2012-03-10 +2012-03-11 + +-- !test_timestamp_arithmetic_18 -- +2012-02-29T23:59:59 +2012-03-01T23:59:59 +2012-03-02T23:59:59 +2012-03-03T23:59:59 +2012-03-04T23:59:59 +2012-03-05T23:59:59 +2012-03-06T23:59:59 +2012-03-07T23:59:59 +2012-03-08T23:59:59 +2012-03-09T23:59:59 +2012-03-10T23:59:59 +2012-03-11T23:59:59 + +-- !test_timestamp_arithmetic_19 -- +\N +2012-03-02T01:00:01 +2012-03-03T02:01:02 +2012-03-04T03:02:03 +2012-03-05T04:03:04 +2012-03-06T05:04:05 +2012-03-07T06:05:06 +2012-03-08T07:06:07 +2012-03-09T08:07:08 +2012-03-10T09:08:09 +2012-03-11T10:09:10 +2012-03-12T11:10:11 +2012-03-13T12:11:12 + +-- !test_timestamp_arithmetic_20 -- +\N +2012-03-01T01:00:02 +2012-03-02T02:01:03 +2012-03-03T03:02:04 +2012-03-04T04:03:05 +2012-03-05T05:04:06 +2012-03-06T06:05:07 +2012-03-07T07:06:08 +2012-03-08T08:07:09 +2012-03-09T09:08:10 +2012-03-10T10:09:11 +2012-03-11T11:10:12 +2012-03-12T12:11:13 + +-- !test_timestamp_arithmetic_21 -- +\N +2012-02-29T01:00:01 +2012-03-01T02:01:02 +2012-03-02T03:02:03 +2012-03-03T04:03:04 +2012-03-04T05:04:05 +2012-03-05T06:05:06 +2012-03-06T07:06:07 +2012-03-07T08:07:08 +2012-03-08T09:08:09 +2012-03-09T10:09:10 +2012-03-10T11:10:11 +2012-03-11T12:11:12 + +-- !test_timestamp_arithmetic_22 -- +\N +2012-03-01T01:00 +2012-03-02T02:01:01 +2012-03-03T03:02:02 +2012-03-04T04:03:03 +2012-03-05T05:04:04 +2012-03-06T06:05:05 +2012-03-07T07:06:06 +2012-03-08T08:07:07 +2012-03-09T09:08:08 +2012-03-10T10:09:09 +2012-03-11T11:10:10 +2012-03-12T12:11:11 + +-- !test_timestamp_arithmetic_23 -- +2012-03-02T01:00:01 +2012-03-03T02:01:02 +2012-03-04T03:02:03 +2012-03-05T04:03:04 +2012-03-06T05:04:05 +2012-03-07T06:05:06 +2012-03-08T07:06:07 +2012-03-09T08:07:08 +2012-03-10T09:08:09 +2012-03-11T10:09:10 +2012-03-12T11:10:11 +2012-03-13T12:11:12 + +-- !test_timestamp_arithmetic_24 -- +2012-03-01T01:00:02 +2012-03-02T02:01:03 +2012-03-03T03:02:04 +2012-03-04T04:03:05 +2012-03-05T05:04:06 +2012-03-06T06:05:07 +2012-03-07T07:06:08 +2012-03-08T08:07:09 +2012-03-09T09:08:10 +2012-03-10T10:09:11 +2012-03-11T11:10:12 +2012-03-12T12:11:13 + +-- !test_timestamp_arithmetic_25 -- +2012-02-29T01:00:01 +2012-03-01T02:01:02 +2012-03-02T03:02:03 +2012-03-03T04:03:04 +2012-03-04T05:04:05 +2012-03-05T06:05:06 +2012-03-06T07:06:07 +2012-03-07T08:07:08 +2012-03-08T09:08:09 +2012-03-09T10:09:10 +2012-03-10T11:10:11 +2012-03-11T12:11:12 + +-- !test_timestamp_arithmetic_26 -- +2012-03-01T01:00 +2012-03-02T02:01:01 +2012-03-03T03:02:02 +2012-03-04T04:03:03 +2012-03-05T05:04:04 +2012-03-06T06:05:05 +2012-03-07T07:06:06 +2012-03-08T08:07:07 +2012-03-09T09:08:08 +2012-03-10T10:09:09 +2012-03-11T11:10:10 +2012-03-12T12:11:11 + +-- !test_timestamp_arithmetic_27 -- +\N +2012-03-02T01:00:01 +2012-03-03T02:01:02 +2012-03-04T03:02:03 +2012-03-05T04:03:04 +2012-03-06T05:04:05 +2012-03-07T06:05:06 +2012-03-08T07:06:07 +2012-03-09T08:07:08 +2012-03-10T09:08:09 +2012-03-11T10:09:10 +2012-03-12T11:10:11 +2012-03-13T12:11:12 + +-- !test_timestamp_arithmetic_28 -- +\N +2012-03-01T01:00:02 +2012-03-02T02:01:03 +2012-03-03T03:02:04 +2012-03-04T04:03:05 +2012-03-05T05:04:06 +2012-03-06T06:05:07 +2012-03-07T07:06:08 +2012-03-08T08:07:09 +2012-03-09T09:08:10 +2012-03-10T10:09:11 +2012-03-11T11:10:12 +2012-03-12T12:11:13 + +-- !test_timestamp_arithmetic_29 -- +\N +2012-02-29T01:00:01 +2012-03-01T02:01:02 +2012-03-02T03:02:03 +2012-03-03T04:03:04 +2012-03-04T05:04:05 +2012-03-05T06:05:06 +2012-03-06T07:06:07 +2012-03-07T08:07:08 +2012-03-08T09:08:09 +2012-03-09T10:09:10 +2012-03-10T11:10:11 +2012-03-11T12:11:12 + +-- !test_timestamp_arithmetic_30 -- +\N +2012-03-01T01:00 +2012-03-02T02:01:01 +2012-03-03T03:02:02 +2012-03-04T04:03:03 +2012-03-05T05:04:04 +2012-03-06T06:05:05 +2012-03-07T07:06:06 +2012-03-08T08:07:07 +2012-03-09T09:08:08 +2012-03-10T10:09:09 +2012-03-11T11:10:10 +2012-03-12T12:11:11 + +-- !test_timestamp_arithmetic_31 -- +2012-03-02T01:00:01 +2012-03-03T02:01:02 +2012-03-04T03:02:03 +2012-03-05T04:03:04 +2012-03-06T05:04:05 +2012-03-07T06:05:06 +2012-03-08T07:06:07 +2012-03-09T08:07:08 +2012-03-10T09:08:09 +2012-03-11T10:09:10 +2012-03-12T11:10:11 +2012-03-13T12:11:12 + +-- !test_timestamp_arithmetic_32 -- +2012-03-01T01:00:02 +2012-03-02T02:01:03 +2012-03-03T03:02:04 +2012-03-04T04:03:05 +2012-03-05T05:04:06 +2012-03-06T06:05:07 +2012-03-07T07:06:08 +2012-03-08T08:07:09 +2012-03-09T09:08:10 +2012-03-10T10:09:11 +2012-03-11T11:10:12 +2012-03-12T12:11:13 + +-- !test_timestamp_arithmetic_33 -- +2012-02-29T01:00:01 +2012-03-01T02:01:02 +2012-03-02T03:02:03 +2012-03-03T04:03:04 +2012-03-04T05:04:05 +2012-03-05T06:05:06 +2012-03-06T07:06:07 +2012-03-07T08:07:08 +2012-03-08T09:08:09 +2012-03-09T10:09:10 +2012-03-10T11:10:11 +2012-03-11T12:11:12 + +-- !test_timestamp_arithmetic_34 -- +2012-03-01T01:00 +2012-03-02T02:01:01 +2012-03-03T03:02:02 +2012-03-04T04:03:03 +2012-03-05T05:04:04 +2012-03-06T06:05:05 +2012-03-07T07:06:06 +2012-03-08T08:07:07 +2012-03-09T09:08:08 +2012-03-10T10:09:09 +2012-03-11T11:10:10 +2012-03-12T12:11:11 + +-- !test_timestamp_arithmetic_35 -- +\N +2012-03-02T01:00:01 +2012-03-03T02:01:02 +2012-03-04T03:02:03 +2012-03-05T04:03:04 +2012-03-06T05:04:05 +2012-03-07T06:05:06 +2012-03-08T07:06:07 +2012-03-09T08:07:08 +2012-03-10T09:08:09 +2012-03-11T10:09:10 +2012-03-12T11:10:11 +2012-03-13T12:11:12 + +-- !test_timestamp_arithmetic_36 -- +\N +2012-03-01T01:00:02 +2012-03-02T02:01:03 +2012-03-03T03:02:04 +2012-03-04T04:03:05 +2012-03-05T05:04:06 +2012-03-06T06:05:07 +2012-03-07T07:06:08 +2012-03-08T08:07:09 +2012-03-09T09:08:10 +2012-03-10T10:09:11 +2012-03-11T11:10:12 +2012-03-12T12:11:13 + +-- !test_timestamp_arithmetic_37 -- +\N +2012-02-29T01:00:01 +2012-03-01T02:01:02 +2012-03-02T03:02:03 +2012-03-03T04:03:04 +2012-03-04T05:04:05 +2012-03-05T06:05:06 +2012-03-06T07:06:07 +2012-03-07T08:07:08 +2012-03-08T09:08:09 +2012-03-09T10:09:10 +2012-03-10T11:10:11 +2012-03-11T12:11:12 + +-- !test_timestamp_arithmetic_38 -- +\N +2012-03-01T01:00 +2012-03-02T02:01:01 +2012-03-03T03:02:02 +2012-03-04T04:03:03 +2012-03-05T05:04:04 +2012-03-06T06:05:05 +2012-03-07T07:06:06 +2012-03-08T08:07:07 +2012-03-09T09:08:08 +2012-03-10T10:09:09 +2012-03-11T11:10:10 +2012-03-12T12:11:11 + +-- !test_timestamp_arithmetic_39 -- +2012-03-02T01:00:01 +2012-03-03T02:01:02 +2012-03-04T03:02:03 +2012-03-05T04:03:04 +2012-03-06T05:04:05 +2012-03-07T06:05:06 +2012-03-08T07:06:07 +2012-03-09T08:07:08 +2012-03-10T09:08:09 +2012-03-11T10:09:10 +2012-03-12T11:10:11 +2012-03-13T12:11:12 + +-- !test_timestamp_arithmetic_40 -- +2012-03-01T01:00:02 +2012-03-02T02:01:03 +2012-03-03T03:02:04 +2012-03-04T04:03:05 +2012-03-05T05:04:06 +2012-03-06T06:05:07 +2012-03-07T07:06:08 +2012-03-08T08:07:09 +2012-03-09T09:08:10 +2012-03-10T10:09:11 +2012-03-11T11:10:12 +2012-03-12T12:11:13 + +-- !test_timestamp_arithmetic_41 -- +2012-02-29T01:00:01 +2012-03-01T02:01:02 +2012-03-02T03:02:03 +2012-03-03T04:03:04 +2012-03-04T05:04:05 +2012-03-05T06:05:06 +2012-03-06T07:06:07 +2012-03-07T08:07:08 +2012-03-08T09:08:09 +2012-03-09T10:09:10 +2012-03-10T11:10:11 +2012-03-11T12:11:12 + +-- !test_timestamp_arithmetic_42 -- +2012-03-01T01:00 +2012-03-02T02:01:01 +2012-03-03T03:02:02 +2012-03-04T04:03:03 +2012-03-05T05:04:04 +2012-03-06T06:05:05 +2012-03-07T07:06:06 +2012-03-08T08:07:07 +2012-03-09T09:08:08 +2012-03-10T10:09:09 +2012-03-11T11:10:10 +2012-03-12T12:11:11 + +-- !test_timestamp_arithmetic_43 -- +\N +2012-03-02T01:00:01 +2012-03-03T02:01:02 +2012-03-04T03:02:03 +2012-03-05T04:03:04 +2012-03-06T05:04:05 +2012-03-07T06:05:06 +2012-03-08T07:06:07 +2012-03-09T08:07:08 +2012-03-10T09:08:09 +2012-03-11T10:09:10 +2012-03-12T11:10:11 +2012-03-13T12:11:12 + +-- !test_timestamp_arithmetic_44 -- +\N +2012-03-01T01:00:02 +2012-03-02T02:01:03 +2012-03-03T03:02:04 +2012-03-04T04:03:05 +2012-03-05T05:04:06 +2012-03-06T06:05:07 +2012-03-07T07:06:08 +2012-03-08T08:07:09 +2012-03-09T09:08:10 +2012-03-10T10:09:11 +2012-03-11T11:10:12 +2012-03-12T12:11:13 + +-- !test_timestamp_arithmetic_45 -- +\N +2012-02-29T01:00:01 +2012-03-01T02:01:02 +2012-03-02T03:02:03 +2012-03-03T04:03:04 +2012-03-04T05:04:05 +2012-03-05T06:05:06 +2012-03-06T07:06:07 +2012-03-07T08:07:08 +2012-03-08T09:08:09 +2012-03-09T10:09:10 +2012-03-10T11:10:11 +2012-03-11T12:11:12 + +-- !test_timestamp_arithmetic_46 -- +\N +2012-03-01T01:00 +2012-03-02T02:01:01 +2012-03-03T03:02:02 +2012-03-04T04:03:03 +2012-03-05T05:04:04 +2012-03-06T06:05:05 +2012-03-07T07:06:06 +2012-03-08T08:07:07 +2012-03-09T09:08:08 +2012-03-10T10:09:09 +2012-03-11T11:10:10 +2012-03-12T12:11:11 + +-- !test_timestamp_arithmetic_47 -- +2012-03-02T01:00:01 +2012-03-03T02:01:02 +2012-03-04T03:02:03 +2012-03-05T04:03:04 +2012-03-06T05:04:05 +2012-03-07T06:05:06 +2012-03-08T07:06:07 +2012-03-09T08:07:08 +2012-03-10T09:08:09 +2012-03-11T10:09:10 +2012-03-12T11:10:11 +2012-03-13T12:11:12 + +-- !test_timestamp_arithmetic_48 -- +2012-03-01T01:00:02 +2012-03-02T02:01:03 +2012-03-03T03:02:04 +2012-03-04T04:03:05 +2012-03-05T05:04:06 +2012-03-06T06:05:07 +2012-03-07T07:06:08 +2012-03-08T08:07:09 +2012-03-09T09:08:10 +2012-03-10T10:09:11 +2012-03-11T11:10:12 +2012-03-12T12:11:13 + +-- !test_timestamp_arithmetic_49 -- +2012-02-29T01:00:01 +2012-03-01T02:01:02 +2012-03-02T03:02:03 +2012-03-03T04:03:04 +2012-03-04T05:04:05 +2012-03-05T06:05:06 +2012-03-06T07:06:07 +2012-03-07T08:07:08 +2012-03-08T09:08:09 +2012-03-09T10:09:10 +2012-03-10T11:10:11 +2012-03-11T12:11:12 + +-- !test_timestamp_arithmetic_50 -- +2012-03-01T01:00 +2012-03-02T02:01:01 +2012-03-03T03:02:02 +2012-03-04T04:03:03 +2012-03-05T05:04:04 +2012-03-06T06:05:05 +2012-03-07T07:06:06 +2012-03-08T08:07:07 +2012-03-09T09:08:08 +2012-03-10T10:09:09 +2012-03-11T11:10:10 +2012-03-12T12:11:11 + diff --git a/regression-test/suites/nereids_function_p0/test_timestamp_arithmetic.sql b/regression-test/suites/nereids_function_p0/test_timestamp_arithmetic.sql new file mode 100644 index 0000000000..c702bf259a --- /dev/null +++ b/regression-test/suites/nereids_function_p0/test_timestamp_arithmetic.sql @@ -0,0 +1,50 @@ +set enable_nereids_planner=true; +set enable_fallback_to_original_planner=false; +select kdt + interval 1 day from fn_test order by kdt; +select kdt + interval 1 second from fn_test order by kdt; +select kdt - interval 1 day from fn_test order by kdt; +select kdt - interval 1 second from fn_test order by kdt; +select kdt + interval 1 day from fn_test_not_nullable order by kdt; +select kdt + interval 1 second from fn_test_not_nullable order by kdt; +select kdt - interval 1 day from fn_test_not_nullable order by kdt; +select kdt - interval 1 second from fn_test_not_nullable order by kdt; +select kdtv2 + interval 1 day from fn_test order by kdt; +select kdtv2 + interval 1 second from fn_test order by kdt; +select kdtv2 - interval 1 day from fn_test order by kdt; +select kdtv2 - interval 1 second from fn_test order by kdt; +select kdtv2 + interval 1 day from fn_test_not_nullable order by kdt; +select kdtv2 + interval 1 second from fn_test_not_nullable order by kdt; +select kdtv2 - interval 1 day from fn_test_not_nullable order by kdt; +select kdtv2 - interval 1 second from fn_test_not_nullable order by kdt; +select kdtm + interval 1 day from fn_test order by kdt; +select kdtm + interval 1 second from fn_test order by kdt; +select kdtm - interval 1 day from fn_test order by kdt; +select kdtm - interval 1 second from fn_test order by kdt; +select kdtm + interval 1 day from fn_test_not_nullable order by kdt; +select kdtm + interval 1 second from fn_test_not_nullable order by kdt; +select kdtm - interval 1 day from fn_test_not_nullable order by kdt; +select kdtm - interval 1 second from fn_test_not_nullable order by kdt; +select kdtmv2s1 + interval 1 day from fn_test order by kdt; +select kdtmv2s1 + interval 1 second from fn_test order by kdt; +select kdtmv2s1 - interval 1 day from fn_test order by kdt; +select kdtmv2s1 - interval 1 second from fn_test order by kdt; +select kdtmv2s1 + interval 1 day from fn_test_not_nullable order by kdt; +select kdtmv2s1 + interval 1 second from fn_test_not_nullable order by kdt; +select kdtmv2s1 - interval 1 day from fn_test_not_nullable order by kdt; +select kdtmv2s1 - interval 1 second from fn_test_not_nullable order by kdt; +select kdtmv2s2 + interval 1 day from fn_test order by kdt; +select kdtmv2s2 + interval 1 second from fn_test order by kdt; +select kdtmv2s2 - interval 1 day from fn_test order by kdt; +select kdtmv2s2 - interval 1 second from fn_test order by kdt; +select kdtmv2s2 + interval 1 day from fn_test_not_nullable order by kdt; +select kdtmv2s2 + interval 1 second from fn_test_not_nullable order by kdt; +select kdtmv2s2 - interval 1 day from fn_test_not_nullable order by kdt; +select kdtmv2s2 - interval 1 second from fn_test_not_nullable order by kdt; +select kdtmv2s3 + interval 1 day from fn_test order by kdt; +select kdtmv2s3 + interval 1 second from fn_test order by kdt; +select kdtmv2s3 - interval 1 day from fn_test order by kdt; +select kdtmv2s3 - interval 1 second from fn_test order by kdt; +select kdtmv2s3 + interval 1 day from fn_test_not_nullable order by kdt; +select kdtmv2s3 + interval 1 second from fn_test_not_nullable order by kdt; +select kdtmv2s3 - interval 1 day from fn_test_not_nullable order by kdt; +select kdtmv2s3 - interval 1 second from fn_test_not_nullable order by kdt;