Skip to content

Commit 998f534

Browse files
authored
Update 5 crates to rust 2024 edition (#19091)
## Which issue does this PR close? This addresses part of #15804 but does not close it. ## Rationale for this change Now that we are on MSRV 1.88 we can use rust edition 2024, which brings let chains and other nice features. It also improves `unsafe` checking. In order to introduce these changes in slower way instead of one massive PR that is too difficult to manage we are updating a few crates at a time. ## What changes are included in this PR? Updates 2 crates to 2024. - datafusion-functions - datafusion-physical-expr - datafusion-functions-aggregate - datafusion-functions-window - datafusion-physical-expr-adapter ## Are these changes tested? Existing unit tests. There are no functional code changes. ## Are there any user-facing changes? None.
1 parent 3a0064d commit 998f534

File tree

220 files changed

+1417
-1215
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

220 files changed

+1417
-1215
lines changed

datafusion/functions-aggregate/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ description = "Traits and types for logical plans and expressions for DataFusion
2121
keywords = ["datafusion", "logical", "plan", "expressions"]
2222
readme = "README.md"
2323
version = { workspace = true }
24-
edition = { workspace = true }
24+
edition = "2024"
2525
homepage = { workspace = true }
2626
repository = { workspace = true }
2727
license = { workspace = true }

datafusion/functions-aggregate/benches/array_agg.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ use arrow::array::{
2323
PrimitiveArray,
2424
};
2525
use arrow::datatypes::{Field, Int64Type};
26-
use criterion::{criterion_group, criterion_main, Criterion};
26+
use criterion::{Criterion, criterion_group, criterion_main};
2727
use datafusion_expr::Accumulator;
2828
use datafusion_functions_aggregate::array_agg::ArrayAggAccumulator;
2929

3030
use arrow::buffer::OffsetBuffer;
31-
use rand::distr::{Distribution, StandardUniform};
32-
use rand::prelude::StdRng;
3331
use rand::Rng;
3432
use rand::SeedableRng;
33+
use rand::distr::{Distribution, StandardUniform};
34+
use rand::prelude::StdRng;
3535

3636
/// Returns fixed seedable RNG
3737
pub fn seedable_rng() -> StdRng {

datafusion/functions-aggregate/benches/count.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use datafusion_expr::{Accumulator, AggregateUDFImpl, GroupsAccumulator};
3030
use datafusion_functions_aggregate::count::Count;
3131
use datafusion_physical_expr::expressions::col;
3232

33-
use criterion::{criterion_group, criterion_main, Criterion};
33+
use criterion::{Criterion, criterion_group, criterion_main};
3434

3535
fn prepare_group_accumulator() -> Box<dyn GroupsAccumulator> {
3636
let schema = Arc::new(Schema::new(vec![Field::new("f", DataType::Int32, true)]));

datafusion/functions-aggregate/benches/min_max_bytes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ use arrow::{
2929
array::{ArrayRef, StringArray},
3030
datatypes::{DataType, Field, Schema},
3131
};
32-
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
33-
use datafusion_expr::{function::AccumulatorArgs, GroupsAccumulator};
32+
use criterion::{BenchmarkId, Criterion, Throughput, criterion_group, criterion_main};
33+
use datafusion_expr::{GroupsAccumulator, function::AccumulatorArgs};
3434
use datafusion_functions_aggregate::min_max;
3535
use datafusion_physical_expr::expressions::col;
3636

datafusion/functions-aggregate/benches/sum.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ use arrow::array::{ArrayRef, BooleanArray};
2222
use arrow::datatypes::{DataType, Field, Int64Type, Schema};
2323
use arrow::util::bench_util::{create_boolean_array, create_primitive_array};
2424

25-
use datafusion_expr::{function::AccumulatorArgs, AggregateUDFImpl, GroupsAccumulator};
25+
use datafusion_expr::{AggregateUDFImpl, GroupsAccumulator, function::AccumulatorArgs};
2626
use datafusion_functions_aggregate::sum::Sum;
2727
use datafusion_physical_expr::expressions::col;
2828

29-
use criterion::{criterion_group, criterion_main, Criterion};
29+
use criterion::{Criterion, criterion_group, criterion_main};
3030

3131
fn prepare_accumulator(data_type: &DataType) -> Box<dyn GroupsAccumulator> {
3232
let field = Field::new("f", data_type.clone(), true).into();

datafusion/functions-aggregate/src/approx_distinct.rs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ use arrow::array::{
2323
GenericBinaryArray, GenericStringArray, OffsetSizeTrait, PrimitiveArray,
2424
};
2525
use arrow::datatypes::{
26-
ArrowPrimitiveType, Date32Type, Date64Type, FieldRef, Int16Type, Int32Type,
27-
Int64Type, Int8Type, Time32MillisecondType, Time32SecondType, Time64MicrosecondType,
26+
ArrowPrimitiveType, Date32Type, Date64Type, FieldRef, Int8Type, Int16Type, Int32Type,
27+
Int64Type, Time32MillisecondType, Time32SecondType, Time64MicrosecondType,
2828
Time64NanosecondType, TimeUnit, TimestampMicrosecondType, TimestampMillisecondType,
29-
TimestampNanosecondType, TimestampSecondType, UInt16Type, UInt32Type, UInt64Type,
30-
UInt8Type,
29+
TimestampNanosecondType, TimestampSecondType, UInt8Type, UInt16Type, UInt32Type,
30+
UInt64Type,
3131
};
3232
use arrow::{array::ArrayRef, datatypes::DataType, datatypes::Field};
3333
use datafusion_common::ScalarValue;
3434
use datafusion_common::{
35-
downcast_value, internal_datafusion_err, internal_err, not_impl_err, DataFusionError,
36-
Result,
35+
DataFusionError, Result, downcast_value, internal_datafusion_err, internal_err,
36+
not_impl_err,
3737
};
3838
use datafusion_expr::function::{AccumulatorArgs, StateFieldsArgs};
3939
use datafusion_expr::utils::format_state_name;
@@ -328,19 +328,23 @@ impl AggregateUDFImpl for ApproxDistinct {
328328

329329
fn state_fields(&self, args: StateFieldsArgs) -> Result<Vec<FieldRef>> {
330330
if args.input_fields[0].data_type().is_null() {
331-
Ok(vec![Field::new(
332-
format_state_name(args.name, self.name()),
333-
DataType::Null,
334-
true,
335-
)
336-
.into()])
331+
Ok(vec![
332+
Field::new(
333+
format_state_name(args.name, self.name()),
334+
DataType::Null,
335+
true,
336+
)
337+
.into(),
338+
])
337339
} else {
338-
Ok(vec![Field::new(
339-
format_state_name(args.name, "hll_registers"),
340-
DataType::Binary,
341-
false,
342-
)
343-
.into()])
340+
Ok(vec![
341+
Field::new(
342+
format_state_name(args.name, "hll_registers"),
343+
DataType::Binary,
344+
false,
345+
)
346+
.into(),
347+
])
344348
}
345349
}
346350

@@ -395,8 +399,8 @@ impl AggregateUDFImpl for ApproxDistinct {
395399
}
396400
other => {
397401
return not_impl_err!(
398-
"Support for 'approx_distinct' for data type {other} is not implemented"
399-
)
402+
"Support for 'approx_distinct' for data type {other} is not implemented"
403+
);
400404
}
401405
};
402406
Ok(accumulator)

datafusion/functions-aggregate/src/approx_median.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use std::any::Any;
2525
use std::fmt::Debug;
2626
use std::sync::Arc;
2727

28-
use datafusion_common::{not_impl_err, Result};
28+
use datafusion_common::{Result, not_impl_err};
2929
use datafusion_expr::function::{AccumulatorArgs, StateFieldsArgs};
3030
use datafusion_expr::utils::format_state_name;
3131
use datafusion_expr::{
@@ -98,12 +98,14 @@ impl AggregateUDFImpl for ApproxMedian {
9898

9999
fn state_fields(&self, args: StateFieldsArgs) -> Result<Vec<FieldRef>> {
100100
if args.input_fields[0].data_type().is_null() {
101-
Ok(vec![Field::new(
102-
format_state_name(args.name, self.name()),
103-
DataType::Null,
104-
true,
105-
)
106-
.into()])
101+
Ok(vec![
102+
Field::new(
103+
format_state_name(args.name, self.name()),
104+
DataType::Null,
105+
true,
106+
)
107+
.into(),
108+
])
107109
} else {
108110
Ok(vec![
109111
Field::new(format_state_name(args.name, "max_size"), UInt64, false),

datafusion/functions-aggregate/src/approx_percentile_cont.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ use arrow::compute::{filter, is_not_null};
2525
use arrow::datatypes::FieldRef;
2626
use arrow::{
2727
array::{
28-
ArrayRef, Float32Array, Float64Array, Int16Array, Int32Array, Int64Array,
29-
Int8Array, UInt16Array, UInt32Array, UInt64Array, UInt8Array,
28+
ArrayRef, Float32Array, Float64Array, Int8Array, Int16Array, Int32Array,
29+
Int64Array, UInt8Array, UInt16Array, UInt32Array, UInt64Array,
3030
},
3131
datatypes::{DataType, Field},
3232
};
3333
use datafusion_common::{
34-
downcast_value, internal_err, not_impl_err, plan_err, DataFusionError, Result,
35-
ScalarValue,
34+
DataFusionError, Result, ScalarValue, downcast_value, internal_err, not_impl_err,
35+
plan_err,
3636
};
3737
use datafusion_expr::expr::{AggregateFunction, Sort};
3838
use datafusion_expr::function::{AccumulatorArgs, StateFieldsArgs};
@@ -42,7 +42,7 @@ use datafusion_expr::{
4242
Accumulator, AggregateUDFImpl, Documentation, Expr, Signature, TypeSignature,
4343
Volatility,
4444
};
45-
use datafusion_functions_aggregate_common::tdigest::{TDigest, DEFAULT_MAX_SIZE};
45+
use datafusion_functions_aggregate_common::tdigest::{DEFAULT_MAX_SIZE, TDigest};
4646
use datafusion_macros::user_doc;
4747
use datafusion_physical_expr_common::physical_expr::PhysicalExpr;
4848

@@ -190,15 +190,19 @@ impl ApproxPercentileCont {
190190
| DataType::Float32
191191
| DataType::Float64 => {
192192
if let Some(max_size) = tdigest_max_size {
193-
ApproxPercentileAccumulator::new_with_max_size(percentile, data_type.clone(), max_size)
193+
ApproxPercentileAccumulator::new_with_max_size(
194+
percentile,
195+
data_type.clone(),
196+
max_size,
197+
)
194198
} else {
195199
ApproxPercentileAccumulator::new(percentile, data_type.clone())
196200
}
197201
}
198202
other => {
199203
return not_impl_err!(
200204
"Support for 'APPROX_PERCENTILE_CONT' for data type {other} is not implemented"
201-
)
205+
);
202206
}
203207
};
204208

@@ -227,8 +231,8 @@ fn validate_input_max_size_expr(expr: &Arc<dyn PhysicalExpr>) -> Result<usize> {
227231
return plan_err!(
228232
"Tdigest max_size value for 'APPROX_PERCENTILE_CONT' must be UInt > 0 literal (got data type {}).",
229233
sv.data_type()
230-
)
231-
},
234+
);
235+
}
232236
};
233237

234238
Ok(max_size)

datafusion/functions-aggregate/src/approx_percentile_cont_with_weight.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ use arrow::compute::{and, filter, is_not_null};
2525
use arrow::datatypes::FieldRef;
2626
use arrow::{array::ArrayRef, datatypes::DataType};
2727
use datafusion_common::ScalarValue;
28-
use datafusion_common::{not_impl_err, plan_err, Result};
28+
use datafusion_common::{Result, not_impl_err, plan_err};
29+
use datafusion_expr::Volatility::Immutable;
2930
use datafusion_expr::expr::{AggregateFunction, Sort};
3031
use datafusion_expr::function::{AccumulatorArgs, StateFieldsArgs};
3132
use datafusion_expr::type_coercion::aggregates::{INTEGERS, NUMERICS};
32-
use datafusion_expr::Volatility::Immutable;
3333
use datafusion_expr::{
3434
Accumulator, AggregateUDFImpl, Documentation, Expr, Signature, TypeSignature,
3535
};
@@ -184,7 +184,9 @@ impl AggregateUDFImpl for ApproxPercentileContWithWeight {
184184
);
185185
}
186186
if arg_types[2] != DataType::Float64 {
187-
return plan_err!("approx_percentile_cont_with_weight requires float64 percentile input types");
187+
return plan_err!(
188+
"approx_percentile_cont_with_weight requires float64 percentile input types"
189+
);
188190
}
189191
if arg_types.len() == 4 && !arg_types[3].is_integer() {
190192
return plan_err!(

datafusion/functions-aggregate/src/array_agg.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ use std::mem::{size_of, size_of_val, take};
2323
use std::sync::Arc;
2424

2525
use arrow::array::{
26-
new_empty_array, Array, ArrayRef, AsArray, BooleanArray, ListArray, StructArray,
26+
Array, ArrayRef, AsArray, BooleanArray, ListArray, StructArray, new_empty_array,
2727
};
28-
use arrow::compute::{filter, SortOptions};
28+
use arrow::compute::{SortOptions, filter};
2929
use arrow::datatypes::{DataType, Field, FieldRef, Fields};
3030

3131
use datafusion_common::cast::as_list_array;
3232
use datafusion_common::utils::{
33-
compare_rows, get_row_at_idx, take_function_args, SingleRowListArrayBuilder,
33+
SingleRowListArrayBuilder, compare_rows, get_row_at_idx, take_function_args,
3434
};
35-
use datafusion_common::{assert_eq_or_internal_err, exec_err, Result, ScalarValue};
35+
use datafusion_common::{Result, ScalarValue, assert_eq_or_internal_err, exec_err};
3636
use datafusion_expr::function::{AccumulatorArgs, StateFieldsArgs};
3737
use datafusion_expr::utils::format_state_name;
3838
use datafusion_expr::{
@@ -113,22 +113,26 @@ impl AggregateUDFImpl for ArrayAgg {
113113

114114
fn state_fields(&self, args: StateFieldsArgs) -> Result<Vec<FieldRef>> {
115115
if args.is_distinct {
116-
return Ok(vec![Field::new_list(
117-
format_state_name(args.name, "distinct_array_agg"),
116+
return Ok(vec![
117+
Field::new_list(
118+
format_state_name(args.name, "distinct_array_agg"),
119+
// See COMMENTS.md to understand why nullable is set to true
120+
Field::new_list_field(args.input_fields[0].data_type().clone(), true),
121+
true,
122+
)
123+
.into(),
124+
]);
125+
}
126+
127+
let mut fields = vec![
128+
Field::new_list(
129+
format_state_name(args.name, "array_agg"),
118130
// See COMMENTS.md to understand why nullable is set to true
119131
Field::new_list_field(args.input_fields[0].data_type().clone(), true),
120132
true,
121133
)
122-
.into()]);
123-
}
124-
125-
let mut fields = vec![Field::new_list(
126-
format_state_name(args.name, "array_agg"),
127-
// See COMMENTS.md to understand why nullable is set to true
128-
Field::new_list_field(args.input_fields[0].data_type().clone(), true),
129-
true,
130-
)
131-
.into()];
134+
.into(),
135+
];
132136

133137
if args.ordering_fields.is_empty() {
134138
return Ok(fields);
@@ -799,8 +803,8 @@ mod tests {
799803
use arrow::datatypes::{FieldRef, Schema};
800804
use datafusion_common::cast::as_generic_string_array;
801805
use datafusion_common::internal_err;
802-
use datafusion_physical_expr::expressions::Column;
803806
use datafusion_physical_expr::PhysicalExpr;
807+
use datafusion_physical_expr::expressions::Column;
804808
use datafusion_physical_expr_common::sort_expr::PhysicalSortExpr;
805809
use std::sync::Arc;
806810

0 commit comments

Comments
 (0)