Skip to content

chore : migrated all the UDFS to invoke_with_args #14779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions datafusion/functions/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,7 @@ macro_rules! make_math_binary_udf {
$OUTPUT_ORDERING(input)
}

fn invoke_with_args(
&self,
args: ScalarFunctionArgs,
) -> Result<ColumnarValue> {
fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
let args = ColumnarValue::values_to_arrays(&args.args)?;
let arr: ArrayRef = match args[0].data_type() {
DataType::Float64 => {
Expand Down Expand Up @@ -364,9 +361,10 @@ macro_rules! make_math_binary_udf {
)
}
};

Ok(ColumnarValue::Array(arr))
}


fn documentation(&self) -> Option<&Documentation> {
Some($GET_DOC())
Expand Down
8 changes: 2 additions & 6 deletions datafusion/functions/src/unicode/character_length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,8 @@ impl ScalarUDFImpl for CharacterLengthFunc {
utf8_to_int_type(&arg_types[0], "character_length")
}

fn invoke_batch(
&self,
args: &[ColumnarValue],
_number_rows: usize,
) -> Result<ColumnarValue> {
make_scalar_function(character_length, vec![])(args)
fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
make_scalar_function(character_length, vec![])(args.args())
}

fn aliases(&self) -> &[String] {
Expand Down
12 changes: 4 additions & 8 deletions datafusion/functions/src/unicode/initcap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,11 @@ impl ScalarUDFImpl for InitcapFunc {
}
}

fn invoke_batch(
&self,
args: &[ColumnarValue],
_number_rows: usize,
) -> Result<ColumnarValue> {
fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
match args[0].data_type() {
DataType::Utf8 => make_scalar_function(initcap::<i32>, vec![])(args),
DataType::LargeUtf8 => make_scalar_function(initcap::<i64>, vec![])(args),
DataType::Utf8View => make_scalar_function(initcap_utf8view, vec![])(args),
DataType::Utf8 => make_scalar_function(initcap::<i32>, vec![])(args.args()),
DataType::LargeUtf8 => make_scalar_function(initcap::<i64>, vec![])(args.args()),
DataType::Utf8View => make_scalar_function(initcap_utf8view, vec![])(args.args()),
other => {
exec_err!("Unsupported data type {other:?} for function `initcap`")
}
Expand Down
10 changes: 3 additions & 7 deletions datafusion/functions/src/unicode/left.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,12 @@ impl ScalarUDFImpl for LeftFunc {
utf8_to_str_type(&arg_types[0], "left")
}

fn invoke_batch(
&self,
args: &[ColumnarValue],
_number_rows: usize,
) -> Result<ColumnarValue> {
fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
match args[0].data_type() {
DataType::Utf8 | DataType::Utf8View => {
make_scalar_function(left::<i32>, vec![])(args)
make_scalar_function(left::<i32>, vec![])(args.args())
}
DataType::LargeUtf8 => make_scalar_function(left::<i64>, vec![])(args),
DataType::LargeUtf8 => make_scalar_function(left::<i64>, vec![])(args.args()),
other => exec_err!(
"Unsupported data type {other:?} for function left,\
expected Utf8View, Utf8 or LargeUtf8."
Expand Down
10 changes: 3 additions & 7 deletions datafusion/functions/src/unicode/lpad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,10 @@ impl ScalarUDFImpl for LPadFunc {
utf8_to_str_type(&arg_types[0], "lpad")
}

fn invoke_batch(
&self,
args: &[ColumnarValue],
_number_rows: usize,
) -> Result<ColumnarValue> {
fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
match args[0].data_type() {
Utf8 | Utf8View => make_scalar_function(lpad::<i32>, vec![])(args),
LargeUtf8 => make_scalar_function(lpad::<i64>, vec![])(args),
Utf8 | Utf8View => make_scalar_function(lpad::<i32>, vec![])(args.args()),
LargeUtf8 => make_scalar_function(lpad::<i64>, vec![])(args.args()),
other => exec_err!("Unsupported data type {other:?} for function lpad"),
}
}
Expand Down
10 changes: 3 additions & 7 deletions datafusion/functions/src/unicode/reverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,10 @@ impl ScalarUDFImpl for ReverseFunc {
utf8_to_str_type(&arg_types[0], "reverse")
}

fn invoke_batch(
&self,
args: &[ColumnarValue],
_number_rows: usize,
) -> Result<ColumnarValue> {
fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
match args[0].data_type() {
Utf8 | Utf8View => make_scalar_function(reverse::<i32>, vec![])(args),
LargeUtf8 => make_scalar_function(reverse::<i64>, vec![])(args),
Utf8 | Utf8View => make_scalar_function(reverse::<i32>, vec![])(args.args()),
LargeUtf8 => make_scalar_function(reverse::<i64>, vec![])(args.args()),
other => {
exec_err!("Unsupported data type {other:?} for function reverse")
}
Expand Down
10 changes: 3 additions & 7 deletions datafusion/functions/src/unicode/right.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,12 @@ impl ScalarUDFImpl for RightFunc {
utf8_to_str_type(&arg_types[0], "right")
}

fn invoke_batch(
&self,
args: &[ColumnarValue],
_number_rows: usize,
) -> Result<ColumnarValue> {
fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
match args[0].data_type() {
DataType::Utf8 | DataType::Utf8View => {
make_scalar_function(right::<i32>, vec![])(args)
make_scalar_function(right::<i32>, vec![])(args.args())
}
DataType::LargeUtf8 => make_scalar_function(right::<i64>, vec![])(args),
DataType::LargeUtf8 => make_scalar_function(right::<i64>, vec![])(args.args()),
other => exec_err!(
"Unsupported data type {other:?} for function right,\
expected Utf8View, Utf8 or LargeUtf8."
Expand Down
18 changes: 7 additions & 11 deletions datafusion/functions/src/unicode/rpad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,31 +108,27 @@ impl ScalarUDFImpl for RPadFunc {
utf8_to_str_type(&arg_types[0], "rpad")
}

fn invoke_batch(
&self,
args: &[ColumnarValue],
_number_rows: usize,
) -> Result<ColumnarValue> {
fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
match (
args.len(),
args[0].data_type(),
args.get(2).map(|arg| arg.data_type()),
) {
(2, Utf8 | Utf8View, _) => {
make_scalar_function(rpad::<i32, i32>, vec![])(args)
make_scalar_function(rpad::<i32, i32>, vec![])(args.args())
}
(2, LargeUtf8, _) => make_scalar_function(rpad::<i64, i64>, vec![])(args),
(2, LargeUtf8, _) => make_scalar_function(rpad::<i64, i64>, vec![])(args.args()),
(3, Utf8 | Utf8View, Some(Utf8 | Utf8View)) => {
make_scalar_function(rpad::<i32, i32>, vec![])(args)
make_scalar_function(rpad::<i32, i32>, vec![])(args.args())
}
(3, LargeUtf8, Some(LargeUtf8)) => {
make_scalar_function(rpad::<i64, i64>, vec![])(args)
make_scalar_function(rpad::<i64, i64>, vec![])(args.args())
}
(3, Utf8 | Utf8View, Some(LargeUtf8)) => {
make_scalar_function(rpad::<i32, i64>, vec![])(args)
make_scalar_function(rpad::<i32, i64>, vec![])(args.args())
}
(3, LargeUtf8, Some(Utf8 | Utf8View)) => {
make_scalar_function(rpad::<i64, i32>, vec![])(args)
make_scalar_function(rpad::<i64, i32>, vec![])(args.args())
}
(_, _, _) => {
exec_err!("Unsupported combination of data types for function rpad")
Expand Down
8 changes: 2 additions & 6 deletions datafusion/functions/src/unicode/strpos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,8 @@ impl ScalarUDFImpl for StrposFunc {
utf8_to_int_type(&arg_types[0], "strpos/instr/position")
}

fn invoke_batch(
&self,
args: &[ColumnarValue],
_number_rows: usize,
) -> Result<ColumnarValue> {
make_scalar_function(strpos, vec![])(args)
fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
make_scalar_function(strpos, vec![])(args.args())
}

fn aliases(&self) -> &[String] {
Expand Down
8 changes: 2 additions & 6 deletions datafusion/functions/src/unicode/substr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,8 @@ impl ScalarUDFImpl for SubstrFunc {
Ok(DataType::Utf8View)
}

fn invoke_batch(
&self,
args: &[ColumnarValue],
_number_rows: usize,
) -> Result<ColumnarValue> {
make_scalar_function(substr, vec![])(args)
fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
make_scalar_function(substr, vec![])(args.args())
}

fn aliases(&self) -> &[String] {
Expand Down
6 changes: 1 addition & 5 deletions datafusion/functions/src/unicode/substrindex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,7 @@ impl ScalarUDFImpl for SubstrIndexFunc {
utf8_to_str_type(&arg_types[0], "substr_index")
}

fn invoke_batch(
&self,
args: &[ColumnarValue],
_number_rows: usize,
) -> Result<ColumnarValue> {
fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
make_scalar_function(substr_index, vec![])(args)
}

Expand Down
9 changes: 3 additions & 6 deletions datafusion/functions/src/unicode/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,10 @@ impl ScalarUDFImpl for TranslateFunc {
utf8_to_str_type(&arg_types[0], "translate")
}

fn invoke_batch(
&self,
args: &[ColumnarValue],
_number_rows: usize,
) -> Result<ColumnarValue> {
make_scalar_function(invoke_translate, vec![])(args)
fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
make_scalar_function(invoke_translate, vec![])(args.args)
}


fn documentation(&self) -> Option<&Documentation> {
self.doc()
Expand Down
Loading