Skip to content

Commit b7f4db4

Browse files
authored
Deprecate ScalarUDF::invoke and invoke_no_args for invoke_batch (#13179)
`invoke_batch` is the one used now. The others are no longer in use and we should deprecate and remove them.
1 parent a2e5330 commit b7f4db4

File tree

24 files changed

+284
-59
lines changed

24 files changed

+284
-59
lines changed

datafusion/expr/src/udf.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ impl ScalarUDF {
193193
/// Invoke the function on `args`, returning the appropriate result.
194194
///
195195
/// See [`ScalarUDFImpl::invoke`] for more details.
196+
#[deprecated(since = "42.1.0", note = "Use `invoke_batch` instead")]
196197
pub fn invoke(&self, args: &[ColumnarValue]) -> Result<ColumnarValue> {
197198
self.inner.invoke(args)
198199
}
@@ -215,13 +216,14 @@ impl ScalarUDF {
215216
/// Invoke the function without `args` but number of rows, returning the appropriate result.
216217
///
217218
/// See [`ScalarUDFImpl::invoke_no_args`] for more details.
219+
#[deprecated(since = "42.1.0", note = "Use `invoke_batch` instead")]
218220
pub fn invoke_no_args(&self, number_rows: usize) -> Result<ColumnarValue> {
219221
self.inner.invoke_no_args(number_rows)
220222
}
221223

222224
/// Returns a `ScalarFunctionImplementation` that can invoke the function
223225
/// during execution
224-
#[deprecated(since = "42.0.0", note = "Use `invoke` or `invoke_no_args` instead")]
226+
#[deprecated(since = "42.0.0", note = "Use `invoke_batch` instead")]
225227
pub fn fun(&self) -> ScalarFunctionImplementation {
226228
let captured = Arc::clone(&self.inner);
227229
Arc::new(move |args| captured.invoke(args))

datafusion/functions-nested/benches/map.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ fn criterion_benchmark(c: &mut Criterion) {
9696

9797
b.iter(|| {
9898
black_box(
99+
#[allow(deprecated)] // TODO use invoke_batch
99100
map_udf()
100101
.invoke(&[keys.clone(), values.clone()])
101102
.expect("map should work on valid values"),

datafusion/functions/benches/character_length.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,28 +84,48 @@ fn criterion_benchmark(c: &mut Criterion) {
8484
let args_string_ascii = gen_string_array(n_rows, str_len, 0.1, 0.0, false);
8585
c.bench_function(
8686
&format!("character_length_StringArray_ascii_str_len_{}", str_len),
87-
|b| b.iter(|| black_box(character_length.invoke(&args_string_ascii))),
87+
|b| {
88+
b.iter(|| {
89+
#[allow(deprecated)] // TODO use invoke_batch
90+
black_box(character_length.invoke(&args_string_ascii))
91+
})
92+
},
8893
);
8994

9095
// StringArray UTF8
9196
let args_string_utf8 = gen_string_array(n_rows, str_len, 0.1, 0.5, false);
9297
c.bench_function(
9398
&format!("character_length_StringArray_utf8_str_len_{}", str_len),
94-
|b| b.iter(|| black_box(character_length.invoke(&args_string_utf8))),
99+
|b| {
100+
b.iter(|| {
101+
#[allow(deprecated)] // TODO use invoke_batch
102+
black_box(character_length.invoke(&args_string_utf8))
103+
})
104+
},
95105
);
96106

97107
// StringViewArray ASCII only
98108
let args_string_view_ascii = gen_string_array(n_rows, str_len, 0.1, 0.0, true);
99109
c.bench_function(
100110
&format!("character_length_StringViewArray_ascii_str_len_{}", str_len),
101-
|b| b.iter(|| black_box(character_length.invoke(&args_string_view_ascii))),
111+
|b| {
112+
b.iter(|| {
113+
#[allow(deprecated)] // TODO use invoke_batch
114+
black_box(character_length.invoke(&args_string_view_ascii))
115+
})
116+
},
102117
);
103118

104119
// StringViewArray UTF8
105120
let args_string_view_utf8 = gen_string_array(n_rows, str_len, 0.1, 0.5, true);
106121
c.bench_function(
107122
&format!("character_length_StringViewArray_utf8_str_len_{}", str_len),
108-
|b| b.iter(|| black_box(character_length.invoke(&args_string_view_utf8))),
123+
|b| {
124+
b.iter(|| {
125+
#[allow(deprecated)] // TODO use invoke_batch
126+
black_box(character_length.invoke(&args_string_view_utf8))
127+
})
128+
},
109129
);
110130
}
111131
}

datafusion/functions/benches/concat.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ fn criterion_benchmark(c: &mut Criterion) {
3838
let args = create_args(size, 32);
3939
let mut group = c.benchmark_group("concat function");
4040
group.bench_function(BenchmarkId::new("concat", size), |b| {
41-
b.iter(|| criterion::black_box(concat().invoke(&args).unwrap()))
41+
b.iter(|| {
42+
#[allow(deprecated)] // TODO use invoke_batch
43+
criterion::black_box(concat().invoke(&args).unwrap())
44+
})
4245
});
4346
group.finish();
4447
}

datafusion/functions/benches/cot.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,18 @@ fn criterion_benchmark(c: &mut Criterion) {
3333
let f32_array = Arc::new(create_primitive_array::<Float32Type>(size, 0.2));
3434
let f32_args = vec![ColumnarValue::Array(f32_array)];
3535
c.bench_function(&format!("cot f32 array: {}", size), |b| {
36-
b.iter(|| black_box(cot_fn.invoke(&f32_args).unwrap()))
36+
b.iter(|| {
37+
#[allow(deprecated)] // TODO use invoke_batch
38+
black_box(cot_fn.invoke(&f32_args).unwrap())
39+
})
3740
});
3841
let f64_array = Arc::new(create_primitive_array::<Float64Type>(size, 0.2));
3942
let f64_args = vec![ColumnarValue::Array(f64_array)];
4043
c.bench_function(&format!("cot f64 array: {}", size), |b| {
41-
b.iter(|| black_box(cot_fn.invoke(&f64_args).unwrap()))
44+
b.iter(|| {
45+
#[allow(deprecated)] // TODO use invoke_batch
46+
black_box(cot_fn.invoke(&f64_args).unwrap())
47+
})
4248
});
4349
}
4450
}

datafusion/functions/benches/date_bin.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ fn criterion_benchmark(c: &mut Criterion) {
4545
let udf = date_bin();
4646

4747
b.iter(|| {
48+
#[allow(deprecated)] // TODO use invoke_batch
4849
black_box(
4950
udf.invoke(&[interval.clone(), timestamps.clone()])
5051
.expect("date_bin should work on valid values"),

datafusion/functions/benches/encoding.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,30 @@ fn criterion_benchmark(c: &mut Criterion) {
2929
let str_array = Arc::new(create_string_array_with_len::<i32>(size, 0.2, 32));
3030
c.bench_function(&format!("base64_decode/{size}"), |b| {
3131
let method = ColumnarValue::Scalar("base64".into());
32+
#[allow(deprecated)] // TODO use invoke_batch
3233
let encoded = encoding::encode()
3334
.invoke(&[ColumnarValue::Array(str_array.clone()), method.clone()])
3435
.unwrap();
3536

3637
let args = vec![encoded, method];
37-
b.iter(|| black_box(decode.invoke(&args).unwrap()))
38+
b.iter(|| {
39+
#[allow(deprecated)] // TODO use invoke_batch
40+
black_box(decode.invoke(&args).unwrap())
41+
})
3842
});
3943

4044
c.bench_function(&format!("hex_decode/{size}"), |b| {
4145
let method = ColumnarValue::Scalar("hex".into());
46+
#[allow(deprecated)] // TODO use invoke_batch
4247
let encoded = encoding::encode()
4348
.invoke(&[ColumnarValue::Array(str_array.clone()), method.clone()])
4449
.unwrap();
4550

4651
let args = vec![encoded, method];
47-
b.iter(|| black_box(decode.invoke(&args).unwrap()))
52+
b.iter(|| {
53+
#[allow(deprecated)] // TODO use invoke_batch
54+
black_box(decode.invoke(&args).unwrap())
55+
})
4856
});
4957
}
5058
}

datafusion/functions/benches/isnan.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,18 @@ fn criterion_benchmark(c: &mut Criterion) {
3232
let f32_array = Arc::new(create_primitive_array::<Float32Type>(size, 0.2));
3333
let f32_args = vec![ColumnarValue::Array(f32_array)];
3434
c.bench_function(&format!("isnan f32 array: {}", size), |b| {
35-
b.iter(|| black_box(isnan.invoke(&f32_args).unwrap()))
35+
b.iter(|| {
36+
#[allow(deprecated)] // TODO use invoke_batch
37+
black_box(isnan.invoke(&f32_args).unwrap())
38+
})
3639
});
3740
let f64_array = Arc::new(create_primitive_array::<Float64Type>(size, 0.2));
3841
let f64_args = vec![ColumnarValue::Array(f64_array)];
3942
c.bench_function(&format!("isnan f64 array: {}", size), |b| {
40-
b.iter(|| black_box(isnan.invoke(&f64_args).unwrap()))
43+
b.iter(|| {
44+
#[allow(deprecated)] // TODO use invoke_batch
45+
black_box(isnan.invoke(&f64_args).unwrap())
46+
})
4147
});
4248
}
4349
}

datafusion/functions/benches/iszero.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,18 @@ fn criterion_benchmark(c: &mut Criterion) {
3232
let f32_array = Arc::new(create_primitive_array::<Float32Type>(size, 0.2));
3333
let f32_args = vec![ColumnarValue::Array(f32_array)];
3434
c.bench_function(&format!("iszero f32 array: {}", size), |b| {
35-
b.iter(|| black_box(iszero.invoke(&f32_args).unwrap()))
35+
b.iter(|| {
36+
#[allow(deprecated)] // TODO use invoke_batch
37+
black_box(iszero.invoke(&f32_args).unwrap())
38+
})
3639
});
3740
let f64_array = Arc::new(create_primitive_array::<Float64Type>(size, 0.2));
3841
let f64_args = vec![ColumnarValue::Array(f64_array)];
3942
c.bench_function(&format!("iszero f64 array: {}", size), |b| {
40-
b.iter(|| black_box(iszero.invoke(&f64_args).unwrap()))
43+
b.iter(|| {
44+
#[allow(deprecated)] // TODO use invoke_batch
45+
black_box(iszero.invoke(&f64_args).unwrap())
46+
})
4147
});
4248
}
4349
}

datafusion/functions/benches/lower.rs

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,32 @@ fn criterion_benchmark(c: &mut Criterion) {
124124
for size in [1024, 4096, 8192] {
125125
let args = create_args1(size, 32);
126126
c.bench_function(&format!("lower_all_values_are_ascii: {}", size), |b| {
127-
b.iter(|| black_box(lower.invoke(&args)))
127+
b.iter(|| {
128+
#[allow(deprecated)] // TODO use invoke_batch
129+
black_box(lower.invoke(&args))
130+
})
128131
});
129132

130133
let args = create_args2(size);
131134
c.bench_function(
132135
&format!("lower_the_first_value_is_nonascii: {}", size),
133-
|b| b.iter(|| black_box(lower.invoke(&args))),
136+
|b| {
137+
b.iter(|| {
138+
#[allow(deprecated)] // TODO use invoke_batch
139+
black_box(lower.invoke(&args))
140+
})
141+
},
134142
);
135143

136144
let args = create_args3(size);
137145
c.bench_function(
138146
&format!("lower_the_middle_value_is_nonascii: {}", size),
139-
|b| b.iter(|| black_box(lower.invoke(&args))),
147+
|b| {
148+
b.iter(|| {
149+
#[allow(deprecated)] // TODO use invoke_batch
150+
black_box(lower.invoke(&args))
151+
})
152+
},
140153
);
141154
}
142155

@@ -151,24 +164,33 @@ fn criterion_benchmark(c: &mut Criterion) {
151164
for &size in &sizes {
152165
let args = create_args4(size, str_len, *null_density, mixed);
153166
c.bench_function(
154-
&format!("lower_all_values_are_ascii_string_views: size: {}, str_len: {}, null_density: {}, mixed: {}",
167+
&format!("lower_all_values_are_ascii_string_views: size: {}, str_len: {}, null_density: {}, mixed: {}",
155168
size, str_len, null_density, mixed),
156-
|b| b.iter(|| black_box(lower.invoke(&args))),
157-
);
169+
|b| b.iter(|| {
170+
#[allow(deprecated)] // TODO use invoke_batch
171+
black_box(lower.invoke(&args))
172+
}),
173+
);
158174

159175
let args = create_args4(size, str_len, *null_density, mixed);
160176
c.bench_function(
161-
&format!("lower_all_values_are_ascii_string_views: size: {}, str_len: {}, null_density: {}, mixed: {}",
177+
&format!("lower_all_values_are_ascii_string_views: size: {}, str_len: {}, null_density: {}, mixed: {}",
162178
size, str_len, null_density, mixed),
163-
|b| b.iter(|| black_box(lower.invoke(&args))),
164-
);
179+
|b| b.iter(|| {
180+
#[allow(deprecated)] // TODO use invoke_batch
181+
black_box(lower.invoke(&args))
182+
}),
183+
);
165184

166185
let args = create_args5(size, 0.1, *null_density);
167186
c.bench_function(
168-
&format!("lower_some_values_are_nonascii_string_views: size: {}, str_len: {}, non_ascii_density: {}, null_density: {}, mixed: {}",
187+
&format!("lower_some_values_are_nonascii_string_views: size: {}, str_len: {}, non_ascii_density: {}, null_density: {}, mixed: {}",
169188
size, str_len, 0.1, null_density, mixed),
170-
|b| b.iter(|| black_box(lower.invoke(&args))),
171-
);
189+
|b| b.iter(|| {
190+
#[allow(deprecated)] // TODO use invoke_batch
191+
black_box(lower.invoke(&args))
192+
}),
193+
);
172194
}
173195
}
174196
}

datafusion/functions/benches/ltrim.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,12 @@ fn run_with_string_type<M: Measurement>(
139139
format!(
140140
"{string_type} [size={size}, len_before={len}, len_after={remaining_len}]",
141141
),
142-
|b| b.iter(|| black_box(ltrim.invoke(&args))),
142+
|b| {
143+
b.iter(|| {
144+
#[allow(deprecated)] // TODO use invoke_batch
145+
black_box(ltrim.invoke(&args))
146+
})
147+
},
143148
);
144149
}
145150

datafusion/functions/benches/make_date.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ fn criterion_benchmark(c: &mut Criterion) {
6262
let days = ColumnarValue::Array(Arc::new(days(&mut rng)) as ArrayRef);
6363

6464
b.iter(|| {
65+
#[allow(deprecated)] // TODO use invoke_batch
6566
black_box(
6667
make_date()
6768
.invoke(&[years.clone(), months.clone(), days.clone()])
@@ -77,6 +78,7 @@ fn criterion_benchmark(c: &mut Criterion) {
7778
let days = ColumnarValue::Array(Arc::new(days(&mut rng)) as ArrayRef);
7879

7980
b.iter(|| {
81+
#[allow(deprecated)] // TODO use invoke_batch
8082
black_box(
8183
make_date()
8284
.invoke(&[year.clone(), months.clone(), days.clone()])
@@ -92,6 +94,7 @@ fn criterion_benchmark(c: &mut Criterion) {
9294
let days = ColumnarValue::Array(Arc::new(days(&mut rng)) as ArrayRef);
9395

9496
b.iter(|| {
97+
#[allow(deprecated)] // TODO use invoke_batch
9598
black_box(
9699
make_date()
97100
.invoke(&[year.clone(), month.clone(), days.clone()])
@@ -106,6 +109,7 @@ fn criterion_benchmark(c: &mut Criterion) {
106109
let day = ColumnarValue::Scalar(ScalarValue::Int32(Some(26)));
107110

108111
b.iter(|| {
112+
#[allow(deprecated)] // TODO use invoke_batch
109113
black_box(
110114
make_date()
111115
.invoke(&[year.clone(), month.clone(), day.clone()])

datafusion/functions/benches/nullif.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ fn criterion_benchmark(c: &mut Criterion) {
3333
ColumnarValue::Array(array),
3434
];
3535
c.bench_function(&format!("nullif scalar array: {}", size), |b| {
36-
b.iter(|| black_box(nullif.invoke(&args).unwrap()))
36+
b.iter(|| {
37+
#[allow(deprecated)] // TODO use invoke_batch
38+
black_box(nullif.invoke(&args).unwrap())
39+
})
3740
});
3841
}
3942
}

datafusion/functions/benches/pad.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,26 @@ fn criterion_benchmark(c: &mut Criterion) {
101101

102102
let args = create_args::<i32>(size, 32, false);
103103
group.bench_function(BenchmarkId::new("utf8 type", size), |b| {
104-
b.iter(|| criterion::black_box(lpad().invoke(&args).unwrap()))
104+
b.iter(|| {
105+
#[allow(deprecated)] // TODO use invoke_batch
106+
criterion::black_box(lpad().invoke(&args).unwrap())
107+
})
105108
});
106109

107110
let args = create_args::<i64>(size, 32, false);
108111
group.bench_function(BenchmarkId::new("largeutf8 type", size), |b| {
109-
b.iter(|| criterion::black_box(lpad().invoke(&args).unwrap()))
112+
b.iter(|| {
113+
#[allow(deprecated)] // TODO use invoke_batch
114+
criterion::black_box(lpad().invoke(&args).unwrap())
115+
})
110116
});
111117

112118
let args = create_args::<i32>(size, 32, true);
113119
group.bench_function(BenchmarkId::new("stringview type", size), |b| {
114-
b.iter(|| criterion::black_box(lpad().invoke(&args).unwrap()))
120+
b.iter(|| {
121+
#[allow(deprecated)] // TODO use invoke_batch
122+
criterion::black_box(lpad().invoke(&args).unwrap())
123+
})
115124
});
116125

117126
group.finish();
@@ -120,18 +129,27 @@ fn criterion_benchmark(c: &mut Criterion) {
120129

121130
let args = create_args::<i32>(size, 32, false);
122131
group.bench_function(BenchmarkId::new("utf8 type", size), |b| {
123-
b.iter(|| criterion::black_box(rpad().invoke(&args).unwrap()))
132+
b.iter(|| {
133+
#[allow(deprecated)] // TODO use invoke_batch
134+
criterion::black_box(rpad().invoke(&args).unwrap())
135+
})
124136
});
125137

126138
let args = create_args::<i64>(size, 32, false);
127139
group.bench_function(BenchmarkId::new("largeutf8 type", size), |b| {
128-
b.iter(|| criterion::black_box(rpad().invoke(&args).unwrap()))
140+
b.iter(|| {
141+
#[allow(deprecated)] // TODO use invoke_batch
142+
criterion::black_box(rpad().invoke(&args).unwrap())
143+
})
129144
});
130145

131146
// rpad for stringview type
132147
let args = create_args::<i32>(size, 32, true);
133148
group.bench_function(BenchmarkId::new("stringview type", size), |b| {
134-
b.iter(|| criterion::black_box(rpad().invoke(&args).unwrap()))
149+
b.iter(|| {
150+
#[allow(deprecated)] // TODO use invoke_batch
151+
criterion::black_box(rpad().invoke(&args).unwrap())
152+
})
135153
});
136154

137155
group.finish();

0 commit comments

Comments
 (0)