sunchao commented on code in PR #5416:
URL: https://github.com/apache/datafusion-comet/pull/5416#discussion_r3849148727


##########
native/spark-expr/src/string_funcs/split.rs:
##########
@@ -159,35 +212,249 @@ pub fn spark_split_sql(args: &[ColumnarValue]) -> 
DataFusionResult<ColumnarValue
                 }
                 _ => return exec_err!("split_sql delimiter must be a string"),
             };
+            let string = string.clone().unwrap();
+
+            let mut offsets_builder = BufferBuilder::<i32>::new(2);
+            let mut values_builder = BufferBuilder::<u8>::new(string.len());
+
+            offsets_builder.append(0);
+
+            if delimiter.is_empty() {
+                values_builder.append_slice(string.as_bytes());
+                offsets_builder.append(string.len() as i32);
+            } else {
+                let mut offset = 0i32;
+                for part in string.split(delimiter.as_str()) {
+                    values_builder.append_slice(part.as_bytes());
+                    offset += part.len() as i32;
+                    offsets_builder.append(offset);
+                }
+            }
 
-            let result = split_sql_string(string.as_ref().unwrap(), delimiter);
-            let string_array = GenericStringArray::<i32>::from(result);
-            let list_array = create_list_array(Arc::new(string_array));
+            let offsets_buffer = offsets_builder.finish();
+            let values_buffer = values_builder.finish();
 
-            Ok(ColumnarValue::Scalar(ScalarValue::List(Arc::new(
-                list_array,
-            ))))
+            let list_field = Arc::new(Field::new("item", DataType::Utf8, 
true));

Review Comment:
   [P2] Preserve the non-null item type in scalar SQL splits
   
   `StringSplitSQL` declares `containsNull = false`, so this UDF is planned to 
return `List(non-null Utf8)`. Setting this field to `true` instead returns 
`List(Utf8)` for every non-null scalar/scalar call, including ordinary nonempty 
delimiters. DataFusion's result-type check in debug/CI builds rejects that 
value before `element_at`: the existing `split_part.sql:38` native query 
(`split_part('a.b.c', '.', 2)`, with constant folding disabled by the test 
harness) now fails in all four Spark 4.x expression jobs ([Linux 4.0 
example](https://github.com/apache/datafusion-comet/actions/runs/32757629315/job/97585045208)).
 Fresh exact-base/previous/head typed-UDF probes reproduce 
pass/pass/type-mismatch. Please keep the item field non-nullable, as in the 
other branches, and cover the declared return type through the UDF wrapper; the 
new direct-helper tests bypass that check.



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