Skip to content

Commit 65f337d

Browse files
authored
perf: Use bulk-NULL builder in uuid (#21845)
## Which issue does this PR close? - Closes #21844. ## Rationale for this change `uuid()` never emits NULLs, so this is a straightforward win. Benchmarks: ``` uuid (1024 rows): 21.618 µs → 20.133 µs, −6.90% (`p < 0.05`) ``` ## What changes are included in this PR? * `GenericStringBuilder` -> `GenericStringArrayBuilder` in `uuid()` implementation ## Are these changes tested? Yes. ## Are there any user-facing changes? No.
1 parent 6f1040b commit 65f337d

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

  • datafusion/functions/src/string

datafusion/functions/src/string/uuid.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717

1818
use std::sync::Arc;
1919

20-
use arrow::array::GenericStringBuilder;
2120
use arrow::datatypes::DataType;
2221
use arrow::datatypes::DataType::Utf8;
2322
use rand::Rng;
2423
use uuid::Uuid;
2524

25+
use crate::strings::GenericStringArrayBuilder;
2626
use datafusion_common::{Result, assert_or_internal_err};
2727
use datafusion_expr::{ColumnarValue, Documentation, Volatility};
2828
use datafusion_expr::{ScalarFunctionArgs, ScalarUDFImpl, Signature};
@@ -87,7 +87,7 @@ impl ScalarUDFImpl for UuidFunc {
8787
let mut randoms = vec![0u128; args.number_rows];
8888
rng.fill(&mut randoms[..]);
8989

90-
let mut builder = GenericStringBuilder::<i32>::with_capacity(
90+
let mut builder = GenericStringArrayBuilder::<i32>::with_capacity(
9191
args.number_rows,
9292
args.number_rows * 36,
9393
);
@@ -101,7 +101,7 @@ impl ScalarUDFImpl for UuidFunc {
101101
builder.append_value(fmt.encode_lower(&mut buffer));
102102
}
103103

104-
Ok(ColumnarValue::Array(Arc::new(builder.finish())))
104+
Ok(ColumnarValue::Array(Arc::new(builder.finish(None)?)))
105105
}
106106

107107
fn documentation(&self) -> Option<&Documentation> {

0 commit comments

Comments
 (0)