This is an automated email from the ASF dual-hosted git repository.

zstan pushed a commit to branch ignite-22785
in repository https://gitbox.apache.org/repos/asf/ignite-3.git

commit 0b7c2cd83b3cc3b3e003b581ed64ec94cfa27d3b
Author: zstan <zs...@apache.com>
AuthorDate: Thu Aug 1 16:37:06 2024 +0300

    fix
---
 .../internal/sql/engine/prepare/PlannerHelper.java |  4 ++--
 .../pruning/PartitionPruningMetadataExtractor.java | 16 +++++++---------
 .../planner/PartitionPruningMetadataTest.java      | 22 +++++++++++-----------
 3 files changed, 20 insertions(+), 22 deletions(-)

diff --git 
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/PlannerHelper.java
 
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/PlannerHelper.java
index 21f1180f6c..093c58f7d6 100644
--- 
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/PlannerHelper.java
+++ 
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/PlannerHelper.java
@@ -147,11 +147,11 @@ public final class PlannerHelper {
                 // The result of `HEP_TO_SIMPLE_KEY_VALUE_OPERATION` phase 
MUST NOT be passed to next stage,
                 // thus if result meets our expectation, then return the 
result, otherwise discard it and
                 // proceed with regular flow
-/*                RelNode simpleOperation = 
planner.transform(PlannerPhase.HEP_TO_SIMPLE_KEY_VALUE_OPERATION, 
rel.getTraitSet(), rel);
+                RelNode simpleOperation = 
planner.transform(PlannerPhase.HEP_TO_SIMPLE_KEY_VALUE_OPERATION, 
rel.getTraitSet(), rel);
 
                 if (simpleOperation instanceof IgniteRel) {
                     return (IgniteRel) simpleOperation;
-                }*/
+                }
             }
 
             RelTraitSet desired = rel.getCluster().traitSet()
