You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2022/12/28 12:34:38 UTC

[GitHub] [ignite-3] ygerzhedovich commented on a diff in pull request #1469: IGNITE-18227: refactoring scan nodes and add support RO index scans.

ygerzhedovich commented on code in PR #1469:
URL: https://github.com/apache/ignite-3/pull/1469#discussion_r1058317496


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/rel/StorageScanNode.java:
##########
@@ -0,0 +1,303 @@
+/*
+ * 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.sql.engine.exec.rel;
+
+import java.util.BitSet;
+import java.util.List;
+import java.util.Queue;
+import java.util.concurrent.Flow;
+import java.util.concurrent.Flow.Publisher;
+import java.util.concurrent.Flow.Subscriber;
+import java.util.concurrent.Flow.Subscription;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import org.apache.ignite.internal.schema.BinaryRow;
+import org.apache.ignite.internal.sql.engine.exec.ExecutionContext;
+import org.apache.ignite.internal.sql.engine.exec.RowHandler;
+import org.apache.ignite.internal.sql.engine.schema.InternalIgniteTable;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Based abstract scan node.
+ */
+public abstract class StorageScanNode<RowT> extends AbstractNode<RowT> {
+    /** Special value to highlights that all row were received and we are not waiting any more. */
+    private static final int NOT_WAITING = -1;
+
+    private final Queue<RowT> inBuff = new LinkedBlockingQueue<>(inBufSize);
+
+    private final @Nullable Predicate<RowT> filters;
+
+    private final @Nullable Function<RowT, RowT> rowTransformer;
+
+    private final Function<BinaryRow, RowT> tableRowConverter;
+
+    private int requested;
+
+    private int waiting;
+
+    private boolean inLoop;
+
+    private Subscription activeSubscription;
+
+    /**
+     * Constructor.
+     *
+     * @param ctx Execution context.
+     * @param rowFactory Row factory.
+     * @param schemaTable The table this node should scan.
+     * @param filters Optional filter to filter out rows.
+     * @param rowTransformer Optional projection function.
+     */
+    public StorageScanNode(
+            ExecutionContext<RowT> ctx,
+            RowHandler.RowFactory<RowT> rowFactory,
+            InternalIgniteTable schemaTable,
+            @Nullable Predicate<RowT> filters,
+            @Nullable Function<RowT, RowT> rowTransformer,
+            @Nullable BitSet requiredColumns
+    ) {
+        super(ctx);
+
+        assert context().transaction() != null || context().transactionTime() != null : "Transaction not initialized.";
+
+        tableRowConverter = row -> schemaTable.toRow(context(), row, rowFactory, requiredColumns);
+
+        this.filters = filters;
+        this.rowTransformer = rowTransformer;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public void request(int rowsCnt) throws Exception {
+        assert rowsCnt > 0 && requested == 0 : "rowsCnt=" + rowsCnt + ", requested=" + requested;
+
+        checkState();
+
+        requested = rowsCnt;
+
+        if (!inLoop) {
+            context().execute(this::push, this::onError);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public void closeInternal() {
+        super.closeInternal();
+
+        if (activeSubscription != null) {
+            activeSubscription.cancel();
+
+            activeSubscription = null;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    protected void rewindInternal() {
+        requested = 0;
+        waiting = 0;
+
+        if (activeSubscription != null) {
+            activeSubscription.cancel();
+
+            activeSubscription = null;
+        }
+    }
+
+    /**
+     *  Publisher of scan node.
+     *
+     *  @return Publisher of scan node or {@code null} in case nothing to scan.
+     */
+    protected abstract Publisher<RowT> scan();

Review Comment:
   It is temporal solution due to IGNITE-18466. After fix need to change return type to CompositePublisher and the method will be invoked just once. However you are right the require shed lights for the current situation.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org