viirya commented on code in PR #19857:
URL: https://github.com/apache/datafusion/pull/19857#discussion_r4198485575
##########
datafusion/expr/src/expr.rs:
##########
@@ -1401,6 +1402,54 @@ impl InSubquery {
}
}
+/// The tuple elements of a multi-column `(a, b, ...) IN (SELECT x, y, ...)`,
+/// given the compared expression `expr` and the `subquery` plan, or `None`
+/// for a single-column `IN`.
+///
+/// The tuple is planned as a `struct` call, which `simplify_expressions` folds
+/// into a struct literal when every element is a literal. It is a
+/// multi-column `IN` only when the subquery returns more than one column;
+/// against a single column the struct is one value compared with a
+/// struct-typed column.
+///
+/// Errors when the number of tuple elements does not match the number of
+/// subquery columns.
+pub fn in_subquery_tuple_values<'a>(
Review Comment:
Confirmed: `((a, b) IN (SELECT 1, 5)) IS NULL` folded to `false` for `(NULL,
5)`. Fixed in ab3120cc9. The `InSubquery` arm of `Expr::nullable` now treats a
tuple `IN` as nullable when any element or any subquery column is nullable.
`null_aware_multi_column.slt` covers `IS NULL` and `IS NOT NULL` over a tuple
`IN` whose subquery columns are both NOT NULL.
##########
datafusion/optimizer/src/analyzer/type_coercion.rs:
##########
@@ -1622,6 +1644,36 @@ fn project_with_column_index(
.map(LogicalPlan::Projection)
}
+/// Coerces a multi-column `(a, b, ...) IN (SELECT x, y, ...)`.
+///
+/// Each tuple element and the subquery column at the same position are cast
+/// to their common comparison type, like the single-column form does for its
+/// one pair.
+fn coerce_multi_column_in_subquery(
Review Comment:
Merged `main` and passed the session time zone into
`coerce_multi_column_in_subquery`, so the scalar branch and every tuple element
both use `comparison_coercion_with_session_timezone`. The new case in
`null_aware_multi_column.slt` compares a naive and a time-zone-aware timestamp
element under `SET TIME ZONE = '+08'`. It fails if the tuple path drops the
session time zone, because the naive value is then read in the aware value's
own zone and matches.
--
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]