Skip to content

Commit 6be228c

Browse files
Blizzaraalamb
andauthored
chore: remove deprecated variants of UDF's invoke (invoke, invoke_no_args, invoke_batch) (#15123)
* chore: remove deprecated variants of UDF's invoke (invoke, invoke_no_args, invoke_batch) Leaving only invoke_with_args * clippy * unused import --------- Co-authored-by: Andrew Lamb <[email protected]>
1 parent 87eec43 commit 6be228c

File tree

9 files changed

+60
-114
lines changed

9 files changed

+60
-114
lines changed

datafusion/core/tests/physical_optimizer/projection_pushdown.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ use datafusion_common::Result;
2929
use datafusion_common::{JoinSide, JoinType, ScalarValue};
3030
use datafusion_execution::object_store::ObjectStoreUrl;
3131
use datafusion_execution::{SendableRecordBatchStream, TaskContext};
32-
use datafusion_expr::{Operator, ScalarUDF, ScalarUDFImpl, Signature, Volatility};
32+
use datafusion_expr::{
33+
Operator, ScalarFunctionArgs, ScalarUDF, ScalarUDFImpl, Signature, Volatility,
34+
};
3335
use datafusion_physical_expr::expressions::{
3436
binary, cast, col, BinaryExpr, CaseExpr, CastExpr, Column, Literal, NegativeExpr,
3537
};
@@ -57,6 +59,7 @@ use datafusion_physical_plan::streaming::StreamingTableExec;
5759
use datafusion_physical_plan::union::UnionExec;
5860
use datafusion_physical_plan::{get_plan_string, ExecutionPlan};
5961

62+
use datafusion_expr_common::columnar_value::ColumnarValue;
6063
use itertools::Itertools;
6164

6265
/// Mocked UDF
@@ -89,6 +92,10 @@ impl ScalarUDFImpl for DummyUDF {
8992
fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
9093
Ok(DataType::Int32)
9194
}
95+
96+
fn invoke_with_args(&self, _args: ScalarFunctionArgs) -> Result<ColumnarValue> {
97+
panic!("dummy - not implemented")
98+
}
9299
}
93100

94101
#[test]

datafusion/core/tests/user_defined/user_defined_scalar_functions.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,10 @@ impl ScalarUDFImpl for CastToI64UDF {
679679
Ok(DataType::Int64)
680680
}
681681

