From 307a91e88bc448f46145ceda78a4423258ffa06e Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 21 Nov 2024 20:29:00 +0800 Subject: [PATCH] [BugFix] Fix for npe NormalizePredicateRule (backport #52326) (#53088) Co-authored-by: Kishore Kumar M V --- .../rewrite/scalar/NormalizePredicateRule.java | 3 ++- .../scalar/NormalizePredicateRuleTest.java | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/rewrite/scalar/NormalizePredicateRule.java b/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/rewrite/scalar/NormalizePredicateRule.java index 4a06a05fc5c2f..0fe790946a39c 100644 --- a/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/rewrite/scalar/NormalizePredicateRule.java +++ b/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/rewrite/scalar/NormalizePredicateRule.java @@ -186,7 +186,8 @@ private Optional getOptimizedCompoundTree(CompoundPredicateOpera parent.setCompoundTreeUniqueLeaves(compoundTreeUniqueLeaves); // this tree can be optimized - if (compoundTreeUniqueLeaves.size() != parent.getCompoundTreeLeafNodeNumber()) { + if (compoundTreeUniqueLeaves != null && + compoundTreeUniqueLeaves.size() != parent.getCompoundTreeLeafNodeNumber()) { ScalarOperator newTree = Utils.createCompound(parent.getCompoundType(), compoundTreeUniqueLeaves.stream().map( node -> { diff --git a/fe/fe-core/src/test/java/com/starrocks/sql/optimizer/rewrite/scalar/NormalizePredicateRuleTest.java b/fe/fe-core/src/test/java/com/starrocks/sql/optimizer/rewrite/scalar/NormalizePredicateRuleTest.java index d92662dba2088..545747fa1171b 100644 --- a/fe/fe-core/src/test/java/com/starrocks/sql/optimizer/rewrite/scalar/NormalizePredicateRuleTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/sql/optimizer/rewrite/scalar/NormalizePredicateRuleTest.java @@ -142,4 +142,20 @@ public void testCompound1() { ScalarOperator res = operatorRewriter.rewrite(compoundPredicateOperator, Lists.newArrayList(new NormalizePredicateRule())); } + + @Test + public void testCompound2() { + InPredicateOperator inOp = new InPredicateOperator( + false, + ConstantOperator.createInt(1063), + new ColumnRefOperator(0, Type.INT, "col1", false), + new ColumnRefOperator(1, Type.INT, "col2", false), + new ColumnRefOperator(2, Type.INT, "col3", false), + new ColumnRefOperator(3, Type.INT, "col4", false) + ); + + ScalarOperatorRewriter operatorRewriter = new ScalarOperatorRewriter(); + ScalarOperator res = + operatorRewriter.rewrite(inOp, Lists.newArrayList(new NormalizePredicateRule())); + } } \ No newline at end of file