JasonLi-cn commented on code in PR #9732:
URL: https://github.com/apache/arrow-datafusion/pull/9732#discussion_r1545186099
##########
datafusion/physical-expr/src/string_expressions.rs:
##########
@@ -227,6 +229,132 @@ pub fn concat(args: &[ColumnarValue]) ->
Result<ColumnarValue> {
}
}
+enum ColumnarValueRef<'a> {
+ Scalar(&'a [u8]),
+ Array(&'a StringArray),
+}
+
+impl<'a> ColumnarValueRef<'a> {
+ #[inline]
+ fn is_valid(&self, i: usize) -> bool {
+ match &self {
+ Self::Scalar(_) => true,
+ Self::Array(array) => array.is_valid(i),
+ }
+ }
+
+ #[inline]
+ fn nulls(&self) -> Option<NullBuffer> {
+ match &self {
+ Self::Scalar(_) => None,
+ Self::Array(array) => array.nulls().map(|b| b.clone()),
+ }
+ }
+}
+
+struct StringArrayBuilder {
Review Comment:
The `Write` trait impl of StringBuilder can meet my current needs, but it is
not very convenient to use, so I've defined a StringArrayBuilder. I agree with
your suggestion to add an unsafe function to StringBuilder.
https://github.com/apache/arrow-rs/blob/9f36c883459405ecd9a5f4fdfa9a3317ab52302c/arrow-array/src/builder/generic_bytes_builder.rs#L231-L257
```rust
let mut builder = GenericStringBuilder::<i32>::new();
// Write data
write!(builder, "foo").unwrap();
write!(builder, "bar").unwrap();
// Finish value
builder.append_value("baz");
// Write second value
write!(builder, "v2").unwrap();
builder.append_value("");
let array = builder.finish();
assert_eq!(array.value(0), "foobarbaz");
assert_eq!(array.value(1), "v2");
```
--
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]