682+
fn invoke_with_args(&self, _args: ScalarFunctionArgs) -> Result<ColumnarValue> {
683+
panic!("dummy - not implemented")
684+
}
685+
682686
// Demonstrate simplifying a UDF
683687
fn simplify(
684688
&self,
@@ -946,6 +950,10 @@ impl ScalarUDFImpl for ScalarFunctionWrapper {
946950
Ok(self.return_type.clone())
947951
}
948952

953+
fn invoke_with_args(&self, _args: ScalarFunctionArgs) -> Result<ColumnarValue> {
954+
panic!("dummy - not implemented")
955+
}
956+
949957
fn simplify(
950958
&self,
951959
args: Vec<Expr>,

datafusion/expr/src/udf.rs

Lines changed: 2 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
use crate::expr::schema_name_from_exprs_comma_separated_without_space;
2121
use crate::simplify::{ExprSimplifyResult, SimplifyInfo};
2222
use crate::sort_properties::{ExprProperties, SortProperties};
23-
use crate::{
24-
ColumnarValue, Documentation, Expr, ScalarFunctionImplementation, Signature,
25-
};
23+
use crate::{ColumnarValue, Documentation, Expr, Signature};
2624
use arrow::datatypes::DataType;
2725
use datafusion_common::{not_impl_err, ExprSchema, Result, ScalarValue};
2826
use datafusion_expr_common::interval_arithmetic::Interval;
@@ -198,53 +196,18 @@ impl ScalarUDF {
198196
self.inner.simplify(args, info)
199197
}
200198

201-
#[deprecated(since = "42.1.0", note = "Use `invoke_with_args` instead")]
202-
pub fn invoke(&self, args: &[ColumnarValue]) -> Result<ColumnarValue> {
203-
#[allow(deprecated)]
204-
self.inner.invoke(args)
205-
}
206-
207199
#[allow(deprecated)]
208200
pub fn is_nullable(&self, args: &[Expr], schema: &dyn ExprSchema) -> bool {
209201
self.inner.is_nullable(args, schema)
210202
}
211203

212-
#[deprecated(since = "46.0.0", note = "Use `invoke_with_args` instead")]
213-
pub fn invoke_batch(
214-
&self,
215-
args: &[ColumnarValue],
216-
number_rows: usize,
217-
) -> Result<ColumnarValue> {
218-
#[allow(deprecated)]
219-
self.inner.invoke_batch(args, number_rows)
220-
}
221-
222204
/// Invoke the function on `args`, returning the appropriate result.
223205
///
224206
/// See [`ScalarUDFImpl::invoke_with_args`] for details.
225207
pub fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
226208
self.inner.invoke_with_args(args)
227209
}
228210

229-
/// Invoke the function without `args` but number of rows, returning the appropriate result.
230-
///
231-
/// Note: This method is deprecated and will be removed in future releases.
232-
/// User defined functions should implement [`Self::invoke_with_args`] instead.
233-
#[deprecated(since = "42.1.0", note = "Use `invoke_with_args` instead")]
234-
pub fn invoke_no_args(&self, number_rows: usize) -> Result<ColumnarValue> {
235-
#[allow(deprecated)]
236-
self.inner.invoke_no_args(number_rows)
237-
}
238-
239-
/// Returns a `ScalarFunctionImplementation` that can invoke the function
240-
/// during execution
241-
#[deprecated(since = "42.0.0", note = "Use `invoke_with_args` instead")]
242-
pub fn fun(&self) -> ScalarFunctionImplementation {
243-
let captured = Arc::clone(&self.inner);
244-
#[allow(deprecated)]
245-
Arc::new(move |args| captured.invoke(args))
246-
}
247-
248211
/// Get the circuits of inner implementation
249212
pub fn short_circuits(&self) -> bool {
250213
self.inner.short_circuits()
@@ -568,47 +531,6 @@ pub trait ScalarUDFImpl: Debug + Send + Sync {
568531
true
569532
}
570533

571-
/// Invoke the function on `args`, returning the appropriate result
572-
///
573-
/// Note: This method is deprecated and will be removed in future releases.
574-
/// User defined functions should implement [`Self::invoke_with_args`] instead.
575-
#[deprecated(since = "42.1.0", note = "Use `invoke_with_args` instead")]
576-
fn invoke(&self, _args: &[ColumnarValue]) -> Result<ColumnarValue> {
577-
not_impl_err!(
578-
"Function {} does not implement invoke but called",
579-
self.name()
580-
)
581-
}
582-
583-
/// Invoke the function with `args` and the number of rows,
584-
/// returning the appropriate result.
585-
///
586-
/// Note: See notes on [`Self::invoke_with_args`]
587-
///
588-
/// Note: This method is deprecated and will be removed in future releases.
589-
/// User defined functions should implement [`Self::invoke_with_args`] instead.
590-
///
591-
/// See <https://github.com/apache/datafusion/issues/13515> for more details.
592-
#[deprecated(since = "46.0.0", note = "Use `invoke_with_args` instead")]
593-
fn invoke_batch(
594-
&self,
595-
args: &[ColumnarValue],
596-
number_rows: usize,
597-
) -> Result<ColumnarValue> {
598-
match args.is_empty() {
599-
true =>
600-
{
601-
#[allow(deprecated)]
602-
self.invoke_no_args(number_rows)
603-
}
604-
false =>
605-
{
606-
#[allow(deprecated)]
607-
self.invoke(args)
608-
}
609-
}
610-
}
611-
612534
/// Invoke the function returning the appropriate result.
613535
///
614536
/// # Performance
@@ -619,23 +541,7 @@ pub trait ScalarUDFImpl: Debug + Send + Sync {
619541
///
620542
/// [`ColumnarValue::values_to_arrays`] can be used to convert the arguments
621543
/// to arrays, which will likely be simpler code, but be slower.
622-
fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
623-
#[allow(deprecated)]
624-
self.invoke_batch(&args.args, args.number_rows)
625-
}
626-
627-
/// Invoke the function without `args`, instead the number of rows are provided,
628-
/// returning the appropriate result.
629-
///
630-
/// Note: This method is deprecated and will be removed in future releases.
631-
/// User defined functions should implement [`Self::invoke_with_args`] instead.
632-
#[deprecated(since = "42.1.0", note = "Use `invoke_with_args` instead")]
633-
fn invoke_no_args(&self, _number_rows: usize) -> Result<ColumnarValue> {
634-
not_impl_err!(
635-
"Function {} does not implement invoke_no_args but called",
636-
self.name()
637-
)
638-
}
544+
fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue>;
639545

640546
/// Returns any aliases (alternate names) for this function.
641547
///

datafusion/functions-nested/src/max.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ use datafusion_common::cast::as_list_array;
2424
use datafusion_common::utils::take_function_args;
2525
use datafusion_common::{exec_err, ScalarValue};
2626
use datafusion_doc::Documentation;
27-
use datafusion_expr::{ColumnarValue, ScalarUDFImpl, Signature, Volatility};
27+
use datafusion_expr::{
28+
ColumnarValue, ScalarFunctionArgs, ScalarUDFImpl, Signature, Volatility,
29+
};
2830
use datafusion_functions_aggregate::min_max;
2931
use datafusion_macros::user_doc;
3032
use itertools::Itertools;
@@ -96,12 +98,11 @@ impl ScalarUDFImpl for ArrayMax {
9698
}
9799
}
98100

99-
fn invoke_batch(
101+
fn invoke_with_args(
100102
&self,
101-
args: &[ColumnarValue],
102-
_number_rows: usize,
103+
args: ScalarFunctionArgs,
103104
) -> datafusion_common::Result<ColumnarValue> {
104-
make_scalar_function(array_max_inner)(args)
105+
make_scalar_function(array_max_inner)(&args.args)
105106
}
106107

107108
fn aliases(&self) -> &[String] {

datafusion/optimizer/src/common_subexpr_eliminate.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -797,8 +797,8 @@ mod test {
797797
use datafusion_expr::logical_plan::{table_scan, JoinType};
798798
use datafusion_expr::{
799799
grouping_set, is_null, not, AccumulatorFactoryFunction, AggregateUDF,
800-
ColumnarValue, ScalarUDF, ScalarUDFImpl, Signature, SimpleAggregateUDF,
801-
Volatility,
800+
ColumnarValue, ScalarFunctionArgs, ScalarUDF, ScalarUDFImpl, Signature,
801+
SimpleAggregateUDF, Volatility,
802802
};
803803
use datafusion_expr::{lit, logical_plan::builder::LogicalPlanBuilder};
804804

@@ -1598,7 +1598,7 @@ mod test {
15981598
Ok(DataType::Int32)
15991599
}
16001600

1601-
fn invoke(&self, _: &[ColumnarValue]) -> Result<ColumnarValue> {
1601+
fn invoke_with_args(&self, _args: ScalarFunctionArgs) -> Result<ColumnarValue> {
16021602
panic!("not implemented")
16031603
}
16041604
}
@@ -1705,5 +1705,9 @@ mod test {
17051705
fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
17061706
Ok(DataType::Float64)
17071707
}
1708+
1709+
fn invoke_with_args(&self, _args: ScalarFunctionArgs) -> Result<ColumnarValue> {
1710+
panic!("dummy - not implemented")
1711+
}
17081712
}
17091713
}

datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4307,6 +4307,10 @@ mod tests {
43074307
fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
43084308
Ok(DataType::Int16)
43094309
}
4310+
4311+
fn invoke_with_args(&self, _args: ScalarFunctionArgs) -> Result<ColumnarValue> {
4312+
panic!("dummy - not implemented")
4313+
}
43104314
}
43114315

43124316
#[test]

datafusion/proto/tests/cases/mod.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616
// under the License.
1717

1818
use arrow::datatypes::{DataType, Field};
19-
use std::any::Any;
20-
use std::fmt::Debug;
21-
19+
use datafusion::logical_expr::ColumnarValue;
2220
use datafusion_common::plan_err;
2321
use datafusion_expr::function::AccumulatorArgs;
2422
use datafusion_expr::{
25-
Accumulator, AggregateUDFImpl, PartitionEvaluator, ScalarUDFImpl, Signature,
26-
Volatility, WindowUDFImpl,
23+
Accumulator, AggregateUDFImpl, PartitionEvaluator, ScalarFunctionArgs, ScalarUDFImpl,
24+
Signature, Volatility, WindowUDFImpl,
2725
};
2826
use datafusion_functions_window_common::field::WindowUDFFieldArgs;
2927
use datafusion_functions_window_common::partition::PartitionEvaluatorArgs;
28+
use std::any::Any;
29+
use std::fmt::Debug;
3030

3131
mod roundtrip_logical_plan;
3232
mod roundtrip_physical_plan;
@@ -69,6 +69,14 @@ impl ScalarUDFImpl for MyRegexUdf {
6969
plan_err!("regex_udf only accepts Utf8 arguments")
7070
}
7171
}
72+
73+
fn invoke_with_args(
74+
&self,
75+
_args: ScalarFunctionArgs,
76+
) -> datafusion_common::Result<ColumnarValue> {
77+
panic!("dummy - not implemented")
78+
}
79+
7280
fn aliases(&self) -> &[String] {
7381
&self.aliases
7482
}

