mbutrovich opened a new issue, #27482:
URL: https://github.com/apache/datafusion/issues/27482

   **Describe the bug**
   
   `lpad(s, n)` on a row where `s` is NULL and `n` is above `i32::MAX` errors 
when `n` is a literal, and returns NULL when `n` comes from a column. A NULL 
fill behaves the same, and so does `rpad`. The [fast path for a scalar 
length](https://github.com/apache/datafusion/blob/e2dc8b048b542e7abdc296254aa54e26eb89d76d/datafusion/functions/src/unicode/pad.rs#L82-L83)
 rejects a length above `i32::MAX` before it looks at any row. The array path 
[skips rows where any argument is 
NULL](https://github.com/apache/datafusion/blob/e2dc8b048b542e7abdc296254aa54e26eb89d76d/datafusion/functions/src/unicode/pad.rs#L400-L406)
 before it checks the length, so it errors only on a row whose string and fill 
are both non-NULL.
   
   **To Reproduce**
   
   ```sql
   -- Literal length: the fast path
   SELECT lpad(s, 2147483648) AS r FROM (VALUES (NULL::text)) AS t(s);
   -- Execution error: lpad requested length 2147483648 too large, maximum 
allowed length is 2147483647
   
   -- The same row with the length from a column: the array path
   SELECT lpad(s, n) AS r FROM (VALUES (NULL::text, 2147483648)) AS t(s, n);
   -- NULL
   
   -- A NULL fill with a literal length
   SELECT lpad(s, 2147483648, f) AS r FROM (VALUES ('a', NULL::text)) AS t(s, 
f);
   -- Execution error: lpad requested length 2147483648 too large, maximum 
allowed length is 2147483647
   
   -- The same row with the length from a column
   SELECT lpad(s, n, f) AS r FROM (VALUES ('a', 2147483648, NULL::text)) AS 
t(s, n, f);
   -- NULL
   ```
   
   The same four queries with `rpad` give the same results.
   
   **Expected behavior**
   
   All four return NULL, as the array path does. 
[`string_literal.slt`](https://github.com/apache/datafusion/blob/e2dc8b048b542e7abdc296254aa54e26eb89d76d/datafusion/sqllogictest/test_files/string/string_literal.slt?plain=1#L267-L300)
 already expects NULL for a NULL string or fill with a literal length in range, 
and #27352 made `split_part`'s fast path return NULL in the same situation 
(#27276).
   
   Could the fast path skip a length above `i32::MAX`, as it already skips one 
above `MAX_SCALAR_TARGET_LEN`, instead of returning the error? The array path 
would then return the error for the first row whose string and fill are 
non-NULL, and NULL for the other rows.
   
   **Additional context**
   
   Property-based tests found this on `main` at e2dc8b048b: one row of a call 
with an array of lengths returned NULL, and the same row called with every 
argument as a scalar returned the error. The reproduction runs on `main` at 
e2dc8b048b. The check in the fast path came with #20657 and moved to `pad.rs` 
in #26367.
   


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