tanclary commented on code in PR #3562:
URL: https://github.com/apache/calcite/pull/3562#discussion_r1435829380


##########
core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcCorrelationDataContext.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * 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.calcite.adapter.jdbc;
+
+import org.apache.calcite.DataContext;
+import org.apache.calcite.adapter.java.JavaTypeFactory;
+import org.apache.calcite.linq4j.QueryProvider;
+import org.apache.calcite.schema.SchemaPlus;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+/**
+ * A special DataContext which handles correlation variable for batch nested 
loop joins.
+ */
+public class JdbcCorrelationDataContext implements DataContext {
+  public static final int OFFSET = 10000;
+
+  private final DataContext delegate;
+  private final Object[] parameters;
+
+  public JdbcCorrelationDataContext(DataContext delegate, Object[] parameters) 
{
+    this.delegate = delegate;
+    this.parameters = parameters;
+  }
+  @Override public @Nullable SchemaPlus getRootSchema() {

Review Comment:
   Needs newline 



##########
core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcImplementor.java:
##########
@@ -18,20 +18,64 @@
 
 import org.apache.calcite.adapter.java.JavaTypeFactory;
 import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.CorrelationId;
 import org.apache.calcite.rel.rel2sql.RelToSqlConverter;
+import org.apache.calcite.rel.rel2sql.SqlImplementor;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.rex.RexCorrelVariable;
 import org.apache.calcite.sql.SqlDialect;
-import org.apache.calcite.util.Util;
+import org.apache.calcite.sql.SqlDynamicParam;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.parser.SqlParserPos;
+
+import java.lang.reflect.Type;
+import java.util.List;
 
 /**
  * State for generating a SQL statement.
  */
 public class JdbcImplementor extends RelToSqlConverter {
-  public JdbcImplementor(SqlDialect dialect, JavaTypeFactory typeFactory) {
+
+  private final JdbcCorrelationDataContextBuilder dataContextBuilder;
+  private final JavaTypeFactory typeFactory;
+
+  public JdbcImplementor(SqlDialect dialect, JavaTypeFactory typeFactory,
+      JdbcCorrelationDataContextBuilder dataContextBuilder) {
     super(dialect);
-    Util.discard(typeFactory);
+    this. typeFactory = typeFactory;
+    this.dataContextBuilder = dataContextBuilder;
+  }
+
+  public JdbcImplementor(SqlDialect dialect, JavaTypeFactory typeFactory) {
+    this(dialect, typeFactory, new JdbcCorrelationDataContextBuilder() {
+      private int counter = 1;
+      @Override public int add(CorrelationId id, int ordinal, Type type) {
+        return counter++;
+      }
+    });
   }
 
   public Result implement(RelNode node) {
     return dispatch(node);
   }
+
+  @Override protected Context getAliasContext(RexCorrelVariable variable) {
+    Context context = correlTableMap.get(variable.id);
+    if (context != null) {
+      return context;
+    }
+    List<RelDataTypeField>  fieldList = variable.getType().getFieldList();

Review Comment:
   Maybe I'm just not very familiar with JDBC but could we potentially add a 
comment or two explaining what is going on here. (If it's obvious to everyone 
but me then maybe not 🤷 



##########
core/src/test/java/org/apache/calcite/test/JdbcAdapterTest.java:
##########
@@ -1147,6 +1153,52 @@ private LockWrapper exclusiveCleanDb(Connection c) 
throws SQLException {
     });
   }
 
+  @Test void testBatchNestedLoopJoinPlan() {
+    final String sql = "SELECT *\n"
+        + "FROM \"s\".\"emps\" A\n"
+        + "LEFT OUTER JOIN \"foodmart\".\"store\" B ON A.\"empid\" = 
B.\"store_id\"";
+    final String explain = "JdbcFilter(condition=[OR(=($cor0.empid0, $0), 
=($cor1.empid0, $0)";
+    final String jdbcSql = "SELECT *\n"
+        + "FROM \"foodmart\".\"store\"\n"

Review Comment:
   Are there any other edge cases or situations we should test? Asked another 
way: Is one test enough to ensure that this works the way we intend?



##########
core/src/test/java/org/apache/calcite/test/JdbcAdapterTest.java:
##########
@@ -1147,6 +1153,52 @@ private LockWrapper exclusiveCleanDb(Connection c) 
throws SQLException {
     });
   }
 
+  @Test void testBatchNestedLoopJoinPlan() {

Review Comment:
   You could add comment with link to JIRA



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