This is an automated email from the ASF dual-hosted git repository.
jackie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git
The following commit(s) were added to refs/heads/master by this push:
new 09c138503b Fix NPE in SingleColumnKeySelector (#11644)
09c138503b is described below
commit 09c138503bf6a408bd3efe4b35e0ad89ffbe9a78
Author: Xiaotian (Jackie) Jiang <[email protected]>
AuthorDate: Wed Sep 20 19:34:05 2023 -0700
Fix NPE in SingleColumnKeySelector (#11644)
---
.../apache/pinot/query/planner/partitioning/EmptyKeySelector.java | 7 +++++--
.../org/apache/pinot/query/planner/partitioning/KeySelector.java | 4 ++++
.../pinot/query/planner/partitioning/SingleColumnKeySelector.java | 7 ++++++-
pinot-query-runtime/src/test/resources/queries/NullHandling.json | 8 ++++++++
4 files changed, 23 insertions(+), 3 deletions(-)
diff --git
a/pinot-query-planner/src/main/java/org/apache/pinot/query/planner/partitioning/EmptyKeySelector.java
b/pinot-query-planner/src/main/java/org/apache/pinot/query/planner/partitioning/EmptyKeySelector.java
index 7f02389eaa..fc02ff257b 100644
---
a/pinot-query-planner/src/main/java/org/apache/pinot/query/planner/partitioning/EmptyKeySelector.java
+++
b/pinot-query-planner/src/main/java/org/apache/pinot/query/planner/partitioning/EmptyKeySelector.java
@@ -18,16 +18,19 @@
*/
package org.apache.pinot.query.planner.partitioning;
+import javax.annotation.Nullable;
+
+
public class EmptyKeySelector implements KeySelector<Integer> {
private EmptyKeySelector() {
}
public static final EmptyKeySelector INSTANCE = new EmptyKeySelector();
- private static final Integer PLACE_HOLDER = 0;
+ @Nullable
@Override
public Integer getKey(Object[] row) {
- return PLACE_HOLDER;
+ return null;
}
@Override
diff --git
a/pinot-query-planner/src/main/java/org/apache/pinot/query/planner/partitioning/KeySelector.java
b/pinot-query-planner/src/main/java/org/apache/pinot/query/planner/partitioning/KeySelector.java
index e5003fbb26..fee3a48e70 100644
---
a/pinot-query-planner/src/main/java/org/apache/pinot/query/planner/partitioning/KeySelector.java
+++
b/pinot-query-planner/src/main/java/org/apache/pinot/query/planner/partitioning/KeySelector.java
@@ -18,6 +18,9 @@
*/
package org.apache.pinot.query.planner.partitioning;
+import javax.annotation.Nullable;
+
+
/**
* The {@code KeySelector} provides a partitioning function to encode a
specific input data type into a key.
*
@@ -31,6 +34,7 @@ public interface KeySelector<T> {
/**
* Extracts the key out of the given row.
*/
+ @Nullable
T getKey(Object[] row);
/**
diff --git
a/pinot-query-planner/src/main/java/org/apache/pinot/query/planner/partitioning/SingleColumnKeySelector.java
b/pinot-query-planner/src/main/java/org/apache/pinot/query/planner/partitioning/SingleColumnKeySelector.java
index 114f532268..071078d3b6 100644
---
a/pinot-query-planner/src/main/java/org/apache/pinot/query/planner/partitioning/SingleColumnKeySelector.java
+++
b/pinot-query-planner/src/main/java/org/apache/pinot/query/planner/partitioning/SingleColumnKeySelector.java
@@ -18,6 +18,9 @@
*/
package org.apache.pinot.query.planner.partitioning;
+import javax.annotation.Nullable;
+
+
public class SingleColumnKeySelector implements KeySelector<Object> {
private final int _keyId;
@@ -25,6 +28,7 @@ public class SingleColumnKeySelector implements
KeySelector<Object> {
_keyId = keyId;
}
+ @Nullable
@Override
public Object getKey(Object[] row) {
return row[_keyId];
@@ -32,6 +36,7 @@ public class SingleColumnKeySelector implements
KeySelector<Object> {
@Override
public int computeHash(Object[] input) {
- return input[_keyId].hashCode() & Integer.MAX_VALUE;
+ Object key = input[_keyId];
+ return key != null ? key.hashCode() & Integer.MAX_VALUE : 0;
}
}
diff --git a/pinot-query-runtime/src/test/resources/queries/NullHandling.json
b/pinot-query-runtime/src/test/resources/queries/NullHandling.json
index 3c5a6a7add..334eb5011a 100644
--- a/pinot-query-runtime/src/test/resources/queries/NullHandling.json
+++ b/pinot-query-runtime/src/test/resources/queries/NullHandling.json
@@ -39,6 +39,10 @@
"description": "LEFT JOIN and AGGREGATE",
"sql": "SELECT COUNT({tbl2}.intCol1), MIN({tbl2}.intCol1),
MAX({tbl2}.doubleCol1), SUM({tbl2}.doubleCol1), AVG({tbl2}.doubleCol1),
BOOL_AND({tbl2}.boolCol1), BOOL_OR({tbl2}.boolCol1) FROM {tbl1} LEFT OUTER JOIN
{tbl2} ON {tbl1}.strCol1 = {tbl2}.strCol1"
},
+ {
+ "description": "LEFT JOIN and GROUP BY",
+ "sql": "SELECT {tbl2}.intCol1, COUNT(*) FROM {tbl1} LEFT OUTER JOIN
{tbl2} ON {tbl1}.strCol1 = {tbl2}.strCol1 GROUP BY {tbl2}.intCol1"
+ },
{
"description": "LEFT JOIN and GROUP BY",
"sql": "SELECT {tbl1}.strCol2, {tbl2}.intCol1, COUNT(*) FROM {tbl1}
LEFT OUTER JOIN {tbl2} ON {tbl1}.strCol1 = {tbl2}.strCol1 GROUP BY
{tbl1}.strCol2, {tbl2}.intCol1"
@@ -47,6 +51,10 @@
"description": "LEFT JOIN and GROUP BY with AGGREGATE",
"sql": "SELECT {tbl1}.strCol2, COUNT({tbl2}.intCol1),
MIN({tbl2}.intCol1), MAX({tbl2}.doubleCol1), SUM({tbl2}.doubleCol1),
AVG({tbl2}.doubleCol1) FROM {tbl1} LEFT OUTER JOIN {tbl2} ON {tbl1}.strCol1 =
{tbl2}.strCol1 GROUP BY {tbl1}.strCol2"
},
+ {
+ "description": "LEFT JOIN and GROUP BY with AGGREGATE",
+ "sql": "SELECT {tbl2}.strCol2, COUNT({tbl2}.intCol1),
MIN({tbl2}.intCol1), MAX({tbl2}.doubleCol1), SUM({tbl2}.doubleCol1),
AVG({tbl2}.doubleCol1) FROM {tbl1} LEFT OUTER JOIN {tbl2} ON {tbl1}.strCol1 =
{tbl2}.strCol1 GROUP BY {tbl2}.strCol2"
+ },
{
"description": "LEFT JOIN and SORT (by default, H2 treats null as the
smallest value, which is different from Postgres, thus we don't test the
default ordering)",
"sql": "SELECT {tbl2}.doubleCol1 AS col FROM {tbl1} LEFT OUTER JOIN
{tbl2} ON {tbl1}.strCol1 = {tbl2}.strCol1 ORDER BY col NULLS FIRST",
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]