Skip to content

Commit c079623

Browse files
authored
Merge branch 'main' into feat_migrate_ffi_to_stabby
2 parents b8c0f3c + 68061a5 commit c079623

22 files changed

Lines changed: 737 additions & 607 deletions

File tree

.github/workflows/stale.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ jobs:
3737
days-before-issue-stale: -1
3838
days-before-issue-close: -1
3939
repo-token: ${{ secrets.GITHUB_TOKEN }}
40+
operations-per-run: 150

Cargo.lock

Lines changed: 12 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ recursive = "0.1.1"
190190
regex = "1.12"
191191
rstest = "0.26.1"
192192
serde_json = "1"
193-
sha2 = "^0.10.9"
193+
sha2 = "^0.11.0"
194194
sqlparser = { version = "0.61.0", default-features = false, features = ["std", "visitor"] }
195195
strum = "0.28.0"
196196
strum_macros = "0.28.0"

benchmarks/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ homepage = { workspace = true }
2525
repository = { workspace = true }
2626
license = { workspace = true }
2727
rust-version = { workspace = true }
28+
publish = false
2829

2930
# Note: add additional linter rules in lib.rs.
3031
# Rust does not support workspace + new linter rules in subcrates yet

datafusion-cli/src/helper.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ impl Highlighter for CliHelper {
124124
fn highlight_char(&self, line: &str, pos: usize, kind: CmdKind) -> bool {
125125
self.highlighter.highlight_char(line, pos, kind)
126126
}
127+
128+
fn highlight_hint<'h>(&self, hint: &'h str) -> Cow<'h, str> {
129+
Color::gray(hint).into()
130+
}
127131
}
128132

129133
impl Hinter for CliHelper {
@@ -134,7 +138,7 @@ impl Hinter for CliHelper {
134138
self.show_hint.set(false);
135139
}
136140
(self.show_hint.get() && line.trim().is_empty())
137-
.then(|| Color::gray(DEFAULT_HINT_SUGGESTION))
141+
.then(|| DEFAULT_HINT_SUGGESTION.to_owned())
138142
}
139143
}
140144

datafusion/functions/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ datafusion-macros = { workspace = true }
8181
hex = { workspace = true, optional = true }
8282
itertools = { workspace = true }
8383
log = { workspace = true }
84-
md-5 = { version = "^0.10.0", optional = true }
84+
md-5 = { version = "^0.11.0", optional = true }
8585
memchr = { workspace = true }
8686
num-traits = { workspace = true }
8787
rand = { workspace = true }

datafusion/functions/src/crypto/basic.rs

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
2020
use arrow::array::{Array, ArrayRef, AsArray, BinaryArray, BinaryArrayType};
2121
use arrow::datatypes::DataType;
22-
use blake2::{Blake2b512, Blake2s256, Digest};
22+
use blake2::{Blake2b512, Blake2s256};
2323
use blake3::Hasher as Blake3;
2424

2525
use arrow::compute::StringArrayType;
@@ -85,7 +85,8 @@ impl fmt::Display for DigestAlgorithm {
8585
}
8686

