This is an automated email from the ASF dual-hosted git repository.
mihaibudiu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/main by this push:
new 0ee723e8cd [CALCITE-7334] Compiling the generated Java code throws an
exception when a scalar subquery is used in the SELECT list
0ee723e8cd is described below
commit 0ee723e8cd9c440928fac6b4ccd05554ed7a3381
Author: Mihai Budiu <[email protected]>
AuthorDate: Wed Aug 12 14:43:31 2026 -0700
[CALCITE-7334] Compiling the generated Java code throws an exception when a
scalar subquery is used in the SELECT list
Signed-off-by: Mihai Budiu <[email protected]>
---
.../adapter/enumerable/EnumerableMergeJoin.java | 8 +++--
core/src/test/resources/sql/sub-query.iq | 35 ++++++++++++++++++++++
2 files changed, 41 insertions(+), 2 deletions(-)
diff --git
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoin.java
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoin.java
index 557362e6bc..fe65699e0c 100644
---
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoin.java
+++
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableMergeJoin.java
@@ -18,6 +18,7 @@
import org.apache.calcite.adapter.java.JavaTypeFactory;
import org.apache.calcite.linq4j.EnumerableDefaults;
+import org.apache.calcite.linq4j.function.Function1;
import org.apache.calcite.linq4j.tree.BlockBuilder;
import org.apache.calcite.linq4j.tree.Expression;
import org.apache.calcite.linq4j.tree.Expressions;
@@ -530,9 +531,12 @@ public static EnumerableMergeJoin create(RelNode left,
RelNode right,
Expressions.list(
leftExpression,
rightExpression,
- Expressions.lambda(
+ // Force Function1: a single BOOLEAN key would otherwise
+ // deduce Predicate1, which does not match the signature of
+ // EnumerableDefaults.mergeJoin
+ Expressions.lambda(Function1.class,
leftKeyPhysType.record(leftExpressions), left_),
- Expressions.lambda(
+ Expressions.lambda(Function1.class,
rightKeyPhysType.record(rightExpressions), right_),
predicate,
EnumUtils.joinSelector(joinType,
diff --git a/core/src/test/resources/sql/sub-query.iq
b/core/src/test/resources/sql/sub-query.iq
index 08c5bcf6e4..4bc3fae31a 100644
--- a/core/src/test/resources/sql/sub-query.iq
+++ b/core/src/test/resources/sql/sub-query.iq
@@ -10150,6 +10150,41 @@ ORDER BY emp.ename;
+--------+------------+
(8 rows)
+!ok
+
+!use scott
+
+# Test case for [CALCITE-7334] Compiling the generated Java code throws an
exception when
+# a scalar sub-query is used in the SELECT list.
+# Result validated against PostgreSQL 14.
+select
+ (SELECT
+ COUNT(*)
+ FROM
+ "scott".emp
+ WHERE
+ v.empno >= 2), 3
+from "scott".emp as v;
++--------+--------+
+| EXPR$0 | EXPR$1 |
++--------+--------+
+| 14 | 3 |
+| 14 | 3 |
+| 14 | 3 |
+| 14 | 3 |
+| 14 | 3 |
+| 14 | 3 |
+| 14 | 3 |
+| 14 | 3 |
+| 14 | 3 |
+| 14 | 3 |
+| 14 | 3 |
+| 14 | 3 |
+| 14 | 3 |
+| 14 | 3 |
++--------+--------+
+(14 rows)
+
!ok
# End sub-query.iq