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


##########
modules/calcite/src/test/java/org/apache/ignite/testsuites/ExecutionTestSuite.java:
##########
@@ -47,7 +46,6 @@
     ContinuousExecutionTest.class,
     MergeJoinExecutionTest.class,
     NestedLoopJoinExecutionTest.class,
-    HashJoinExecutionTest.class,

Review Comment:
   Why it was excluded?



##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/AbstractRightMaterializedJoinNode.java:
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.rel;
+
+import java.util.ArrayDeque;
+import java.util.Deque;
+import org.apache.calcite.rel.type.RelDataType;
+import 
org.apache.ignite.internal.processors.query.calcite.exec.ExecutionContext;
+import org.apache.ignite.internal.util.typedef.F;
+import org.jetbrains.annotations.Nullable;
+
+/** Right-part materialized join node. Holds data from the right part locally. 
*/
+public abstract class AbstractRightMaterializedJoinNode<Row> extends 
MemoryTrackingNode<Row> {
+    /** */
+    protected static final int HALF_BUF_SIZE = IN_BUFFER_SIZE >> 1;
+
+    /** Special flag which marks that all the rows are received. */
+    protected static final int NOT_WAITING = -1;
+
+    /** */
+    protected final Deque<Row> leftInBuf = new ArrayDeque<>(IN_BUFFER_SIZE);
+
+    /** */
+    protected boolean inLoop;
+
+    /** */
+    protected int requested;
+
+    /** */
+    protected int waitingLeft;
+
+    /** */
+    protected int waitingRight;
+
+    /** */
+    protected @Nullable Row left;
+
+    /** */
+    protected int processed;
+
+    /** */
+    protected AbstractRightMaterializedJoinNode(ExecutionContext<Row> ctx, 
RelDataType rowType) {
+        super(ctx, rowType);
+    }
+
+    /** */
+    protected abstract void join() throws Exception;
+
+    /** */
+    protected abstract void pushRight(Row row) throws Exception;
+
+    /** {@inheritDoc} */
+    @Override public void request(int rowsCnt) throws Exception {
+        assert !F.isEmpty(sources()) && sources().size() == 2;
+        assert rowsCnt > 0 && requested == 0;
+
+        checkState();
+
+        requested = rowsCnt;
+
+        if (!inLoop)
+            context().execute(this::doJoin, this::onError);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void rewindInternal() {
+        requested = 0;
+        waitingLeft = 0;
+        waitingRight = 0;
+        left = null;
+
+        leftInBuf.clear();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected Downstream<Row> requestDownstream(int idx) {
+        if (idx == 0) {
+            return new Downstream<>() {
+                @Override public void push(Row row) throws Exception {
+                    pushLeft(row);
+                }
+
+                @Override public void end() throws Exception {
+                    endLeft();
+                }
+
+                @Override public void onError(Throwable e) {
+                    AbstractRightMaterializedJoinNode.this.onError(e);
+                }
+            };
+        }
+        else if (idx == 1) {
+            return new Downstream<>() {
+                @Override public void push(Row row) throws Exception {
+                    pushRight(row);
+                }
+
+                @Override public void end() throws Exception {
+                    endRight();
+                }
+
+                @Override public void onError(Throwable e) {
+                    AbstractRightMaterializedJoinNode.this.onError(e);
+                }
+            };
+        }
+
+        throw new IndexOutOfBoundsException();
+    }
+
+    /** */
+    private void pushLeft(Row row) throws Exception {
+        assert downstream() != null;
+        assert waitingLeft > 0;
+
+        checkState();
+
+        --waitingLeft;
+
+        leftInBuf.add(row);
+
+        join();
+    }
+
+    /** */
+    private void endLeft() throws Exception {
+        assert downstream() != null;
+        assert waitingLeft > 0;
+
+        checkState();
+
+        waitingLeft = NOT_WAITING;
+
+        join();
+    }
+
+    /** */
+    private void endRight() throws Exception {
+        assert downstream() != null;
+        assert waitingRight > 0;
+
+        checkState();
+
+        waitingRight = NOT_WAITING;
+
+        join();
+    }
+
+    /** */
+    protected void tryToRequestInputs() throws Exception {
+        if (waitingLeft == 0 && leftInBuf.size() <= HALF_BUF_SIZE)
+            leftSource().request(waitingLeft = IN_BUFFER_SIZE - 
leftInBuf.size());
+
+        if (waitingRight == 0 && requested > 0)
+            rightSource().request(waitingRight = IN_BUFFER_SIZE);
+    }
+
+    /** */
+    protected Node<Row> leftSource() {
+        return sources().get(0);
+    }
+
+    /** */
+    protected Node<Row> rightSource() {
+        return sources().get(1);
+    }
+
+    /** */
+    private void doJoin() throws Exception {
+        checkState();
+
+        join();
+    }
+
+    /** */
+    protected boolean rescheduleJoin() {
+        if (processed++ > IN_BUFFER_SIZE) {
+            processed = 0;

Review Comment:
   Maybe reset to zero at least at `doJoin`? Or before any `join` call? It will 
prevent premature exit on exceed processed rows count on previous step.



##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/NestedLoopJoinNode.java:
##########
@@ -517,10 +385,13 @@ private static class FullOuterJoin<Row> extends 
NestedLoopJoinNode<Row> {
         /** */
         private int lastPushedInd;
 
-        /**
-         * @param ctx Execution context.
-         * @param cond Join expression.
-         */
+        /** */
+        private Row left;

Review Comment:
   Why new field was introduced intead of `left` from 
`AbstractRightMaterializedJoinNode`?



##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/NestedLoopJoinNode.java:
##########
@@ -17,212 +17,71 @@
 
 package org.apache.ignite.internal.processors.query.calcite.exec.rel;
 
-import java.util.ArrayDeque;
 import java.util.ArrayList;
 import java.util.BitSet;
-import java.util.Deque;
 import java.util.List;
 import java.util.function.BiPredicate;
 import org.apache.calcite.rel.core.JoinRelType;
 import org.apache.calcite.rel.type.RelDataType;
 import 
org.apache.ignite.internal.processors.query.calcite.exec.ExecutionContext;
 import org.apache.ignite.internal.processors.query.calcite.exec.RowHandler;
-import org.apache.ignite.internal.util.typedef.F;
-import org.jetbrains.annotations.NotNull;
 
 /** */
-public abstract class NestedLoopJoinNode<Row> extends MemoryTrackingNode<Row> {
-    /** */
-    private static final int HALF_BUF_SIZE = IN_BUFFER_SIZE >> 1;
-
-    /** Special value to highlights that all row were received and we are not 
waiting any more. */
-    protected static final int NOT_WAITING = -1;
-
+public abstract class NestedLoopJoinNode<Row> extends 
AbstractRightMaterializedJoinNode<Row> {
     /** */
     protected final BiPredicate<Row, Row> cond;
 
     /** */
-    protected final RowHandler<Row> handler;
-
-    /** */
-    protected int requested;
-
-    /** */
-    protected Row left;
-
-    /** */
-    protected int rightIdx;

Review Comment:
   Why this field was moved to children classes?



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