8787
macro_rules! digest_to_array {
88-
($METHOD:ident, $INPUT:expr) => {{
88+
($MODULE:ident, $METHOD:ident, $INPUT:expr) => {{
89+
use $MODULE::Digest;
8990
let binary_array: BinaryArray = $INPUT
9091
.iter()
9192
.map(|x| x.map(|x| $METHOD::digest(x)))
@@ -95,20 +96,23 @@ macro_rules! digest_to_array {
9596
}
9697

9798
macro_rules! digest_to_scalar {
98-
($METHOD: ident, $INPUT:expr) => {{ ScalarValue::Binary($INPUT.map(|v| $METHOD::digest(v).as_slice().to_vec())) }};
99+
($MODULE: ident, $METHOD: ident, $INPUT:expr) => {{
100+
use $MODULE::Digest;
101+
ScalarValue::Binary($INPUT.map(|v| $METHOD::digest(v).as_slice().to_vec()))
102+
}};
99103
}
100104

101105
impl DigestAlgorithm {
102106
/// digest an optional string to its hash value, null values are returned as is
103107
fn digest_scalar(self, value: Option<&[u8]>) -> ColumnarValue {
104108
ColumnarValue::Scalar(match self {
105-
Self::Md5 => digest_to_scalar!(Md5, value),
106-
Self::Sha224 => digest_to_scalar!(Sha224, value),
107-
Self::Sha256 => digest_to_scalar!(Sha256, value),
108-
Self::Sha384 => digest_to_scalar!(Sha384, value),
109-
Self::Sha512 => digest_to_scalar!(Sha512, value),
110-
Self::Blake2b => digest_to_scalar!(Blake2b512, value),
111-
Self::Blake2s => digest_to_scalar!(Blake2s256, value),
109+
Self::Md5 => digest_to_scalar!(md5, Md5, value),
110+
Self::Sha224 => digest_to_scalar!(sha2, Sha224, value),
111+
Self::Sha256 => digest_to_scalar!(sha2, Sha256, value),
112+
Self::Sha384 => digest_to_scalar!(sha2, Sha384, value),
113+
Self::Sha512 => digest_to_scalar!(sha2, Sha512, value),
114+
Self::Blake2b => digest_to_scalar!(blake2, Blake2b512, value),
115+
Self::Blake2s => digest_to_scalar!(blake2, Blake2s256, value),
112116
Self::Blake3 => ScalarValue::Binary(value.map(|v| {
113117
let mut digest = Blake3::default();
114118
digest.update(v);
@@ -125,13 +129,13 @@ impl DigestAlgorithm {
125129
StringArrType: StringArrayType<'a>,
126130
{
127131
match self {
128-
Self::Md5 => digest_to_array!(Md5, input_value),
129-
Self::Sha224 => digest_to_array!(Sha224, input_value),
130-
Self::Sha256 => digest_to_array!(Sha256, input_value),
131-
Self::Sha384 => digest_to_array!(Sha384, input_value),
132-
Self::Sha512 => digest_to_array!(Sha512, input_value),
133-
Self::Blake2b => digest_to_array!(Blake2b512, input_value),
134-
Self::Blake2s => digest_to_array!(Blake2s256, input_value),
132+
Self::Md5 => digest_to_array!(md5, Md5, input_value),
133+
Self::Sha224 => digest_to_array!(sha2, Sha224, input_value),
134+
Self::Sha256 => digest_to_array!(sha2, Sha256, input_value),
135+
Self::Sha384 => digest_to_array!(sha2, Sha384, input_value),
136+
Self::Sha512 => digest_to_array!(sha2, Sha512, input_value),
137+
Self::Blake2b => digest_to_array!(blake2, Blake2b512, input_value),
138+
Self::Blake2s => digest_to_array!(blake2, Blake2s256, input_value),
135139
Self::Blake3 => {
136140
let binary_array: BinaryArray = input_value
137141
.iter()
@@ -156,13 +160,13 @@ impl DigestAlgorithm {
156160
BinaryArrType: BinaryArrayType<'a>,
157161
{
158162
match self {
159-
Self::Md5 => digest_to_array!(Md5, input_value),
160-
Self::Sha224 => digest_to_array!(Sha224, input_value),
161-
Self::Sha256 => digest_to_array!(Sha256, input_value),
162-
Self::Sha384 => digest_to_array!(Sha384, input_value),
163-
Self::Sha512 => digest_to_array!(Sha512, input_value),
164-
Self::Blake2b => digest_to_array!(Blake2b512, input_value),
165-
Self::Blake2s => digest_to_array!(Blake2s256, input_value),
163+
Self::Md5 => digest_to_array!(md5, Md5, input_value),
164+
Self::Sha224 => digest_to_array!(sha2, Sha224, input_value),
165+
Self::Sha256 => digest_to_array!(sha2, Sha256, input_value),
166+
Self::Sha384 => digest_to_array!(sha2, Sha384, input_value),
167+
Self::Sha512 => digest_to_array!(sha2, Sha512, input_value),
168+
Self::Blake2b => digest_to_array!(blake2, Blake2b512, input_value),
169+
Self::Blake2s => digest_to_array!(blake2, Blake2s256, input_value),
166170
Self::Blake3 => {
167171
let binary_array: BinaryArray = input_value
168172
.iter()

datafusion/functions/src/strings.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,17 @@ impl StringViewArrayBuilder {
604604
let offset: u32 = i32::try_from(self.in_progress.len())
605605
.expect("offset exceeds i32::MAX") as u32;
606606
self.in_progress.extend_from_slice(v);
607-
self.views.push(make_view(v, buffer_index, offset));
607+
608+
// Build the ByteView inline rather than going through `make_view`,
609+
// which is marked as `[inline(never)]`.
610+
let view = ByteView {
611+
length,
612+
// SAFETY: length > 12 here, so v has at least 4 bytes.
613+
prefix: u32::from_le_bytes(v[0..4].try_into().unwrap()),
614+
buffer_index,
615+
offset,
616+
};
617+
self.views.push(view.into());
608618
}
609619

610620
/// Append an empty placeholder row. The corresponding slot must be

datafusion/functions/src/unicode/initcap.rs

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717

1818
use std::sync::Arc;
1919

20-
use arrow::array::{
21-
Array, ArrayRef, GenericStringArray, GenericStringBuilder, OffsetSizeTrait,
22-
StringViewBuilder,
23-
};
20+
use arrow::array::{Array, ArrayRef, GenericStringArray, OffsetSizeTrait};
2421
use arrow::buffer::{Buffer, OffsetBuffer};
2522
use arrow::datatypes::DataType;
2623

24+
use crate::strings::{GenericStringArrayBuilder, StringViewArrayBuilder};
2725
use crate::utils::{make_scalar_function, utf8_to_str_type};
2826
use datafusion_common::cast::{as_generic_string_array, as_string_view_array};
2927
use datafusion_common::types::logical_string;
@@ -157,21 +155,35 @@ fn initcap<T: OffsetSizeTrait>(args: &[ArrayRef]) -> Result<ArrayRef> {
157155
return Ok(initcap_ascii_array(string_array));
158156
}
159157

160-
let mut builder = GenericStringBuilder::<T>::with_capacity(
161-
string_array.len(),
158+
let len = string_array.len();
159+
let mut builder = GenericStringArrayBuilder::<T>::with_capacity(
160+
len,
162161
string_array.value_data().len(),
163162
);
164163

165164
let mut container = String::new();
166-
string_array.iter().for_each(|str| match str {
167-
Some(s) => {
165+
let nulls = string_array.nulls().cloned();
166+
if let Some(ref n) = nulls {
167+
for i in 0..len {
168+
if n.is_null(i) {
169+
builder.append_placeholder();
170+
} else {
171+
// SAFETY: not null per check above.
172+
let s = unsafe { string_array.value_unchecked(i) };
173+
initcap_string(s, &mut container);
174+
builder.append_value(&container);
175+
}
176+
}
177+
} else {
178+
for i in 0..len {
179+
// SAFETY: no null buffer means every index is valid.
180+
let s = unsafe { string_array.value_unchecked(i) };
168181
initcap_string(s, &mut container);
169182
builder.append_value(&container);
170183
}
171-
None => builder.append_null(),
172-
});
184+
}
173185

174-
Ok(Arc::new(builder.finish()) as ArrayRef)
186+
Ok(Arc::new(builder.finish(nulls)?) as ArrayRef)
175187
}
176188

177189
/// Fast path for `Utf8` or `LargeUtf8` arrays that are ASCII-only. We can use a
@@ -232,18 +244,32 @@ fn initcap_ascii_array<T: OffsetSizeTrait>(
232244

233245
fn initcap_utf8view(args: &[ArrayRef]) -> Result<ArrayRef> {
234246
let string_view_array = as_string_view_array(&args[0])?;
235-
let mut builder = StringViewBuilder::with_capacity(string_view_array.len());
247+
let len = string_view_array.len();
248+
let mut builder = StringViewArrayBuilder::with_capacity(len);
236249
let mut container = String::new();
237250

238-
string_view_array.iter().for_each(|str| match str {
239-
Some(s) => {
251+
let nulls = string_view_array.nulls().cloned();
252+
if let Some(ref n) = nulls {
253+
for i in 0..len {
254+
if n.is_null(i) {
255+
builder.append_placeholder();
256+
} else {
257+
// SAFETY: not null per check above.
258+
let s = unsafe { string_view_array.value_unchecked(i) };
259+
initcap_string(s, &mut container);
260+
builder.append_value(&container);
261+
}
262+
}
263+
} else {
264+
for i in 0..len {
265+
// SAFETY: no null buffer means every index is valid.
266+
let s = unsafe { string_view_array.value_unchecked(i) };
240267
initcap_string(s, &mut container);
241268
builder.append_value(&container);
242269
}
243-
None => builder.append_null(),
244-
});
270+
}
245271

246-
Ok(Arc::new(builder.finish()) as ArrayRef)
272+
Ok(Arc::new(builder.finish(nulls)?) as ArrayRef)
247273
}
248274

249275
fn initcap_string(input: &str, container: &mut String) {

0 commit comments

Comments
 (0)