datafusion/sql/src/unparser/expr.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,8 +1661,8 @@ mod tests {
16611661
use datafusion_expr::{
16621662
case, cast, col, cube, exists, grouping_set, interval_datetime_lit,
16631663
interval_year_month_lit, lit, not, not_exists, out_ref_col, placeholder, rollup,
1664-
table_scan, try_cast, when, ScalarUDF, ScalarUDFImpl, Signature, Volatility,
1665-
WindowFrame, WindowFunctionDefinition,
1664+
table_scan, try_cast, when, ColumnarValue, ScalarFunctionArgs, ScalarUDF,
1665+
ScalarUDFImpl, Signature, Volatility, WindowFrame, WindowFunctionDefinition,
16661666
};
16671667
use datafusion_expr::{interval_month_day_nano_lit, ExprFunctionExt};
16681668
use datafusion_functions::expr_fn::{get_field, named_struct};
@@ -1711,6 +1711,10 @@ mod tests {
17111711
fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
17121712
Ok(DataType::Int32)
17131713
}
1714+
1715+
fn invoke_with_args(&self, _args: ScalarFunctionArgs) -> Result<ColumnarValue> {
1716+
panic!("dummy - not implemented")
1717+
}
17141718
}
17151719
// See sql::tests for E2E tests.
17161720

datafusion/sql/tests/sql_integration.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ use datafusion_expr::{
3030
col,
3131
logical_plan::{LogicalPlan, Prepare},
3232
test::function_stub::sum_udaf,
33-
CreateIndex, DdlStatement, ScalarUDF, ScalarUDFImpl, Signature, Statement,
34-
Volatility,
33+
ColumnarValue, CreateIndex, DdlStatement, ScalarFunctionArgs, ScalarUDF,
34+
ScalarUDFImpl, Signature, Statement, Volatility,
3535
};
3636
use datafusion_functions::{string, unicode};
3737
use datafusion_sql::{
@@ -2477,6 +2477,10 @@ impl ScalarUDFImpl for DummyUDF {
24772477
fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
24782478
Ok(self.return_type.clone())
24792479
}
2480+
2481+
fn invoke_with_args(&self, _args: ScalarFunctionArgs) -> Result<ColumnarValue> {
2482+
panic!("dummy - not implemented")
2483+
}
24802484
}
24812485

24822486
/// Create logical plan, write with formatter, compare to expected output

0 commit comments

Comments
 (0)