Jackie-Jiang commented on code in PR #15848:
URL: https://github.com/apache/pinot/pull/15848#discussion_r2101317071


##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/join/LookupTable.java:
##########
@@ -35,7 +35,7 @@ public abstract class LookupTable {
   /**
    * Adds a row to the lookup table.
    */
-  public abstract void addRow(Object key, Object[] row);
+  public abstract void addRow(@Nullable Object key, Object[] row);

Review Comment:
   Also add annotation to `ObjectLookupTable`



##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/join/LookupTable.java:
##########
@@ -68,6 +68,13 @@ protected static void convertValueToList(Map.Entry<?, 
Object> entry) {
     }
   }
 
+  protected static Object convertArrayToList(Object value) {

Review Comment:
   Consider using the same name `convertValueToList()`? `convertArrayToList` is 
a little bit confusing, especially when we wrap the entire array as one element 
in the list



##########
pinot-query-runtime/src/test/resources/queries/NullHandling.json:
##########
@@ -64,6 +64,26 @@
         "description": "LEFT JOIN and GROUP BY with AGGREGATE AND SORT",
         "sql": "SELECT {tbl1}.strCol2, COUNT({tbl2}.intCol1), 
MIN({tbl2}.intCol1) AS minCol, MAX({tbl2}.doubleCol1) AS maxCol, 
SUM({tbl2}.doubleCol1) FROM {tbl1} LEFT OUTER JOIN {tbl2} ON {tbl1}.strCol1 = 
{tbl2}.strCol1 GROUP BY {tbl1}.strCol2 ORDER BY minCol DESC NULLS LAST, maxCol 
ASC NULLS LAST",
         "keepOutputRowOrder": true
+      },
+      {
+        "description": "Joining with nullable int column",
+        "sql": "SET enableNullHandling = TRUE;\nWITH tableWithNull AS (\n    
SELECT cast(intCol1 as INT) col1,\n           CASE\n               WHEN intCol1 
> 0 THEN NULL\n               ELSE cast(intCol1 as INT)\n           END AS 
nullableCol1\n    FROM {tbl1}\n)\nSELECT t1.col1\nFROM tableWithNull as 
t1\nJOIN tableWithNull as t2\nON t1.col1 = t2.nullableCol1",

Review Comment:
   (minor) Reformat the queries to be more readable



##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/join/PrimitiveLookupTable.java:
##########
@@ -0,0 +1,104 @@
+/**
+ * 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.pinot.query.runtime.operator.join;
+
+import com.google.common.collect.Sets;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import javax.annotation.Nullable;
+
+
+public abstract class PrimitiveLookupTable extends LookupTable {
+
+  private Object _valueForNullKey;
+
+  @Override
+  public void addRow(@Nullable Object key, Object[] row) {
+    if (key == null) {
+      _valueForNullKey = computeNewValue(row, _valueForNullKey);
+      return;
+    }
+    addRowNotNullKey(key, row);
+  }
+
+  @Override
+  public void finish() {
+    if (!_keysUnique) {
+      if (_valueForNullKey != null) {
+        _valueForNullKey = convertArrayToList(_valueForNullKey);
+      }
+      finishNotNullKey();
+    }
+  }
+
+  protected abstract void finishNotNullKey();
+
+  protected abstract void addRowNotNullKey(Object key, Object[] row);
+
+  @Override
+  public boolean containsKey(@Nullable Object key) {
+    if (key == null) {
+      return _valueForNullKey != null;
+    }
+    return containsNotNullKey(key);
+  }
+
+  protected abstract boolean containsNotNullKey(Object key);
+
+  @Nullable
+  @Override
+  public Object lookup(@Nullable Object key) {
+    if (key == null) {
+      return _valueForNullKey;
+    }
+    return lookupNotNullKey(key);
+  }
+
+  protected abstract Object lookupNotNullKey(Object key);
+
+  @SuppressWarnings("rawtypes")
+  @Override
+  public Set<Map.Entry> entrySet() {
+    Set notNullSet = notNullKeyEntrySet();
+    if (_valueForNullKey != null) {
+      HashSet<Map.Entry<Object, Object>> nullEntry = Sets.newHashSet(new 
Map.Entry<Object, Object>() {

Review Comment:
   Alternatively, we can probably return an `Iterator<Map.Entry>` to further 
reduce the overhead



##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/join/PrimitiveLookupTable.java:
##########
@@ -0,0 +1,104 @@
+/**
+ * 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.pinot.query.runtime.operator.join;
+
+import com.google.common.collect.Sets;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import javax.annotation.Nullable;
+
+
+public abstract class PrimitiveLookupTable extends LookupTable {
+
+  private Object _valueForNullKey;
+
+  @Override
+  public void addRow(@Nullable Object key, Object[] row) {
+    if (key == null) {
+      _valueForNullKey = computeNewValue(row, _valueForNullKey);
+      return;
+    }
+    addRowNotNullKey(key, row);
+  }
+
+  @Override
+  public void finish() {
+    if (!_keysUnique) {
+      if (_valueForNullKey != null) {
+        _valueForNullKey = convertArrayToList(_valueForNullKey);
+      }
+      finishNotNullKey();
+    }
+  }
+
+  protected abstract void finishNotNullKey();
+
+  protected abstract void addRowNotNullKey(Object key, Object[] row);
+
+  @Override
+  public boolean containsKey(@Nullable Object key) {
+    if (key == null) {
+      return _valueForNullKey != null;
+    }
+    return containsNotNullKey(key);
+  }
+
+  protected abstract boolean containsNotNullKey(Object key);
+
+  @Nullable
+  @Override
+  public Object lookup(@Nullable Object key) {
+    if (key == null) {
+      return _valueForNullKey;
+    }
+    return lookupNotNullKey(key);
+  }
+
+  protected abstract Object lookupNotNullKey(Object key);
+
+  @SuppressWarnings("rawtypes")
+  @Override
+  public Set<Map.Entry> entrySet() {
+    Set notNullSet = notNullKeyEntrySet();
+    if (_valueForNullKey != null) {
+      HashSet<Map.Entry<Object, Object>> nullEntry = Sets.newHashSet(new 
Map.Entry<Object, Object>() {

Review Comment:
   Should have less overhead if we do `Set.of(new Map.Entry)`



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to