TechWizard9999 commented on code in PR #27496:
URL: https://github.com/apache/datafusion/pull/27496#discussion_r4658658443


##########
datafusion/functions/src/unicode/pad.rs:
##########
@@ -75,25 +75,25 @@ pub(crate) fn invoke_pad<S: PadSide>(args: 
ScalarFunctionArgs) -> Result<Columna
         args, number_rows, ..
     } = args;
 
-    const MAX_SCALAR_TARGET_LEN: usize = 16384;
+    const MAX_SCALAR_TARGET_LEN: i64 = 16384;
 
     // If target_len and fill (if specified) are constants, use the scalar
-    // fast path.
-    if let Some(target_len) = try_as_scalar_i64(&args[1]) {
-        let target_len = parse_target_len(target_len, S::NAME)?;
+    // fast path. Skip it for very large `target_len` values to avoid
+    // consuming too much memory. Such large padding values are uncommon
+    // in practice. This also leaves a length above `i32::MAX` to the array
+    // path, which returns NULL for a NULL string or fill before checking it.
+    if let Some(target_len) = try_as_scalar_i64(&args[1])
+        && target_len <= MAX_SCALAR_TARGET_LEN
+    {
+        let target_len = target_len.max(0) as usize;

Review Comment:
   Used parse_target_len now. Thanks.



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