zstan commented on code in PR #2441:
URL: https://github.com/apache/ignite-3/pull/2441#discussion_r1296723352
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/schema/IgniteIndex.java:
##########
@@ -59,132 +72,185 @@ public static Collation of(boolean asc, boolean
nullsFirst) {
this.asc = asc;
this.nullsFirst = nullsFirst;
}
+
}
+
/**
* Type of the index.
*/
public enum Type {
- HASH, SORTED
+ HASH, SORTED;
}
- private final List<String> columns;
+ private final int id;
- private final @Nullable List<Collation> collations;
+ private final String name;
- private final Index<?> index;
+ private final IgniteDistribution tableDistribution;
- private final Type type;
+ private final RelCollation outputCollation;
- /**
- * Constructs the Index object.
- *
- * @param index A data access object to wrap.
- */
- public IgniteIndex(Index<?> index) {
- this.index = Objects.requireNonNull(index, "index");
+ private final RelCollation indexCollation;
- this.columns = index.descriptor().columns();
- this.collations = deriveCollations(index);
- this.type = index instanceof SortedIndex ? Type.SORTED : Type.HASH;
- }
+ private final Type type;
- /**
- * Constructs the Index object.
- */
- @TestOnly
- public IgniteIndex(Type type, List<String> columns, @Nullable
List<Collation> collations) {
- assert type == Type.SORTED ^ collations == null;
+ private RelDataType rowType;
- this.columns = columns;
- this.collations = collations;
+ /** Constructor. */
+ public IgniteIndex(int id, String name, Type type, IgniteDistribution
tableDistribution, RelCollation outputCollation) {
+ this.id = id;
+ this.name = name;
this.type = type;
+ this.tableDistribution = tableDistribution;
+ this.outputCollation = outputCollation;
- index = null;
+ indexCollation = (type == Type.SORTED) ?
createIndexCollation(outputCollation.getFieldCollations()) : null;
Review Comment:
you make remapping for SORTED indexes only, can you explain - why ?
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/schema/IgniteIndex.java:
##########
@@ -59,132 +72,185 @@ public static Collation of(boolean asc, boolean
nullsFirst) {
this.asc = asc;
this.nullsFirst = nullsFirst;
}
+
Review Comment:
redundant line
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/schema/IgniteIndex.java:
##########
@@ -59,132 +72,185 @@ public static Collation of(boolean asc, boolean
nullsFirst) {
this.asc = asc;
this.nullsFirst = nullsFirst;
}
+
}
+
Review Comment:
redundant
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/schema/IgniteIndex.java:
##########
@@ -59,132 +72,185 @@ public static Collation of(boolean asc, boolean
nullsFirst) {
this.asc = asc;
this.nullsFirst = nullsFirst;
}
+
}
+
/**
* Type of the index.
*/
public enum Type {
- HASH, SORTED
+ HASH, SORTED;
}
- private final List<String> columns;
+ private final int id;
- private final @Nullable List<Collation> collations;
+ private final String name;
- private final Index<?> index;
+ private final IgniteDistribution tableDistribution;
- private final Type type;
+ private final RelCollation outputCollation;
- /**
- * Constructs the Index object.
- *
- * @param index A data access object to wrap.
- */
- public IgniteIndex(Index<?> index) {
- this.index = Objects.requireNonNull(index, "index");
+ private final RelCollation indexCollation;
- this.columns = index.descriptor().columns();
- this.collations = deriveCollations(index);
- this.type = index instanceof SortedIndex ? Type.SORTED : Type.HASH;
- }
+ private final Type type;
- /**
- * Constructs the Index object.
- */
- @TestOnly
- public IgniteIndex(Type type, List<String> columns, @Nullable
List<Collation> collations) {
- assert type == Type.SORTED ^ collations == null;
+ private RelDataType rowType;
- this.columns = columns;
- this.collations = collations;
+ /** Constructor. */
+ public IgniteIndex(int id, String name, Type type, IgniteDistribution
tableDistribution, RelCollation outputCollation) {
+ this.id = id;
+ this.name = name;
this.type = type;
+ this.tableDistribution = tableDistribution;
+ this.outputCollation = outputCollation;
- index = null;
+ indexCollation = (type == Type.SORTED) ?
createIndexCollation(outputCollation.getFieldCollations()) : null;
}
- /** Returns a list of names of indexed columns. */
- public List<String> columns() {
- return columns;
+ /** Returns an id of the index. */
+ public int id() {
+ return id;
}
- /**
- * Returns a list of collations.
- *
- * <p>The size of the collations list is guaranteed to match the size of
indexed columns. The i-th
- * collation is related to an i-th column.
- *
- * @return The list of collations or {@code null} if not applicable.
- */
- public @Nullable List<Collation> collations() {
- return collations;
+ /** Returns the name of this index. */
+ public String name() {
+ return name;
}
- /** Returns the name of a current index. */
- public String name() {
- return index.name();
+ /** Returns the type of this index. */
+ public Type type() {
+ return type;
}
- /** Returns an object providing access to a data. */
- public Index<?> index() {
- return index;
+ /** Returns the collation of this index. */
+ public RelCollation collation() {
+ return outputCollation;
}
- /** Returns id of this index. */
- public int id() {
- return index.id();
+ /** Returns index row type. */
+ public RelDataType rowType(IgniteTypeFactory factory, TableDescriptor
tableDescriptor) {
+ if (rowType == null) {
+ rowType = createRowType(factory, tableDescriptor, outputCollation);
+ }
+ return rowType;
+ }
+
+ /**
+ * Translates this index into relational operator.
+ */
+ public IgniteLogicalIndexScan toRel(
+ RelOptCluster cluster,
+ RelOptTable relOptTable,
+ List<RexNode> proj,
+ RexNode condition,
+ ImmutableBitSet requiredCols
+ ) {
+ RelTraitSet traitSet = cluster.traitSetOf(Convention.Impl.NONE)
+ .replace(tableDistribution)
+ .replace(type() == Type.HASH ? RelCollations.EMPTY :
outputCollation);
+
+ return IgniteLogicalIndexScan.create(cluster, traitSet, relOptTable,
name, proj, condition, requiredCols);
}
- public int tableId() {
- return index.tableId();
+ static RelCollation createIndexCollation(CatalogIndexDescriptor
descriptor, TableDescriptor tableDescriptor) {
+ if (descriptor instanceof CatalogSortedIndexDescriptor) {
+ CatalogSortedIndexDescriptor sortedIndexDescriptor =
(CatalogSortedIndexDescriptor) descriptor;
+ List<CatalogIndexColumnDescriptor> columns =
sortedIndexDescriptor.columns();
+ List<RelFieldCollation> fieldCollations = new
ArrayList<>(columns.size());
+
+ for (int i = 0; i < columns.size(); i++) {
Review Comment:
```suggestion
for (CatalogIndexColumnDescriptor column : columns) {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]