Skip to content

Commit

Permalink
Deprecate ScalarUDF::invoke and invoke_no_args for invoke_batch
Browse files Browse the repository at this point in the history
`invoke_batch` is the one used now. The others are no longer in use and
we should deprecate and remove them.
  • Loading branch information
findepi committed Oct 30, 2024
1 parent 223bb02 commit bb26b5c
Show file tree
Hide file tree
Showing 24 changed files with 284 additions and 59 deletions.
4 changes: 3 additions & 1 deletion datafusion/expr/src/udf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ impl ScalarUDF {
/// Invoke the function on `args`, returning the appropriate result.
///
/// See [`ScalarUDFImpl::invoke`] for more details.
#[deprecated(since = "42.1.0", note = "Use `invoke_batch` instead")]
pub fn invoke(&self, args: &[ColumnarValue]) -> Result<ColumnarValue> {
self.inner.invoke(args)
}
Expand All @@ -215,13 +216,14 @@ impl ScalarUDF {
/// Invoke the function without `args` but number of rows, returning the appropriate result.
///
/// See [`ScalarUDFImpl::invoke_no_args`] for more details.
#[deprecated(since = "42.1.0", note = "Use `invoke_batch` instead")]
pub fn invoke_no_args(&self, number_rows: usize) -> Result<ColumnarValue> {
self.inner.invoke_no_args(number_rows)
}

/// Returns a `ScalarFunctionImplementation` that can invoke the function
/// during execution
#[deprecated(since = "42.0.0", note = "Use `invoke` or `invoke_no_args` instead")]
#[deprecated(since = "42.0.0", note = "Use `invoke_batch` instead")]
pub fn fun(&self) -> ScalarFunctionImplementation {
let captured = Arc::clone(&self.inner);
Arc::new(move |args| captured.invoke(args))
Expand Down
1 change: 1 addition & 0 deletions datafusion/functions-nested/benches/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ fn criterion_benchmark(c: &mut Criterion) {

b.iter(|| {
black_box(
#[allow(deprecated)] // TODO use invoke_batch
map_udf()
.invoke(&[keys.clone(), values.clone()])
.expect("map should work on valid values"),
Expand Down
28 changes: 24 additions & 4 deletions datafusion/functions/benches/character_length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,28 +84,48 @@ fn criterion_benchmark(c: &mut Criterion) {
let args_string_ascii = gen_string_array(n_rows, str_len, 0.1, 0.0, false);
c.bench_function(
&format!("character_length_StringArray_ascii_str_len_{}", str_len),
|b| b.iter(|| black_box(character_length.invoke(&args_string_ascii))),
|b| {
b.iter(|| {
#[allow(deprecated)] // TODO use invoke_batch
black_box(character_length.invoke(&args_string_ascii))
})
},
);

// StringArray UTF8
let args_string_utf8 = gen_string_array(n_rows, str_len, 0.1, 0.5, false);
c.bench_function(
&format!("character_length_StringArray_utf8_str_len_{}", str_len),
|b| b.iter(|| black_box(character_length.invoke(&args_string_utf8))),
|b| {
b.iter(|| {
#[allow(deprecated)] // TODO use invoke_batch
black_box(character_length.invoke(&args_string_utf8))
})
},
);

// StringViewArray ASCII only
let args_string_view_ascii = gen_string_array(n_rows, str_len, 0.1, 0.0, true);
c.bench_function(
&format!("character_length_StringViewArray_ascii_str_len_{}", str_len),
|b| b.iter(|| black_box(character_length.invoke(&args_string_view_ascii))),
|b| {
b.iter(|| {
#[allow(deprecated)] // TODO use invoke_batch
black_box(character_length.invoke(&args_string_view_ascii))
})
},
);

// StringViewArray UTF8
let args_string_view_utf8 = gen_string_array(n_rows, str_len, 0.1, 0.5, true);
c.bench_function(
&format!("character_length_StringViewArray_utf8_str_len_{}", str_len),
|b| b.iter(|| black_box(character_length.invoke(&args_string_view_utf8))),
|b| {
b.iter(|| {
#[allow(deprecated)] // TODO use invoke_batch
black_box(character_length.invoke(&args_string_view_utf8))
})
},
);
}
}
Expand Down
5 changes: 4 additions & 1 deletion datafusion/functions/benches/concat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ fn criterion_benchmark(c: &mut Criterion) {
let args = create_args(size, 32);
let mut group = c.benchmark_group("concat function");
group.bench_function(BenchmarkId::new("concat", size), |b| {
b.iter(|| criterion::black_box(concat().invoke(&args).unwrap()))
b.iter(|| {
#[allow(deprecated)] // TODO use invoke_batch
criterion::black_box(concat().invoke(&args).unwrap())
})
});
group.finish();
}
Expand Down
10 changes: 8 additions & 2 deletions datafusion/functions/benches/cot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,18 @@ fn criterion_benchmark(c: &mut Criterion) {
let f32_array = Arc::new(create_primitive_array::<Float32Type>(size, 0.2));
let f32_args = vec![ColumnarValue::Array(f32_array)];
c.bench_function(&format!("cot f32 array: {}", size), |b| {
b.iter(|| black_box(cot_fn.invoke(&f32_args).unwrap()))
b.iter(|| {
#[allow(deprecated)] // TODO use invoke_batch
black_box(cot_fn.invoke(&f32_args).unwrap())
})
});
let f64_array = Arc::new(create_primitive_array::<Float64Type>(size, 0.2));
let f64_args = vec![ColumnarValue::Array(f64_array)];
c.bench_function(&format!("cot f64 array: {}", size), |b| {
b.iter(|| black_box(cot_fn.invoke(&f64_args).unwrap()))
b.iter(|| {
#[allow(deprecated)] // TODO use invoke_batch
black_box(cot_fn.invoke(&f64_args).unwrap())
})
});
}
}
Expand Down
1 change: 1 addition & 0 deletions datafusion/functions/benches/date_bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ fn criterion_benchmark(c: &mut Criterion) {
let udf = date_bin();

b.iter(|| {
#[allow(deprecated)] // TODO use invoke_batch
black_box(
udf.invoke(&[interval.clone(), timestamps.clone()])
.expect("date_bin should work on valid values"),
Expand Down
12 changes: 10 additions & 2 deletions datafusion/functions/benches/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,30 @@ fn criterion_benchmark(c: &mut Criterion) {
let str_array = Arc::new(create_string_array_with_len::<i32>(size, 0.2, 32));
c.bench_function(&format!("base64_decode/{size}"), |b| {
let method = ColumnarValue::Scalar("base64".into());
#[allow(deprecated)] // TODO use invoke_batch
let encoded = encoding::encode()
.invoke(&[ColumnarValue::Array(str_array.clone()), method.clone()])
.unwrap();

let args = vec![encoded, method];
b.iter(|| black_box(decode.invoke(&args).unwrap()))
b.iter(|| {
#[allow(deprecated)] // TODO use invoke_batch
black_box(decode.invoke(&args).unwrap())
})
});

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

let args = vec![encoded, method];
b.iter(|| black_box(decode.invoke(&args).unwrap()))
b.iter(|| {
#[allow(deprecated)] // TODO use invoke_batch
black_box(decode.invoke(&args).unwrap())
})
});
}
}
Expand Down
10 changes: 8 additions & 2 deletions datafusion/functions/benches/isnan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,18 @@ fn criterion_benchmark(c: &mut Criterion) {
let f32_array = Arc::new(create_primitive_array::<Float32Type>(size, 0.2));
let f32_args = vec![ColumnarValue::Array(f32_array)];
c.bench_function(&format!("isnan f32 array: {}", size), |b| {
b.iter(|| black_box(isnan.invoke(&f32_args).unwrap()))
b.iter(|| {
#[allow(deprecated)] // TODO use invoke_batch
black_box(isnan.invoke(&f32_args).unwrap())
})
});
let f64_array = Arc::new(create_primitive_array::<Float64Type>(size, 0.2));
let f64_args = vec![ColumnarValue::Array(f64_array)];
c.bench_function(&format!("isnan f64 array: {}", size), |b| {
b.iter(|| black_box(isnan.invoke(&f64_args).unwrap()))
b.iter(|| {
#[allow(deprecated)] // TODO use invoke_batch
black_box(isnan.invoke(&f64_args).unwrap())
})
});
}
}
Expand Down
10 changes: 8 additions & 2 deletions datafusion/functions/benches/iszero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,18 @@ fn criterion_benchmark(c: &mut Criterion) {
let f32_array = Arc::new(create_primitive_array::<Float32Type>(size, 0.2));
let f32_args = vec![ColumnarValue::Array(f32_array)];
c.bench_function(&format!("iszero f32 array: {}", size), |b| {
b.iter(|| black_box(iszero.invoke(&f32_args).unwrap()))
b.iter(|| {
#[allow(deprecated)] // TODO use invoke_batch
black_box(iszero.invoke(&f32_args).unwrap())
})
});
let f64_array = Arc::new(create_primitive_array::<Float64Type>(size, 0.2));
let f64_args = vec![ColumnarValue::Array(f64_array)];
c.bench_function(&format!("iszero f64 array: {}", size), |b| {
b.iter(|| black_box(iszero.invoke(&f64_args).unwrap()))
b.iter(|| {
#[allow(deprecated)] // TODO use invoke_batch
black_box(iszero.invoke(&f64_args).unwrap())
})
});
}
}
Expand Down
46 changes: 34 additions & 12 deletions datafusion/functions/benches/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,32 @@ fn criterion_benchmark(c: &mut Criterion) {
for size in [1024, 4096, 8192] {
let args = create_args1(size, 32);
c.bench_function(&format!("lower_all_values_are_ascii: {}", size), |b| {
b.iter(|| black_box(lower.invoke(&args)))
b.iter(|| {
#[allow(deprecated)] // TODO use invoke_batch
black_box(lower.invoke(&args))
})
});

let args = create_args2(size);
c.bench_function(
&format!("lower_the_first_value_is_nonascii: {}", size),
|b| b.iter(|| black_box(lower.invoke(&args))),
|b| {
b.iter(|| {
#[allow(deprecated)] // TODO use invoke_batch
black_box(lower.invoke(&args))
})
},
);

let args = create_args3(size);
c.bench_function(
&format!("lower_the_middle_value_is_nonascii: {}", size),
|b| b.iter(|| black_box(lower.invoke(&args))),
|b| {
b.iter(|| {
#[allow(deprecated)] // TODO use invoke_batch
black_box(lower.invoke(&args))
})
},
);
}

Expand All @@ -151,24 +164,33 @@ fn criterion_benchmark(c: &mut Criterion) {
for &size in &sizes {
let args = create_args4(size, str_len, *null_density, mixed);
c.bench_function(
&format!("lower_all_values_are_ascii_string_views: size: {}, str_len: {}, null_density: {}, mixed: {}",
&format!("lower_all_values_are_ascii_string_views: size: {}, str_len: {}, null_density: {}, mixed: {}",
size, str_len, null_density, mixed),
|b| b.iter(|| black_box(lower.invoke(&args))),
);
|b| b.iter(|| {
#[allow(deprecated)] // TODO use invoke_batch
black_box(lower.invoke(&args))
}),
);

let args = create_args4(size, str_len, *null_density, mixed);
c.bench_function(
&format!("lower_all_values_are_ascii_string_views: size: {}, str_len: {}, null_density: {}, mixed: {}",
&format!("lower_all_values_are_ascii_string_views: size: {}, str_len: {}, null_density: {}, mixed: {}",
size, str_len, null_density, mixed),
|b| b.iter(|| black_box(lower.invoke(&args))),
);
|b| b.iter(|| {
#[allow(deprecated)] // TODO use invoke_batch
black_box(lower.invoke(&args))
}),
);

let args = create_args5(size, 0.1, *null_density);
c.bench_function(
&format!("lower_some_values_are_nonascii_string_views: size: {}, str_len: {}, non_ascii_density: {}, null_density: {}, mixed: {}",
&format!("lower_some_values_are_nonascii_string_views: size: {}, str_len: {}, non_ascii_density: {}, null_density: {}, mixed: {}",
size, str_len, 0.1, null_density, mixed),
|b| b.iter(|| black_box(lower.invoke(&args))),
);
|b| b.iter(|| {
#[allow(deprecated)] // TODO use invoke_batch
black_box(lower.invoke(&args))
}),
);
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion datafusion/functions/benches/ltrim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,12 @@ fn run_with_string_type<M: Measurement>(
format!(
"{string_type} [size={size}, len_before={len}, len_after={remaining_len}]",
),
|b| b.iter(|| black_box(ltrim.invoke(&args))),
|b| {
b.iter(|| {
#[allow(deprecated)] // TODO use invoke_batch
black_box(ltrim.invoke(&args))
})
},
);
}

Expand Down
4 changes: 4 additions & 0 deletions datafusion/functions/benches/make_date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ fn criterion_benchmark(c: &mut Criterion) {
let days = ColumnarValue::Array(Arc::new(days(&mut rng)) as ArrayRef);

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

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

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

b.iter(|| {
#[allow(deprecated)] // TODO use invoke_batch
black_box(
make_date()
.invoke(&[year.clone(), month.clone(), day.clone()])
Expand Down
5 changes: 4 additions & 1 deletion datafusion/functions/benches/nullif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ fn criterion_benchmark(c: &mut Criterion) {
ColumnarValue::Array(array),
];
c.bench_function(&format!("nullif scalar array: {}", size), |b| {
b.iter(|| black_box(nullif.invoke(&args).unwrap()))
b.iter(|| {
#[allow(deprecated)] // TODO use invoke_batch
black_box(nullif.invoke(&args).unwrap())
})
});
}
}
Expand Down
30 changes: 24 additions & 6 deletions datafusion/functions/benches/pad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,26 @@ fn criterion_benchmark(c: &mut Criterion) {

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

let args = create_args::<i64>(size, 32, false);
group.bench_function(BenchmarkId::new("largeutf8 type", size), |b| {
b.iter(|| criterion::black_box(lpad().invoke(&args).unwrap()))
b.iter(|| {
#[allow(deprecated)] // TODO use invoke_batch
criterion::black_box(lpad().invoke(&args).unwrap())
})
});

let args = create_args::<i32>(size, 32, true);
group.bench_function(BenchmarkId::new("stringview type", size), |b| {
b.iter(|| criterion::black_box(lpad().invoke(&args).unwrap()))
b.iter(|| {
#[allow(deprecated)] // TODO use invoke_batch
criterion::black_box(lpad().invoke(&args).unwrap())
})
});

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

let args = create_args::<i32>(size, 32, false);
group.bench_function(BenchmarkId::new("utf8 type", size), |b| {
b.iter(|| criterion::black_box(rpad().invoke(&args).unwrap()))
b.iter(|| {
#[allow(deprecated)] // TODO use invoke_batch
criterion::black_box(rpad().invoke(&args).unwrap())
})
});

let args = create_args::<i64>(size, 32, false);
group.bench_function(BenchmarkId::new("largeutf8 type", size), |b| {
b.iter(|| criterion::black_box(rpad().invoke(&args).unwrap()))
b.iter(|| {
#[allow(deprecated)] // TODO use invoke_batch
criterion::black_box(rpad().invoke(&args).unwrap())
})
});

// rpad for stringview type
let args = create_args::<i32>(size, 32, true);
group.bench_function(BenchmarkId::new("stringview type", size), |b| {
b.iter(|| criterion::black_box(rpad().invoke(&args).unwrap()))
b.iter(|| {
#[allow(deprecated)] // TODO use invoke_batch
criterion::black_box(rpad().invoke(&args).unwrap())
})
});

group.finish();
Expand Down
Loading

0 comments on commit bb26b5c

Please sign in to comment.