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

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


The following commit(s) were added to refs/heads/ignite-19497 by this push:
     new 9c71741302 minor.
9c71741302 is described below

commit 9c71741302510a6fcb280a546a4280064866e14c
Author: amashenkov <[email protected]>
AuthorDate: Thu Aug 17 12:00:33 2023 +0300

    minor.
---
 .../sql/engine/exec/LogicalRelImplementor.java     |  6 ++-
 .../internal/sql/engine/schema/IgniteIndex.java    | 55 ++++++++--------------
 2 files changed, 24 insertions(+), 37 deletions(-)

diff --git 
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/LogicalRelImplementor.java
 
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/LogicalRelImplementor.java
index 3135a26571..e01c07d422 100644
--- 
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/LogicalRelImplementor.java
+++ 
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/LogicalRelImplementor.java
@@ -344,7 +344,11 @@ public class LogicalRelImplementor<RowT> implements 
IgniteRelVisitor<Node<RowT>>
         RangeIterable<RowT> ranges = null;
 
         if (searchBounds != null) {
-            Comparator<RowT> searchRowComparator = 
IgniteIndex.createComparator(expressionFactory, idx);
+            Comparator<RowT> searchRowComparator = null;
+
+            if (idx.type() == Type.SORTED) {
+                searchRowComparator = 
expressionFactory.comparator(IgniteIndex.createSearchRowCollation(idx.collation()));
+            }
 
             ranges = expressionFactory.ranges(searchBounds, 
idx.rowType(typeFactory, tbl.descriptor()), searchRowComparator);
         }
diff --git 
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/schema/IgniteIndex.java
 
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/schema/IgniteIndex.java
index 1f95e927bc..9a6c88e27b 100644
--- 
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/schema/IgniteIndex.java
+++ 
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/schema/IgniteIndex.java
@@ -20,7 +20,6 @@ package org.apache.ignite.internal.sql.engine.schema;
 import static 
org.apache.ignite.internal.sql.engine.util.TypeUtils.native2relationalType;
 
 import java.util.ArrayList;
-import java.util.Comparator;
 import java.util.List;
 import org.apache.calcite.plan.Convention;
 import org.apache.calcite.plan.RelOptCluster;
@@ -39,11 +38,9 @@ import 
org.apache.ignite.internal.catalog.descriptors.CatalogHashIndexDescriptor
 import 
org.apache.ignite.internal.catalog.descriptors.CatalogIndexColumnDescriptor;
 import org.apache.ignite.internal.catalog.descriptors.CatalogIndexDescriptor;
 import 
org.apache.ignite.internal.catalog.descriptors.CatalogSortedIndexDescriptor;
-import org.apache.ignite.internal.sql.engine.exec.exp.ExpressionFactory;
 import 
org.apache.ignite.internal.sql.engine.rel.logical.IgniteLogicalIndexScan;
 import org.apache.ignite.internal.sql.engine.trait.IgniteDistribution;
 import org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory;
-import org.jetbrains.annotations.Nullable;
 
 /**
  * Schema object representing an Index.
@@ -72,10 +69,8 @@ public class IgniteIndex {
             this.asc = asc;
             this.nullsFirst = nullsFirst;
         }
-
     }
 
-
     /**
      * Type of the index.
      */
@@ -89,23 +84,19 @@ public class IgniteIndex {
 
     private final IgniteDistribution tableDistribution;
 
-    private final RelCollation outputCollation;
-
-    private final RelCollation indexCollation;
+    private final RelCollation collation;
 
     private final Type type;
 
     private RelDataType rowType;
 
     /** Constructor. */
-    public IgniteIndex(int id, String name, Type type, IgniteDistribution 
tableDistribution, RelCollation outputCollation) {
+    public IgniteIndex(int id, String name, Type type, IgniteDistribution 
tableDistribution, RelCollation collation) {
         this.id = id;
         this.name = name;
         this.type = type;
         this.tableDistribution = tableDistribution;
-        this.outputCollation = outputCollation;
-
-        indexCollation = (type == Type.SORTED) ? 
createIndexCollation(outputCollation.getFieldCollations()) : null;
+        this.collation = collation;
     }
 
     /** Returns an id of the index. */
@@ -125,13 +116,13 @@ public class IgniteIndex {
 
     /** Returns the collation of this index. */
     public RelCollation collation() {
-        return outputCollation;
+        return collation;
     }
 
     /** Returns index row type. */
     public RelDataType rowType(IgniteTypeFactory factory, TableDescriptor 
tableDescriptor) {
         if (rowType == null) {
-            rowType = createRowType(factory, tableDescriptor, outputCollation);
+            rowType = createRowType(factory, tableDescriptor, collation);
         }
         return rowType;
     }
@@ -148,7 +139,7 @@ public class IgniteIndex {
     ) {
         RelTraitSet traitSet = cluster.traitSetOf(Convention.Impl.NONE)
                 .replace(tableDistribution)
-                .replace(type() == Type.HASH ? RelCollations.EMPTY : 
outputCollation);
+                .replace(type() == Type.HASH ? RelCollations.EMPTY : 
collation);
 
         return IgniteLogicalIndexScan.create(cluster, traitSet, relOptTable, 
name, proj, condition, requiredCols);
     }
@@ -203,22 +194,6 @@ public class IgniteIndex {
         }
     }
 
-    /**
-     * Creates {@link RelCollation} object from a given collations.
-     *
-     * @param collations Original collation.
-     * @return a {@link RelCollation} object.
-     */
-    private static RelCollation createIndexCollation(List<RelFieldCollation> 
collations) {
-        int i = 0;
-        List<RelFieldCollation> result = new ArrayList<>(collations.size());
-        for (RelFieldCollation fieldCollation : collations) {
-            result.add(fieldCollation.withFieldIndex(i++));
-        }
-
-        return RelCollations.of(result);
-    }
-
     //TODO: cache rowType as it can't be changed.
 
     /**
@@ -245,12 +220,20 @@ public class IgniteIndex {
         return b.build();
     }
 
-    /** Index row collation. */
-    public static <RowT> @Nullable Comparator<RowT> 
createComparator(ExpressionFactory<RowT> factory, IgniteIndex index) {
-        if (index.type != Type.SORTED) {
-            return null;
+    /**
+     * Creates {@link RelCollation} for search row from given index collation.
+     *
+     * @param indexCollation Original index collation.
+     * @return a {@link RelCollation} object.
+     */
+    public static RelCollation createSearchRowCollation(RelCollation 
indexCollation) {
+        List<RelFieldCollation> collations = 
indexCollation.getFieldCollations();
+        List<RelFieldCollation> result = new ArrayList<>(collations.size());
+
+        for (int i = 0; i < collations.size(); i++) {
+            result.add(collations.get(i).withFieldIndex(i));
         }
 
-        return factory.comparator(index.indexCollation);
+        return RelCollations.of(result);
     }
 }

Reply via email to