alex-plekhanov commented on code in PR #10153:
URL: https://github.com/apache/ignite/pull/10153#discussion_r1019069792


##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/IgniteIndex.java:
##########
@@ -104,6 +104,11 @@ public <Row> Iterable<Row> scan(
      * @param requiredColumns  Required columns.
      * @return Index records for {@code grp}.
      */
-    public <Row> Iterable<Row> firstOrLast(boolean first, 
ExecutionContext<Row> ectx, ColocationGroup grp,
-        @Nullable ImmutableBitSet requiredColumns);
+    public <Row> Iterable<Row> firstOrLast(
+        boolean first,
+        ExecutionContext<Row> ectx,
+        ColocationGroup grp,
+        @Nullable ImmutableBitSet
+            requiredColumns

Review Comment:
   Redundant NL



##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/LogicalRelImplementor.java:
##########
@@ -419,6 +421,56 @@ public LogicalRelImplementor(
         }
     }
 
+    /** {@inheritDoc} */
+    @Override public Node<Row> visit(IgniteIndexBound idxBndRel) {
+        IgniteTable tbl = idxBndRel.getTable().unwrap(IgniteTable.class);
+        IgniteIndex idx = tbl.getIndex(idxBndRel.indexName());
+        IgniteTypeFactory typeFactory = ctx.getTypeFactory();
+        ColocationGroup grp = ctx.group(idxBndRel.sourceId());
+        ImmutableBitSet requiredColumns = idxBndRel.requiredColumns();
+        RelDataType rowType = tbl.getRowType(typeFactory, requiredColumns);
+
+        if (idx != null && !tbl.isIndexRebuildInProgress())
+            return new ScanNode<>(ctx, rowType, 
idx.firstOrLast(idxBndRel.first(), ctx, grp, requiredColumns));
+        else {
+            assert requiredColumns.asList().size() == 1;

Review Comment:
   `requiredColumns.cardinality()`



##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/LogicalRelImplementor.java:
##########
@@ -419,6 +421,56 @@ public LogicalRelImplementor(
         }
     }
 
+    /** {@inheritDoc} */
+    @Override public Node<Row> visit(IgniteIndexBound idxBndRel) {
+        IgniteTable tbl = idxBndRel.getTable().unwrap(IgniteTable.class);
+        IgniteIndex idx = tbl.getIndex(idxBndRel.indexName());
+        IgniteTypeFactory typeFactory = ctx.getTypeFactory();
+        ColocationGroup grp = ctx.group(idxBndRel.sourceId());
+        ImmutableBitSet requiredColumns = idxBndRel.requiredColumns();
+        RelDataType rowType = tbl.getRowType(typeFactory, requiredColumns);
+
+        if (idx != null && !tbl.isIndexRebuildInProgress())
+            return new ScanNode<>(ctx, rowType, 
idx.firstOrLast(idxBndRel.first(), ctx, grp, requiredColumns));
+        else {
+            assert requiredColumns.asList().size() == 1;
+
+            RexBuilder b = new RexBuilder(typeFactory);

Review Comment:
   Redundant



##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/IndexFirstLastScan.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.internal.processors.query.calcite.exec;
+
+import java.util.List;
+import org.apache.calcite.util.ImmutableBitSet;
+import org.apache.calcite.util.ImmutableIntList;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.cache.query.index.sorted.IndexKeyType;
+import org.apache.ignite.internal.cache.query.index.sorted.IndexRow;
+import 
org.apache.ignite.internal.cache.query.index.sorted.inline.IndexQueryContext;
+import 
org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexImpl;
+import 
org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType;
+import org.apache.ignite.internal.cache.query.index.sorted.inline.io.InlineIO;
+import org.apache.ignite.internal.cache.query.index.sorted.keys.IndexKey;
+import org.apache.ignite.internal.cache.query.index.sorted.keys.NullIndexKey;
+import org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree;
+import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusIO;
+import 
org.apache.ignite.internal.processors.query.calcite.schema.CacheTableDescriptor;
+import org.apache.ignite.internal.util.lang.GridCursor;
+import org.apache.ignite.internal.util.typedef.F;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Takes only first or last index value excluding nulls.
+ */
+public class IndexFirstLastScan<Row> extends IndexScan<Row> {
+    /**
+     * @param first {@code True} to take first index value. {@code False} to 
take last value.
+     * @param ectx Execution context.
+     * @param desc Table descriptor.
+     * @param idx Phisycal index.
+     * @param idxFieldMapping Mapping from index keys to row fields.
+     * @param parts Mapping from index keys to row fields.
+     * @param requiredColumns Required columns.
+     */
+    public IndexFirstLastScan(
+        boolean first,
+        ExecutionContext<Row> ectx,
+        CacheTableDescriptor desc,
+        InlineIndexImpl idx,
+        ImmutableIntList idxFieldMapping,
+        int[] parts,
+        @Nullable ImmutableBitSet requiredColumns
+    ) {
+        super(ectx, desc, new FirstLastIndexWrapper(idx, first), 
idxFieldMapping, parts, null, null, null,
+            requiredColumns);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IndexQueryContext indexQueryContext() {
+        IndexQueryContext res = super.indexQueryContext();
+
+        BPlusTree.TreeRowClosure<IndexRow, IndexRow> f = res.rowFilter();
+
+        List<InlineIndexKeyType> inlineKeyTypes = 
idx.segment(0).rowHandler().inlineIndexKeyTypes();
+
+        InlineIndexKeyType keyType = F.isEmpty(inlineKeyTypes) ? null : 
inlineKeyTypes.get(0);
+
+        return new IndexQueryContext(res.cacheFilter(), new 
BPlusTree.TreeRowClosure<IndexRow, IndexRow>() {
+            /** {@inheritDoc} */
+            @Override public boolean apply(BPlusTree<IndexRow, IndexRow> tree, 
BPlusIO<IndexRow> io, long pageAddr,

Review Comment:
   Still not fixed



##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/AbstractBasicIntegrationTest.java:
##########
@@ -250,6 +250,12 @@ public DelegatingIgniteIndex(IgniteIndex delegate) {
         @Override public long count(ExecutionContext<?> ectx, ColocationGroup 
grp) {
             return delegate.count(ectx, grp);
         }
+
+        /** {@inheritDoc} */
+        @Override public <Row> Iterable<Row> firstOrLast(boolean first, 
ExecutionContext<Row> ectx, ColocationGroup grp,

Review Comment:
   Checkstyle



-- 
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]

Reply via email to