This is an automated email from the ASF dual-hosted git repository.

stoty pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/master by this push:
     new 31acf16f55 PHOENIX-7090 Hash join throw NullPointerException when 
subquery return null
31acf16f55 is described below

commit 31acf16f557ddd1750486bfd93d3fe1cae8a3c2d
Author: chaijunjie0101 <1340011...@qq.com>
AuthorDate: Tue Oct 31 09:53:49 2023 +0800

    PHOENIX-7090 Hash join throw NullPointerException when subquery return null
---
 .../apache/phoenix/end2end/join/SubqueryIT.java    | 24 ++++++++++++++++++++++
 .../org/apache/phoenix/execute/HashJoinPlan.java   |  4 +++-
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
index fa730fc0c2..6d3a474557 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
@@ -1095,5 +1095,29 @@ public class SubqueryIT extends BaseJoinIT {
         }
     }
 
+    @Test
+    public void testSubqueryReturnSingleAndCompare() throws Exception {
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            String table1 = getTableName(conn, JOIN_CUSTOMER_TABLE_FULL_NAME);
+            String table2 = getTableName(conn, JOIN_ORDER_TABLE_FULL_NAME);
+            String query = "SELECT * FROM " +
+                    table1 + " WHERE \"customer_id\" = (" +
+                    "SELECT \"customer_id\" FROM " + table2 +
+                    " WHERE PRICE = ? LIMIT 1)";
+            PreparedStatement ps1 = conn.prepareStatement(query);
+
+            // PRICE = -1, not exist this data, subquery will not return any 
data
+            ps1.setInt(1, -1);
+            ResultSet rs1 = ps1.executeQuery();
+            assertFalse(rs1.next());
+
+            PreparedStatement ps2 = conn.prepareStatement(query);
+            ps2.setInt(1, 100);
+            ResultSet rs2 = ps2.executeQuery();
+            assertTrue(rs2.next());
+            assertEquals("0000000004", rs2.getString("customer_id"));
+            assertEquals("C4", rs2.getString("NAME"));
+        }
+    }
 }
 
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/HashJoinPlan.java 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/HashJoinPlan.java
index eace84187c..6cd49d7f4e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/HashJoinPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/HashJoinPlan.java
@@ -462,7 +462,9 @@ public class HashJoinPlan extends DelegateQueryPlan {
                 }
 
                 Object result = expectSingleRow ? (values.isEmpty() ? null : 
values.get(0)) : PArrayDataType.instantiatePhoenixArray(baseType, 
values.toArray());
-                parent.getContext().setSubqueryResult(select, result);
+                if (result != null) {
+                    parent.getContext().setSubqueryResult(select, result);
+                }
                 return null;
             } finally {
                 iterator.close();

Reply via email to