From 44d763d3654d270956f0449e95b0dff26ea1a726 Mon Sep 17 00:00:00 2001 From: feiniaofeiafei Date: Mon, 2 Dec 2024 16:20:59 +0800 Subject: [PATCH 01/10] add xx_add xx_diff xx_sub --- .../rules/OneRangePartitionEvaluator.java | 7 +++-- .../expressions/functions/Monotonic.java | 4 +++ .../expressions/functions/scalar/DaysAdd.java | 24 ++++++++++++++- .../functions/scalar/DaysDiff.java | 29 ++++++++++++++++++- .../expressions/functions/scalar/DaysSub.java | 24 ++++++++++++++- .../functions/scalar/HoursAdd.java | 24 ++++++++++++++- .../functions/scalar/HoursDiff.java | 29 ++++++++++++++++++- .../functions/scalar/HoursSub.java | 24 ++++++++++++++- .../functions/scalar/MicroSecondsAdd.java | 24 ++++++++++++++- .../functions/scalar/MicroSecondsDiff.java | 29 ++++++++++++++++++- .../functions/scalar/MicroSecondsSub.java | 24 ++++++++++++++- .../functions/scalar/MilliSecondsAdd.java | 24 ++++++++++++++- .../functions/scalar/MilliSecondsDiff.java | 29 ++++++++++++++++++- .../functions/scalar/MilliSecondsSub.java | 24 ++++++++++++++- .../functions/scalar/MinutesAdd.java | 24 ++++++++++++++- .../functions/scalar/MinutesDiff.java | 29 ++++++++++++++++++- .../functions/scalar/MinutesSub.java | 24 ++++++++++++++- .../functions/scalar/MonthsAdd.java | 24 ++++++++++++++- .../functions/scalar/MonthsDiff.java | 29 ++++++++++++++++++- .../functions/scalar/MonthsSub.java | 24 ++++++++++++++- .../functions/scalar/SecondsAdd.java | 24 ++++++++++++++- .../functions/scalar/SecondsDiff.java | 29 ++++++++++++++++++- .../functions/scalar/SecondsSub.java | 24 ++++++++++++++- .../functions/scalar/YearsAdd.java | 24 ++++++++++++++- .../functions/scalar/YearsDiff.java | 29 ++++++++++++++++++- .../functions/scalar/YearsSub.java | 24 ++++++++++++++- 26 files changed, 601 insertions(+), 26 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/OneRangePartitionEvaluator.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/OneRangePartitionEvaluator.java index 7e91d5502f7fad..e31a5c7be99011 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/OneRangePartitionEvaluator.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/OneRangePartitionEvaluator.java @@ -800,6 +800,9 @@ private EvaluateRangeResult computeMonotonicFunctionRange(EvaluateRangeResult re return new EvaluateRangeResult((Expression) func, ImmutableMap.of((Expression) func, context.rangeMap.get(func)), result.childrenResult); } + if (!func.isMonotonic()) { + return result; + } int childIndex = func.getMonotonicFunctionChildIndex(); Expression funcChild = func.child(childIndex); boolean isNullable = partitionSlotContainsNull.getOrDefault(funcChild, true); @@ -807,10 +810,10 @@ private EvaluateRangeResult computeMonotonicFunctionRange(EvaluateRangeResult re : new NonNullable(funcChild)); partitionSlotContainsNull.put((Expression) func, withNullable.nullable()); - if (!result.childrenResult.get(0).columnRanges.containsKey(funcChild)) { + if (!result.childrenResult.get(childIndex).columnRanges.containsKey(funcChild)) { return result; } - ColumnRange childRange = result.childrenResult.get(0).columnRanges.get(funcChild); + ColumnRange childRange = result.childrenResult.get(childIndex).columnRanges.get(funcChild); if (childRange.isEmptyRange() || childRange.asRanges().size() != 1 || (!childRange.span().hasLowerBound() && !childRange.span().hasUpperBound())) { return result; diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/Monotonic.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/Monotonic.java index bcaa040cb2a650..c2a869c9185371 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/Monotonic.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/Monotonic.java @@ -21,6 +21,10 @@ /** monotonicity of expressions */ public interface Monotonic extends ExpressionTrait { + default boolean isMonotonic() { + return true; + } + // true means that the function is an increasing function boolean isPositive(); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DaysAdd.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DaysAdd.java index e02c20eee82a04..95e5d3db318e89 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DaysAdd.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DaysAdd.java @@ -22,7 +22,9 @@ import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.ComputeSignatureForDateArithmetic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; +import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; +import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeType; @@ -41,7 +43,7 @@ */ public class DaysAdd extends ScalarFunction implements BinaryExpression, ExplicitlyCastableSignature, - ComputeSignatureForDateArithmetic, PropagateNullableOnDateLikeV2Args { + ComputeSignatureForDateArithmetic, PropagateNullableOnDateLikeV2Args, Monotonic { // When enable_date_conversion is true, we prefer to V2 signature. // This preference follows original planner. refer to ScalarType.getDefaultDateType() private static final List SIGNATURES = Config.enable_date_conversion ? ImmutableList.of( @@ -77,4 +79,24 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitDaysAdd(this, context); } + + @Override + public boolean isMonotonic() { + return child(1) instanceof IntegerLiteral; + } + + @Override + public boolean isPositive() { + return true; + } + + @Override + public int getMonotonicFunctionChildIndex() { + return 0; + } + + @Override + public Expression withConstantArgs(Expression literal) { + return new DaysAdd(literal, child(1)); + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DaysDiff.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DaysDiff.java index e0343f1148f162..c65a4b56119d83 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DaysDiff.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DaysDiff.java @@ -20,7 +20,9 @@ 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.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; +import org.apache.doris.nereids.trees.expressions.literal.Literal; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.BigIntType; @@ -37,7 +39,7 @@ * ScalarFunction 'days_diff'. This class is generated by GenerateFunction. */ public class DaysDiff extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(BigIntType.INSTANCE) @@ -73,4 +75,29 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitDaysDiff(this, context); } + + @Override + public boolean isMonotonic() { + return !(child(0) instanceof Literal) && child(1) instanceof Literal + || child(0) instanceof Literal && !(child(1) instanceof Literal); + } + + @Override + public boolean isPositive() { + return child(1) instanceof Literal; + } + + @Override + public int getMonotonicFunctionChildIndex() { + return child(1) instanceof Literal ? 0 : 1; + } + + @Override + public Expression withConstantArgs(Expression literal) { + if (child(1) instanceof Literal) { + return new DaysDiff(literal, child(1)); + } else { + return new DaysDiff(child(0), literal); + } + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DaysSub.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DaysSub.java index 8d135dc6c9cf72..c2b408b933a101 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DaysSub.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DaysSub.java @@ -22,7 +22,9 @@ import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.ComputeSignatureForDateArithmetic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; +import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; +import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeType; @@ -41,7 +43,7 @@ */ public class DaysSub extends ScalarFunction implements BinaryExpression, ExplicitlyCastableSignature, - ComputeSignatureForDateArithmetic, PropagateNullableOnDateLikeV2Args { + ComputeSignatureForDateArithmetic, PropagateNullableOnDateLikeV2Args, Monotonic { // When enable_date_conversion is true, we prefer to V2 signature. // This preference follows original planner. refer to ScalarType.getDefaultDateType() private static final List SIGNATURES = Config.enable_date_conversion ? ImmutableList.of( @@ -77,4 +79,24 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitDaysSub(this, context); } + + @Override + public boolean isMonotonic() { + return child(1) instanceof IntegerLiteral; + } + + @Override + public boolean isPositive() { + return true; + } + + @Override + public int getMonotonicFunctionChildIndex() { + return 0; + } + + @Override + public Expression withConstantArgs(Expression literal) { + return new DaysSub(literal, child(1)); + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HoursAdd.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HoursAdd.java index cb4e601b14d001..e29414b76a6b6e 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HoursAdd.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HoursAdd.java @@ -20,7 +20,9 @@ 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.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; +import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeType; @@ -38,7 +40,7 @@ * ScalarFunction 'days_add'. */ public class HoursAdd extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { public static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT) @@ -67,4 +69,24 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitHoursAdd(this, context); } + + @Override + public boolean isMonotonic() { + return child(1) instanceof IntegerLiteral; + } + + @Override + public boolean isPositive() { + return true; + } + + @Override + public int getMonotonicFunctionChildIndex() { + return 0; + } + + @Override + public Expression withConstantArgs(Expression literal) { + return new HoursAdd(literal, child(1)); + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HoursDiff.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HoursDiff.java index 452e3110ff764d..1b71306a359111 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HoursDiff.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HoursDiff.java @@ -20,7 +20,9 @@ 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.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; +import org.apache.doris.nereids.trees.expressions.literal.Literal; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.BigIntType; @@ -37,7 +39,7 @@ * ScalarFunction 'hours_diff'. This class is generated by GenerateFunction. */ public class HoursDiff extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { public static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(BigIntType.INSTANCE) @@ -73,4 +75,29 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitHoursDiff(this, context); } + + @Override + public boolean isMonotonic() { + return !(child(0) instanceof Literal) && child(1) instanceof Literal + || child(0) instanceof Literal && !(child(1) instanceof Literal); + } + + @Override + public boolean isPositive() { + return child(1) instanceof Literal; + } + + @Override + public int getMonotonicFunctionChildIndex() { + return child(1) instanceof Literal ? 0 : 1; + } + + @Override + public Expression withConstantArgs(Expression literal) { + if (child(1) instanceof Literal) { + return new HoursDiff(literal, child(1)); + } else { + return new HoursDiff(child(0), literal); + } + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HoursSub.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HoursSub.java index e53f8ecb90528a..ac244d04dd12a6 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HoursSub.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HoursSub.java @@ -20,7 +20,9 @@ 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.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; +import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeType; @@ -38,7 +40,7 @@ * ScalarFunction 'hours_sub'. */ public class HoursSub extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { public static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT) @@ -67,4 +69,24 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitHoursSub(this, context); } + + @Override + public boolean isMonotonic() { + return child(1) instanceof IntegerLiteral; + } + + @Override + public boolean isPositive() { + return true; + } + + @Override + public int getMonotonicFunctionChildIndex() { + return 0; + } + + @Override + public Expression withConstantArgs(Expression literal) { + return new HoursSub(literal, child(1)); + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MicroSecondsAdd.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MicroSecondsAdd.java index 8d792259440dd2..9951939837796f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MicroSecondsAdd.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MicroSecondsAdd.java @@ -20,7 +20,9 @@ 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.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; +import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeV2Type; @@ -35,7 +37,7 @@ * ScalarFunction 'MicroSeconds_add'. */ public class MicroSecondsAdd extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.MAX) @@ -66,4 +68,24 @@ public FunctionSignature computeSignature(FunctionSignature signature) { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitMicroSecondsAdd(this, context); } + + @Override + public boolean isMonotonic() { + return child(1) instanceof IntegerLiteral; + } + + @Override + public boolean isPositive() { + return true; + } + + @Override + public int getMonotonicFunctionChildIndex() { + return 0; + } + + @Override + public Expression withConstantArgs(Expression literal) { + return new MicroSecondsAdd(literal, child(1)); + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MicroSecondsDiff.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MicroSecondsDiff.java index 8bf3a9648396d7..0d093363d5c7e7 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MicroSecondsDiff.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MicroSecondsDiff.java @@ -20,7 +20,9 @@ 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.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; +import org.apache.doris.nereids.trees.expressions.literal.Literal; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.BigIntType; @@ -35,7 +37,7 @@ * ScalarFunction 'microseconds_diff'. This class is generated by GenerateFunction. */ public class MicroSecondsDiff extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(BigIntType.INSTANCE) @@ -67,4 +69,29 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitMicroSecondsDiff(this, context); } + + @Override + public boolean isMonotonic() { + return !(child(0) instanceof Literal) && child(1) instanceof Literal + || child(0) instanceof Literal && !(child(1) instanceof Literal); + } + + @Override + public boolean isPositive() { + return child(1) instanceof Literal; + } + + @Override + public int getMonotonicFunctionChildIndex() { + return child(1) instanceof Literal ? 0 : 1; + } + + @Override + public Expression withConstantArgs(Expression literal) { + if (child(1) instanceof Literal) { + return new MicroSecondsDiff(literal, child(1)); + } else { + return new MicroSecondsDiff(child(0), literal); + } + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MicroSecondsSub.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MicroSecondsSub.java index 2894d1fffc902f..16836a8f4c6590 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MicroSecondsSub.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MicroSecondsSub.java @@ -20,7 +20,9 @@ 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.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; +import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeV2Type; @@ -35,7 +37,7 @@ * ScalarFunction 'MicroSeconds_sub'. */ public class MicroSecondsSub extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.MAX) @@ -66,4 +68,24 @@ public FunctionSignature computeSignature(FunctionSignature signature) { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitMicroSecondsSub(this, context); } + + @Override + public boolean isMonotonic() { + return child(1) instanceof IntegerLiteral; + } + + @Override + public boolean isPositive() { + return true; + } + + @Override + public int getMonotonicFunctionChildIndex() { + return 0; + } + + @Override + public Expression withConstantArgs(Expression literal) { + return new MicroSecondsSub(literal, child(1)); + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MilliSecondsAdd.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MilliSecondsAdd.java index 1cb56b13f84ed5..d608850bd7d7bb 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MilliSecondsAdd.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MilliSecondsAdd.java @@ -20,7 +20,9 @@ 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.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; +import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeV2Type; @@ -35,7 +37,7 @@ * ScalarFunction 'MilliSeconds_add'. */ public class MilliSecondsAdd extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.MAX) @@ -66,4 +68,24 @@ public FunctionSignature computeSignature(FunctionSignature signature) { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitMilliSecondsAdd(this, context); } + + @Override + public boolean isMonotonic() { + return child(1) instanceof IntegerLiteral; + } + + @Override + public boolean isPositive() { + return true; + } + + @Override + public int getMonotonicFunctionChildIndex() { + return 0; + } + + @Override + public Expression withConstantArgs(Expression literal) { + return new MilliSecondsAdd(literal, child(1)); + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MilliSecondsDiff.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MilliSecondsDiff.java index 4500bd69460d98..a54b50a948b0af 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MilliSecondsDiff.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MilliSecondsDiff.java @@ -20,7 +20,9 @@ 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.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; +import org.apache.doris.nereids.trees.expressions.literal.Literal; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.BigIntType; @@ -35,7 +37,7 @@ * ScalarFunction 'milliseconds_diff'. This class is generated by GenerateFunction. */ public class MilliSecondsDiff extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(BigIntType.INSTANCE) @@ -67,4 +69,29 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitMilliSecondsDiff(this, context); } + + @Override + public boolean isMonotonic() { + return !(child(0) instanceof Literal) && child(1) instanceof Literal + || child(0) instanceof Literal && !(child(1) instanceof Literal); + } + + @Override + public boolean isPositive() { + return child(1) instanceof Literal; + } + + @Override + public int getMonotonicFunctionChildIndex() { + return child(1) instanceof Literal ? 0 : 1; + } + + @Override + public Expression withConstantArgs(Expression literal) { + if (child(1) instanceof Literal) { + return new MilliSecondsDiff(literal, child(1)); + } else { + return new MilliSecondsDiff(child(0), literal); + } + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MilliSecondsSub.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MilliSecondsSub.java index 42891b7e7e0b22..8554b2fd5a6349 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MilliSecondsSub.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MilliSecondsSub.java @@ -20,7 +20,9 @@ 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.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; +import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeV2Type; @@ -35,7 +37,7 @@ * ScalarFunction 'MilliSeconds_sub'. */ public class MilliSecondsSub extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.MAX) @@ -66,4 +68,24 @@ public FunctionSignature computeSignature(FunctionSignature signature) { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitMilliSecondsSub(this, context); } + + @Override + public boolean isMonotonic() { + return child(1) instanceof IntegerLiteral; + } + + @Override + public boolean isPositive() { + return true; + } + + @Override + public int getMonotonicFunctionChildIndex() { + return 0; + } + + @Override + public Expression withConstantArgs(Expression literal) { + return new MilliSecondsSub(literal, child(1)); + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinutesAdd.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinutesAdd.java index f4c02fb84ca3d6..c86d0b2c3c1a0c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinutesAdd.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinutesAdd.java @@ -20,7 +20,9 @@ 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.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; +import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeType; @@ -38,7 +40,7 @@ * ScalarFunction 'minutes_add'. */ public class MinutesAdd extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT) @@ -67,4 +69,24 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitMinutesAdd(this, context); } + + @Override + public boolean isMonotonic() { + return child(1) instanceof IntegerLiteral; + } + + @Override + public boolean isPositive() { + return true; + } + + @Override + public int getMonotonicFunctionChildIndex() { + return 0; + } + + @Override + public Expression withConstantArgs(Expression literal) { + return new MinutesAdd(literal, child(1)); + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinutesDiff.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinutesDiff.java index 4d011116334bf4..c9e9d1b5b160fe 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinutesDiff.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinutesDiff.java @@ -20,7 +20,9 @@ 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.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; +import org.apache.doris.nereids.trees.expressions.literal.Literal; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.BigIntType; @@ -37,7 +39,7 @@ * ScalarFunction 'minutes_diff'. This class is generated by GenerateFunction. */ public class MinutesDiff extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(BigIntType.INSTANCE) @@ -73,4 +75,29 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitMinutesDiff(this, context); } + + @Override + public boolean isMonotonic() { + return !(child(0) instanceof Literal) && child(1) instanceof Literal + || child(0) instanceof Literal && !(child(1) instanceof Literal); + } + + @Override + public boolean isPositive() { + return child(1) instanceof Literal; + } + + @Override + public int getMonotonicFunctionChildIndex() { + return child(1) instanceof Literal ? 0 : 1; + } + + @Override + public Expression withConstantArgs(Expression literal) { + if (child(1) instanceof Literal) { + return new MinutesDiff(literal, child(1)); + } else { + return new MinutesDiff(child(0), literal); + } + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinutesSub.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinutesSub.java index 4fb616957813a7..0cfdc01474d886 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinutesSub.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinutesSub.java @@ -20,7 +20,9 @@ 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.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; +import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeType; @@ -38,7 +40,7 @@ * ScalarFunction 'minutes_sub'. */ public class MinutesSub extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT) @@ -67,4 +69,24 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitMinutesSub(this, context); } + + @Override + public boolean isMonotonic() { + return child(1) instanceof IntegerLiteral; + } + + @Override + public boolean isPositive() { + return true; + } + + @Override + public int getMonotonicFunctionChildIndex() { + return 0; + } + + @Override + public Expression withConstantArgs(Expression literal) { + return new MinutesSub(literal, child(1)); + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthsAdd.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthsAdd.java index 5126400b71efaa..05338077e81c89 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthsAdd.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthsAdd.java @@ -22,7 +22,9 @@ import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.ComputeSignatureForDateArithmetic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; +import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; +import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeType; @@ -41,7 +43,7 @@ */ public class MonthsAdd extends ScalarFunction implements BinaryExpression, ExplicitlyCastableSignature, - ComputeSignatureForDateArithmetic, PropagateNullableOnDateLikeV2Args { + ComputeSignatureForDateArithmetic, PropagateNullableOnDateLikeV2Args, Monotonic { // When enable_date_conversion is true, we prefer to V2 signature. // This preference follows original planner. refer to ScalarType.getDefaultDateType() @@ -78,4 +80,24 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitMonthsAdd(this, context); } + + @Override + public boolean isMonotonic() { + return child(1) instanceof IntegerLiteral; + } + + @Override + public boolean isPositive() { + return true; + } + + @Override + public int getMonotonicFunctionChildIndex() { + return 0; + } + + @Override + public Expression withConstantArgs(Expression literal) { + return new MonthsAdd(literal, child(1)); + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthsDiff.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthsDiff.java index 373265b1e3822a..221dab7a4ae45b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthsDiff.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthsDiff.java @@ -20,7 +20,9 @@ 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.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; +import org.apache.doris.nereids.trees.expressions.literal.Literal; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.BigIntType; @@ -37,7 +39,7 @@ * ScalarFunction 'months_diff'. This class is generated by GenerateFunction. */ public class MonthsDiff extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(BigIntType.INSTANCE).args(DateV2Type.INSTANCE, DateV2Type.INSTANCE), @@ -73,4 +75,29 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitMonthsDiff(this, context); } + + @Override + public boolean isMonotonic() { + return !(child(0) instanceof Literal) && child(1) instanceof Literal + || child(0) instanceof Literal && !(child(1) instanceof Literal); + } + + @Override + public boolean isPositive() { + return child(1) instanceof Literal; + } + + @Override + public int getMonotonicFunctionChildIndex() { + return child(1) instanceof Literal ? 0 : 1; + } + + @Override + public Expression withConstantArgs(Expression literal) { + if (child(1) instanceof Literal) { + return new MonthsDiff(literal, child(1)); + } else { + return new MonthsDiff(child(0), literal); + } + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthsSub.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthsSub.java index 1c2985a6e136e2..12a05f74ad9d5b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthsSub.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthsSub.java @@ -22,7 +22,9 @@ import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.ComputeSignatureForDateArithmetic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; +import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; +import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeType; @@ -41,7 +43,7 @@ */ public class MonthsSub extends ScalarFunction implements BinaryExpression, ExplicitlyCastableSignature, - ComputeSignatureForDateArithmetic, PropagateNullableOnDateLikeV2Args { + ComputeSignatureForDateArithmetic, PropagateNullableOnDateLikeV2Args, Monotonic { // When enable_date_conversion is true, we prefer to V2 signature. // This preference follows original planner. refer to ScalarType.getDefaultDateType() @@ -78,4 +80,24 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitMonthsSub(this, context); } + + @Override + public boolean isMonotonic() { + return child(1) instanceof IntegerLiteral; + } + + @Override + public boolean isPositive() { + return true; + } + + @Override + public int getMonotonicFunctionChildIndex() { + return 0; + } + + @Override + public Expression withConstantArgs(Expression literal) { + return new MonthsSub(literal, child(1)); + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondsAdd.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondsAdd.java index a6e131f5263537..40431a36bb44be 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondsAdd.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondsAdd.java @@ -20,7 +20,9 @@ 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.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; +import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeType; @@ -38,7 +40,7 @@ * ScalarFunction 'minutes_add'. */ public class SecondsAdd extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT) @@ -67,4 +69,24 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitSecondsAdd(this, context); } + + @Override + public boolean isMonotonic() { + return child(1) instanceof IntegerLiteral; + } + + @Override + public boolean isPositive() { + return true; + } + + @Override + public int getMonotonicFunctionChildIndex() { + return 0; + } + + @Override + public Expression withConstantArgs(Expression literal) { + return new SecondsAdd(literal, child(1)); + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondsDiff.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondsDiff.java index 4dd7e12b9e2f32..5eae7d75f30365 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondsDiff.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondsDiff.java @@ -20,7 +20,9 @@ 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.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; +import org.apache.doris.nereids.trees.expressions.literal.Literal; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.BigIntType; @@ -37,7 +39,7 @@ * ScalarFunction 'seconds_diff'. This class is generated by GenerateFunction. */ public class SecondsDiff extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(BigIntType.INSTANCE) @@ -73,4 +75,29 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitSecondsDiff(this, context); } + + @Override + public boolean isMonotonic() { + return !(child(0) instanceof Literal) && child(1) instanceof Literal + || child(0) instanceof Literal && !(child(1) instanceof Literal); + } + + @Override + public boolean isPositive() { + return child(1) instanceof Literal; + } + + @Override + public int getMonotonicFunctionChildIndex() { + return child(1) instanceof Literal ? 0 : 1; + } + + @Override + public Expression withConstantArgs(Expression literal) { + if (child(1) instanceof Literal) { + return new SecondsDiff(literal, child(1)); + } else { + return new SecondsDiff(child(0), literal); + } + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondsSub.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondsSub.java index 37c59b2168bda2..8e10d7665b7ed6 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondsSub.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondsSub.java @@ -20,7 +20,9 @@ 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.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; +import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeType; @@ -38,7 +40,7 @@ * ScalarFunction 'Seconds_sub'. */ public class SecondsSub extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT) @@ -67,4 +69,24 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitSecondsSub(this, context); } + + @Override + public boolean isMonotonic() { + return child(1) instanceof IntegerLiteral; + } + + @Override + public boolean isPositive() { + return true; + } + + @Override + public int getMonotonicFunctionChildIndex() { + return 0; + } + + @Override + public Expression withConstantArgs(Expression literal) { + return new SecondsSub(literal, child(1)); + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearsAdd.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearsAdd.java index 33c9e1c6dfa5e8..e41865f569e53f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearsAdd.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearsAdd.java @@ -22,7 +22,9 @@ import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.ComputeSignatureForDateArithmetic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; +import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; +import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeType; @@ -41,7 +43,7 @@ */ public class YearsAdd extends ScalarFunction implements BinaryExpression, ExplicitlyCastableSignature, - ComputeSignatureForDateArithmetic, PropagateNullableOnDateLikeV2Args { + ComputeSignatureForDateArithmetic, PropagateNullableOnDateLikeV2Args, Monotonic { // When enable_date_conversion is true, we prefer to V2 signature. // This preference follows original planner. refer to ScalarType.getDefaultDateType() @@ -78,4 +80,24 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitYearsAdd(this, context); } + + @Override + public boolean isMonotonic() { + return child(1) instanceof IntegerLiteral; + } + + @Override + public boolean isPositive() { + return true; + } + + @Override + public int getMonotonicFunctionChildIndex() { + return 0; + } + + @Override + public Expression withConstantArgs(Expression literal) { + return new YearsAdd(literal, child(1)); + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearsDiff.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearsDiff.java index e217d8da72902a..a778e41e93a323 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearsDiff.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearsDiff.java @@ -20,7 +20,9 @@ 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.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; +import org.apache.doris.nereids.trees.expressions.literal.Literal; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.BigIntType; @@ -37,7 +39,7 @@ * ScalarFunction 'years_diff'. This class is generated by GenerateFunction. */ public class YearsDiff extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(BigIntType.INSTANCE).args(DateV2Type.INSTANCE, DateV2Type.INSTANCE), @@ -73,4 +75,29 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitYearsDiff(this, context); } + + @Override + public boolean isMonotonic() { + return !(child(0) instanceof Literal) && child(1) instanceof Literal + || child(0) instanceof Literal && !(child(1) instanceof Literal); + } + + @Override + public boolean isPositive() { + return child(1) instanceof Literal; + } + + @Override + public int getMonotonicFunctionChildIndex() { + return child(1) instanceof Literal ? 0 : 1; + } + + @Override + public Expression withConstantArgs(Expression literal) { + if (child(1) instanceof Literal) { + return new YearsDiff(literal, child(1)); + } else { + return new YearsDiff(child(0), literal); + } + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearsSub.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearsSub.java index b70444178df508..09b6d643b96652 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearsSub.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearsSub.java @@ -22,7 +22,9 @@ import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.ComputeSignatureForDateArithmetic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; +import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; +import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeType; @@ -41,7 +43,7 @@ */ public class YearsSub extends ScalarFunction implements BinaryExpression, ExplicitlyCastableSignature, - ComputeSignatureForDateArithmetic, PropagateNullableOnDateLikeV2Args { + ComputeSignatureForDateArithmetic, PropagateNullableOnDateLikeV2Args, Monotonic { // When enable_date_conversion is true, we prefer to V2 signature. // This preference follows original planner. refer to ScalarType.getDefaultDateType() @@ -78,4 +80,24 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitYearsSub(this, context); } + + @Override + public boolean isMonotonic() { + return child(1) instanceof IntegerLiteral; + } + + @Override + public boolean isPositive() { + return true; + } + + @Override + public int getMonotonicFunctionChildIndex() { + return 0; + } + + @Override + public Expression withConstantArgs(Expression literal) { + return new YearsSub(literal, child(1)); + } } From 8789c4f4cb83b0660924833956cb7569cfd8d550 Mon Sep 17 00:00:00 2001 From: feiniaofeiafei Date: Tue, 3 Dec 2024 20:12:35 +0800 Subject: [PATCH 02/10] add xx_floor xx_ceil and test --- .../functions/DateAddSubMonotonic.java | 38 +++ .../functions/DateCeilFloorMonotonic.java | 47 +++ .../functions/DateDiffMonotonic.java | 39 +++ .../expressions/functions/scalar/DayCeil.java | 18 +- .../functions/scalar/DayFloor.java | 18 +- .../expressions/functions/scalar/DaysAdd.java | 20 +- .../functions/scalar/DaysDiff.java | 20 +- .../expressions/functions/scalar/DaysSub.java | 20 +- .../functions/scalar/HourCeil.java | 18 +- .../functions/scalar/HourFloor.java | 18 +- .../functions/scalar/HoursAdd.java | 21 +- .../functions/scalar/HoursDiff.java | 20 +- .../functions/scalar/HoursSub.java | 21 +- .../functions/scalar/MicroSecondsAdd.java | 21 +- .../functions/scalar/MicroSecondsDiff.java | 20 +- .../functions/scalar/MicroSecondsSub.java | 21 +- .../functions/scalar/MilliSecondsAdd.java | 21 +- .../functions/scalar/MilliSecondsDiff.java | 20 +- .../functions/scalar/MilliSecondsSub.java | 21 +- .../functions/scalar/MinuteCeil.java | 18 +- .../functions/scalar/MinuteFloor.java | 18 +- .../functions/scalar/MinutesAdd.java | 21 +- .../functions/scalar/MinutesDiff.java | 20 +- .../functions/scalar/MinutesSub.java | 21 +- .../functions/scalar/MonthCeil.java | 18 +- .../functions/scalar/MonthFloor.java | 18 +- .../functions/scalar/MonthsAdd.java | 20 +- .../functions/scalar/MonthsDiff.java | 20 +- .../functions/scalar/MonthsSub.java | 20 +- .../functions/scalar/SecondCeil.java | 18 +- .../functions/scalar/SecondFloor.java | 18 +- .../functions/scalar/SecondsAdd.java | 21 +- .../functions/scalar/SecondsDiff.java | 20 +- .../functions/scalar/SecondsSub.java | 21 +- .../functions/scalar/YearCeil.java | 18 +- .../functions/scalar/YearFloor.java | 18 +- .../functions/scalar/YearsAdd.java | 20 +- .../functions/scalar/YearsDiff.java | 20 +- .../functions/scalar/YearsSub.java | 20 +- .../test_add_sub_diff_ceil_floor.groovy | 296 ++++++++++++++++++ 40 files changed, 682 insertions(+), 444 deletions(-) create mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/DateAddSubMonotonic.java create mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/DateCeilFloorMonotonic.java create mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/DateDiffMonotonic.java create mode 100644 regression-test/suites/nereids_rules_p0/partition_prune/test_add_sub_diff_ceil_floor.groovy diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/DateAddSubMonotonic.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/DateAddSubMonotonic.java new file mode 100644 index 00000000000000..46c9497ea7f020 --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/DateAddSubMonotonic.java @@ -0,0 +1,38 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.doris.nereids.trees.expressions.functions; + +import org.apache.doris.nereids.trees.expressions.literal.Literal; + +/** monotonicity for XX_ADD XX_SUB */ +public interface DateAddSubMonotonic extends Monotonic { + @Override + default boolean isMonotonic() { + return child(1) instanceof Literal; + } + + @Override + default boolean isPositive() { + return true; + } + + @Override + default int getMonotonicFunctionChildIndex() { + return 0; + } +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/DateCeilFloorMonotonic.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/DateCeilFloorMonotonic.java new file mode 100644 index 00000000000000..b06dfae13b5a40 --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/DateCeilFloorMonotonic.java @@ -0,0 +1,47 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.doris.nereids.trees.expressions.functions; + +import org.apache.doris.nereids.trees.expressions.literal.Literal; + +/** monotonicity of XX_CEIL and XX_FLOOR */ +public interface DateCeilFloorMonotonic extends Monotonic { + @Override + default boolean isMonotonic() { + switch (arity()) { + case 1: + return true; + case 2: + return !(child(0) instanceof Literal) && child(1) instanceof Literal; + case 3: + return !(child(0) instanceof Literal) && child(1) instanceof Literal && child(2) instanceof Literal; + default: + return false; + } + } + + @Override + default boolean isPositive() { + return true; + } + + @Override + default int getMonotonicFunctionChildIndex() { + return 0; + } +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/DateDiffMonotonic.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/DateDiffMonotonic.java new file mode 100644 index 00000000000000..8b86d8ed1c194f --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/DateDiffMonotonic.java @@ -0,0 +1,39 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.doris.nereids.trees.expressions.functions; + +import org.apache.doris.nereids.trees.expressions.literal.Literal; + +/** monotonicity for XX_DIFF */ +public interface DateDiffMonotonic extends Monotonic { + @Override + default boolean isMonotonic() { + return !(child(0) instanceof Literal) && child(1) instanceof Literal + || child(0) instanceof Literal && !(child(1) instanceof Literal); + } + + @Override + default boolean isPositive() { + return child(1) instanceof Literal; + } + + @Override + default int getMonotonicFunctionChildIndex() { + return child(1) instanceof Literal ? 0 : 1; + } +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DayCeil.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DayCeil.java index e77c307b523869..e0eeece6b300c0 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DayCeil.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DayCeil.java @@ -20,6 +20,7 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable; +import org.apache.doris.nereids.trees.expressions.functions.DateCeilFloorMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullLiteral; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; @@ -37,7 +38,7 @@ * ScalarFunction 'day_ceil'. This class is generated by GenerateFunction. */ public class DayCeil extends ScalarFunction - implements ExplicitlyCastableSignature, AlwaysNullable, PropagateNullLiteral { + implements ExplicitlyCastableSignature, AlwaysNullable, PropagateNullLiteral, DateCeilFloorMonotonic { public static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT).args(DateTimeV2Type.SYSTEM_DEFAULT), @@ -106,4 +107,19 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitDayCeil(this, context); } + + @Override + public Expression withConstantArgs(Expression literal) { + switch (arity()) { + case 1: + return new DayCeil(literal); + case 2: + return new DayCeil(literal, child(1)); + case 3: + return new DayCeil(literal, child(1), child(2)); + default: + // should not reach + return null; + } + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DayFloor.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DayFloor.java index b7e04e3a374629..804658ce984fa9 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DayFloor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DayFloor.java @@ -20,6 +20,7 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable; +import org.apache.doris.nereids.trees.expressions.functions.DateCeilFloorMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullLiteral; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; @@ -37,7 +38,7 @@ * ScalarFunction 'day_floor'. This class is generated by GenerateFunction. */ public class DayFloor extends ScalarFunction - implements ExplicitlyCastableSignature, AlwaysNullable, PropagateNullLiteral { + implements ExplicitlyCastableSignature, AlwaysNullable, PropagateNullLiteral, DateCeilFloorMonotonic { public static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT).args(DateTimeV2Type.SYSTEM_DEFAULT), @@ -106,4 +107,19 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitDayFloor(this, context); } + + @Override + public Expression withConstantArgs(Expression literal) { + switch (arity()) { + case 1: + return new DayFloor(literal); + case 2: + return new DayFloor(literal, child(1)); + case 3: + return new DayFloor(literal, child(1), child(2)); + default: + // should not reach + return null; + } + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DaysAdd.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DaysAdd.java index 95e5d3db318e89..a231816a330eff 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DaysAdd.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DaysAdd.java @@ -21,10 +21,9 @@ import org.apache.doris.common.Config; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.ComputeSignatureForDateArithmetic; +import org.apache.doris.nereids.trees.expressions.functions.DateAddSubMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; -import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; -import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeType; @@ -43,7 +42,7 @@ */ public class DaysAdd extends ScalarFunction implements BinaryExpression, ExplicitlyCastableSignature, - ComputeSignatureForDateArithmetic, PropagateNullableOnDateLikeV2Args, Monotonic { + ComputeSignatureForDateArithmetic, PropagateNullableOnDateLikeV2Args, DateAddSubMonotonic { // When enable_date_conversion is true, we prefer to V2 signature. // This preference follows original planner. refer to ScalarType.getDefaultDateType() private static final List SIGNATURES = Config.enable_date_conversion ? ImmutableList.of( @@ -80,21 +79,6 @@ public R accept(ExpressionVisitor visitor, C context) { return visitor.visitDaysAdd(this, context); } - @Override - public boolean isMonotonic() { - return child(1) instanceof IntegerLiteral; - } - - @Override - public boolean isPositive() { - return true; - } - - @Override - public int getMonotonicFunctionChildIndex() { - return 0; - } - @Override public Expression withConstantArgs(Expression literal) { return new DaysAdd(literal, child(1)); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DaysDiff.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DaysDiff.java index c65a4b56119d83..c6f3377fdc99c5 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DaysDiff.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DaysDiff.java @@ -19,8 +19,8 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.DateDiffMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; -import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; import org.apache.doris.nereids.trees.expressions.literal.Literal; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; @@ -39,7 +39,7 @@ * ScalarFunction 'days_diff'. This class is generated by GenerateFunction. */ public class DaysDiff extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, DateDiffMonotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(BigIntType.INSTANCE) @@ -76,22 +76,6 @@ public R accept(ExpressionVisitor visitor, C context) { return visitor.visitDaysDiff(this, context); } - @Override - public boolean isMonotonic() { - return !(child(0) instanceof Literal) && child(1) instanceof Literal - || child(0) instanceof Literal && !(child(1) instanceof Literal); - } - - @Override - public boolean isPositive() { - return child(1) instanceof Literal; - } - - @Override - public int getMonotonicFunctionChildIndex() { - return child(1) instanceof Literal ? 0 : 1; - } - @Override public Expression withConstantArgs(Expression literal) { if (child(1) instanceof Literal) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DaysSub.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DaysSub.java index c2b408b933a101..5dab58ecdf63c5 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DaysSub.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DaysSub.java @@ -21,10 +21,9 @@ import org.apache.doris.common.Config; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.ComputeSignatureForDateArithmetic; +import org.apache.doris.nereids.trees.expressions.functions.DateAddSubMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; -import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; -import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeType; @@ -43,7 +42,7 @@ */ public class DaysSub extends ScalarFunction implements BinaryExpression, ExplicitlyCastableSignature, - ComputeSignatureForDateArithmetic, PropagateNullableOnDateLikeV2Args, Monotonic { + ComputeSignatureForDateArithmetic, PropagateNullableOnDateLikeV2Args, DateAddSubMonotonic { // When enable_date_conversion is true, we prefer to V2 signature. // This preference follows original planner. refer to ScalarType.getDefaultDateType() private static final List SIGNATURES = Config.enable_date_conversion ? ImmutableList.of( @@ -80,21 +79,6 @@ public R accept(ExpressionVisitor visitor, C context) { return visitor.visitDaysSub(this, context); } - @Override - public boolean isMonotonic() { - return child(1) instanceof IntegerLiteral; - } - - @Override - public boolean isPositive() { - return true; - } - - @Override - public int getMonotonicFunctionChildIndex() { - return 0; - } - @Override public Expression withConstantArgs(Expression literal) { return new DaysSub(literal, child(1)); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HourCeil.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HourCeil.java index e76151ef9d682c..4c8a98ca9fd025 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HourCeil.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HourCeil.java @@ -20,6 +20,7 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable; +import org.apache.doris.nereids.trees.expressions.functions.DateCeilFloorMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullLiteral; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; @@ -36,7 +37,7 @@ * ScalarFunction 'hour_ceil'. This class is generated by GenerateFunction. */ public class HourCeil extends ScalarFunction - implements ExplicitlyCastableSignature, AlwaysNullable, PropagateNullLiteral { + implements ExplicitlyCastableSignature, AlwaysNullable, PropagateNullLiteral, DateCeilFloorMonotonic { public static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT).args(DateTimeV2Type.SYSTEM_DEFAULT), @@ -100,4 +101,19 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitHourCeil(this, context); } + + @Override + public Expression withConstantArgs(Expression literal) { + switch (arity()) { + case 1: + return new HourCeil(literal); + case 2: + return new HourCeil(literal, child(1)); + case 3: + return new HourCeil(literal, child(1), child(2)); + default: + // should not reach + return null; + } + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HourFloor.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HourFloor.java index 567f0a2dd188da..1148c3191612f0 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HourFloor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HourFloor.java @@ -20,6 +20,7 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable; +import org.apache.doris.nereids.trees.expressions.functions.DateCeilFloorMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullLiteral; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; @@ -36,7 +37,7 @@ * ScalarFunction 'hour_floor'. This class is generated by GenerateFunction. */ public class HourFloor extends ScalarFunction - implements ExplicitlyCastableSignature, AlwaysNullable, PropagateNullLiteral { + implements ExplicitlyCastableSignature, AlwaysNullable, PropagateNullLiteral, DateCeilFloorMonotonic { public static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT).args(DateTimeV2Type.SYSTEM_DEFAULT), @@ -100,4 +101,19 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitHourFloor(this, context); } + + @Override + public Expression withConstantArgs(Expression literal) { + switch (arity()) { + case 1: + return new HourFloor(literal); + case 2: + return new HourFloor(literal, child(1)); + case 3: + return new HourFloor(literal, child(1), child(2)); + default: + // should not reach + return null; + } + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HoursAdd.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HoursAdd.java index e29414b76a6b6e..4c10b204597975 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HoursAdd.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HoursAdd.java @@ -19,10 +19,9 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.DateAddSubMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; -import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; -import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeType; @@ -40,7 +39,8 @@ * ScalarFunction 'days_add'. */ public class HoursAdd extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, + DateAddSubMonotonic { public static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT) @@ -70,21 +70,6 @@ public R accept(ExpressionVisitor visitor, C context) { return visitor.visitHoursAdd(this, context); } - @Override - public boolean isMonotonic() { - return child(1) instanceof IntegerLiteral; - } - - @Override - public boolean isPositive() { - return true; - } - - @Override - public int getMonotonicFunctionChildIndex() { - return 0; - } - @Override public Expression withConstantArgs(Expression literal) { return new HoursAdd(literal, child(1)); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HoursDiff.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HoursDiff.java index 1b71306a359111..63942cd56e9e5b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HoursDiff.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HoursDiff.java @@ -19,8 +19,8 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.DateDiffMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; -import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; import org.apache.doris.nereids.trees.expressions.literal.Literal; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; @@ -39,7 +39,7 @@ * ScalarFunction 'hours_diff'. This class is generated by GenerateFunction. */ public class HoursDiff extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, DateDiffMonotonic { public static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(BigIntType.INSTANCE) @@ -76,22 +76,6 @@ public R accept(ExpressionVisitor visitor, C context) { return visitor.visitHoursDiff(this, context); } - @Override - public boolean isMonotonic() { - return !(child(0) instanceof Literal) && child(1) instanceof Literal - || child(0) instanceof Literal && !(child(1) instanceof Literal); - } - - @Override - public boolean isPositive() { - return child(1) instanceof Literal; - } - - @Override - public int getMonotonicFunctionChildIndex() { - return child(1) instanceof Literal ? 0 : 1; - } - @Override public Expression withConstantArgs(Expression literal) { if (child(1) instanceof Literal) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HoursSub.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HoursSub.java index ac244d04dd12a6..49e8e5cb50f69a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HoursSub.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HoursSub.java @@ -19,10 +19,9 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.DateAddSubMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; -import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; -import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeType; @@ -40,7 +39,8 @@ * ScalarFunction 'hours_sub'. */ public class HoursSub extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, + DateAddSubMonotonic { public static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT) @@ -70,21 +70,6 @@ public R accept(ExpressionVisitor visitor, C context) { return visitor.visitHoursSub(this, context); } - @Override - public boolean isMonotonic() { - return child(1) instanceof IntegerLiteral; - } - - @Override - public boolean isPositive() { - return true; - } - - @Override - public int getMonotonicFunctionChildIndex() { - return 0; - } - @Override public Expression withConstantArgs(Expression literal) { return new HoursSub(literal, child(1)); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MicroSecondsAdd.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MicroSecondsAdd.java index 9951939837796f..33dd5809f2b1a8 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MicroSecondsAdd.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MicroSecondsAdd.java @@ -19,10 +19,9 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.DateAddSubMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; -import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; -import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeV2Type; @@ -37,7 +36,8 @@ * ScalarFunction 'MicroSeconds_add'. */ public class MicroSecondsAdd extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, + DateAddSubMonotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.MAX) @@ -69,21 +69,6 @@ public R accept(ExpressionVisitor visitor, C context) { return visitor.visitMicroSecondsAdd(this, context); } - @Override - public boolean isMonotonic() { - return child(1) instanceof IntegerLiteral; - } - - @Override - public boolean isPositive() { - return true; - } - - @Override - public int getMonotonicFunctionChildIndex() { - return 0; - } - @Override public Expression withConstantArgs(Expression literal) { return new MicroSecondsAdd(literal, child(1)); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MicroSecondsDiff.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MicroSecondsDiff.java index 0d093363d5c7e7..160e8a96b13e68 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MicroSecondsDiff.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MicroSecondsDiff.java @@ -19,8 +19,8 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.DateDiffMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; -import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; import org.apache.doris.nereids.trees.expressions.literal.Literal; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; @@ -37,7 +37,7 @@ * ScalarFunction 'microseconds_diff'. This class is generated by GenerateFunction. */ public class MicroSecondsDiff extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, DateDiffMonotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(BigIntType.INSTANCE) @@ -70,22 +70,6 @@ public R accept(ExpressionVisitor visitor, C context) { return visitor.visitMicroSecondsDiff(this, context); } - @Override - public boolean isMonotonic() { - return !(child(0) instanceof Literal) && child(1) instanceof Literal - || child(0) instanceof Literal && !(child(1) instanceof Literal); - } - - @Override - public boolean isPositive() { - return child(1) instanceof Literal; - } - - @Override - public int getMonotonicFunctionChildIndex() { - return child(1) instanceof Literal ? 0 : 1; - } - @Override public Expression withConstantArgs(Expression literal) { if (child(1) instanceof Literal) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MicroSecondsSub.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MicroSecondsSub.java index 16836a8f4c6590..20c880fb879298 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MicroSecondsSub.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MicroSecondsSub.java @@ -19,10 +19,9 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.DateAddSubMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; -import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; -import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeV2Type; @@ -37,7 +36,8 @@ * ScalarFunction 'MicroSeconds_sub'. */ public class MicroSecondsSub extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, + DateAddSubMonotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.MAX) @@ -69,21 +69,6 @@ public R accept(ExpressionVisitor visitor, C context) { return visitor.visitMicroSecondsSub(this, context); } - @Override - public boolean isMonotonic() { - return child(1) instanceof IntegerLiteral; - } - - @Override - public boolean isPositive() { - return true; - } - - @Override - public int getMonotonicFunctionChildIndex() { - return 0; - } - @Override public Expression withConstantArgs(Expression literal) { return new MicroSecondsSub(literal, child(1)); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MilliSecondsAdd.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MilliSecondsAdd.java index d608850bd7d7bb..244b661db3afed 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MilliSecondsAdd.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MilliSecondsAdd.java @@ -19,10 +19,9 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.DateAddSubMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; -import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; -import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeV2Type; @@ -37,7 +36,8 @@ * ScalarFunction 'MilliSeconds_add'. */ public class MilliSecondsAdd extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, + DateAddSubMonotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.MAX) @@ -69,21 +69,6 @@ public R accept(ExpressionVisitor visitor, C context) { return visitor.visitMilliSecondsAdd(this, context); } - @Override - public boolean isMonotonic() { - return child(1) instanceof IntegerLiteral; - } - - @Override - public boolean isPositive() { - return true; - } - - @Override - public int getMonotonicFunctionChildIndex() { - return 0; - } - @Override public Expression withConstantArgs(Expression literal) { return new MilliSecondsAdd(literal, child(1)); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MilliSecondsDiff.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MilliSecondsDiff.java index a54b50a948b0af..0e8c623ce176b2 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MilliSecondsDiff.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MilliSecondsDiff.java @@ -19,8 +19,8 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.DateDiffMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; -import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; import org.apache.doris.nereids.trees.expressions.literal.Literal; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; @@ -37,7 +37,7 @@ * ScalarFunction 'milliseconds_diff'. This class is generated by GenerateFunction. */ public class MilliSecondsDiff extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, DateDiffMonotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(BigIntType.INSTANCE) @@ -70,22 +70,6 @@ public R accept(ExpressionVisitor visitor, C context) { return visitor.visitMilliSecondsDiff(this, context); } - @Override - public boolean isMonotonic() { - return !(child(0) instanceof Literal) && child(1) instanceof Literal - || child(0) instanceof Literal && !(child(1) instanceof Literal); - } - - @Override - public boolean isPositive() { - return child(1) instanceof Literal; - } - - @Override - public int getMonotonicFunctionChildIndex() { - return child(1) instanceof Literal ? 0 : 1; - } - @Override public Expression withConstantArgs(Expression literal) { if (child(1) instanceof Literal) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MilliSecondsSub.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MilliSecondsSub.java index 8554b2fd5a6349..10b4f8184d12d8 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MilliSecondsSub.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MilliSecondsSub.java @@ -19,10 +19,9 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.DateAddSubMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; -import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; -import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeV2Type; @@ -37,7 +36,8 @@ * ScalarFunction 'MilliSeconds_sub'. */ public class MilliSecondsSub extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, + DateAddSubMonotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.MAX) @@ -69,21 +69,6 @@ public R accept(ExpressionVisitor visitor, C context) { return visitor.visitMilliSecondsSub(this, context); } - @Override - public boolean isMonotonic() { - return child(1) instanceof IntegerLiteral; - } - - @Override - public boolean isPositive() { - return true; - } - - @Override - public int getMonotonicFunctionChildIndex() { - return 0; - } - @Override public Expression withConstantArgs(Expression literal) { return new MilliSecondsSub(literal, child(1)); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinuteCeil.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinuteCeil.java index b00eaff07c2c62..55e34cd1435565 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinuteCeil.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinuteCeil.java @@ -20,6 +20,7 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable; +import org.apache.doris.nereids.trees.expressions.functions.DateCeilFloorMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeType; @@ -35,7 +36,7 @@ * ScalarFunction 'minute_ceil'. This class is generated by GenerateFunction. */ public class MinuteCeil extends ScalarFunction - implements ExplicitlyCastableSignature, AlwaysNullable { + implements ExplicitlyCastableSignature, AlwaysNullable, DateCeilFloorMonotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT).args(DateTimeV2Type.SYSTEM_DEFAULT), @@ -99,4 +100,19 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitMinuteCeil(this, context); } + + @Override + public Expression withConstantArgs(Expression literal) { + switch (arity()) { + case 1: + return new MinuteCeil(literal); + case 2: + return new MinuteCeil(literal, child(1)); + case 3: + return new MinuteCeil(literal, child(1), child(2)); + default: + // should not reach + return null; + } + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinuteFloor.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinuteFloor.java index 683acc3a48381c..7aab30162aa14f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinuteFloor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinuteFloor.java @@ -20,6 +20,7 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable; +import org.apache.doris.nereids.trees.expressions.functions.DateCeilFloorMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeType; @@ -35,7 +36,7 @@ * ScalarFunction 'minute_floor'. This class is generated by GenerateFunction. */ public class MinuteFloor extends ScalarFunction - implements ExplicitlyCastableSignature, AlwaysNullable { + implements ExplicitlyCastableSignature, AlwaysNullable, DateCeilFloorMonotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT).args(DateTimeV2Type.SYSTEM_DEFAULT), @@ -99,4 +100,19 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitMinuteFloor(this, context); } + + @Override + public Expression withConstantArgs(Expression literal) { + switch (arity()) { + case 1: + return new MinuteFloor(literal); + case 2: + return new MinuteFloor(literal, child(1)); + case 3: + return new MinuteFloor(literal, child(1), child(2)); + default: + // should not reach + return null; + } + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinutesAdd.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinutesAdd.java index c86d0b2c3c1a0c..8ba1642f6248b6 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinutesAdd.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinutesAdd.java @@ -19,10 +19,9 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.DateAddSubMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; -import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; -import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeType; @@ -40,7 +39,8 @@ * ScalarFunction 'minutes_add'. */ public class MinutesAdd extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, + DateAddSubMonotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT) @@ -70,21 +70,6 @@ public R accept(ExpressionVisitor visitor, C context) { return visitor.visitMinutesAdd(this, context); } - @Override - public boolean isMonotonic() { - return child(1) instanceof IntegerLiteral; - } - - @Override - public boolean isPositive() { - return true; - } - - @Override - public int getMonotonicFunctionChildIndex() { - return 0; - } - @Override public Expression withConstantArgs(Expression literal) { return new MinutesAdd(literal, child(1)); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinutesDiff.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinutesDiff.java index c9e9d1b5b160fe..91c254be7c14dc 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinutesDiff.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinutesDiff.java @@ -19,8 +19,8 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.DateDiffMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; -import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; import org.apache.doris.nereids.trees.expressions.literal.Literal; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; @@ -39,7 +39,7 @@ * ScalarFunction 'minutes_diff'. This class is generated by GenerateFunction. */ public class MinutesDiff extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, DateDiffMonotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(BigIntType.INSTANCE) @@ -76,22 +76,6 @@ public R accept(ExpressionVisitor visitor, C context) { return visitor.visitMinutesDiff(this, context); } - @Override - public boolean isMonotonic() { - return !(child(0) instanceof Literal) && child(1) instanceof Literal - || child(0) instanceof Literal && !(child(1) instanceof Literal); - } - - @Override - public boolean isPositive() { - return child(1) instanceof Literal; - } - - @Override - public int getMonotonicFunctionChildIndex() { - return child(1) instanceof Literal ? 0 : 1; - } - @Override public Expression withConstantArgs(Expression literal) { if (child(1) instanceof Literal) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinutesSub.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinutesSub.java index 0cfdc01474d886..2a29d9e1659963 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinutesSub.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinutesSub.java @@ -19,10 +19,9 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.DateAddSubMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; -import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; -import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeType; @@ -40,7 +39,8 @@ * ScalarFunction 'minutes_sub'. */ public class MinutesSub extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, + DateAddSubMonotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT) @@ -70,21 +70,6 @@ public R accept(ExpressionVisitor visitor, C context) { return visitor.visitMinutesSub(this, context); } - @Override - public boolean isMonotonic() { - return child(1) instanceof IntegerLiteral; - } - - @Override - public boolean isPositive() { - return true; - } - - @Override - public int getMonotonicFunctionChildIndex() { - return 0; - } - @Override public Expression withConstantArgs(Expression literal) { return new MinutesSub(literal, child(1)); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthCeil.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthCeil.java index 627568cf28a145..7d3514610d49ea 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthCeil.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthCeil.java @@ -20,6 +20,7 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable; +import org.apache.doris.nereids.trees.expressions.functions.DateCeilFloorMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullLiteral; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; @@ -37,7 +38,7 @@ * ScalarFunction 'month_ceil'. This class is generated by GenerateFunction. */ public class MonthCeil extends ScalarFunction - implements ExplicitlyCastableSignature, AlwaysNullable, PropagateNullLiteral { + implements ExplicitlyCastableSignature, AlwaysNullable, PropagateNullLiteral, DateCeilFloorMonotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT).args(DateTimeV2Type.SYSTEM_DEFAULT), @@ -106,4 +107,19 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitMonthCeil(this, context); } + + @Override + public Expression withConstantArgs(Expression literal) { + switch (arity()) { + case 1: + return new MonthCeil(literal); + case 2: + return new MonthCeil(literal, child(1)); + case 3: + return new MonthCeil(literal, child(1), child(2)); + default: + // should not reach + return null; + } + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthFloor.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthFloor.java index f3b0b66c1396d1..f2535a674ddc94 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthFloor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthFloor.java @@ -20,6 +20,7 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable; +import org.apache.doris.nereids.trees.expressions.functions.DateCeilFloorMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullLiteral; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; @@ -37,7 +38,7 @@ * ScalarFunction 'month_floor'. This class is generated by GenerateFunction. */ public class MonthFloor extends ScalarFunction - implements ExplicitlyCastableSignature, AlwaysNullable, PropagateNullLiteral { + implements ExplicitlyCastableSignature, AlwaysNullable, PropagateNullLiteral, DateCeilFloorMonotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT).args(DateTimeV2Type.SYSTEM_DEFAULT), @@ -106,4 +107,19 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitMonthFloor(this, context); } + + @Override + public Expression withConstantArgs(Expression literal) { + switch (arity()) { + case 1: + return new MonthFloor(literal); + case 2: + return new MonthFloor(literal, child(1)); + case 3: + return new MonthFloor(literal, child(1), child(2)); + default: + // should not reach + return null; + } + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthsAdd.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthsAdd.java index 05338077e81c89..1cca6d8446fef6 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthsAdd.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthsAdd.java @@ -21,10 +21,9 @@ import org.apache.doris.common.Config; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.ComputeSignatureForDateArithmetic; +import org.apache.doris.nereids.trees.expressions.functions.DateAddSubMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; -import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; -import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeType; @@ -43,7 +42,7 @@ */ public class MonthsAdd extends ScalarFunction implements BinaryExpression, ExplicitlyCastableSignature, - ComputeSignatureForDateArithmetic, PropagateNullableOnDateLikeV2Args, Monotonic { + ComputeSignatureForDateArithmetic, PropagateNullableOnDateLikeV2Args, DateAddSubMonotonic { // When enable_date_conversion is true, we prefer to V2 signature. // This preference follows original planner. refer to ScalarType.getDefaultDateType() @@ -81,21 +80,6 @@ public R accept(ExpressionVisitor visitor, C context) { return visitor.visitMonthsAdd(this, context); } - @Override - public boolean isMonotonic() { - return child(1) instanceof IntegerLiteral; - } - - @Override - public boolean isPositive() { - return true; - } - - @Override - public int getMonotonicFunctionChildIndex() { - return 0; - } - @Override public Expression withConstantArgs(Expression literal) { return new MonthsAdd(literal, child(1)); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthsDiff.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthsDiff.java index 221dab7a4ae45b..a850767a49fa40 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthsDiff.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthsDiff.java @@ -19,8 +19,8 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.DateDiffMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; -import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; import org.apache.doris.nereids.trees.expressions.literal.Literal; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; @@ -39,7 +39,7 @@ * ScalarFunction 'months_diff'. This class is generated by GenerateFunction. */ public class MonthsDiff extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, DateDiffMonotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(BigIntType.INSTANCE).args(DateV2Type.INSTANCE, DateV2Type.INSTANCE), @@ -76,22 +76,6 @@ public R accept(ExpressionVisitor visitor, C context) { return visitor.visitMonthsDiff(this, context); } - @Override - public boolean isMonotonic() { - return !(child(0) instanceof Literal) && child(1) instanceof Literal - || child(0) instanceof Literal && !(child(1) instanceof Literal); - } - - @Override - public boolean isPositive() { - return child(1) instanceof Literal; - } - - @Override - public int getMonotonicFunctionChildIndex() { - return child(1) instanceof Literal ? 0 : 1; - } - @Override public Expression withConstantArgs(Expression literal) { if (child(1) instanceof Literal) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthsSub.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthsSub.java index 12a05f74ad9d5b..9c5824a1b9eebb 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthsSub.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthsSub.java @@ -21,10 +21,9 @@ import org.apache.doris.common.Config; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.ComputeSignatureForDateArithmetic; +import org.apache.doris.nereids.trees.expressions.functions.DateAddSubMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; -import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; -import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeType; @@ -43,7 +42,7 @@ */ public class MonthsSub extends ScalarFunction implements BinaryExpression, ExplicitlyCastableSignature, - ComputeSignatureForDateArithmetic, PropagateNullableOnDateLikeV2Args, Monotonic { + ComputeSignatureForDateArithmetic, PropagateNullableOnDateLikeV2Args, DateAddSubMonotonic { // When enable_date_conversion is true, we prefer to V2 signature. // This preference follows original planner. refer to ScalarType.getDefaultDateType() @@ -81,21 +80,6 @@ public R accept(ExpressionVisitor visitor, C context) { return visitor.visitMonthsSub(this, context); } - @Override - public boolean isMonotonic() { - return child(1) instanceof IntegerLiteral; - } - - @Override - public boolean isPositive() { - return true; - } - - @Override - public int getMonotonicFunctionChildIndex() { - return 0; - } - @Override public Expression withConstantArgs(Expression literal) { return new MonthsSub(literal, child(1)); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondCeil.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondCeil.java index 04cd08f4c8ce7b..b530cff9bfc8c9 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondCeil.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondCeil.java @@ -20,6 +20,7 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable; +import org.apache.doris.nereids.trees.expressions.functions.DateCeilFloorMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullLiteral; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; @@ -36,7 +37,7 @@ * ScalarFunction 'second_ceil'. This class is generated by GenerateFunction. */ public class SecondCeil extends ScalarFunction - implements ExplicitlyCastableSignature, AlwaysNullable, PropagateNullLiteral { + implements ExplicitlyCastableSignature, AlwaysNullable, PropagateNullLiteral, DateCeilFloorMonotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT).args(DateTimeV2Type.SYSTEM_DEFAULT), @@ -100,4 +101,19 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitSecondCeil(this, context); } + + @Override + public Expression withConstantArgs(Expression literal) { + switch (arity()) { + case 1: + return new SecondCeil(literal); + case 2: + return new SecondCeil(literal, child(1)); + case 3: + return new SecondCeil(literal, child(1), child(2)); + default: + // should not reach + return null; + } + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondFloor.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondFloor.java index ae0af1106073ac..806aad402220a5 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondFloor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondFloor.java @@ -20,6 +20,7 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable; +import org.apache.doris.nereids.trees.expressions.functions.DateCeilFloorMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullLiteral; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; @@ -36,7 +37,7 @@ * ScalarFunction 'second_floor'. This class is generated by GenerateFunction. */ public class SecondFloor extends ScalarFunction - implements ExplicitlyCastableSignature, AlwaysNullable, PropagateNullLiteral { + implements ExplicitlyCastableSignature, AlwaysNullable, PropagateNullLiteral, DateCeilFloorMonotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT).args(DateTimeV2Type.SYSTEM_DEFAULT), @@ -101,4 +102,19 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitSecondFloor(this, context); } + + @Override + public Expression withConstantArgs(Expression literal) { + switch (arity()) { + case 1: + return new SecondFloor(literal); + case 2: + return new SecondFloor(literal, child(1)); + case 3: + return new SecondFloor(literal, child(1), child(2)); + default: + // should not reach + return null; + } + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondsAdd.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondsAdd.java index 40431a36bb44be..3afa8f134193ec 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondsAdd.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondsAdd.java @@ -19,10 +19,9 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.DateAddSubMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; -import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; -import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeType; @@ -40,7 +39,8 @@ * ScalarFunction 'minutes_add'. */ public class SecondsAdd extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, + DateAddSubMonotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT) @@ -70,21 +70,6 @@ public R accept(ExpressionVisitor visitor, C context) { return visitor.visitSecondsAdd(this, context); } - @Override - public boolean isMonotonic() { - return child(1) instanceof IntegerLiteral; - } - - @Override - public boolean isPositive() { - return true; - } - - @Override - public int getMonotonicFunctionChildIndex() { - return 0; - } - @Override public Expression withConstantArgs(Expression literal) { return new SecondsAdd(literal, child(1)); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondsDiff.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondsDiff.java index 5eae7d75f30365..c81999d4fa2c98 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondsDiff.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondsDiff.java @@ -19,8 +19,8 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.DateDiffMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; -import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; import org.apache.doris.nereids.trees.expressions.literal.Literal; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; @@ -39,7 +39,7 @@ * ScalarFunction 'seconds_diff'. This class is generated by GenerateFunction. */ public class SecondsDiff extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, DateDiffMonotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(BigIntType.INSTANCE) @@ -76,22 +76,6 @@ public R accept(ExpressionVisitor visitor, C context) { return visitor.visitSecondsDiff(this, context); } - @Override - public boolean isMonotonic() { - return !(child(0) instanceof Literal) && child(1) instanceof Literal - || child(0) instanceof Literal && !(child(1) instanceof Literal); - } - - @Override - public boolean isPositive() { - return child(1) instanceof Literal; - } - - @Override - public int getMonotonicFunctionChildIndex() { - return child(1) instanceof Literal ? 0 : 1; - } - @Override public Expression withConstantArgs(Expression literal) { if (child(1) instanceof Literal) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondsSub.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondsSub.java index 8e10d7665b7ed6..d3093f84e1a2dc 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondsSub.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondsSub.java @@ -19,10 +19,9 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.DateAddSubMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; -import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; -import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeType; @@ -40,7 +39,8 @@ * ScalarFunction 'Seconds_sub'. */ public class SecondsSub extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, + DateAddSubMonotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT) @@ -70,21 +70,6 @@ public R accept(ExpressionVisitor visitor, C context) { return visitor.visitSecondsSub(this, context); } - @Override - public boolean isMonotonic() { - return child(1) instanceof IntegerLiteral; - } - - @Override - public boolean isPositive() { - return true; - } - - @Override - public int getMonotonicFunctionChildIndex() { - return 0; - } - @Override public Expression withConstantArgs(Expression literal) { return new SecondsSub(literal, child(1)); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearCeil.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearCeil.java index bc294638be99cd..19a7626d5721d1 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearCeil.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearCeil.java @@ -20,6 +20,7 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable; +import org.apache.doris.nereids.trees.expressions.functions.DateCeilFloorMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeType; @@ -36,7 +37,7 @@ * ScalarFunction 'year_ceil'. This class is generated by GenerateFunction. */ public class YearCeil extends ScalarFunction - implements ExplicitlyCastableSignature, AlwaysNullable { + implements ExplicitlyCastableSignature, AlwaysNullable, DateCeilFloorMonotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT).args(DateTimeV2Type.SYSTEM_DEFAULT), @@ -105,4 +106,19 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitYearCeil(this, context); } + + @Override + public Expression withConstantArgs(Expression literal) { + switch (arity()) { + case 1: + return new YearCeil(literal); + case 2: + return new YearCeil(literal, child(1)); + case 3: + return new YearCeil(literal, child(1), child(2)); + default: + // should not reach + return null; + } + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearFloor.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearFloor.java index 5415502a769579..06f7894768ae78 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearFloor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearFloor.java @@ -20,6 +20,7 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable; +import org.apache.doris.nereids.trees.expressions.functions.DateCeilFloorMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeType; @@ -36,7 +37,7 @@ * ScalarFunction 'year_floor'. This class is generated by GenerateFunction. */ public class YearFloor extends ScalarFunction - implements ExplicitlyCastableSignature, AlwaysNullable { + implements ExplicitlyCastableSignature, AlwaysNullable, DateCeilFloorMonotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT).args(DateTimeV2Type.SYSTEM_DEFAULT), @@ -105,4 +106,19 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitYearFloor(this, context); } + + @Override + public Expression withConstantArgs(Expression literal) { + switch (arity()) { + case 1: + return new YearFloor(literal); + case 2: + return new YearFloor(literal, child(1)); + case 3: + return new YearFloor(literal, child(1), child(2)); + default: + // should not reach + return null; + } + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearsAdd.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearsAdd.java index e41865f569e53f..9b81378d9871bc 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearsAdd.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearsAdd.java @@ -21,10 +21,9 @@ import org.apache.doris.common.Config; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.ComputeSignatureForDateArithmetic; +import org.apache.doris.nereids.trees.expressions.functions.DateAddSubMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; -import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; -import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeType; @@ -43,7 +42,7 @@ */ public class YearsAdd extends ScalarFunction implements BinaryExpression, ExplicitlyCastableSignature, - ComputeSignatureForDateArithmetic, PropagateNullableOnDateLikeV2Args, Monotonic { + ComputeSignatureForDateArithmetic, PropagateNullableOnDateLikeV2Args, DateAddSubMonotonic { // When enable_date_conversion is true, we prefer to V2 signature. // This preference follows original planner. refer to ScalarType.getDefaultDateType() @@ -81,21 +80,6 @@ public R accept(ExpressionVisitor visitor, C context) { return visitor.visitYearsAdd(this, context); } - @Override - public boolean isMonotonic() { - return child(1) instanceof IntegerLiteral; - } - - @Override - public boolean isPositive() { - return true; - } - - @Override - public int getMonotonicFunctionChildIndex() { - return 0; - } - @Override public Expression withConstantArgs(Expression literal) { return new YearsAdd(literal, child(1)); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearsDiff.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearsDiff.java index a778e41e93a323..61b637449f1797 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearsDiff.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearsDiff.java @@ -19,8 +19,8 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.DateDiffMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; -import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; import org.apache.doris.nereids.trees.expressions.literal.Literal; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; @@ -39,7 +39,7 @@ * ScalarFunction 'years_diff'. This class is generated by GenerateFunction. */ public class YearsDiff extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, Monotonic { + implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args, DateDiffMonotonic { private static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(BigIntType.INSTANCE).args(DateV2Type.INSTANCE, DateV2Type.INSTANCE), @@ -76,22 +76,6 @@ public R accept(ExpressionVisitor visitor, C context) { return visitor.visitYearsDiff(this, context); } - @Override - public boolean isMonotonic() { - return !(child(0) instanceof Literal) && child(1) instanceof Literal - || child(0) instanceof Literal && !(child(1) instanceof Literal); - } - - @Override - public boolean isPositive() { - return child(1) instanceof Literal; - } - - @Override - public int getMonotonicFunctionChildIndex() { - return child(1) instanceof Literal ? 0 : 1; - } - @Override public Expression withConstantArgs(Expression literal) { if (child(1) instanceof Literal) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearsSub.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearsSub.java index 09b6d643b96652..6f46727d937a28 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearsSub.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearsSub.java @@ -21,10 +21,9 @@ import org.apache.doris.common.Config; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.ComputeSignatureForDateArithmetic; +import org.apache.doris.nereids.trees.expressions.functions.DateAddSubMonotonic; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; -import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; -import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DateTimeType; @@ -43,7 +42,7 @@ */ public class YearsSub extends ScalarFunction implements BinaryExpression, ExplicitlyCastableSignature, - ComputeSignatureForDateArithmetic, PropagateNullableOnDateLikeV2Args, Monotonic { + ComputeSignatureForDateArithmetic, PropagateNullableOnDateLikeV2Args, DateAddSubMonotonic { // When enable_date_conversion is true, we prefer to V2 signature. // This preference follows original planner. refer to ScalarType.getDefaultDateType() @@ -81,21 +80,6 @@ public R accept(ExpressionVisitor visitor, C context) { return visitor.visitYearsSub(this, context); } - @Override - public boolean isMonotonic() { - return child(1) instanceof IntegerLiteral; - } - - @Override - public boolean isPositive() { - return true; - } - - @Override - public int getMonotonicFunctionChildIndex() { - return 0; - } - @Override public Expression withConstantArgs(Expression literal) { return new YearsSub(literal, child(1)); diff --git a/regression-test/suites/nereids_rules_p0/partition_prune/test_add_sub_diff_ceil_floor.groovy b/regression-test/suites/nereids_rules_p0/partition_prune/test_add_sub_diff_ceil_floor.groovy new file mode 100644 index 00000000000000..0945f45883ec4b --- /dev/null +++ b/regression-test/suites/nereids_rules_p0/partition_prune/test_add_sub_diff_ceil_floor.groovy @@ -0,0 +1,296 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +suite("test_add_sub_diff_ceil_floor") { + sql "set disable_nereids_rules='REWRITE_FILTER_EXPRESSION'" + sql "drop table if exists always_mono_func" + sql """create table always_mono_func (a int, dt datetime, d date, c varchar(100)) duplicate key(a) + partition by range(dt) ( + partition p1 values less than ("2017-01-01"), + partition p2 values less than ("2018-01-01"), + partition p3 values less than ("2019-01-01"), + partition p4 values less than ("2020-01-01"), + partition p5 values less than ("2021-01-01") + ) distributed by hash(a) properties("replication_num"="1");""" + sql """INSERT INTO always_mono_func SELECT number, + date_add('2016-01-01 00:00:00', interval number month), + cast(date_add('2022-01-01 00:00:00', interval number month) as date), cast(number as varchar(65533)) FROM numbers('number'='55');""" + sql "INSERT INTO always_mono_func values(3,null,null,null);" + + // xx_add + explain { + sql """select * from always_mono_func where years_add(dt,1) >'2019-01-01' """ + contains("partitions=3/5 (p3,p4,p5)") + } + explain { + sql """select * from always_mono_func where months_add(dt,2) >'2019-01-01' """ + contains("partitions=3/5 (p3,p4,p5)") + } + explain { + sql """select * from always_mono_func where days_add(dt,10) >'2019-01-01' """ + contains("partitions=3/5 (p3,p4,p5)") + } + explain { + sql """select * from always_mono_func where hours_add(dt,1) >'2019-01-01' """ + contains("partitions=3/5 (p3,p4,p5)") + } + explain { + sql """select * from always_mono_func where minutes_add(dt,2) >'2019-01-01' """ + contains("partitions=3/5 (p3,p4,p5)") + } + explain { + sql """select * from always_mono_func where seconds_add(dt,10) >'2019-01-01' """ + contains("partitions=3/5 (p3,p4,p5)") + } + explain { + sql """select * from always_mono_func where milliseconds_add(dt,2) >'2019-01-01' """ + contains("partitions=3/5 (p3,p4,p5)") + } + explain { + sql """select * from always_mono_func where microseconds_add(dt,10) >'2019-01-01' """ + contains("partitions=3/5 (p3,p4,p5)") + } + // xx_sub + explain { + sql """select * from always_mono_func where years_sub(dt,1) <='2018-01-01' """ + contains("4/5 (p1,p2,p3,p4)") + } + explain { + sql """select * from always_mono_func where months_sub(dt,2) <='2018-01-01' """ + contains("partitions=3/5 (p1,p2,p3)") + } + explain { + sql """select * from always_mono_func where days_sub(dt,10) <='2018-01-01' """ + contains("partitions=3/5 (p1,p2,p3)") + } + explain { + sql """select * from always_mono_func where hours_sub(dt,1) <='2018-01-01' """ + contains("partitions=3/5 (p1,p2,p3)") + } + explain { + sql """select * from always_mono_func where minutes_sub(dt,2) <= '2018-01-01' """ + contains("partitions=3/5 (p1,p2,p3)") + } + explain { + sql """select * from always_mono_func where seconds_sub(dt,10) <= '2018-01-01' """ + contains("partitions=3/5 (p1,p2,p3)") + } + explain { + sql """select * from always_mono_func where milliseconds_sub(dt,2) <= '2018-01-01' """ + contains("partitions=3/5 (p1,p2,p3)") + } + explain { + sql """select * from always_mono_func where microseconds_sub(dt,10) <= '2018-01-01' """ + contains("partitions=3/5 (p1,p2,p3)") + } + + // xx_diff + // first arg is dt. positive + explain { + sql """select * from always_mono_func where years_diff(dt,'2017-01-01') <2 """ + contains("partitions=3/5 (p1,p2,p3)") + } + explain { + sql """select * from always_mono_func where months_diff(dt,'2017-01-01') <2 """ + contains("partitions=2/5 (p1,p2)") + } + explain { + sql """select * from always_mono_func where days_diff(dt,'2017-01-01') <2 """ + contains("partitions=2/5 (p1,p2)") + } + explain { + sql """select * from always_mono_func where hours_diff(dt,'2017-01-01') <2 """ + contains("partitions=2/5 (p1,p2)") + } + explain { + sql """select * from always_mono_func where minutes_diff(dt,'2017-01-01') <2 """ + contains("partitions=2/5 (p1,p2)") + } + explain { + sql """select * from always_mono_func where seconds_diff(dt,'2017-01-01') <2 """ + contains("partitions=2/5 (p1,p2)") + } + explain { + sql """select * from always_mono_func where milliseconds_diff(dt,'2017-01-01') <2 """ + contains("partitions=2/5 (p1,p2)") + } + explain { + sql """select * from always_mono_func where microseconds_diff(dt,'2017-01-01') <2 """ + contains("partitions=2/5 (p1,p2)") + } + // second arg is dt. not positive + explain { + sql """select * from always_mono_func where years_diff('2021-01-01',dt) <2 """ + contains("partitions=2/5 (p4,p5)") + } + explain { + sql """select * from always_mono_func where months_diff('2021-01-01',dt) <2 """ + contains("partitions=1/5 (p5)") + } + explain { + sql """select * from always_mono_func where days_diff('2021-01-01',dt) <2 """ + contains("partitions=1/5 (p5)") + } + explain { + sql """select * from always_mono_func where hours_diff('2021-01-01',dt) <2 """ + contains("partitions=1/5 (p5)") + } + explain { + sql """select * from always_mono_func where minutes_diff('2021-01-01',dt) <2 """ + contains("partitions=1/5 (p5)") + } + explain { + sql """select * from always_mono_func where seconds_diff('2021-01-01',dt) <2 """ + contains("partitions=1/5 (p5)") + } + explain { + sql """select * from always_mono_func where milliseconds_diff('2021-01-01',dt) <2 """ + contains("partitions=1/5 (p5)") + } + explain { + sql """select * from always_mono_func where microseconds_diff('2021-01-01',dt) <2 """ + contains("partitions=1/5 (p5)") + } + explain { + sql """select * from always_mono_func where years_diff('2021-01-01',dt) <=2 """ + contains("partitions=3/5 (p3,p4,p5)") + } + explain { + sql """select * from always_mono_func where months_diff('2020-01-01',dt) >2 """ + contains("partitions=4/5 (p1,p2,p3,p4)") + } + explain { + sql """select * from always_mono_func where days_diff('2020-01-01',dt) >=2 """ + contains("partitions=4/5 (p1,p2,p3,p4)") + } + + // xx_ceil + explain { + sql """select * from always_mono_func where year_ceil(dt) <'2019-01-01' """ + contains("partitions=3/5 (p1,p2,p3)") + } + explain { + sql """select * from always_mono_func where month_ceil(dt) <'2019-02-01' """ + contains("partitions=4/5 (p1,p2,p3,p4)") + } + explain { + sql """select * from always_mono_func where day_ceil(dt) <'2019-01-01' """ + contains("partitions=3/5 (p1,p2,p3)") + } + explain { + sql """select * from always_mono_func where hour_ceil(dt) <'2019-01-01' """ + contains("partitions=3/5 (p1,p2,p3)") + } + explain { + sql """select * from always_mono_func where minute_ceil(dt) <'2019-01-01' """ + contains("partitions=3/5 (p1,p2,p3)") + } + explain { + sql """select * from always_mono_func where second_ceil(dt) <'2019-01-01' """ + contains("partitions=3/5 (p1,p2,p3)") + } + // xx_ceil with other args + explain { + sql """select * from always_mono_func where year_ceil(dt,5) <'2019-01-01' """ + contains("partitions=1/5 (p1)") + } + explain { + sql """select * from always_mono_func where year_ceil(dt,'2013-01-01') <'2019-01-01' """ + contains("partitions=3/5 (p1,p2,p3)") + } + explain { + sql """select * from always_mono_func where year_ceil(dt,5,'2013-01-01') <'2019-01-01'""" + contains(" partitions=3/5 (p1,p2,p3)") + } + explain { + sql """select * from always_mono_func where hour_ceil(dt,c) <'2019-01-01' """ + contains("partitions=5/5 (p1,p2,p3,p4,p5)") + } + + // xx_floor + explain { + sql """select * from always_mono_func where year_floor(dt) <='2019-01-01' """ + contains("partitions=4/5 (p1,p2,p3,p4)") + } + explain { + sql """select * from always_mono_func where month_floor(dt) <='2019-02-01' """ + contains("partitions=4/5 (p1,p2,p3,p4)") + } + explain { + sql """select * from always_mono_func where day_floor(dt) <='2019-01-01' """ + contains("partitions=4/5 (p1,p2,p3,p4)") + } + explain { + sql """select * from always_mono_func where hour_floor(dt) <='2019-01-01' """ + contains("partitions=4/5 (p1,p2,p3,p4)") + } + explain { + sql """select * from always_mono_func where minute_floor(dt) <='2019-01-01' """ + contains("partitions=4/5 (p1,p2,p3,p4)") + } + explain { + sql """select * from always_mono_func where second_floor(dt) <'2019-01-01' """ + contains("partitions=3/5 (p1,p2,p3)") + } + + // xx_floor with other args + explain { + sql """select * from always_mono_func where month_floor(dt,'2015-01-01') <='2019-02-01' """ + contains("partitions=4/5 (p1,p2,p3,p4)") + } + explain { + sql """select * from always_mono_func where month_floor(dt,5,'2015-01-01') <='2019-02-01' """ + contains("partitions=4/5 (p1,p2,p3,p4)") + } + explain { + sql """select * from always_mono_func where month_floor(dt,5) <='2019-02-01' """ + contains("partitions=4/5 (p1,p2,p3,p4)") + } + explain { + sql """select * from always_mono_func where hour_floor(dt,c,'2015-01-01') <='2019-01-01' """ + contains("partitions=5/5 (p1,p2,p3,p4,p5)") + } + + // diff nest function + explain { + sql """select * from always_mono_func where years_diff('2021-01-01',month_ceil(hours_add(dt, 1))) <=2 """ + contains("partitions=4/5 (p2,p3,p4,p5)") + } + explain { + sql "select * from always_mono_func where years_diff('2021-01-01',month_ceil(hours_sub(dt, 1))) <=2" + contains("partitions=3/5 (p3,p4,p5)") + } + // mixed with non-function predicates + explain { + sql "select * from always_mono_func where years_diff('2021-01-01',month_ceil(hours_sub(dt, 1))) <=2 and dt>'2019-06-01'" + contains("partitions=2/5 (p4,p5)") + } + explain { + sql """select * from always_mono_func where years_diff('2021-01-01',month_ceil(hours_sub(dt, 1))) <=2 and date_trunc(dt,'day')>'2019-06-01' """ + contains("partitions=2/5 (p4,p5)") + } + explain { + sql """select * from always_mono_func where months_diff(months_add(dt,10), '2018-01-01') =2 """ + contains("partitions=1/5 (p2)") + } + + // hours_add second arg is not literal, so will not do pruning + explain { + sql """select * from always_mono_func where hours_add(dt, years_diff(dt,'2018-01-01')) <'2018-01-01' """ + contains("partitions=5/5 (p1,p2,p3,p4,p5)") + } +} \ No newline at end of file From bf5996f26a56fee8c0765226d36c23a505824493 Mon Sep 17 00:00:00 2001 From: feiniaofeiafei Date: Tue, 3 Dec 2024 20:15:19 +0800 Subject: [PATCH 03/10] modify regression table name --- .../test_add_sub_diff_ceil_floor.groovy | 130 +++++++++--------- 1 file changed, 65 insertions(+), 65 deletions(-) diff --git a/regression-test/suites/nereids_rules_p0/partition_prune/test_add_sub_diff_ceil_floor.groovy b/regression-test/suites/nereids_rules_p0/partition_prune/test_add_sub_diff_ceil_floor.groovy index 0945f45883ec4b..12ddff6eb0ec8b 100644 --- a/regression-test/suites/nereids_rules_p0/partition_prune/test_add_sub_diff_ceil_floor.groovy +++ b/regression-test/suites/nereids_rules_p0/partition_prune/test_add_sub_diff_ceil_floor.groovy @@ -17,8 +17,8 @@ suite("test_add_sub_diff_ceil_floor") { sql "set disable_nereids_rules='REWRITE_FILTER_EXPRESSION'" - sql "drop table if exists always_mono_func" - sql """create table always_mono_func (a int, dt datetime, d date, c varchar(100)) duplicate key(a) + sql "drop table if exists test_add_sub_diff_ceil_floor_t" + sql """create table test_add_sub_diff_ceil_floor_t (a int, dt datetime, d date, c varchar(100)) duplicate key(a) partition by range(dt) ( partition p1 values less than ("2017-01-01"), partition p2 values less than ("2018-01-01"), @@ -26,271 +26,271 @@ suite("test_add_sub_diff_ceil_floor") { partition p4 values less than ("2020-01-01"), partition p5 values less than ("2021-01-01") ) distributed by hash(a) properties("replication_num"="1");""" - sql """INSERT INTO always_mono_func SELECT number, + sql """INSERT INTO test_add_sub_diff_ceil_floor_t SELECT number, date_add('2016-01-01 00:00:00', interval number month), cast(date_add('2022-01-01 00:00:00', interval number month) as date), cast(number as varchar(65533)) FROM numbers('number'='55');""" - sql "INSERT INTO always_mono_func values(3,null,null,null);" + sql "INSERT INTO test_add_sub_diff_ceil_floor_t values(3,null,null,null);" // xx_add explain { - sql """select * from always_mono_func where years_add(dt,1) >'2019-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where years_add(dt,1) >'2019-01-01' """ contains("partitions=3/5 (p3,p4,p5)") } explain { - sql """select * from always_mono_func where months_add(dt,2) >'2019-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where months_add(dt,2) >'2019-01-01' """ contains("partitions=3/5 (p3,p4,p5)") } explain { - sql """select * from always_mono_func where days_add(dt,10) >'2019-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where days_add(dt,10) >'2019-01-01' """ contains("partitions=3/5 (p3,p4,p5)") } explain { - sql """select * from always_mono_func where hours_add(dt,1) >'2019-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where hours_add(dt,1) >'2019-01-01' """ contains("partitions=3/5 (p3,p4,p5)") } explain { - sql """select * from always_mono_func where minutes_add(dt,2) >'2019-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where minutes_add(dt,2) >'2019-01-01' """ contains("partitions=3/5 (p3,p4,p5)") } explain { - sql """select * from always_mono_func where seconds_add(dt,10) >'2019-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where seconds_add(dt,10) >'2019-01-01' """ contains("partitions=3/5 (p3,p4,p5)") } explain { - sql """select * from always_mono_func where milliseconds_add(dt,2) >'2019-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where milliseconds_add(dt,2) >'2019-01-01' """ contains("partitions=3/5 (p3,p4,p5)") } explain { - sql """select * from always_mono_func where microseconds_add(dt,10) >'2019-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where microseconds_add(dt,10) >'2019-01-01' """ contains("partitions=3/5 (p3,p4,p5)") } // xx_sub explain { - sql """select * from always_mono_func where years_sub(dt,1) <='2018-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where years_sub(dt,1) <='2018-01-01' """ contains("4/5 (p1,p2,p3,p4)") } explain { - sql """select * from always_mono_func where months_sub(dt,2) <='2018-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where months_sub(dt,2) <='2018-01-01' """ contains("partitions=3/5 (p1,p2,p3)") } explain { - sql """select * from always_mono_func where days_sub(dt,10) <='2018-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where days_sub(dt,10) <='2018-01-01' """ contains("partitions=3/5 (p1,p2,p3)") } explain { - sql """select * from always_mono_func where hours_sub(dt,1) <='2018-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where hours_sub(dt,1) <='2018-01-01' """ contains("partitions=3/5 (p1,p2,p3)") } explain { - sql """select * from always_mono_func where minutes_sub(dt,2) <= '2018-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where minutes_sub(dt,2) <= '2018-01-01' """ contains("partitions=3/5 (p1,p2,p3)") } explain { - sql """select * from always_mono_func where seconds_sub(dt,10) <= '2018-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where seconds_sub(dt,10) <= '2018-01-01' """ contains("partitions=3/5 (p1,p2,p3)") } explain { - sql """select * from always_mono_func where milliseconds_sub(dt,2) <= '2018-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where milliseconds_sub(dt,2) <= '2018-01-01' """ contains("partitions=3/5 (p1,p2,p3)") } explain { - sql """select * from always_mono_func where microseconds_sub(dt,10) <= '2018-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where microseconds_sub(dt,10) <= '2018-01-01' """ contains("partitions=3/5 (p1,p2,p3)") } // xx_diff // first arg is dt. positive explain { - sql """select * from always_mono_func where years_diff(dt,'2017-01-01') <2 """ + sql """select * from test_add_sub_diff_ceil_floor_t where years_diff(dt,'2017-01-01') <2 """ contains("partitions=3/5 (p1,p2,p3)") } explain { - sql """select * from always_mono_func where months_diff(dt,'2017-01-01') <2 """ + sql """select * from test_add_sub_diff_ceil_floor_t where months_diff(dt,'2017-01-01') <2 """ contains("partitions=2/5 (p1,p2)") } explain { - sql """select * from always_mono_func where days_diff(dt,'2017-01-01') <2 """ + sql """select * from test_add_sub_diff_ceil_floor_t where days_diff(dt,'2017-01-01') <2 """ contains("partitions=2/5 (p1,p2)") } explain { - sql """select * from always_mono_func where hours_diff(dt,'2017-01-01') <2 """ + sql """select * from test_add_sub_diff_ceil_floor_t where hours_diff(dt,'2017-01-01') <2 """ contains("partitions=2/5 (p1,p2)") } explain { - sql """select * from always_mono_func where minutes_diff(dt,'2017-01-01') <2 """ + sql """select * from test_add_sub_diff_ceil_floor_t where minutes_diff(dt,'2017-01-01') <2 """ contains("partitions=2/5 (p1,p2)") } explain { - sql """select * from always_mono_func where seconds_diff(dt,'2017-01-01') <2 """ + sql """select * from test_add_sub_diff_ceil_floor_t where seconds_diff(dt,'2017-01-01') <2 """ contains("partitions=2/5 (p1,p2)") } explain { - sql """select * from always_mono_func where milliseconds_diff(dt,'2017-01-01') <2 """ + sql """select * from test_add_sub_diff_ceil_floor_t where milliseconds_diff(dt,'2017-01-01') <2 """ contains("partitions=2/5 (p1,p2)") } explain { - sql """select * from always_mono_func where microseconds_diff(dt,'2017-01-01') <2 """ + sql """select * from test_add_sub_diff_ceil_floor_t where microseconds_diff(dt,'2017-01-01') <2 """ contains("partitions=2/5 (p1,p2)") } // second arg is dt. not positive explain { - sql """select * from always_mono_func where years_diff('2021-01-01',dt) <2 """ + sql """select * from test_add_sub_diff_ceil_floor_t where years_diff('2021-01-01',dt) <2 """ contains("partitions=2/5 (p4,p5)") } explain { - sql """select * from always_mono_func where months_diff('2021-01-01',dt) <2 """ + sql """select * from test_add_sub_diff_ceil_floor_t where months_diff('2021-01-01',dt) <2 """ contains("partitions=1/5 (p5)") } explain { - sql """select * from always_mono_func where days_diff('2021-01-01',dt) <2 """ + sql """select * from test_add_sub_diff_ceil_floor_t where days_diff('2021-01-01',dt) <2 """ contains("partitions=1/5 (p5)") } explain { - sql """select * from always_mono_func where hours_diff('2021-01-01',dt) <2 """ + sql """select * from test_add_sub_diff_ceil_floor_t where hours_diff('2021-01-01',dt) <2 """ contains("partitions=1/5 (p5)") } explain { - sql """select * from always_mono_func where minutes_diff('2021-01-01',dt) <2 """ + sql """select * from test_add_sub_diff_ceil_floor_t where minutes_diff('2021-01-01',dt) <2 """ contains("partitions=1/5 (p5)") } explain { - sql """select * from always_mono_func where seconds_diff('2021-01-01',dt) <2 """ + sql """select * from test_add_sub_diff_ceil_floor_t where seconds_diff('2021-01-01',dt) <2 """ contains("partitions=1/5 (p5)") } explain { - sql """select * from always_mono_func where milliseconds_diff('2021-01-01',dt) <2 """ + sql """select * from test_add_sub_diff_ceil_floor_t where milliseconds_diff('2021-01-01',dt) <2 """ contains("partitions=1/5 (p5)") } explain { - sql """select * from always_mono_func where microseconds_diff('2021-01-01',dt) <2 """ + sql """select * from test_add_sub_diff_ceil_floor_t where microseconds_diff('2021-01-01',dt) <2 """ contains("partitions=1/5 (p5)") } explain { - sql """select * from always_mono_func where years_diff('2021-01-01',dt) <=2 """ + sql """select * from test_add_sub_diff_ceil_floor_t where years_diff('2021-01-01',dt) <=2 """ contains("partitions=3/5 (p3,p4,p5)") } explain { - sql """select * from always_mono_func where months_diff('2020-01-01',dt) >2 """ + sql """select * from test_add_sub_diff_ceil_floor_t where months_diff('2020-01-01',dt) >2 """ contains("partitions=4/5 (p1,p2,p3,p4)") } explain { - sql """select * from always_mono_func where days_diff('2020-01-01',dt) >=2 """ + sql """select * from test_add_sub_diff_ceil_floor_t where days_diff('2020-01-01',dt) >=2 """ contains("partitions=4/5 (p1,p2,p3,p4)") } // xx_ceil explain { - sql """select * from always_mono_func where year_ceil(dt) <'2019-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where year_ceil(dt) <'2019-01-01' """ contains("partitions=3/5 (p1,p2,p3)") } explain { - sql """select * from always_mono_func where month_ceil(dt) <'2019-02-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where month_ceil(dt) <'2019-02-01' """ contains("partitions=4/5 (p1,p2,p3,p4)") } explain { - sql """select * from always_mono_func where day_ceil(dt) <'2019-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where day_ceil(dt) <'2019-01-01' """ contains("partitions=3/5 (p1,p2,p3)") } explain { - sql """select * from always_mono_func where hour_ceil(dt) <'2019-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where hour_ceil(dt) <'2019-01-01' """ contains("partitions=3/5 (p1,p2,p3)") } explain { - sql """select * from always_mono_func where minute_ceil(dt) <'2019-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where minute_ceil(dt) <'2019-01-01' """ contains("partitions=3/5 (p1,p2,p3)") } explain { - sql """select * from always_mono_func where second_ceil(dt) <'2019-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where second_ceil(dt) <'2019-01-01' """ contains("partitions=3/5 (p1,p2,p3)") } // xx_ceil with other args explain { - sql """select * from always_mono_func where year_ceil(dt,5) <'2019-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where year_ceil(dt,5) <'2019-01-01' """ contains("partitions=1/5 (p1)") } explain { - sql """select * from always_mono_func where year_ceil(dt,'2013-01-01') <'2019-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where year_ceil(dt,'2013-01-01') <'2019-01-01' """ contains("partitions=3/5 (p1,p2,p3)") } explain { - sql """select * from always_mono_func where year_ceil(dt,5,'2013-01-01') <'2019-01-01'""" + sql """select * from test_add_sub_diff_ceil_floor_t where year_ceil(dt,5,'2013-01-01') <'2019-01-01'""" contains(" partitions=3/5 (p1,p2,p3)") } explain { - sql """select * from always_mono_func where hour_ceil(dt,c) <'2019-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where hour_ceil(dt,c) <'2019-01-01' """ contains("partitions=5/5 (p1,p2,p3,p4,p5)") } // xx_floor explain { - sql """select * from always_mono_func where year_floor(dt) <='2019-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where year_floor(dt) <='2019-01-01' """ contains("partitions=4/5 (p1,p2,p3,p4)") } explain { - sql """select * from always_mono_func where month_floor(dt) <='2019-02-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where month_floor(dt) <='2019-02-01' """ contains("partitions=4/5 (p1,p2,p3,p4)") } explain { - sql """select * from always_mono_func where day_floor(dt) <='2019-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where day_floor(dt) <='2019-01-01' """ contains("partitions=4/5 (p1,p2,p3,p4)") } explain { - sql """select * from always_mono_func where hour_floor(dt) <='2019-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where hour_floor(dt) <='2019-01-01' """ contains("partitions=4/5 (p1,p2,p3,p4)") } explain { - sql """select * from always_mono_func where minute_floor(dt) <='2019-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where minute_floor(dt) <='2019-01-01' """ contains("partitions=4/5 (p1,p2,p3,p4)") } explain { - sql """select * from always_mono_func where second_floor(dt) <'2019-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where second_floor(dt) <'2019-01-01' """ contains("partitions=3/5 (p1,p2,p3)") } // xx_floor with other args explain { - sql """select * from always_mono_func where month_floor(dt,'2015-01-01') <='2019-02-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where month_floor(dt,'2015-01-01') <='2019-02-01' """ contains("partitions=4/5 (p1,p2,p3,p4)") } explain { - sql """select * from always_mono_func where month_floor(dt,5,'2015-01-01') <='2019-02-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where month_floor(dt,5,'2015-01-01') <='2019-02-01' """ contains("partitions=4/5 (p1,p2,p3,p4)") } explain { - sql """select * from always_mono_func where month_floor(dt,5) <='2019-02-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where month_floor(dt,5) <='2019-02-01' """ contains("partitions=4/5 (p1,p2,p3,p4)") } explain { - sql """select * from always_mono_func where hour_floor(dt,c,'2015-01-01') <='2019-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where hour_floor(dt,c,'2015-01-01') <='2019-01-01' """ contains("partitions=5/5 (p1,p2,p3,p4,p5)") } // diff nest function explain { - sql """select * from always_mono_func where years_diff('2021-01-01',month_ceil(hours_add(dt, 1))) <=2 """ + sql """select * from test_add_sub_diff_ceil_floor_t where years_diff('2021-01-01',month_ceil(hours_add(dt, 1))) <=2 """ contains("partitions=4/5 (p2,p3,p4,p5)") } explain { - sql "select * from always_mono_func where years_diff('2021-01-01',month_ceil(hours_sub(dt, 1))) <=2" + sql "select * from test_add_sub_diff_ceil_floor_t where years_diff('2021-01-01',month_ceil(hours_sub(dt, 1))) <=2" contains("partitions=3/5 (p3,p4,p5)") } // mixed with non-function predicates explain { - sql "select * from always_mono_func where years_diff('2021-01-01',month_ceil(hours_sub(dt, 1))) <=2 and dt>'2019-06-01'" + sql "select * from test_add_sub_diff_ceil_floor_t where years_diff('2021-01-01',month_ceil(hours_sub(dt, 1))) <=2 and dt>'2019-06-01'" contains("partitions=2/5 (p4,p5)") } explain { - sql """select * from always_mono_func where years_diff('2021-01-01',month_ceil(hours_sub(dt, 1))) <=2 and date_trunc(dt,'day')>'2019-06-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where years_diff('2021-01-01',month_ceil(hours_sub(dt, 1))) <=2 and date_trunc(dt,'day')>'2019-06-01' """ contains("partitions=2/5 (p4,p5)") } explain { - sql """select * from always_mono_func where months_diff(months_add(dt,10), '2018-01-01') =2 """ + sql """select * from test_add_sub_diff_ceil_floor_t where months_diff(months_add(dt,10), '2018-01-01') =2 """ contains("partitions=1/5 (p2)") } // hours_add second arg is not literal, so will not do pruning explain { - sql """select * from always_mono_func where hours_add(dt, years_diff(dt,'2018-01-01')) <'2018-01-01' """ + sql """select * from test_add_sub_diff_ceil_floor_t where hours_add(dt, years_diff(dt,'2018-01-01')) <'2018-01-01' """ contains("partitions=5/5 (p1,p2,p3,p4,p5)") } } \ No newline at end of file From ea24c9e2b0f686798e0f39bf1ce81b93ec20775d Mon Sep 17 00:00:00 2001 From: feiniaofeiafei Date: Wed, 4 Dec 2024 11:19:53 +0800 Subject: [PATCH 04/10] If the computed newRange is from positive infinity to negative infinity, then directly return result. --- .../rules/expression/rules/OneRangePartitionEvaluator.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/OneRangePartitionEvaluator.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/OneRangePartitionEvaluator.java index e31a5c7be99011..8766c470a5dca4 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/OneRangePartitionEvaluator.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/OneRangePartitionEvaluator.java @@ -845,6 +845,9 @@ private EvaluateRangeResult computeMonotonicFunctionRange(EvaluateRangeResult re if (upperValue instanceof Literal) { newRange = newRange.withUpperBound((Literal) upperValue); } + if (!newRange.span().hasLowerBound() && !newRange.span().hasUpperBound()) { + return result; + } context.rangeMap.put((Expression) func, newRange); newRanges.put((Expression) func, newRange); return new EvaluateRangeResult((Expression) func, newRanges, result.childrenResult); From dfc2426031eaf07cbd2d2827292caf43e9581a0e Mon Sep 17 00:00:00 2001 From: feiniaofeiafei Date: Thu, 5 Dec 2024 14:32:12 +0800 Subject: [PATCH 05/10] add lower and upper for isMonotonic --- .../rules/OneRangePartitionEvaluator.java | 13 ++++-- .../functions/DateAddSubMonotonic.java | 2 +- .../functions/DateCeilFloorMonotonic.java | 2 +- .../functions/DateDiffMonotonic.java | 2 +- .../expressions/functions/Monotonic.java | 3 +- .../functions/scalar/FromDays.java | 18 ++++++++- .../functions/scalar/UnixTimestamp.java | 40 ++++++++++++++++++- .../expressions/literal/DateTimeLiteral.java | 5 +-- 8 files changed, 72 insertions(+), 13 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/OneRangePartitionEvaluator.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/OneRangePartitionEvaluator.java index 8766c470a5dca4..eb9fd6e149160b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/OneRangePartitionEvaluator.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/OneRangePartitionEvaluator.java @@ -48,6 +48,7 @@ import org.apache.doris.nereids.trees.expressions.literal.BooleanLiteral; import org.apache.doris.nereids.trees.expressions.literal.Literal; import org.apache.doris.nereids.trees.expressions.literal.MaxLiteral; +import org.apache.doris.nereids.trees.expressions.literal.NullLiteral; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.BooleanType; import org.apache.doris.nereids.util.ExpressionUtils; @@ -800,9 +801,6 @@ private EvaluateRangeResult computeMonotonicFunctionRange(EvaluateRangeResult re return new EvaluateRangeResult((Expression) func, ImmutableMap.of((Expression) func, context.rangeMap.get(func)), result.childrenResult); } - if (!func.isMonotonic()) { - return result; - } int childIndex = func.getMonotonicFunctionChildIndex(); Expression funcChild = func.child(childIndex); boolean isNullable = partitionSlotContainsNull.getOrDefault(funcChild, true); @@ -819,13 +817,20 @@ private EvaluateRangeResult computeMonotonicFunctionRange(EvaluateRangeResult re return result; } Range span = childRange.span(); + // null means positive infinity or negative infinity Literal lower = span.hasLowerBound() ? span.lowerEndpoint().getValue() : null; Literal upper = span.hasUpperBound() && !(span.upperEndpoint().getValue() instanceof MaxLiteral) ? span.upperEndpoint().getValue() : null; + if (!func.isMonotonic(lower, upper)) { + return result; + } Expression lowerValue = lower != null ? FoldConstantRuleOnFE.evaluate(func.withConstantArgs(lower), expressionRewriteContext) : null; Expression upperValue = upper != null ? FoldConstantRuleOnFE.evaluate(func.withConstantArgs(upper), expressionRewriteContext) : null; + if (lowerValue instanceof NullLiteral || upperValue instanceof NullLiteral) { + return result; + } if (!func.isPositive()) { Expression temp = lowerValue; lowerValue = upperValue; @@ -845,7 +850,7 @@ private EvaluateRangeResult computeMonotonicFunctionRange(EvaluateRangeResult re if (upperValue instanceof Literal) { newRange = newRange.withUpperBound((Literal) upperValue); } - if (!newRange.span().hasLowerBound() && !newRange.span().hasUpperBound()) { + if (newRange.isEmptyRange() || !newRange.span().hasLowerBound() && !newRange.span().hasUpperBound()) { return result; } context.rangeMap.put((Expression) func, newRange); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/DateAddSubMonotonic.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/DateAddSubMonotonic.java index 46c9497ea7f020..7fec22fd9d317d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/DateAddSubMonotonic.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/DateAddSubMonotonic.java @@ -22,7 +22,7 @@ /** monotonicity for XX_ADD XX_SUB */ public interface DateAddSubMonotonic extends Monotonic { @Override - default boolean isMonotonic() { + default boolean isMonotonic(Literal lower, Literal upper) { return child(1) instanceof Literal; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/DateCeilFloorMonotonic.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/DateCeilFloorMonotonic.java index b06dfae13b5a40..71ad80a347176a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/DateCeilFloorMonotonic.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/DateCeilFloorMonotonic.java @@ -22,7 +22,7 @@ /** monotonicity of XX_CEIL and XX_FLOOR */ public interface DateCeilFloorMonotonic extends Monotonic { @Override - default boolean isMonotonic() { + default boolean isMonotonic(Literal lower, Literal upper) { switch (arity()) { case 1: return true; diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/DateDiffMonotonic.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/DateDiffMonotonic.java index 8b86d8ed1c194f..daaea895b6d15b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/DateDiffMonotonic.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/DateDiffMonotonic.java @@ -22,7 +22,7 @@ /** monotonicity for XX_DIFF */ public interface DateDiffMonotonic extends Monotonic { @Override - default boolean isMonotonic() { + default boolean isMonotonic(Literal lower, Literal upper) { return !(child(0) instanceof Literal) && child(1) instanceof Literal || child(0) instanceof Literal && !(child(1) instanceof Literal); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/Monotonic.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/Monotonic.java index c2a869c9185371..feec5933890e67 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/Monotonic.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/Monotonic.java @@ -18,10 +18,11 @@ package org.apache.doris.nereids.trees.expressions.functions; import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.literal.Literal; /** monotonicity of expressions */ public interface Monotonic extends ExpressionTrait { - default boolean isMonotonic() { + default boolean isMonotonic(Literal lower, Literal upper) { return true; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/FromDays.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/FromDays.java index c3d19588ce5f2f..1799c1461fc1b4 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/FromDays.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/FromDays.java @@ -21,6 +21,7 @@ import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; +import org.apache.doris.nereids.trees.expressions.functions.Monotonic; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullLiteral; import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; @@ -36,7 +37,7 @@ * ScalarFunction 'from_days'. This class is generated by GenerateFunction. */ public class FromDays extends ScalarFunction - implements UnaryExpression, ExplicitlyCastableSignature, AlwaysNullable, PropagateNullLiteral { + implements UnaryExpression, ExplicitlyCastableSignature, AlwaysNullable, PropagateNullLiteral, Monotonic { public static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateV2Type.INSTANCE).args(IntegerType.INSTANCE) @@ -67,4 +68,19 @@ public List getSignatures() { public R accept(ExpressionVisitor visitor, C context) { return visitor.visitFromDays(this, context); } + + @Override + public boolean isPositive() { + return true; + } + + @Override + public int getMonotonicFunctionChildIndex() { + return 0; + } + + @Override + public Expression withConstantArgs(Expression literal) { + return new FromDays(literal); + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/UnixTimestamp.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/UnixTimestamp.java index 633e1e7d4f3bda..fecae8613f3759 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/UnixTimestamp.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/UnixTimestamp.java @@ -20,6 +20,9 @@ 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.Monotonic; +import org.apache.doris.nereids.trees.expressions.literal.DateTimeLiteral; +import org.apache.doris.nereids.trees.expressions.literal.Literal; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DataType; import org.apache.doris.nereids.types.DateTimeType; @@ -39,7 +42,9 @@ /** * ScalarFunction 'unix_timestamp'. This class is generated by GenerateFunction. */ -public class UnixTimestamp extends ScalarFunction implements ExplicitlyCastableSignature { +public class UnixTimestamp extends ScalarFunction implements ExplicitlyCastableSignature, Monotonic { + private static final DateTimeLiteral MIN = new DateTimeLiteral("1970-01-01 00:00:00"); + private static final DateTimeLiteral MAX = new DateTimeLiteral("2038-01-19 03:14:07"); // we got changes when computeSignature private static final List SIGNATURES = ImmutableList.of( @@ -145,4 +150,37 @@ public R accept(ExpressionVisitor visitor, C context) { public boolean isDeterministic() { return !this.children.isEmpty(); } + + @Override + public boolean isPositive() { + return true; + } + + @Override + public int getMonotonicFunctionChildIndex() { + return 0; + } + + @Override + public Expression withConstantArgs(Expression literal) { + return new UnixTimestamp(literal); + } + + @Override + public boolean isMonotonic(Literal lower, Literal upper) { + if (arity() != 1) { + return false; + } + if (null == lower) { + lower = DateTimeLiteral.MIN_DATETIME; + } + if (null == upper) { + upper = DateTimeLiteral.MAX_DATETIME; + } + if (lower.compareTo(MAX) <= 0 && upper.compareTo(MAX) > 0) { + return false; + } else { + return true; + } + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateTimeLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateTimeLiteral.java index 27470187eae0d2..0a5c02409c113a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateTimeLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateTimeLiteral.java @@ -43,11 +43,10 @@ * date time literal. */ public class DateTimeLiteral extends DateLiteral { + public static final DateTimeLiteral MIN_DATETIME = new DateTimeLiteral(0000, 1, 1, 0, 0, 0); + public static final DateTimeLiteral MAX_DATETIME = new DateTimeLiteral(9999, 12, 31, 23, 59, 59); protected static final int MAX_MICROSECOND = 999999; - private static final DateTimeLiteral MIN_DATETIME = new DateTimeLiteral(0000, 1, 1, 0, 0, 0); - private static final DateTimeLiteral MAX_DATETIME = new DateTimeLiteral(9999, 12, 31, 23, 59, 59); - private static final Logger LOG = LogManager.getLogger(DateTimeLiteral.class); protected long hour; From 3002086600d3ee33fb1f95fd5168e5db9e22993f Mon Sep 17 00:00:00 2001 From: feiniaofeiafei Date: Tue, 17 Dec 2024 19:45:06 +0800 Subject: [PATCH 06/10] modify by comment --- .../expressions/functions/scalar/DayCeil.java | 3 +-- .../functions/scalar/DayFloor.java | 3 +-- .../functions/scalar/HourCeil.java | 3 +-- .../functions/scalar/HourFloor.java | 3 +-- .../functions/scalar/MinuteCeil.java | 3 +-- .../functions/scalar/MinuteFloor.java | 3 +-- .../functions/scalar/MonthCeil.java | 3 +-- .../functions/scalar/MonthFloor.java | 3 +-- .../functions/scalar/SecondCeil.java | 3 +-- .../functions/scalar/SecondFloor.java | 3 +-- .../functions/scalar/YearCeil.java | 3 +-- .../functions/scalar/YearFloor.java | 3 +-- .../test_add_sub_diff_ceil_floor.groovy | 19 ++++++++++++++++++- 13 files changed, 30 insertions(+), 25 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DayCeil.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DayCeil.java index e0eeece6b300c0..740363b50aad2b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DayCeil.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DayCeil.java @@ -118,8 +118,7 @@ public Expression withConstantArgs(Expression literal) { case 3: return new DayCeil(literal, child(1), child(2)); default: - // should not reach - return null; + throw new IllegalStateException("The function " + getName() + " has invalid child number."); } } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DayFloor.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DayFloor.java index 804658ce984fa9..5ba7fc13c7526b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DayFloor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DayFloor.java @@ -118,8 +118,7 @@ public Expression withConstantArgs(Expression literal) { case 3: return new DayFloor(literal, child(1), child(2)); default: - // should not reach - return null; + throw new IllegalStateException("The function " + getName() + " has invalid child number."); } } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HourCeil.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HourCeil.java index 4c8a98ca9fd025..13358e18d74770 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HourCeil.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HourCeil.java @@ -112,8 +112,7 @@ public Expression withConstantArgs(Expression literal) { case 3: return new HourCeil(literal, child(1), child(2)); default: - // should not reach - return null; + throw new IllegalStateException("The function " + getName() + " has invalid child number."); } } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HourFloor.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HourFloor.java index 1148c3191612f0..f48e26ea443f25 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HourFloor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/HourFloor.java @@ -112,8 +112,7 @@ public Expression withConstantArgs(Expression literal) { case 3: return new HourFloor(literal, child(1), child(2)); default: - // should not reach - return null; + throw new IllegalStateException("The function " + getName() + " has invalid child number."); } } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinuteCeil.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinuteCeil.java index 55e34cd1435565..4f3e317d00ef39 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinuteCeil.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinuteCeil.java @@ -111,8 +111,7 @@ public Expression withConstantArgs(Expression literal) { case 3: return new MinuteCeil(literal, child(1), child(2)); default: - // should not reach - return null; + throw new IllegalStateException("The function " + getName() + " has invalid child number."); } } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinuteFloor.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinuteFloor.java index 7aab30162aa14f..cefb5222c764ad 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinuteFloor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MinuteFloor.java @@ -111,8 +111,7 @@ public Expression withConstantArgs(Expression literal) { case 3: return new MinuteFloor(literal, child(1), child(2)); default: - // should not reach - return null; + throw new IllegalStateException("The function " + getName() + " has invalid child number."); } } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthCeil.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthCeil.java index 7d3514610d49ea..a1f4628dd6a9ab 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthCeil.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthCeil.java @@ -118,8 +118,7 @@ public Expression withConstantArgs(Expression literal) { case 3: return new MonthCeil(literal, child(1), child(2)); default: - // should not reach - return null; + throw new IllegalStateException("The function " + getName() + " has invalid child number."); } } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthFloor.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthFloor.java index f2535a674ddc94..d55d52ab68ce5a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthFloor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MonthFloor.java @@ -118,8 +118,7 @@ public Expression withConstantArgs(Expression literal) { case 3: return new MonthFloor(literal, child(1), child(2)); default: - // should not reach - return null; + throw new IllegalStateException("The function " + getName() + " has invalid child number."); } } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondCeil.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondCeil.java index b530cff9bfc8c9..3b0e657698743a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondCeil.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondCeil.java @@ -112,8 +112,7 @@ public Expression withConstantArgs(Expression literal) { case 3: return new SecondCeil(literal, child(1), child(2)); default: - // should not reach - return null; + throw new IllegalStateException("The function " + getName() + " has invalid child number."); } } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondFloor.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondFloor.java index 806aad402220a5..c06fff06aed016 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondFloor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SecondFloor.java @@ -113,8 +113,7 @@ public Expression withConstantArgs(Expression literal) { case 3: return new SecondFloor(literal, child(1), child(2)); default: - // should not reach - return null; + throw new IllegalStateException("The function " + getName() + " has invalid child number."); } } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearCeil.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearCeil.java index 19a7626d5721d1..37c952af815d86 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearCeil.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearCeil.java @@ -117,8 +117,7 @@ public Expression withConstantArgs(Expression literal) { case 3: return new YearCeil(literal, child(1), child(2)); default: - // should not reach - return null; + throw new IllegalStateException("The function " + getName() + " has invalid child number."); } } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearFloor.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearFloor.java index 06f7894768ae78..00a1ad918f7ffa 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearFloor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/YearFloor.java @@ -117,8 +117,7 @@ public Expression withConstantArgs(Expression literal) { case 3: return new YearFloor(literal, child(1), child(2)); default: - // should not reach - return null; + throw new IllegalStateException("The function " + getName() + " has invalid child number."); } } } diff --git a/regression-test/suites/nereids_rules_p0/partition_prune/test_add_sub_diff_ceil_floor.groovy b/regression-test/suites/nereids_rules_p0/partition_prune/test_add_sub_diff_ceil_floor.groovy index 12ddff6eb0ec8b..8582dad9ec7b27 100644 --- a/regression-test/suites/nereids_rules_p0/partition_prune/test_add_sub_diff_ceil_floor.groovy +++ b/regression-test/suites/nereids_rules_p0/partition_prune/test_add_sub_diff_ceil_floor.groovy @@ -272,7 +272,7 @@ suite("test_add_sub_diff_ceil_floor") { } explain { sql "select * from test_add_sub_diff_ceil_floor_t where years_diff('2021-01-01',month_ceil(hours_sub(dt, 1))) <=2" - contains("partitions=3/5 (p3,p4,p5)") + contains("partitions=4/5 (p1,p3,p4,p5)") } // mixed with non-function predicates explain { @@ -293,4 +293,21 @@ suite("test_add_sub_diff_ceil_floor") { sql """select * from test_add_sub_diff_ceil_floor_t where hours_add(dt, years_diff(dt,'2018-01-01')) <'2018-01-01' """ contains("partitions=5/5 (p1,p2,p3,p4,p5)") } + + // max + sql "drop table if exists max_t" + sql """create table max_t (a int, dt datetime, d date, c varchar(100)) duplicate key(a) + partition by range(dt) ( + partition p1 values less than ("2017-01-01"), + partition p2 values less than ("2018-01-01"), + partition p3 values less than ("2019-01-01"), + partition p4 values less than ("2020-01-01"), + partition p5 values less than ("2021-01-01"), + partition p6 values less than MAX + ) distributed by hash(a) properties("replication_num"="1");""" + sql """INSERT INTO max_t SELECT number, + date_add('2016-01-01 00:00:00', interval number month), + cast(date_add('2022-01-01 00:00:00', interval number month) as date), cast(number as varchar(65533)) FROM numbers('number'='100');""" + sql "INSERT INTO max_t values(3,null,null,null);" + } \ No newline at end of file From 41c026b6560249cf64852fe2b0fda055287e8f34 Mon Sep 17 00:00:00 2001 From: feiniaofeiafei Date: Tue, 17 Dec 2024 21:15:48 +0800 Subject: [PATCH 07/10] add regression cases --- .../test_add_sub_diff_ceil_floor.groovy | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/regression-test/suites/nereids_rules_p0/partition_prune/test_add_sub_diff_ceil_floor.groovy b/regression-test/suites/nereids_rules_p0/partition_prune/test_add_sub_diff_ceil_floor.groovy index 8582dad9ec7b27..6cc8042c3e4616 100644 --- a/regression-test/suites/nereids_rules_p0/partition_prune/test_add_sub_diff_ceil_floor.groovy +++ b/regression-test/suites/nereids_rules_p0/partition_prune/test_add_sub_diff_ceil_floor.groovy @@ -310,4 +310,35 @@ suite("test_add_sub_diff_ceil_floor") { cast(date_add('2022-01-01 00:00:00', interval number month) as date), cast(number as varchar(65533)) FROM numbers('number'='100');""" sql "INSERT INTO max_t values(3,null,null,null);" + explain { + sql "select * from max_t where years_diff('2021-01-01',month_ceil(hours_add(dt, 1),'1990-01-05')) <=2 ;" + contains("partitions=5/6 (p2,p3,p4,p5,p6)") + } + explain { + sql "select * from max_t where years_diff('2021-01-01',month_ceil(hours_add(dt, 1),10,'1990-01-05')) <=2 ;" + contains("partitions=5/6 (p2,p3,p4,p5,p6)") + } + + explain { + sql """select * from max_t where years_diff('2021-01-01',month_ceil(hours_add(dt, 1),10,'1990-01-05')) <=2 and dt >'2018-01-01';""" + contains("partitions=4/6 (p3,p4,p5,p6)") + } + + explain { + sql """select * from max_t where months_diff('2021-01-01',month_floor(hours_add(dt, 1),10,'1990-01-05')) <=2;""" + contains("partitions=3/6 (p1,p5,p6)") + } + + explain { + sql """select * from max_t where months_diff('2021-01-01',month_floor(hours_add(dt, 1),12,'1000-01-01')) > 2""" + contains("partitions=5/6 (p1,p2,p3,p4,p5)") + } + explain { + sql """select * from max_t where months_diff('2021-01-01',month_floor(hours_add(dt, 1),12,'1000-01-01')) > 2 and month_floor(dt) >'2018-01-01' """ + contains("partitions=3/6 (p3,p4,p5)") + } + explain { + sql """select * from max_t where hours_sub(hours_add(dt, 1),1) >'2018-01-01' and days_diff(hours_sub(hours_add(dt, 1),1),'2021-01-01') >2""" + contains("partitions=1/6 (p6)") + } } \ No newline at end of file From 46df61a0469558272018eb9875299ae702c60ef0 Mon Sep 17 00:00:00 2001 From: feiniaofeiafei Date: Wed, 18 Dec 2024 20:00:25 +0800 Subject: [PATCH 08/10] add regression case for unix_timestamp and from_days --- .../test_add_sub_diff_ceil_floor.groovy | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/regression-test/suites/nereids_rules_p0/partition_prune/test_add_sub_diff_ceil_floor.groovy b/regression-test/suites/nereids_rules_p0/partition_prune/test_add_sub_diff_ceil_floor.groovy index 6cc8042c3e4616..23e2c6d44b5e0f 100644 --- a/regression-test/suites/nereids_rules_p0/partition_prune/test_add_sub_diff_ceil_floor.groovy +++ b/regression-test/suites/nereids_rules_p0/partition_prune/test_add_sub_diff_ceil_floor.groovy @@ -341,4 +341,53 @@ suite("test_add_sub_diff_ceil_floor") { sql """select * from max_t where hours_sub(hours_add(dt, 1),1) >'2018-01-01' and days_diff(hours_sub(hours_add(dt, 1),1),'2021-01-01') >2""" contains("partitions=1/6 (p6)") } + + // from_days and unix_timestamp + explain { + sql """select * from max_t where unix_timestamp(dt) > 1547838847 """ + contains("partitions=3/6 (p4,p5,p6)") + } + + sql "drop table if exists partition_int_from_days" + sql """ + CREATE TABLE `partition_int_from_days` ( + `a` int NULL, + `b` int NULL + ) ENGINE=OLAP + DUPLICATE KEY(`a`, `b`) + PARTITION BY RANGE(`a`) + (PARTITION p1 VALUES [("-2147483648"), ("100000")), + PARTITION p2 VALUES [("100000"), ("738000")), + PARTITION p3 VALUES [("738000"), ("90000000")), + PARTITION p4 VALUES [("90000000"), (MAXVALUE))) + DISTRIBUTED BY HASH(`a`) BUCKETS 10 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); """ + sql """ + insert into partition_int_from_days values(100,100),(100022,1002),(738004,33),(90000003,89); + """ + explain { + sql """select * from partition_int_from_days where from_days(a)>'2020-07-29' """ + contains("partitions=3/4 (p1,p3,p4)") + } + + + sql "drop table if exists unix_time_t" + sql """create table unix_time_t (a int, dt datetime, d date, c varchar(100)) duplicate key(a) + partition by range(dt) ( + partition p1 values less than ("1980-01-01"), + partition p2 values less than ("2018-01-01"), + partition p3 values less than ("2039-01-01"), + partition p4 values less than MAXVALUE + ) distributed by hash(a) properties("replication_num"="1");""" + sql """INSERT INTO unix_time_t values(1,'1979-01-01','1979-01-01','abc'),(1,'2012-01-01','2012-01-01','abc'),(1,'2020-01-01','2020-01-01','abc'),(1,'2045-01-01','2045-01-01','abc')""" + sql "INSERT INTO unix_time_t values(3,null,null,null);" + show create table unix_time_t + select unix_timestamp('2018-01-02') + explain { + sql """explain select * from unix_time_t where unix_timestamp(dt) > 1514822400 """ + contains("partitions=2/4 (p3,p4)") + } + } \ No newline at end of file From d0f566bcb391d957f7b25173f4f38e14f3ea49df Mon Sep 17 00:00:00 2001 From: feiniaofeiafei Date: Thu, 19 Dec 2024 10:53:34 +0800 Subject: [PATCH 09/10] add cases --- .../functions/scalar/UnixTimestamp.java | 1 - .../test_add_sub_diff_ceil_floor.groovy | 22 +++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/UnixTimestamp.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/UnixTimestamp.java index fecae8613f3759..178187ad9cbc65 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/UnixTimestamp.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/UnixTimestamp.java @@ -43,7 +43,6 @@ * ScalarFunction 'unix_timestamp'. This class is generated by GenerateFunction. */ public class UnixTimestamp extends ScalarFunction implements ExplicitlyCastableSignature, Monotonic { - private static final DateTimeLiteral MIN = new DateTimeLiteral("1970-01-01 00:00:00"); private static final DateTimeLiteral MAX = new DateTimeLiteral("2038-01-19 03:14:07"); // we got changes when computeSignature diff --git a/regression-test/suites/nereids_rules_p0/partition_prune/test_add_sub_diff_ceil_floor.groovy b/regression-test/suites/nereids_rules_p0/partition_prune/test_add_sub_diff_ceil_floor.groovy index 23e2c6d44b5e0f..bda9dc81af7cfe 100644 --- a/regression-test/suites/nereids_rules_p0/partition_prune/test_add_sub_diff_ceil_floor.groovy +++ b/regression-test/suites/nereids_rules_p0/partition_prune/test_add_sub_diff_ceil_floor.groovy @@ -303,7 +303,7 @@ suite("test_add_sub_diff_ceil_floor") { partition p3 values less than ("2019-01-01"), partition p4 values less than ("2020-01-01"), partition p5 values less than ("2021-01-01"), - partition p6 values less than MAX + partition p6 values less than MAXVALUE ) distributed by hash(a) properties("replication_num"="1");""" sql """INSERT INTO max_t SELECT number, date_add('2016-01-01 00:00:00', interval number month), @@ -383,11 +383,25 @@ suite("test_add_sub_diff_ceil_floor") { ) distributed by hash(a) properties("replication_num"="1");""" sql """INSERT INTO unix_time_t values(1,'1979-01-01','1979-01-01','abc'),(1,'2012-01-01','2012-01-01','abc'),(1,'2020-01-01','2020-01-01','abc'),(1,'2045-01-01','2045-01-01','abc')""" sql "INSERT INTO unix_time_t values(3,null,null,null);" - show create table unix_time_t - select unix_timestamp('2018-01-02') explain { - sql """explain select * from unix_time_t where unix_timestamp(dt) > 1514822400 """ + sql """ select * from unix_time_t where unix_timestamp(dt) > 1514822400 """ contains("partitions=2/4 (p3,p4)") } + explain { + sql """select * from unix_time_t where unix_timestamp(dt) < 2147454847;""" + contains("partitions=4/4 (p1,p2,p3,p4)") + } + explain { + sql """select * from unix_time_t where unix_timestamp(dt) = 2147454847""" + contains("partitions=2/4 (p3,p4)") + } + explain { + sql """select * from unix_time_t where unix_timestamp(dt) = 2147454847 and dt<'2038-01-01'""" + contains("partitions=1/4 (p3)") + } + explain { + sql """select * from unix_time_t where unix_timestamp(dt) <=0""" + contains("partitions=3/4 (p1,p3,p4)") + } } \ No newline at end of file From f1d448401189e6fec15a56def24610f39d2edf42 Mon Sep 17 00:00:00 2001 From: feiniaofeiafei Date: Thu, 19 Dec 2024 12:09:31 +0800 Subject: [PATCH 10/10] fix ut --- .../nereids_rules_p0/partition_prune/test_convert_tz.groovy | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/regression-test/suites/nereids_rules_p0/partition_prune/test_convert_tz.groovy b/regression-test/suites/nereids_rules_p0/partition_prune/test_convert_tz.groovy index c309d10d067194..3e033a78eb963c 100644 --- a/regression-test/suites/nereids_rules_p0/partition_prune/test_convert_tz.groovy +++ b/regression-test/suites/nereids_rules_p0/partition_prune/test_convert_tz.groovy @@ -46,13 +46,13 @@ suite("test_convert_tz") { } explain { sql "SELECT * FROM test_convert_tz WHERE convert_tz(timestamp, 'Asia/Shanghai', 'Europe/Paris') > '2021-01-01';"; - contains("partitions=2/3 (p2,p3)") + contains("partitions=3/3 (p1,p2,p3)") } explain { sql """SELECT * FROM test_convert_tz WHERE convert_tz(timestamp, 'Asia/Shanghai', 'Europe/Paris') < '2021-02-24' and convert_tz(timestamp, 'Asia/Shanghai', 'Europe/Paris') > '2021-01-01';""" - contains("partitions=2/3 (p2,p3)") + contains("partitions=3/3 (p1,p2,p3)") } explain { @@ -93,7 +93,7 @@ suite("test_convert_tz") { } explain { sql "SELECT * FROM test_convert_tz WHERE not convert_tz(timestamp, 'Asia/Shanghai', 'Europe/Paris') <= '2021-01-01';"; - contains("partitions=2/3 (p2,p3)") + contains("partitions=3/3 (p1,p2,p3)") } } } \ No newline at end of file