diff --git 
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/pruning/PartitionPruningMetadataExtractor.java
 
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/pruning/PartitionPruningMetadataExtractor.java
index fa4a26ad76..5ee64273a3 100644
--- 
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/pruning/PartitionPruningMetadataExtractor.java
+++ 
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/pruning/PartitionPruningMetadataExtractor.java
@@ -183,6 +183,7 @@ public class PartitionPruningMetadataExtractor extends 
IgniteRelShuttle {
                     // found projection before union, thus mapping is required
                     if (!projectsExpressions.isEmpty()) {
                         assert projectsExpressions.size() == 1 : "unexpected 
projections";
+                        // erase projection and store it for mapping needs
                         mappingProjections = 
projectsExpressions.poll().getFirst();
                     } else {
                         mappingProjections = Collections.emptyList();
@@ -199,17 +200,14 @@ public class PartitionPruningMetadataExtractor extends 
IgniteRelShuttle {
         /** {@inheritDoc} */
         @Override
         public IgniteRel visit(IgniteValues rel) {
-            Pair<List<RexNode>, List<List<RexNode>>> head = 
projectsExpressions.pollLast();
+            Pair<List<RexNode>, List<List<RexNode>>> head = 
projectsExpressions.peekLast();
 
-            if (head == null) {
+            if (head == null || head.getSecond() != null) {
                 projectsExpressions.add(new Pair<>(null, 
Commons.cast(rel.getTuples())));
             } else {
-                if (head.getSecond() == null) {
-                    projectsExpressions.add(new Pair<>(head.getFirst(), 
Commons.cast(rel.getTuples())));
-                } else {
-                    projectsExpressions.add(head);
-                    projectsExpressions.add(new Pair<>(null, 
Commons.cast(rel.getTuples())));
-                }
+                // no projection without values are possible
+                projectsExpressions.pollLast();
+                projectsExpressions.add(new Pair<>(head.getFirst(), 
Commons.cast(rel.getTuples())));
             }
 
             return super.visit(rel);
@@ -331,7 +329,7 @@ public class PartitionPruningMetadataExtractor extends 
IgniteRelShuttle {
             }
         }
 
-        List<RexNode> andEqNodes = new ArrayList<>();
+        List<RexNode> andEqNodes = new ArrayList<>(finalExpressions.size());
 
         RelDataType rowTypes = table.getRowType(Commons.typeFactory());
 
diff --git 
a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/PartitionPruningMetadataTest.java
 
b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/PartitionPruningMetadataTest.java
index 916d0ff47d..66da1cc24b 100644
--- 
a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/PartitionPruningMetadataTest.java
+++ 
b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/PartitionPruningMetadataTest.java
@@ -151,7 +151,6 @@ public class PartitionPruningMetadataTest extends 
AbstractPlannerTest {
         SIMPLE_1a11("t VALUES ((SELECT 100), ?)", TABLE_C1_NULLABLE_C2),
         SIMPLE_1a12("t VALUES (?, (SELECT 100))", TABLE_C1_NULLABLE_C2),
         SIMPLE_1a13("t VALUES (?, ?)", TABLE_C1_NULLABLE_C2, "[c1=?0]"),
-        SIMPLE_1a141("t(c2, c1) VALUES (?, ?), (?, ?)", TABLE_C1_NULLABLE_C2, 
"[c1=?1]", "[c1=?3]"),
         SIMPLE_1a14("t VALUES (?, ?), (?, ?)", TABLE_C1_NULLABLE_C2, 
"[c1=?0]", "[c1=?2]"),
         SIMPLE_1a15("t VALUES ('100', 1)", TABLE_C1_NULLABLE_C2, "[c1=100]"),
         SIMPLE_1a16("t VALUES ('100'::smallint, 1)", TABLE_C1_NULLABLE_C2, 
"[c1=100]"),
@@ -160,6 +159,7 @@ public class PartitionPruningMetadataTest extends 
AbstractPlannerTest {
         SIMPLE_1a3("t(C1) VALUES (1), (SELECT 1)", TABLE_C1_NULLABLE_C2),
         // union can be used here
         SIMPLE_1a4("t(C1) VALUES (?), (?), (1)", TABLE_C1_NULLABLE_C2, 
"[c1=?0]", "[c1=?1]", "[c1=1]"),
+        SIMPLE_1a40("t(C2, C1) VALUES (?, ?), (?, ?)", TABLE_C1_NULLABLE_C2, 
"[c1=?1]", "[c1=?3]"),
         SIMPLE_1a41("t VALUES (?, ?)", TABLE_C1_NULLABLE_C2, "[c1=?0]"),
         SIMPLE_1a42("t VALUES (?, ?, ?)", TABLE_C1_C2_NULLABLE_C3, "[c1=?0, 
c2=?1]"),
         // values with projection and rex expression case
@@ -193,16 +193,16 @@ public class PartitionPruningMetadataTest extends 
AbstractPlannerTest {
         SIMPLE_1j3("t(C4, C2, C3, C1) VALUES (?, ?, ?, ?), (2, 3, 4, 5)", 
TABLE_C1_C2_C3, "[c1=?3, c2=?1, c3=?2]", "[c1=5, c2=3, c3=4]"),
 
         SIMPLE_1h1(String.format("t(C1) VALUES (%d)", Long.MAX_VALUE), 
TABLE_C1_NULLABLE_C2),
-        //
-        //TEST00("t(C1, C2, C3) SELECT ?, t.x, t.y FROM (SELECT ?::int, 103) 
as T(x, y)", TABLE_C1_C2_NULLABLE_C3),
-        TEST0("t(C1, C2, C3) SELECT ?, t.x, t.y FROM (SELECT 102, 103) as T(x, 
y)", TABLE_C1_C2_NULLABLE_C3, "[c1=?0, c2=102]"),
-        TEST1("t(C1, C2) SELECT ?, t.x FROM (SELECT 102) as T(x)", 
TABLE_C1_NULLABLE_C2, "[c1=?0]"),
-        TEST2("t(C1, C2) SELECT 101, t.x FROM (SELECT 102) as T(x)", 
TABLE_C1_NULLABLE_C2, "[c1=101]"),
-        TEST3("t(C1, C2) SELECT t.x, 102 FROM (SELECT 101) as T(x)", 
TABLE_C1_NULLABLE_C2, "[c1=101]"),
-        TEST4("t(C1, C2) SELECT t.x, 102 FROM (SELECT ?::int) as T(x)", 
TABLE_C1_NULLABLE_C2, "[c1=?0]"),
-        TEST5("t(C2, C1) SELECT 102, t.x FROM (SELECT ?::int) as T(x)", 
TABLE_C1_NULLABLE_C2, "[c1=?0]"),
-        TEST6("t(C3, C2, C1) SELECT 103, t.y, t.x FROM (SELECT 101, 102) as 
T(x, y)", TABLE_C1_C2_NULLABLE_C3, "[c1=101, c2=102]"),
-        TEST7("t(C1, C2, C3) SELECT t.x, t.y, 103 FROM (SELECT ?::int, ?::int) 
as T(x, y)", TABLE_C1_C2_NULLABLE_C3, "[c1=?0, c2=?1]")
+
+        SIMPLE_1i1("t(C1, C2, C3) SELECT ?, t.x, t.y FROM (SELECT ?::int, 103) 
as T(x, y)", TABLE_C1_C2_NULLABLE_C3, "[c1=?0, c2=?1]"),
+        SIMPLE_1i2("t(C1, C2, C3) SELECT ?, t.x, t.y FROM (SELECT 102, 103) as 
T(x, y)", TABLE_C1_C2_NULLABLE_C3, "[c1=?0, c2=102]"),
+        SIMPLE_1i3("t(C1, C2) SELECT ?, t.x FROM (SELECT 102) as T(x)", 
TABLE_C1_NULLABLE_C2, "[c1=?0]"),
+        SIMPLE_1i4("t(C1, C2) SELECT 101, t.x FROM (SELECT 102) as T(x)", 
TABLE_C1_NULLABLE_C2, "[c1=101]"),
+        SIMPLE_1i5("t(C1, C2) SELECT t.x, 102 FROM (SELECT 101) as T(x)", 
TABLE_C1_NULLABLE_C2, "[c1=101]"),
+        SIMPLE_1i6("t(C1, C2) SELECT t.x, 102 FROM (SELECT ?::int) as T(x)", 
TABLE_C1_NULLABLE_C2, "[c1=?0]"),
+        SIMPLE_1i7("t(C2, C1) SELECT 102, t.x FROM (SELECT ?::int) as T(x)", 
TABLE_C1_NULLABLE_C2, "[c1=?0]"),
+        SIMPLE_1i8("t(C3, C2, C1) SELECT 103, t.y, t.x FROM (SELECT 101, 102) 
as T(x, y)", TABLE_C1_C2_NULLABLE_C3, "[c1=101, c2=102]"),
+        SIMPLE_1i9("t(C1, C2, C3) SELECT t.x, t.y, 103 FROM (SELECT ?::int, 
?::int) as T(x, y)", TABLE_C1_C2_NULLABLE_C3, "[c1=?0, c2=?1]")
         ;
 
         private final TestCase data;

Reply via email to