sam-1112 commented on issue #7247:
URL: 
https://github.com/apache/datafusion-comet/issues/7247#issuecomment-7311378072

   <!-- comet-7746-scalar-expansion-followup -->
   
   Tracking the all-scalar padding case reported in the review of #7746 under 
this existing scalar-expansion issue, rather than treating it as fixed by the 
kernel output-size guards.
   
   Review: 
https://github.com/apache/datafusion-comet/pull/7746#pullrequestreview-6122340943
   
   The kernel-level reproducer is:
   
   ```rust
   let value = spark_lpad(&[
       ColumnarValue::Scalar(ScalarValue::Utf8(Some("x".into()))),
       ColumnarValue::Scalar(ScalarValue::Int32(Some(262_144))),
   ])?; // valid 262,144-byte Utf8 scalar
   value.into_array_of_size(8_192)?; // 2,147,483,648 value bytes: offset 
overflow
   ```
   
   I independently reproduced the expansion boundary with the locked DataFusion 
55.2.0 and Arrow 59.3.2: a 262,144-byte `ScalarValue::Utf8` converts to a 
one-row array successfully, while `ColumnarValue::into_array_of_size(8192)` 
panics with `offset overflow`. Arrow checks 
`OffsetBuffer::<i32>::from_repeated_length` before allocating the repeated 
value bytes, so this failing probe does not allocate a 2 GiB values buffer.
   
   `ColumnarValue::into_array_of_size` delegates scalar expansion to 
`ScalarValue::to_array_of_size`; its Utf8 arm calls 
`StringArray::new_repeated`, which reaches that offset assertion. The 
all-scalar lpad result is valid on its own. A guard inside lpad cannot know how 
many rows its consumer will request, and rejecting the scalar there would 
reject valid scalar-only uses. Runtime conditionals can produce a scalar even 
when a plan expression references columns (see #7245).
   
   Remaining work for this case:
   
   - [ ] Validate the scalar's expanded byte total with checked arithmetic 
before the scalar-to-array boundary allocates, returning a recoverable error 
instead of panicking.
   - [ ] Preserve scalar-only consumers and null/empty scalar behavior.
   - [ ] Cover a runtime-scalar conditional as well as a literal, and the 
offset boundary. Use an injected small limit for routine regression coverage 
where possible.
   - [ ] Cover the padding-produced scalar in the operator batch-bounding work 
(#7316, with the additional operators tracked by #7689 / #7762) so supported 
queries can match Spark rather than merely fail safely.
   
   #7746 remains part of #7500 and does not close #7247. Its allocation guards 
cover the bytes materialized by its kernels, not a later projection's scalar 
expansion.
   


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