This is an automated email from the ASF dual-hosted git repository. stoty pushed a commit to branch 5.1 in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/5.1 by this push: new 858e715885 PHOENIX-7090 Hash join throw NullPointerException when subquery return null 858e715885 is described below commit 858e715885a3dcc9df080d4e4aa482ca2687a0fd 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 285cd037ce..027f0033cc 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 25d9fb3818..74f38ed63c 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();