1fanwang commented on code in PR #7741:
URL: https://github.com/apache/datafusion-comet/pull/7741#discussion_r4700708717


##########
native/spark-expr/src/conditional_funcs/lazy_logical.rs:
##########
@@ -104,17 +104,18 @@ impl LazyLogical {
 ///
 /// Spark's `In` returns true at the first candidate that equals the value, 
and NULL if none does
 /// and one is NULL, which is that of `value = c1 OR value = c2 OR ...`. A 
candidate that can fail
-/// is then evaluated only for the rows that the ones before it have not 
matched. The value is
-/// evaluated once per term, so this requires it to be a cheap expression that 
cannot fail.
-/// This returns `None` when no candidate after the first can fail, when the 
value cannot be
-/// evaluated again, and when a candidate has another type than the value.
+/// is then evaluated only for the rows that the ones before it have not 
matched, and no candidate
+/// is evaluated for a row whose value is NULL, which Spark returns NULL for 
at once. The value is
+/// evaluated once per term, so this requires it to be deterministic.
+/// This returns `None` when no candidate after the first can fail, when the 
value is not
+/// deterministic, and when a candidate has another type than the value.
 pub fn lazy_in_list(
     value: &Arc<dyn PhysicalExpr>,
     candidates: &[Arc<dyn PhysicalExpr>],
     negated: bool,
     schema: &Schema,
 ) -> Result<Option<Arc<dyn PhysicalExpr>>> {
-    if candidates.iter().skip(1).all(|c| cannot_fail(c, schema)) || 
!is_infallible(value, schema) {
+    if candidates.iter().skip(1).all(|c| cannot_fail(c, schema)) || 
!is_deterministic(value) {

Review Comment:
   Confirmed, and fixed in cc5dfaf2b16cf18b1c0156f3fc8433faf7cdd6c4. Added the 
same GetStructField arm that infallible already has, in the same spot relative 
to CaseWhenExpr and IfExpr:
   
   
https://github.com/apache/datafusion-comet/blob/cc5dfaf2b16cf18b1c0156f3fc8433faf7cdd6c4/native/spark-expr/src/conditional_funcs/lazy_logical.rs#L195-L216
   
   It covers both callers, the lazy_in_list gate and the try_new speculate 
flag. Added a unit test building s.x IN (0, CAST(t AS INT)) with a struct field 
value and an unparseable string on the row the first candidate matches: it 
errored on main and passes now.
   
   
https://github.com/apache/datafusion-comet/blob/cc5dfaf2b16cf18b1c0156f3fc8433faf7cdd6c4/native/spark-expr/src/conditional_funcs/lazy_logical.rs#L546-L568



##########
native/spark-expr/src/conditional_funcs/lazy_logical.rs:
##########
@@ -104,17 +104,18 @@ impl LazyLogical {
 ///
 /// Spark's `In` returns true at the first candidate that equals the value, 
and NULL if none does
 /// and one is NULL, which is that of `value = c1 OR value = c2 OR ...`. A 
candidate that can fail
-/// is then evaluated only for the rows that the ones before it have not 
matched. The value is
-/// evaluated once per term, so this requires it to be a cheap expression that 
cannot fail.
-/// This returns `None` when no candidate after the first can fail, when the 
value cannot be
-/// evaluated again, and when a candidate has another type than the value.
+/// is then evaluated only for the rows that the ones before it have not 
matched, and no candidate
+/// is evaluated for a row whose value is NULL, which Spark returns NULL for 
at once. The value is
+/// evaluated once per term, so this requires it to be deterministic.
+/// This returns `None` when no candidate after the first can fail, when the 
value is not

Review Comment:
   Confirmed, and fixed in cc5dfaf2b16cf18b1c0156f3fc8433faf7cdd6c4 with the 
nullable local reused both places, as suggested:
   
   
https://github.com/apache/datafusion-comet/blob/cc5dfaf2b16cf18b1c0156f3fc8433faf7cdd6c4/native/spark-expr/src/conditional_funcs/lazy_logical.rs#L118-L130
   
   The later CaseWhenExpr wrap only runs once the gate lets the chain get 
built, so it never helped the cases where the gate bailed out first, and the 
eager fallback has no value-is-NULL short circuit of its own, so this was a 
real gap rather than a redundant one. One side effect it surfaced is below.
   
   <details>
   <summary>Trace and a side effect it surfaced</summary>
   
   DataFusion's in_list, which spark_in_list falls back to, evaluates every 
candidate expression over the whole batch with no awareness of Spark's 
value-is-NULL rule at all, so a candidate that can fail still runs there. The 
CaseWhenExpr wrap further down only ever runs for a value that reaches it, 
which a gate bailout upstream of it prevented.
   
   Making the skip conditional on nullability had a side effect: a nested value 
with a float leaf and an unrecognized candidate type used to always hit the 
same vacuous skip(1) and fall back, which two existing nested_comparison tests 
relied on incidentally for their own, unrelated NestedPredicate coverage. 
lazy_in_list now declines any nested-with-float-leaf value outright up front, 
deferring to that existing path (see the commit message for the full reasoning).
   
   Added a unit test for the CAST(s AS INT), 1 shape and a 
logical_lazy_ansi.sql query for the same shape.
   </details>



-- 
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]

Reply via email to