You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by zs...@apache.org on 2024/08/01 13:39:08 UTC

(ignite-3) branch ignite-22785 created (now 0b7c2cd83b)

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

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


      at 0b7c2cd83b fix

This branch includes the following new commits:

     new e5414f3e33 Merge branch 'main' into ignite-22785
     new 70af6b51f0 interm
     new d1a2336625 tests ok
     new 754405f7c1 test ok 2
     new bf24c615d6 test ok 3
     new 0b7c2cd83b fix

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(ignite-3) 05/06: test ok 3

Posted by zs...@apache.org.
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 bf24c615d6684e174cd271b0abb02175b52d5f4b
Author: zstan <zs...@apache.com>
AuthorDate: Thu Aug 1 16:11:29 2024 +0300

    test ok 3
---
 .../pruning/PartitionPruningMetadataExtractor.java | 81 ++++++++--------------
 1 file changed, 28 insertions(+), 53 deletions(-)

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 340e8d0e26..fa4a26ad76 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
@@ -161,10 +161,8 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
     }
 
     private static class ModifyNodeShuttle extends IgniteRelShuttle {
-        List<List<RexNode>> projections = null;
         List<RexNode> mappingProjections = null;
-        List<List<RexNode>> expressions = null;
-        TargetMapping mapping;
+        @Nullable TargetMapping mapping;
         Deque<Pair<@Nullable List<RexNode>, @Nullable List<List<RexNode>>>> projectsExpressions = new ArrayDeque<>();
         boolean unionRaised = false;
         IgniteRel previous = null;
@@ -182,6 +180,7 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
         public IgniteRel visit(IgniteProject rel) {
             if (unionRaised) {
                 if (mappingProjections == null) {
+                    // found projection before union, thus mapping is required
                     if (!projectsExpressions.isEmpty()) {
                         assert projectsExpressions.size() == 1 : "unexpected projections";
                         mappingProjections = projectsExpressions.poll().getFirst();
@@ -255,6 +254,8 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
 
         IgniteTable table = rel.getTable().unwrap(IgniteTable.class);
 
+        assert table != null;
+
         RexBuilder rexBuilder = rel.getCluster().getRexBuilder();
 
         ModifyNodeShuttle modify = new ModifyNodeShuttle();
@@ -277,7 +278,7 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
             long sourceId,
             IgniteTable table,
             Queue<Pair<@Nullable List<RexNode>, @Nullable List<List<RexNode>>>> projectsExpressions,
-            TargetMapping mapping,
+            @Nullable TargetMapping mapping,
             RexBuilder rexBuilder
     ) {
         if (projectsExpressions.isEmpty()) {
@@ -292,57 +293,41 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
 
         List<List<RexNode>> finalExpressions = new ArrayList<>();
 
-        boolean projectsFound = projectsExpressions.stream().anyMatch(p -> p.getFirst() != null);
+        for (Pair<@Nullable List<RexNode>, @Nullable List<List<RexNode>>> prjExp : projectsExpressions) {
+            @Nullable List<RexNode> projections = prjExp.getFirst();
+            @Nullable List<List<RexNode>> expressions = prjExp.getSecond();
 
-        if (projectsFound) {
-            for (Pair<@Nullable List<RexNode>, @Nullable List<List<RexNode>>> prjExp : projectsExpressions) {
-                @Nullable List<RexNode> projections1 = prjExp.getFirst();
-                @Nullable List<List<RexNode>> expressions1 = prjExp.getSecond();
+            if (projections != null) {
+                List<RexNode> projectionsReplaced = replaceInputRefs(projections);
 
-                if (projections1 != null) {
-                    List<RexNode> projectionsReplaced = replaceInputRefs(projections1);
+                boolean refFound = !projectionsReplaced.equals(projections);
 
-                    boolean refFound = !projectionsReplaced.equals(projections1);
+                projections = projectionsReplaced;
 
-                    projections1 = projectionsReplaced;
+                assert expressions != null;
 
-                    assert expressions1 != null;
+                for (List<RexNode> exp : expressions) {
+                    if (!refFound) {
+                        // no references are found, all important in projections
+                        finalExpressions.add(projections);
+                    } else {
+                        // otherwise exchange references with appropriate representations
+                        List<RexNode> modifiedExpressions = new ArrayList<>(projections);
 
-                    for (List<RexNode> exp : expressions1) {
-                        if (!refFound) {
-                            finalExpressions.add(projections1);
-                        } else {
-                            List<RexNode> newExprNodes = new ArrayList<>(projections1);
+                        for (int i = 0; i < projections.size(); ++i) {
+                            RexNode prjNode = projections.get(i);
 
-                            for (int prjIndex = 0; prjIndex < projections1.size(); ++prjIndex) {
-                                RexNode prjNode = projections1.get(prjIndex);
-                                if (prjNode instanceof RexLocalRef) {
-                                    RexLocalRef node0 = (RexLocalRef) prjNode;
-                                    newExprNodes.set(prjIndex, exp.get(node0.getIndex()));
-                                }
+                            if (prjNode instanceof RexLocalRef) {
+                                RexLocalRef node0 = (RexLocalRef) prjNode;
+                                modifiedExpressions.set(i, exp.get(node0.getIndex()));
                             }
-
-                            finalExpressions.add(newExprNodes);
-                        }
-                    }
-                } else {
-                    for (List<RexNode> exp : expressions1) {
-                        if (exp != null) {
-                            finalExpressions.add(exp);
                         }
-                    }
-                }
-            }
-
 
-        } else {
-            for (Pair<@Nullable List<RexNode>, @Nullable List<List<RexNode>>> prjExp : projectsExpressions) {
-                @Nullable List<List<RexNode>> expressions1 = prjExp.getSecond();
-                for (List<RexNode> exp : expressions1) {
-                    if (exp != null) {
-                        finalExpressions.add(exp);
+                        finalExpressions.add(modifiedExpressions);
                     }
                 }
+            } else if (expressions != null) {
+                finalExpressions.addAll(expressions);
             }
         }
 
@@ -350,15 +335,7 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
 
         RelDataType rowTypes = table.getRowType(Commons.typeFactory());
 
-        boolean dynParamsFound = false;
-
         for (List<RexNode> items : finalExpressions) {
-            // if dynamic parameters are present seems we need to skip the next one gathered from values and useless here.
-            if (dynParamsFound) {
-                dynParamsFound = false;
-                continue;
-            }
-
             List<RexNode> andNodes = new ArrayList<>(keysList.size());
             for (int key : keysList) {
                 RexNode node = items.get(mapping != null ? mapping.getSourceOpt(key) : key);
@@ -378,8 +355,6 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
             } else {
                 andEqNodes.add(andNodes.get(0));
             }
-
-            //dynParamsFound = items.stream().anyMatch(RexDynamicParam.class::isInstance);
         }
 
         if (!nullOrEmpty(andEqNodes)) {


(ignite-3) 03/06: tests ok

Posted by zs...@apache.org.
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 d1a2336625fff26d6c8ded66de14c4ed7a716bed
Author: zstan <zs...@apache.com>
AuthorDate: Thu Aug 1 12:33:29 2024 +0300

    tests ok
---
 .../pruning/PartitionPruningMetadataExtractor.java | 152 +++++++++++++--------
 .../planner/PartitionPruningMetadataTest.java      |   8 +-
 2 files changed, 96 insertions(+), 64 deletions(-)

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 0c669b42e3..f73f1a0a54 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
@@ -30,32 +30,30 @@ import it.unimi.dsi.fastutil.ints.IntArrayList;
 import it.unimi.dsi.fastutil.ints.IntList;
 import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
 import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
+import java.util.ArrayDeque;
 import java.util.ArrayList;
+import java.util.Deque;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
+import java.util.Queue;
 import java.util.Set;
-import org.apache.calcite.linq4j.Ord;
 import org.apache.calcite.rel.type.RelDataType;
 import org.apache.calcite.rex.RexBuilder;
 import org.apache.calcite.rex.RexCall;
 import org.apache.calcite.rex.RexDynamicParam;
 import org.apache.calcite.rex.RexFieldAccess;
-import org.apache.calcite.rex.RexInputRef;
 import org.apache.calcite.rex.RexLiteral;
 import org.apache.calcite.rex.RexLocalRef;
 import org.apache.calcite.rex.RexNode;
 import org.apache.calcite.rex.RexShuttle;
-import org.apache.calcite.rex.RexSlot;
 import org.apache.calcite.rex.RexUtil;
 import org.apache.calcite.sql.SqlKind;
 import org.apache.calcite.sql.fun.SqlStdOperatorTable;
 import org.apache.calcite.sql.type.SqlTypeName;
 import org.apache.calcite.util.ImmutableBitSet;
 import org.apache.calcite.util.Util;
-import org.apache.calcite.util.mapping.MappingType;
-import org.apache.calcite.util.mapping.Mappings;
 import org.apache.calcite.util.mapping.Mappings.TargetMapping;
 import org.apache.ignite.internal.sql.engine.prepare.IgniteRelShuttle;
 import org.apache.ignite.internal.sql.engine.rel.IgniteExchange;
@@ -72,6 +70,7 @@ import org.apache.ignite.internal.sql.engine.trait.IgniteDistribution;
 import org.apache.ignite.internal.sql.engine.util.Commons;
 import org.apache.ignite.internal.sql.engine.util.RexUtils;
 import org.apache.ignite.internal.tostring.S;
+import org.apache.ignite.internal.util.Pair;
 import org.jetbrains.annotations.Nullable;
 import org.jetbrains.annotations.VisibleForTesting;
 
@@ -164,6 +163,8 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
         List<List<RexNode>> projections = null;
         List<List<RexNode>> mappingProjections = null;
         List<List<RexNode>> expressions = null;
+        TargetMapping mapping;
+        Deque<Pair<@Nullable List<RexNode>, @Nullable List<List<RexNode>>>> projectsExpressions = new ArrayDeque<>();
         boolean unionRaised = false;
         IgniteRel previous = null;
         private static final Map<Class<?>, Set<Class<?>>> allowRelTransfers = new HashMap<>();
@@ -184,12 +185,16 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
                 if (projections != null) {
                     //throw Util.FoundOne.NULL;
                     mappingProjections = new ArrayList<>(projections);
+
                     projections.clear();
                 }
                 if (projections == null) {
                     projections = new ArrayList<>();
                 }
                 projections.add(rel.getProjects());
+
+                projectsExpressions.clear();
+                projectsExpressions.add(new Pair<>(rel.getProjects(), null));
                 //projections = rel.getProjects();
             } else {
                 // projections after union
@@ -197,6 +202,8 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
                     projections = new ArrayList<>();
                 }
                 projections.add(rel.getProjects());
+
+                projectsExpressions.add(new Pair<>(rel.getProjects(), null));
             }
 
             return super.visit(rel);
@@ -212,8 +219,23 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
             //List<RexNode> values = Commons.cast(rel.getTuples());
             //var values = rel.getTuples();
 
+            List<List<RexNode>> exps = new ArrayList<>();
+
             for (List<RexLiteral> values : rel.getTuples()) {
                 expressions.add(new ArrayList<>(values));
+                exps.add(new ArrayList<>(values));
+            }
+
+            Pair<List<RexNode>, List<List<RexNode>>> head = projectsExpressions.pollLast();
+            if (head == null) {
+                projectsExpressions.add(new Pair<>(null, exps));
+            } else {
+                if (head.getSecond() == null) {
+                    projectsExpressions.add(new Pair<>(head.getFirst(), exps));
+                } else {
+                    projectsExpressions.add(head);
+                    projectsExpressions.add(new Pair<>(null, exps));
+                }
             }
 
             return super.visit(rel);
@@ -263,6 +285,11 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
             return rel;
         }
 
+        if (modify.mappingProjections != null) {
+            modify.mapping = RexUtils.inversePermutation(modify.mappingProjections.get(0), // !!!!
+                    table.getRowType(Commons.typeFactory()), false);
+        }
+
         if (modify.mappingProjections != null) {
             List<RexNode> mappingProjections = replaceInputRefs(modify.mappingProjections.get(0));
             TargetMapping mapping = RexUtils.inversePermutation(mappingProjections, // !!!!
@@ -270,6 +297,21 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
 
             //assert mapping.size() == table.getRowType(Commons.typeFactory()).getFieldCount(); // to think !!
 
+            for (int i = 0; i < modify.expressions.size(); ++i) {
+                List<RexNode> expressions = modify.expressions.get(i);
+
+                if (mapping.size() != expressions.size()) {
+                    continue;
+                }
+
+                List<RexNode> newExpressions = new ArrayList<>(expressions);
+
+                for (int nodeIdx = 0; nodeIdx < expressions.size(); ++nodeIdx) {
+                    newExpressions.set(nodeIdx, expressions.get(mapping.getSourceOpt(nodeIdx)));
+                }
+                modify.expressions.set(i, newExpressions);
+            }
+
             for (int i = 0; i < modify.projections.size(); ++i) {
                 List<RexNode> projections = modify.projections.get(i);
                 List<RexNode> newProjections = new ArrayList<>(projections);
@@ -280,7 +322,7 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
             }
         }
 
-        extractFromValues(rel.sourceId(), table, modify.projections, modify.expressions, rexBuilder);
+        extractFromValues(rel.sourceId(), table, modify.projections, modify.expressions, modify.projectsExpressions, modify.mapping, rexBuilder);
 
         return super.visit(rel);
     }
@@ -290,6 +332,8 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
             IgniteTable table,
             @Nullable List<List<RexNode>> projections,
             @Nullable List<List<RexNode>> expressions,
+            Queue<Pair<@Nullable List<RexNode>, @Nullable List<List<RexNode>>>> projectsExpressions,
+            TargetMapping mapping,
             RexBuilder rexBuilder
     ) {
         if (expressions == null) {
@@ -304,69 +348,57 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
 
         boolean processed = false;
 
+        List<List<RexNode>> finalExpressions = new ArrayList<>();
+
         if (projections != null) {
-            boolean refFound = false;
-            for (int i = 0; i < projections.size(); ++i) {
-                List<RexNode> projectionsReplaced = replaceInputRefs(projections.get(i));
-                refFound = !projectionsReplaced.equals(projections.get(i));
+            for (Pair<@Nullable List<RexNode>, @Nullable List<List<RexNode>>> prjExp : projectsExpressions) {
+                @Nullable List<RexNode> projections1 = prjExp.getFirst();
+                @Nullable List<List<RexNode>> expressions1 = prjExp.getSecond();
 
-                if (refFound) {
-                    projections.set(i, projectionsReplaced);
-                }
-            }
+                if (projections1 != null) {
+                    List<RexNode> projectionsReplaced = replaceInputRefs(projections1);
 
-            processed = true;
-
-            if (projections.size() == 1) {
-                for (int i = 0; i < expressions.size(); ++i) {
-                    List<RexNode> prjNodes = projections.get(0);
-                    List<RexNode> exprNodes = expressions.get(i);
-                    List<RexNode> newExprNodes = new ArrayList<>(prjNodes);
-
-                    for (int prjIndex = 0; prjIndex < prjNodes.size(); ++prjIndex) {
-                        RexNode prjNode = prjNodes.get(prjIndex);
-                        if (prjNode instanceof RexDynamicParam) {
-                            newExprNodes.set(prjIndex, prjNode);
-                        } else if (prjNode instanceof RexLocalRef) {
-                            RexLocalRef node0 = (RexLocalRef) prjNode;
-                            newExprNodes.set(prjIndex, exprNodes.get(node0.getIndex()));
-                        }
-                    }
+                    boolean refFound = !projectionsReplaced.equals(projections1);
 
-                    expressions.set(i, newExprNodes);
-                }
-            } else {
-                //assert expressions.size() == 1;
-                for (int prjIndex = 0; prjIndex < projections.size(); ++prjIndex) {
-                    List<RexNode> prjNode = projections.get(prjIndex);
-                    expressions.set(prjIndex, prjNode);
-                }
-            }
+                    projections1 = projectionsReplaced;
+
+                    assert expressions1 != null;
+
+                    for (List<RexNode> exp : expressions1) {
+                        if (!refFound) {
+                            finalExpressions.add(projections1);
+                        } else {
+                            List<RexNode> newExprNodes = new ArrayList<>(projections1);
 
-            // projections after union
-            if (processed) {
-/*                if (projections.size() > 1) {
-                    for (List<RexNode> exprs : expressions) {
-                        for (List<RexNode> prjs : projections) {
-                            for (int i = 0; i < prjs.size(); ++i) {
-                                RexNode node = prjs.get(i);
-                                if (node instanceof RexLocalRef) {
-                                    RexLocalRef node0 = (RexLocalRef) node;
-                                    prjs.set(i, exprs.get(node0.getIndex()));
+                            for (int prjIndex = 0; prjIndex < projections1.size(); ++prjIndex) {
+                                RexNode prjNode = projections1.get(prjIndex);
+                                if (prjNode instanceof RexLocalRef) {
+                                    RexLocalRef node0 = (RexLocalRef) prjNode;
+                                    newExprNodes.set(prjIndex, exp.get(node0.getIndex()));
                                 }
                             }
+
+                            finalExpressions.add(newExprNodes);
                         }
                     }
-                }*/
+                } else {
+                    for (List<RexNode> exp : expressions1) {
+                        if (exp != null) {
+                            finalExpressions.add(exp);
+                        }
+                    }
+                }
+            }
 
-                //projections = projectionsReplaced;
-                //expressions = List.of(projections);
 
-/*                mapping = RexUtils.inversePermutation(projections,
-                        table.getRowType(Commons.typeFactory()), true);*/
-            } else {
-                // no references are found, projections contains materialized data without any refs.
-                expressions = projections;
+        } else {
+            for (Pair<@Nullable List<RexNode>, @Nullable List<List<RexNode>>> prjExp : projectsExpressions) {
+                @Nullable List<List<RexNode>> expressions1 = prjExp.getSecond();
+                for (List<RexNode> exp : expressions1) {
+                    if (exp != null) {
+                        finalExpressions.add(exp);
+                    }
+                }
             }
         }
 
@@ -376,7 +408,7 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
 
         boolean dynParamsFound = false;
 
-        for (List<RexNode> items : expressions) {
+        for (List<RexNode> items : finalExpressions) {
             // if dynamic parameters are present seems we need to skip the next one gathered from values and useless here.
             if (dynParamsFound) {
                 dynParamsFound = false;
@@ -385,7 +417,7 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
 
             List<RexNode> andNodes = new ArrayList<>(keysList.size());
             for (int key : keysList) {
-                RexNode node = items.get(key);
+                RexNode node = items.get(mapping != null ? mapping.getSourceOpt(key) : key);
 
                 if (!isValueExpr(node)) {
                     return;
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..74a5158ccf 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
@@ -147,17 +147,17 @@ public class PartitionPruningMetadataTest extends AbstractPlannerTest {
     }
 
     enum TestCaseBasicInsert {
-        SIMPLE_1a1("t(C1) VALUES (SELECT 100)", TABLE_C1_NULLABLE_C2),
+/*        SIMPLE_1a1("t(C1) VALUES (SELECT 100)", TABLE_C1_NULLABLE_C2),
         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_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]"),
         // values with rex expression case
         SIMPLE_1a2("t(C1) VALUES (1), (2)", TABLE_C1_NULLABLE_C2, "[c1=1]", "[c1=2]"),
-        SIMPLE_1a3("t(C1) VALUES (1), (SELECT 1)", TABLE_C1_NULLABLE_C2),
+        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_1a41("t VALUES (?, ?)", TABLE_C1_NULLABLE_C2, "[c1=?0]"),


(ignite-3) 02/06: interm

Posted by zs...@apache.org.
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 70af6b51f07e4095ad3391478e6df4be7c2c34c8
Author: zstan <zs...@apache.com>
AuthorDate: Thu Aug 1 08:27:59 2024 +0300

    interm
---
 .../internal/sql/engine/prepare/PlannerHelper.java |  11 +-
 .../pruning/PartitionPruningMetadataExtractor.java | 137 ++++++++++++++++-----
 .../planner/PartitionPruningMetadataTest.java      |  14 ++-
 3 files changed, 124 insertions(+), 38 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 30823ba767..21f1180f6c 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
@@ -21,7 +21,6 @@ import static org.apache.ignite.internal.sql.engine.hint.IgniteHint.DISABLE_RULE
 import static org.apache.ignite.internal.sql.engine.hint.IgniteHint.ENFORCE_JOIN_ORDER;
 import static org.apache.ignite.internal.sql.engine.util.Commons.fastQueryOptimizationEnabled;
 import static org.apache.ignite.internal.sql.engine.util.Commons.shortRuleName;
-import static org.apache.ignite.internal.sql.engine.util.Commons.simpleKeyValueOptimization;
 
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -148,13 +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
-                if (simpleKeyValueOptimization()) {
-                    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;
-                    }
-                }
+                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 a61092a5ef..0c669b42e3 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
@@ -36,22 +36,27 @@ import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Set;
+import org.apache.calcite.linq4j.Ord;
 import org.apache.calcite.rel.type.RelDataType;
 import org.apache.calcite.rex.RexBuilder;
 import org.apache.calcite.rex.RexCall;
 import org.apache.calcite.rex.RexDynamicParam;
 import org.apache.calcite.rex.RexFieldAccess;
+import org.apache.calcite.rex.RexInputRef;
 import org.apache.calcite.rex.RexLiteral;
 import org.apache.calcite.rex.RexLocalRef;
 import org.apache.calcite.rex.RexNode;
 import org.apache.calcite.rex.RexShuttle;
+import org.apache.calcite.rex.RexSlot;
 import org.apache.calcite.rex.RexUtil;
 import org.apache.calcite.sql.SqlKind;
 import org.apache.calcite.sql.fun.SqlStdOperatorTable;
 import org.apache.calcite.sql.type.SqlTypeName;
 import org.apache.calcite.util.ImmutableBitSet;
 import org.apache.calcite.util.Util;
+import org.apache.calcite.util.mapping.MappingType;
 import org.apache.calcite.util.mapping.Mappings;
+import org.apache.calcite.util.mapping.Mappings.TargetMapping;
 import org.apache.ignite.internal.sql.engine.prepare.IgniteRelShuttle;
 import org.apache.ignite.internal.sql.engine.rel.IgniteExchange;
 import org.apache.ignite.internal.sql.engine.rel.IgniteIndexScan;
@@ -156,7 +161,8 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
     }
 
     private static class ModifyNodeShuttle extends IgniteRelShuttle {
-        List<RexNode> projections = null;
+        List<List<RexNode>> projections = null;
+        List<List<RexNode>> mappingProjections = null;
         List<List<RexNode>> expressions = null;
         boolean unionRaised = false;
         IgniteRel previous = null;
@@ -172,18 +178,25 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
         /** {@inheritDoc} */
         @Override
         public IgniteRel visit(IgniteProject rel) {
-            if (!unionRaised) {
+            if (unionRaised) {
+                unionRaised = false;
                 // unexpected branch
                 if (projections != null) {
-                    throw Util.FoundOne.NULL;
+                    //throw Util.FoundOne.NULL;
+                    mappingProjections = new ArrayList<>(projections);
+                    projections.clear();
                 }
-                projections = rel.getProjects();
+                if (projections == null) {
+                    projections = new ArrayList<>();
+                }
+                projections.add(rel.getProjects());
+                //projections = rel.getProjects();
             } else {
                 // projections after union
-                if (expressions == null) {
-                    expressions = new ArrayList<>();
+                if (projections == null) {
+                    projections = new ArrayList<>();
                 }
-                expressions.add(rel.getProjects());
+                projections.add(rel.getProjects());
             }
 
             return super.visit(rel);
@@ -196,9 +209,12 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
                 expressions = new ArrayList<>();
             }
 
-            List<List<RexNode>> values = Commons.cast(rel.getTuples());
+            //List<RexNode> values = Commons.cast(rel.getTuples());
+            //var values = rel.getTuples();
 
-            expressions.addAll(values);
+            for (List<RexLiteral> values : rel.getTuples()) {
+                expressions.add(new ArrayList<>(values));
+            }
 
             return super.visit(rel);
         }
@@ -247,6 +263,23 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
             return rel;
         }
 
+        if (modify.mappingProjections != null) {
+            List<RexNode> mappingProjections = replaceInputRefs(modify.mappingProjections.get(0));
+            TargetMapping mapping = RexUtils.inversePermutation(mappingProjections, // !!!!
+                    table.getRowType(Commons.typeFactory()), true);
+
+            //assert mapping.size() == table.getRowType(Commons.typeFactory()).getFieldCount(); // to think !!
+
+            for (int i = 0; i < modify.projections.size(); ++i) {
+                List<RexNode> projections = modify.projections.get(i);
+                List<RexNode> newProjections = new ArrayList<>(projections);
+                for (int nodeIdx = 0; nodeIdx < projections.size(); ++nodeIdx) {
+                    newProjections.set(nodeIdx, projections.get(mapping.getSourceOpt(nodeIdx)));
+                }
+                modify.projections.set(i, newProjections);
+            }
+        }
+
         extractFromValues(rel.sourceId(), table, modify.projections, modify.expressions, rexBuilder);
 
         return super.visit(rel);
@@ -255,7 +288,7 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
     private void extractFromValues(
             long sourceId,
             IgniteTable table,
-            @Nullable List<RexNode> projections,
+            @Nullable List<List<RexNode>> projections,
             @Nullable List<List<RexNode>> expressions,
             RexBuilder rexBuilder
     ) {
@@ -269,23 +302,71 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
             return;
         }
 
-        Mappings.TargetMapping mapping = null;
+        boolean processed = false;
 
         if (projections != null) {
-            List<RexNode> projectionsReplaced = replaceInputRefs(projections);
+            boolean refFound = false;
+            for (int i = 0; i < projections.size(); ++i) {
+                List<RexNode> projectionsReplaced = replaceInputRefs(projections.get(i));
+                refFound = !projectionsReplaced.equals(projections.get(i));
 
-            boolean refFound = !projectionsReplaced.equals(projections);
+                if (refFound) {
+                    projections.set(i, projectionsReplaced);
+                }
+            }
 
-            if (refFound) {
-                projections = replaceInputRefs(projections);
+            processed = true;
+
+            if (projections.size() == 1) {
+                for (int i = 0; i < expressions.size(); ++i) {
+                    List<RexNode> prjNodes = projections.get(0);
+                    List<RexNode> exprNodes = expressions.get(i);
+                    List<RexNode> newExprNodes = new ArrayList<>(prjNodes);
+
+                    for (int prjIndex = 0; prjIndex < prjNodes.size(); ++prjIndex) {
+                        RexNode prjNode = prjNodes.get(prjIndex);
+                        if (prjNode instanceof RexDynamicParam) {
+                            newExprNodes.set(prjIndex, prjNode);
+                        } else if (prjNode instanceof RexLocalRef) {
+                            RexLocalRef node0 = (RexLocalRef) prjNode;
+                            newExprNodes.set(prjIndex, exprNodes.get(node0.getIndex()));
+                        }
+                    }
 
-                mapping = RexUtils.inversePermutation(projections,
-                        table.getRowType(Commons.typeFactory()), true);
+                    expressions.set(i, newExprNodes);
+                }
             } else {
-                // no references are found, projections contains materialized data without any refs.
-                expressions = List.of(projections);
+                //assert expressions.size() == 1;
+                for (int prjIndex = 0; prjIndex < projections.size(); ++prjIndex) {
+                    List<RexNode> prjNode = projections.get(prjIndex);
+                    expressions.set(prjIndex, prjNode);
+                }
+            }
+
+            // projections after union
+            if (processed) {
+/*                if (projections.size() > 1) {
+                    for (List<RexNode> exprs : expressions) {
+                        for (List<RexNode> prjs : projections) {
+                            for (int i = 0; i < prjs.size(); ++i) {
+                                RexNode node = prjs.get(i);
+                                if (node instanceof RexLocalRef) {
+                                    RexLocalRef node0 = (RexLocalRef) node;
+                                    prjs.set(i, exprs.get(node0.getIndex()));
+                                }
+                            }
+                        }
+                    }
+                }*/
+
+                //projections = projectionsReplaced;
+                //expressions = List.of(projections);
 
-                projections = null;
+/*                mapping = RexUtils.inversePermutation(projections,
+                        table.getRowType(Commons.typeFactory()), true);*/
+            } else {
+                // no references are found, projections contains materialized data without any refs.
+                expressions = projections;
             }
         }
 
@@ -304,19 +385,15 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
 
             List<RexNode> andNodes = new ArrayList<>(keysList.size());
             for (int key : keysList) {
-                RexNode lit = items.get(mapping != null ? mapping.getSourceOpt(key) : key);
-                if (!isValueExpr(lit)) {
+                RexNode node = items.get(key);
+
+                if (!isValueExpr(node)) {
                     return;
                 }
 
-                RexLocalRef ref;
-                if (projections != null) {
-                    ref = (RexLocalRef) projections.get(mapping.getSourceOpt(key));
-                } else {
-                    ref = rexBuilder.makeLocalRef(rowTypes.getFieldList().get(key).getType(), key);
-                }
+                RexLocalRef ref = rexBuilder.makeLocalRef(rowTypes.getFieldList().get(key).getType(), key);
 
-                RexNode eq = rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, ref, lit);
+                RexNode eq = rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, ref, node);
                 andNodes.add(eq);
             }
             if (andNodes.size() > 1) {
@@ -326,7 +403,7 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
                 andEqNodes.add(andNodes.get(0));
             }
 
-            dynParamsFound = items.stream().anyMatch(RexDynamicParam.class::isInstance);
+            //dynParamsFound = items.stream().anyMatch(RexDynamicParam.class::isInstance);
         }
 
         if (!nullOrEmpty(andEqNodes)) {
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 d1a0ad3276..916d0ff47d 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
@@ -127,7 +127,7 @@ public class PartitionPruningMetadataTest extends AbstractPlannerTest {
     /** Basic test cases for partition pruning metadata extractor, insert case. */
     @ParameterizedTest(name = "INSERT: {0}")
     @EnumSource(TestCaseBasicInsert.class)
-    @WithSystemProperty(key = "SIMPLE_KEY_VALUE_OPERATION", value = "false")
+    @WithSystemProperty(key = "FAST_QUERY_OPTIMIZATION_ENABLED", value = "false")
     public void testBasicInsertNoOptimization(TestCaseBasicInsert testCaseSimple) {
         checkPruningMetadata(testCaseSimple.data, SqlKind.INSERT);
     }
@@ -151,6 +151,7 @@ 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]"),
@@ -163,6 +164,7 @@ public class PartitionPruningMetadataTest extends AbstractPlannerTest {
         SIMPLE_1a42("t VALUES (?, ?, ?)", TABLE_C1_C2_NULLABLE_C3, "[c1=?0, c2=?1]"),
         // values with projection and rex expression case
         SIMPLE_1a5("t(C2, C1) VALUES (null, 1), (null, 2)", TABLE_C1_NULLABLE_C2, "[c1=1]", "[c1=2]"),
+        SIMPLE_1a511("t(C2, C1, C3) VALUES (?, ?, 1), (?, ?, 2)", TABLE_C1_C2_NULLABLE_C3, "[c1=?1, c2=?0]", "[c1=?3, c2=?2]"),
         SIMPLE_1a51("t(C2, C1) VALUES (?, ?), (?, ?)", TABLE_C1_NULLABLE_C2, "[c1=?1]", "[c1=?3]"),
         SIMPLE_1a52("t(C2, C1) VALUES (?, ?)", TABLE_C1_NULLABLE_C2, "[c1=?1]"),
         SIMPLE_1a53("t(C2, C1) VALUES (?, ?), ((SELECT 1), (SELECT 1))", TABLE_C1_NULLABLE_C2),
@@ -191,6 +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]")
         ;
 
         private final TestCase data;


(ignite-3) 06/06: fix

Posted by zs...@apache.org.
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;


(ignite-3) 01/06: Merge branch 'main' into ignite-22785

Posted by zs...@apache.org.
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 e5414f3e3390052c5eb1a241f32ce2198005f7ea
Merge: 2925fd2523 b76bb14caa
Author: zstan <zs...@apache.com>
AuthorDate: Wed Jul 31 14:35:56 2024 +0300

    Merge branch 'main' into ignite-22785

 .../org/apache/ignite/compute/IgniteCompute.java   |   20 +-
 .../org/apache/ignite/compute/TaskDescriptor.java  |  129 +
 .../apache/ignite/compute/task/MapReduceTask.java  |    4 +-
 .../internal/client/proto/ClientMessagePacker.java |    2 +-
 .../ClientComputeExecuteMapReduceRequest.java      |    4 +-
 .../apache/ignite/client/ClientOperationType.java  |    3 +-
 .../ignite/internal/client/ClientChannel.java      |   12 +
 .../ignite/internal/client/ReliableChannel.java    |   23 +
 .../ignite/internal/client/TcpIgniteClient.java    |    9 +
 .../internal/client/compute/ClientCompute.java     |   20 +-
 .../apache/ignite/client/ClientComputeTest.java    |   11 +-
 .../client/ObservableTimestampPropagationTest.java |    4 +-
 .../ignite/client/PartitionAwarenessTest.java      |    3 +-
 .../org/apache/ignite/client/RetryPolicyTest.java  |    6 +-
 .../apache/ignite/client/fakes/FakeCompute.java    |    7 +-
 modules/cluster-management/build.gradle            |    7 +-
 .../management/ClusterManagementGroupManager.java  |   83 +-
 .../management/network/CmgMessageCallback.java     |   44 +
 .../management/network/CmgMessageHandler.java      |  161 +
 .../network/CmgMessageHandlerFactory.java          |   88 -
 .../ClusterManagementGroupManagerTest.java         |  153 +
 .../management/network/CmgMessageHandlerTest.java  |  148 +
 .../ignite/internal/compute/ItComputeBaseTest.java |   17 +-
 .../ignite/internal/compute/ItMapReduceTest.java   |   24 +-
 .../internal/compute/AntiHijackIgniteCompute.java  |   12 +-
 .../ignite/internal/compute/IgniteComputeImpl.java |   13 +-
 .../metastorage/dsl/CompoundCondition.java         |   27 +-
 .../metastorage/dsl/CompoundConditionType.java     |   19 +-
 .../internal/metastorage/dsl/ConditionType.java    |   19 +-
 .../internal/metastorage/dsl/Conditions.java       |   36 +-
 .../ignite/internal/metastorage/dsl/Operation.java |   11 +-
 .../internal/metastorage/dsl/OperationType.java    |   19 +-
 .../internal/metastorage/dsl/Operations.java       |    6 +-
 .../internal/metastorage/dsl/SimpleCondition.java  |   11 +-
 .../metastorage/dsl/CompoundConditionTypeTest.java |   14 +-
 .../metastorage/dsl/ConditionTypeTest.java         |   42 +-
 .../metastorage/dsl/OperationTypeTest.java         |   16 +-
 .../internal/network/processor/TypeUtils.java      |   19 +
 .../MessageDeserializerGenerator.java              |   75 +-
 .../serialization/MessageSerializerGenerator.java  |   52 +-
 .../internal/network/annotations/Transferable.java |    2 +
 .../internal/network/messages/AllTypesMessage.java |    2 +
 .../internal/network/messages/TestEnum.java}       |   28 +-
 .../replicator/ItReplicaLifecycleTest.java         |    2 +
 .../network/disaster/LocalPartitionStateEnum.java  |   16 +-
 .../disaster/LocalPartitionStateMessage.java       |   13 +-
 .../replication/MultipleRowPkReplicaRequest.java   |   11 +-
 .../replication/MultipleRowReplicaRequest.java     |   11 +-
 .../network/replication/RequestType.java           |   17 +-
 .../replication/SingleRowPkReplicaRequest.java     |   11 +-
 .../replication/SingleRowReplicaRequest.java       |   11 +-
 .../network/replication/SwapRowReplicaRequest.java |   11 +-
 .../disaster/LocalPartitionStateEnumTest.java      |   20 +-
 .../network/replication/RequestTypeTest.java       |   73 +
 .../Apache.Ignite.Benchmarks.csproj                |    2 +-
 .../SerializerHandlerReadBenchmarks.cs             |    6 +-
 .../Apache.Ignite.Internal.Generators.csproj       |    3 +-
 .../ExceptionsGenerator.cs                         |    7 +-
 .../Apache.Ignite.Tests/Apache.Ignite.Tests.csproj |    4 +-
 .../Compute/ComputeClusterAwarenessTests.cs        |    4 +-
 .../Apache.Ignite.Tests/Compute/ComputeTests.cs    |  152 +-
 .../dotnet/Apache.Ignite.Tests/ConnectionTests.cs  |  117 +
 .../dotnet/Apache.Ignite.Tests/ConsoleLogger.cs    |    4 +-
 .../dotnet/Apache.Ignite.Tests/FakeServer.cs       |   36 +-
 .../Apache.Ignite.Tests/IgniteClientTests.cs       |   20 +
 .../dotnet/Apache.Ignite.Tests/IgniteProxy.cs      |    4 +-
 .../dotnet/Apache.Ignite.Tests/IgniteServerBase.cs |    4 +-
 .../dotnet/Apache.Ignite.Tests/ListLogger.cs       |    4 +-
 .../dotnet/Apache.Ignite.Tests/MetricsTests.cs     |    4 +-
 .../dotnet/Apache.Ignite.Tests/MultiClusterTest.cs |    4 +-
 .../Table/PartitionManagerTests.cs                 |    7 +-
 .../dotnet/Apache.Ignite.Tests/TestUtils.cs        |    2 +-
 .../Transactions/TransactionsTests.cs              |    4 +-
 .../dotnet/Apache.Ignite/Apache.Ignite.csproj      |    2 +-
 .../dotnet/Apache.Ignite/ClientOperationType.cs    |    7 +-
 .../dotnet/Apache.Ignite/Compute/ICompute.cs       |   16 +-
 .../dotnet/Apache.Ignite/Compute/IJobExecution.cs  |    6 +-
 .../dotnet/Apache.Ignite/Compute/ITaskExecution.cs |   80 +
 .../dotnet/Apache.Ignite/Compute/JobStatus.cs      |    2 +-
 .../dotnet/Apache.Ignite/Compute/JobTarget.cs      |   14 +
 .../Apache.Ignite/Compute/TaskDescriptor.cs}       |   25 +-
 .../dotnet/Apache.Ignite/Compute/TaskState.cs}     |   35 +-
 .../Compute/{JobStatus.cs => TaskStatus.cs}        |   16 +-
 .../Apache.Ignite/Internal/ClientFailoverSocket.cs |   19 +
 .../dotnet/Apache.Ignite/Internal/ClientSocket.cs  |   50 +-
 .../Apache.Ignite/Internal/Compute/Compute.cs      |  101 +-
 .../Apache.Ignite/Internal/Compute/JobExecution.cs |    4 +-
 .../Compute/{JobExecution.cs => TaskExecution.cs}  |   50 +-
 .../Apache.Ignite/Internal/IgniteClientInternal.cs |   23 +-
 .../dotnet/Apache.Ignite/Internal/LogMessages.cs   |   10 +-
 .../Apache.Ignite/Internal/Network/ClusterNode.cs  |   14 +-
 .../Internal/Network/ConnectionInfo.cs             |    5 +
 .../Apache.Ignite/Internal/Network/SslInfo.cs      |    9 +
 .../Apache.Ignite/Internal/Proto/ClientOp.cs       |    3 +
 .../Internal/Proto/ClientOpExtensions.cs           |    1 +
 .../Apache.Ignite/Internal/Sql/ColumnMetadata.cs   |   20 +-
 .../Apache.Ignite/Internal/Sql/ColumnOrigin.cs     |   15 +-
 .../Internal/Sql/ResultSetMetadata.cs              |    4 +
 .../dotnet/Apache.Ignite/Network/IClusterNode.cs   |    2 +-
 .../dotnet/Apache.Ignite/RetryReadPolicy.cs        |    1 +
 .../Apache.Ignite/Table/ReceiverDescriptor.cs      |    2 +
 modules/platforms/dotnet/Directory.Build.props     |    6 +-
 .../ignite/raft/jraft/entity/EnumOutter.java       |   25 +-
 .../ignite/raft/jraft/entity/RaftOutter.java       |    1 -
 .../ignite/raft/jraft/entity/EntryTypeTest.java}   |   23 +-
 .../cluster/management/ItClusterInitTest.java      |    2 +-
 .../runner/app/PlatformTestNodeRunner.java         |   37 +
 .../client/ItThinClientComputeMarshallingTest.java |    5 +-
 .../runner/app/client/ItThinClientComputeTest.java |   16 +-
 .../app/client/ItThinClientConnectionTest.java     |   20 +
 .../sql/engine/ItSqlUsesKeyValuePutTest.java       |   86 +-
 .../sql/engine/exec/UpdatableTableImpl.java        |    6 +-
 .../engine/exec/exp/agg/AccumulatorsFactory.java   |    2 +-
 .../internal/sql/engine/prepare/IgnitePlanner.java |    9 +-
 .../engine/prepare/IgniteSqlToRelConvertor.java    |   10 +-
 .../internal/sql/engine/prepare/PlannerHelper.java |  137 +-
 .../ignite/internal/sql/engine/util/Commons.java   |   11 +-
 .../sql/engine/planner/DmlPlannerTest.java         |    2 +
 .../sql/engine/planner/DynamicParametersTest.java  |    2 +
 .../sql/engine/planner/ImplicitCastsTest.java      |    2 +
 .../planner/datatypes/BaseTypeCoercionTest.java    |   15 +-
 .../datatypes/NumericInTypeCoercionTest.java       | 3093 ++++++++++++++++++++
 .../ignite/distributed/ReplicaUnavailableTest.java |    2 +-
 .../disaster/DisasterRecoveryManager.java          |    2 +-
 .../distributed/storage/InternalTableImpl.java     |   32 +-
 .../PartitionReplicaListenerIndexLockingTest.java  |    8 +-
 .../replication/PartitionReplicaListenerTest.java  |   28 +-
 .../replicator/action/RequestTypeTest.java         |   59 +-
 .../java/org/apache/ignite/internal/tx/TxMeta.java |    2 +-
 .../org/apache/ignite/internal/tx/TxState.java     |   15 +-
 .../org/apache/ignite/internal/tx/TxStateMeta.java |    2 +-
 .../ignite/internal/tx/TxStateMetaAbandoned.java   |    2 +-
 .../ignite/internal/tx/TxStateMetaFinishing.java   |    2 +-
 .../tx/message/TransactionMetaMessage.java         |   13 +-
 .../org/apache/ignite/internal/tx/TxStateTest.java |   17 +-
 135 files changed, 5577 insertions(+), 642 deletions(-)

diff --cc modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/PlannerHelper.java
index 2e21765ab5,093c58f7d6..30823ba767
--- 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
@@@ -19,14 -19,17 +19,18 @@@ package org.apache.ignite.internal.sql.
  
  import static org.apache.ignite.internal.sql.engine.hint.IgniteHint.DISABLE_RULE;
  import static org.apache.ignite.internal.sql.engine.hint.IgniteHint.ENFORCE_JOIN_ORDER;
+ import static org.apache.ignite.internal.sql.engine.util.Commons.fastQueryOptimizationEnabled;
  import static org.apache.ignite.internal.sql.engine.util.Commons.shortRuleName;
 +import static org.apache.ignite.internal.sql.engine.util.Commons.simpleKeyValueOptimization;
  
  import java.util.ArrayList;
+ import java.util.HashMap;
  import java.util.HashSet;
  import java.util.List;
+ import java.util.Map;
  import java.util.Set;
  import org.apache.calcite.plan.RelOptPlanner.CannotPlanException;
+ import org.apache.calcite.plan.RelOptTable;
  import org.apache.calcite.plan.RelOptUtil;
  import org.apache.calcite.plan.RelTraitSet;
  import org.apache.calcite.rel.RelCollations;


(ignite-3) 04/06: test ok 2

Posted by zs...@apache.org.
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 754405f7c197b42e2041c3b0e7efefa5518994ae
Author: zstan <zs...@apache.com>
AuthorDate: Thu Aug 1 15:37:52 2024 +0300

    test ok 2
---
 .../pruning/PartitionPruningMetadataExtractor.java | 112 ++++++---------------
 .../planner/PartitionPruningMetadataTest.java      |   8 +-
 2 files changed, 32 insertions(+), 88 deletions(-)

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 f73f1a0a54..340e8d0e26 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
@@ -32,6 +32,7 @@ import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
 import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
 import java.util.ArrayDeque;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Deque;
 import java.util.HashMap;
 import java.util.List;
@@ -161,7 +162,7 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
 
     private static class ModifyNodeShuttle extends IgniteRelShuttle {
         List<List<RexNode>> projections = null;
-        List<List<RexNode>> mappingProjections = null;
+        List<RexNode> mappingProjections = null;
         List<List<RexNode>> expressions = null;
         TargetMapping mapping;
         Deque<Pair<@Nullable List<RexNode>, @Nullable List<List<RexNode>>>> projectsExpressions = new ArrayDeque<>();
@@ -180,61 +181,35 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
         @Override
         public IgniteRel visit(IgniteProject rel) {
             if (unionRaised) {
-                unionRaised = false;
-                // unexpected branch
-                if (projections != null) {
-                    //throw Util.FoundOne.NULL;
-                    mappingProjections = new ArrayList<>(projections);
-
-                    projections.clear();
-                }
-                if (projections == null) {
-                    projections = new ArrayList<>();
-                }
-                projections.add(rel.getProjects());
-
-                projectsExpressions.clear();
-                projectsExpressions.add(new Pair<>(rel.getProjects(), null));
-                //projections = rel.getProjects();
-            } else {
-                // projections after union
-                if (projections == null) {
-                    projections = new ArrayList<>();
+                if (mappingProjections == null) {
+                    if (!projectsExpressions.isEmpty()) {
+                        assert projectsExpressions.size() == 1 : "unexpected projections";
+                        mappingProjections = projectsExpressions.poll().getFirst();
+                    } else {
+                        mappingProjections = Collections.emptyList();
+                    }
                 }
-                projections.add(rel.getProjects());
-
-                projectsExpressions.add(new Pair<>(rel.getProjects(), null));
             }
 
+            // fill projections, appropriate values will be filled further
+            projectsExpressions.add(new Pair<>(rel.getProjects(), null));
+
             return super.visit(rel);
         }
 
         /** {@inheritDoc} */
         @Override
         public IgniteRel visit(IgniteValues rel) {
-            if (expressions == null) {
-                expressions = new ArrayList<>();
-            }
-
-            //List<RexNode> values = Commons.cast(rel.getTuples());
-            //var values = rel.getTuples();
-
-            List<List<RexNode>> exps = new ArrayList<>();
-
-            for (List<RexLiteral> values : rel.getTuples()) {
-                expressions.add(new ArrayList<>(values));
-                exps.add(new ArrayList<>(values));
-            }
-
             Pair<List<RexNode>, List<List<RexNode>>> head = projectsExpressions.pollLast();
+
             if (head == null) {
-                projectsExpressions.add(new Pair<>(null, exps));
+                projectsExpressions.add(new Pair<>(null, Commons.cast(rel.getTuples())));
             } else {
                 if (head.getSecond() == null) {
-                    projectsExpressions.add(new Pair<>(head.getFirst(), exps));
+                    projectsExpressions.add(new Pair<>(head.getFirst(), Commons.cast(rel.getTuples())));
                 } else {
                     projectsExpressions.add(head);
-                    projectsExpressions.add(new Pair<>(null, exps));
+                    projectsExpressions.add(new Pair<>(null, Commons.cast(rel.getTuples())));
                 }
             }
 
@@ -244,6 +219,11 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
         /** {@inheritDoc} */
         @Override
         public IgniteRel visit(IgniteUnionAll rel) {
+            // unexpected branch
+            if (unionRaised) {
+                throw Util.FoundOne.NULL;
+            }
+
             unionRaised = true;
             return super.visit(rel);
         }
@@ -285,44 +265,10 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
             return rel;
         }
 
-        if (modify.mappingProjections != null) {
-            modify.mapping = RexUtils.inversePermutation(modify.mappingProjections.get(0), // !!!!
-                    table.getRowType(Commons.typeFactory()), false);
-        }
-
-        if (modify.mappingProjections != null) {
-            List<RexNode> mappingProjections = replaceInputRefs(modify.mappingProjections.get(0));
-            TargetMapping mapping = RexUtils.inversePermutation(mappingProjections, // !!!!
-                    table.getRowType(Commons.typeFactory()), true);
-
-            //assert mapping.size() == table.getRowType(Commons.typeFactory()).getFieldCount(); // to think !!
-
-            for (int i = 0; i < modify.expressions.size(); ++i) {
-                List<RexNode> expressions = modify.expressions.get(i);
-
-                if (mapping.size() != expressions.size()) {
-                    continue;
-                }
-
-                List<RexNode> newExpressions = new ArrayList<>(expressions);
+        modify.mapping = nullOrEmpty(modify.mappingProjections) ? null : RexUtils.inversePermutation(modify.mappingProjections,
+                table.getRowType(Commons.typeFactory()), false);
 
-                for (int nodeIdx = 0; nodeIdx < expressions.size(); ++nodeIdx) {
-                    newExpressions.set(nodeIdx, expressions.get(mapping.getSourceOpt(nodeIdx)));
-                }
-                modify.expressions.set(i, newExpressions);
-            }
-
-            for (int i = 0; i < modify.projections.size(); ++i) {
-                List<RexNode> projections = modify.projections.get(i);
-                List<RexNode> newProjections = new ArrayList<>(projections);
-                for (int nodeIdx = 0; nodeIdx < projections.size(); ++nodeIdx) {
-                    newProjections.set(nodeIdx, projections.get(mapping.getSourceOpt(nodeIdx)));
-                }
-                modify.projections.set(i, newProjections);
-            }
-        }
-
-        extractFromValues(rel.sourceId(), table, modify.projections, modify.expressions, modify.projectsExpressions, modify.mapping, rexBuilder);
+        extractFromValues(rel.sourceId(), table, modify.projectsExpressions, modify.mapping, rexBuilder);
 
         return super.visit(rel);
     }
@@ -330,13 +276,11 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
     private void extractFromValues(
             long sourceId,
             IgniteTable table,
-            @Nullable List<List<RexNode>> projections,
-            @Nullable List<List<RexNode>> expressions,
             Queue<Pair<@Nullable List<RexNode>, @Nullable List<List<RexNode>>>> projectsExpressions,
             TargetMapping mapping,
             RexBuilder rexBuilder
     ) {
-        if (expressions == null) {
+        if (projectsExpressions.isEmpty()) {
             return;
         }
 
@@ -346,11 +290,11 @@ public class PartitionPruningMetadataExtractor extends IgniteRelShuttle {
             return;
         }
 
-        boolean processed = false;
-
         List<List<RexNode>> finalExpressions = new ArrayList<>();
 
-        if (projections != null) {
+        boolean projectsFound = projectsExpressions.stream().anyMatch(p -> p.getFirst() != null);
+
+        if (projectsFound) {
             for (Pair<@Nullable List<RexNode>, @Nullable List<List<RexNode>>> prjExp : projectsExpressions) {
                 @Nullable List<RexNode> projections1 = prjExp.getFirst();
                 @Nullable List<List<RexNode>> expressions1 = prjExp.getSecond();
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 74a5158ccf..916d0ff47d 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
@@ -147,17 +147,17 @@ public class PartitionPruningMetadataTest extends AbstractPlannerTest {
     }
 
     enum TestCaseBasicInsert {
-/*        SIMPLE_1a1("t(C1) VALUES (SELECT 100)", TABLE_C1_NULLABLE_C2),
+        SIMPLE_1a1("t(C1) VALUES (SELECT 100)", TABLE_C1_NULLABLE_C2),
         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_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]"),
         // values with rex expression case
         SIMPLE_1a2("t(C1) VALUES (1), (2)", TABLE_C1_NULLABLE_C2, "[c1=1]", "[c1=2]"),
-        SIMPLE_1a3("t(C1) VALUES (1), (SELECT 1)", TABLE_C1_NULLABLE_C2),*/
+        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_1a41("t VALUES (?, ?)", TABLE_C1_NULLABLE_C2, "[c1=?0]"),