From c38ac66e3c7510bbca65b40a7e8cc92eac9b28dc Mon Sep 17 00:00:00 2001 From: 924060929 <924060929@qq.com> Date: Sat, 16 Mar 2024 22:27:37 +0800 Subject: [PATCH] save --- .../expression/ExpressionNormalization.java | 22 +++++++++---------- .../rules/expression/check/CheckCast.java | 2 ++ .../rules/DigitalMaskingConvert.java | 2 ++ .../expression/rules/InPredicateDedup.java | 2 ++ .../rules/InPredicateToEqualToRule.java | 1 + .../rules/NormalizeBinaryPredicatesRule.java | 2 ++ .../rules/ReplaceVariableByLiteral.java | 1 + .../SimplifyArithmeticComparisonRule.java | 2 ++ .../rules/SimplifyArithmeticRule.java | 2 ++ .../rules/SupportJavaDateFormatter.java | 2 ++ .../expression/ExpressionRewriteTest.java | 8 +++---- .../SimplifyArithmeticRuleTest.java | 20 ++++++++++------- .../SimplifyArithmeticComparisonRuleTest.java | 2 +- .../rules/SimplifyCastRuleTest.java | 2 +- .../SimplifyComparisonPredicateTest.java | 4 ++-- 15 files changed, 47 insertions(+), 27 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/ExpressionNormalization.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/ExpressionNormalization.java index a9778c2b3224df1..e8c35f52313ea19 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/ExpressionNormalization.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/ExpressionNormalization.java @@ -42,20 +42,20 @@ public class ExpressionNormalization extends ExpressionRewrite { // from_unixtime(timestamp, 'yyyyMMdd') to 'yyyyMMdd' public static final List NORMALIZE_REWRITE_RULES = ImmutableList.of( bottomUp( - new ReplaceVariableByLiteral(), - new SupportJavaDateFormatter(), - new NormalizeBinaryPredicatesRule(), - new InPredicateDedup(), - new InPredicateToEqualToRule(), - new SimplifyNotExprRule(), - new SimplifyArithmeticRule() + ReplaceVariableByLiteral.INSTANCE, + SupportJavaDateFormatter.INSTANCE, + NormalizeBinaryPredicatesRule.INSTANCE, + InPredicateDedup.INSTANCE, + InPredicateToEqualToRule.INSTANCE, + SimplifyNotExprRule.INSTANCE, + SimplifyArithmeticRule.INSTANCE ), FoldConstantRule.INSTANCE, bottomUp( - new SimplifyCastRule(), - new DigitalMaskingConvert(), - new SimplifyArithmeticComparisonRule(), - new CheckCast() + SimplifyCastRule.INSTANCE, + DigitalMaskingConvert.INSTANCE, + SimplifyArithmeticComparisonRule.INSTANCE, + CheckCast.INSTANCE ) ); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/check/CheckCast.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/check/CheckCast.java index 723c60c90c1b749..a0e1d7568e8892b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/check/CheckCast.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/check/CheckCast.java @@ -39,6 +39,8 @@ * check cast valid */ public class CheckCast implements ExpressionPatternRuleFactory { + public static CheckCast INSTANCE = new CheckCast(); + @Override public List> buildRules() { return ImmutableList.of( diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/DigitalMaskingConvert.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/DigitalMaskingConvert.java index 03e40f171bc80d5..95d25e3c5924545 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/DigitalMaskingConvert.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/DigitalMaskingConvert.java @@ -34,6 +34,8 @@ * Convert DigitalMasking to Concat */ public class DigitalMaskingConvert implements ExpressionPatternRuleFactory { + public static DigitalMaskingConvert INSTANCE = new DigitalMaskingConvert(); + @Override public List> buildRules() { return ImmutableList.of( diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/InPredicateDedup.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/InPredicateDedup.java index 4a41d53610169d0..3760dcf0e72420d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/InPredicateDedup.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/InPredicateDedup.java @@ -33,6 +33,8 @@ * where A in (x, x) ==> where A in (x) */ public class InPredicateDedup implements ExpressionPatternRuleFactory { + public static final InPredicateDedup INSTANCE = new InPredicateDedup(); + @Override public List> buildRules() { return ImmutableList.of( diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/InPredicateToEqualToRule.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/InPredicateToEqualToRule.java index 3c7834f3503aaac..353de7f41f62a14 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/InPredicateToEqualToRule.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/InPredicateToEqualToRule.java @@ -39,6 +39,7 @@ * They are same processes, so must change synchronously. */ public class InPredicateToEqualToRule implements ExpressionPatternRuleFactory { + public static final InPredicateToEqualToRule INSTANCE = new InPredicateToEqualToRule(); @Override public List> buildRules() { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/NormalizeBinaryPredicatesRule.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/NormalizeBinaryPredicatesRule.java index f0c0e2c97d7dda8..e73104793cd9168 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/NormalizeBinaryPredicatesRule.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/NormalizeBinaryPredicatesRule.java @@ -32,6 +32,8 @@ * 5 > id -> id < 5 */ public class NormalizeBinaryPredicatesRule implements ExpressionPatternRuleFactory { + public static final NormalizeBinaryPredicatesRule INSTANCE = new NormalizeBinaryPredicatesRule(); + @Override public List> buildRules() { return ImmutableList.of( diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/ReplaceVariableByLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/ReplaceVariableByLiteral.java index 5b85ef5cee3a8a3..b4c5552706c589a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/ReplaceVariableByLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/ReplaceVariableByLiteral.java @@ -30,6 +30,7 @@ * replace varaible to real expression */ public class ReplaceVariableByLiteral implements ExpressionPatternRuleFactory { + public static ReplaceVariableByLiteral INSTANCE = new ReplaceVariableByLiteral(); @Override public List> buildRules() { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyArithmeticComparisonRule.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyArithmeticComparisonRule.java index 35e8b32c520fa3a..9326511ba2ab850 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyArithmeticComparisonRule.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyArithmeticComparisonRule.java @@ -58,6 +58,8 @@ * a / -2 > 1 => a < -2 */ public class SimplifyArithmeticComparisonRule implements ExpressionPatternRuleFactory { + public static SimplifyArithmeticComparisonRule INSTANCE = new SimplifyArithmeticComparisonRule(); + // don't rearrange multiplication because divide may loss precision private static final Map, Class> REARRANGEMENT_MAP = ImmutableMap ., Class>builder() diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyArithmeticRule.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyArithmeticRule.java index 808ad37758c9e90..2b4fa9b5ec7d70c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyArithmeticRule.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyArithmeticRule.java @@ -45,6 +45,8 @@ * TODO: handle cases like: '1 - IA < 1' to 'IA > 0' */ public class SimplifyArithmeticRule implements ExpressionPatternRuleFactory { + public static final SimplifyArithmeticRule INSTANCE = new SimplifyArithmeticRule(); + @Override public List> buildRules() { return ImmutableList.of( diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SupportJavaDateFormatter.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SupportJavaDateFormatter.java index 61e53c9e90f6f5e..27b929a2b9f865a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SupportJavaDateFormatter.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SupportJavaDateFormatter.java @@ -33,6 +33,8 @@ /** SupportJavaDateFormatter2 */ public class SupportJavaDateFormatter implements ExpressionPatternRuleFactory { + public static final SupportJavaDateFormatter INSTANCE = new SupportJavaDateFormatter(); + @Override public List> buildRules() { return ImmutableList.of( diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/ExpressionRewriteTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/ExpressionRewriteTest.java index 115d036d6c690ea..c88e2b4c03b0573 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/ExpressionRewriteTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/ExpressionRewriteTest.java @@ -82,7 +82,7 @@ void testNotRewrite() { @Test void testNormalizeExpressionRewrite() { executor = new ExpressionRuleExecutor(ImmutableList.of( - ExpressionRewrite.bottomUp(new NormalizeBinaryPredicatesRule()) + ExpressionRewrite.bottomUp(NormalizeBinaryPredicatesRule.INSTANCE) )); assertRewrite("1 = 1", "1 = 1"); @@ -165,7 +165,7 @@ void testExtractCommonFactorRewrite() { @Test void testInPredicateToEqualToRule() { executor = new ExpressionRuleExecutor(ImmutableList.of( - bottomUp(new InPredicateToEqualToRule()) + bottomUp(InPredicateToEqualToRule.INSTANCE) )); assertRewrite("a in (1)", "a = 1"); @@ -183,7 +183,7 @@ void testInPredicateToEqualToRule() { @Test void testInPredicateDedup() { executor = new ExpressionRuleExecutor(ImmutableList.of( - bottomUp(new InPredicateDedup()) + bottomUp(InPredicateDedup.INSTANCE) )); assertRewrite("a in (1, 2, 1, 2)", "a in (1, 2)"); @@ -192,7 +192,7 @@ void testInPredicateDedup() { @Test void testSimplifyCastRule() { executor = new ExpressionRuleExecutor(ImmutableList.of( - bottomUp(new SimplifyCastRule()) + bottomUp(SimplifyCastRule.INSTANCE) )); // deduplicate diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/SimplifyArithmeticRuleTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/SimplifyArithmeticRuleTest.java index c1b17cc4b87cda6..f5038ace19c6ff9 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/SimplifyArithmeticRuleTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/SimplifyArithmeticRuleTest.java @@ -29,7 +29,7 @@ class SimplifyArithmeticRuleTest extends ExpressionRewriteTestHelper { @Test void testSimplifyArithmetic() { executor = new ExpressionRuleExecutor(ImmutableList.of( - ExpressionRewrite.bottomUp(new SimplifyArithmeticRule()), + bottomUp(SimplifyArithmeticRule.INSTANCE), FunctionBinder.INSTANCE, FoldConstantRule.INSTANCE )); @@ -55,7 +55,7 @@ void testSimplifyArithmetic() { @Test void testSimplifyArithmeticRuleOnly() { executor = new ExpressionRuleExecutor(ImmutableList.of( - ExpressionRewrite.bottomUp(new SimplifyArithmeticRule()) + bottomUp(SimplifyArithmeticRule.INSTANCE) )); // add and subtract @@ -94,10 +94,12 @@ void testSimplifyArithmeticRuleOnly() { @Test void testSimplifyArithmeticComparison() { executor = new ExpressionRuleExecutor(ImmutableList.of( - ExpressionRewrite.bottomUp(new SimplifyArithmeticRule()), + bottomUp(SimplifyArithmeticRule.INSTANCE), FoldConstantRule.INSTANCE, - ExpressionRewrite.bottomUp(new SimplifyArithmeticComparisonRule()), - ExpressionRewrite.bottomUp(new SimplifyArithmeticRule()), + bottomUp( + SimplifyArithmeticComparisonRule.INSTANCE, + SimplifyArithmeticRule.INSTANCE + ), FunctionBinder.INSTANCE, FoldConstantRule.INSTANCE )); @@ -134,10 +136,12 @@ void testSimplifyArithmeticComparison() { @Test void testSimplifyDateTimeComparison() { executor = new ExpressionRuleExecutor(ImmutableList.of( - ExpressionRewrite.bottomUp(new SimplifyArithmeticRule()), + bottomUp(SimplifyArithmeticRule.INSTANCE), FoldConstantRule.INSTANCE, - ExpressionRewrite.bottomUp(new SimplifyArithmeticComparisonRule()), - ExpressionRewrite.bottomUp(new SimplifyArithmeticRule()), + bottomUp( + SimplifyArithmeticComparisonRule.INSTANCE, + SimplifyArithmeticRule.INSTANCE + ), FunctionBinder.INSTANCE, FoldConstantRule.INSTANCE )); diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rules/SimplifyArithmeticComparisonRuleTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rules/SimplifyArithmeticComparisonRuleTest.java index aef6c459b24904b..4d932187611136d 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rules/SimplifyArithmeticComparisonRuleTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rules/SimplifyArithmeticComparisonRuleTest.java @@ -39,7 +39,7 @@ public void testProcess() { Map nameToSlot = new HashMap<>(); nameToSlot.put("a", new SlotReference("a", IntegerType.INSTANCE)); executor = new ExpressionRuleExecutor(ImmutableList.of( - ExpressionRewrite.bottomUp(new SimplifyArithmeticComparisonRule()) + ExpressionRewrite.bottomUp(SimplifyArithmeticComparisonRule.INSTANCE) )); assertRewriteAfterSimplify("a + 1 > 1", "a > cast((1 - 1) as INT)", nameToSlot); assertRewriteAfterSimplify("a - 1 > 1", "a > cast((1 + 1) as INT)", nameToSlot); diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rules/SimplifyCastRuleTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rules/SimplifyCastRuleTest.java index 2f076a031f34013..71bfd37a5780e20 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rules/SimplifyCastRuleTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rules/SimplifyCastRuleTest.java @@ -52,7 +52,7 @@ class SimplifyCastRuleTest extends ExpressionRewriteTestHelper { @Test public void testSimplify() { executor = new ExpressionRuleExecutor(ImmutableList.of( - ExpressionRewrite.bottomUp(new SimplifyCastRule())) + ExpressionRewrite.bottomUp(SimplifyCastRule.INSTANCE)) ); assertRewriteAfterSimplify("CAST('1' AS STRING)", "'1'", StringType.INSTANCE); assertRewriteAfterSimplify("CAST('1' AS VARCHAR)", "'1'", diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rules/SimplifyComparisonPredicateTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rules/SimplifyComparisonPredicateTest.java index b36b9b9c7cc2576..1955571231bb230 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rules/SimplifyComparisonPredicateTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rules/SimplifyComparisonPredicateTest.java @@ -43,7 +43,7 @@ class SimplifyComparisonPredicateTest extends ExpressionRewriteTestHelper { void testSimplifyComparisonPredicateRule() { executor = new ExpressionRuleExecutor(ImmutableList.of( bottomUp( - new SimplifyCastRule(), + SimplifyCastRule.INSTANCE, SimplifyComparisonPredicate.INSTANCE ) )); @@ -93,7 +93,7 @@ void testSimplifyComparisonPredicateRule() { void testDateTimeV2CmpDateTimeV2() { executor = new ExpressionRuleExecutor(ImmutableList.of( bottomUp( - new SimplifyCastRule(), + SimplifyCastRule.INSTANCE, SimplifyComparisonPredicate.INSTANCE ) ));