Skip to content

Commit 40a6a71

Browse files
committed
Fix clippy due to UnionFields::new is deprecated
1 parent 120d2b0 commit 40a6a71

7 files changed

Lines changed: 32 additions & 17 deletions

File tree

datafusion/common/src/scalar/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8868,7 +8868,7 @@ mod tests {
88688868
.unwrap(),
88698869
ScalarValue::try_new_null(&DataType::Map(map_field_ref, false)).unwrap(),
88708870
ScalarValue::try_new_null(&DataType::Union(
8871-
UnionFields::new(vec![42], vec![field_ref]),
8871+
UnionFields::try_new(vec![42], vec![field_ref]).unwrap(),
88728872
UnionMode::Dense,
88738873
))
88748874
.unwrap(),
@@ -8971,13 +8971,14 @@ mod tests {
89718971
}
89728972

89738973
// Test union type
8974-
let union_fields = UnionFields::new(
8974+
let union_fields = UnionFields::try_new(
89758975
vec![0, 1],
89768976
vec![
89778977
Field::new("i32", DataType::Int32, false),
89788978
Field::new("f64", DataType::Float64, false),
89798979
],
8980-
);
8980+
)
8981+
.unwrap();
89818982
let union_result = ScalarValue::new_default(&DataType::Union(
89828983
union_fields.clone(),
89838984
UnionMode::Sparse,

datafusion/datasource-avro/src/avro_to_arrow/schema.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ fn schema_to_field_with_props(
118118
.map(|s| schema_to_field_with_props(s, None, has_nullable, None))
119119
.collect::<Result<Vec<Field>>>()?;
120120
let type_ids = 0_i8..fields.len() as i8;
121-
DataType::Union(UnionFields::new(type_ids, fields), UnionMode::Dense)
121+
DataType::Union(
122+
UnionFields::try_new(type_ids, fields).unwrap(),
123+
UnionMode::Dense,
124+
)
122125
}
123126
}
124127
AvroSchema::Record(RecordSchema { fields, .. }) => {

datafusion/functions/src/core/union_extract.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,14 @@ mod tests {
189189
fn test_scalar_value() -> Result<()> {
190190
let fun = UnionExtractFun::new();
191191

192-
let fields = UnionFields::new(
192+
let fields = UnionFields::try_new(
193193
vec![1, 3],
194194
vec![
195195
Field::new("str", DataType::Utf8, false),
196196
Field::new("int", DataType::Int32, false),
197197
],
198-
);
198+
)
199+
.unwrap();
199200

200201
let args = vec![
201202
ColumnarValue::Scalar(ScalarValue::Union(

datafusion/physical-plan/src/filter.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,13 +1557,14 @@ mod tests {
15571557
#[test]
15581558
fn test_equivalence_properties_union_type() -> Result<()> {
15591559
let union_type = DataType::Union(
1560-
UnionFields::new(
1560+
UnionFields::try_new(
15611561
vec![0, 1],
15621562
vec![
15631563
Field::new("f1", DataType::Int32, true),
15641564
Field::new("f2", DataType::Utf8, true),
15651565
],
1566-
),
1566+
)
1567+
.unwrap(),
15671568
UnionMode::Sparse,
15681569
);
15691570

datafusion/proto-common/src/from_proto/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,11 @@ impl TryFrom<&protobuf::arrow_type::ArrowTypeEnum> for DataType {
310310
false => union.type_ids.iter().map(|i| *i as i8).collect(),
311311
};
312312

313-
DataType::Union(UnionFields::new(type_ids, union_fields), union_mode)
313+
let union_fields =
314+
UnionFields::try_new(type_ids, union_fields).map_err(|e| {
315+
DataFusionError::from(e).context("Deserializing Union DataType")
316+
})?;
317+
DataType::Union(union_fields, union_mode)
314318
}
315319
arrow_type::ArrowTypeEnum::Dictionary(dict) => {
316320
let key_datatype = dict.as_ref().key.as_deref().required("key")?;
@@ -602,7 +606,9 @@ impl TryFrom<&protobuf::ScalarValue> for ScalarValue {
602606
.collect::<Option<Vec<_>>>();
603607
let fields = fields.ok_or_else(|| Error::required("UnionField"))?;
604608
let fields = parse_proto_fields_to_fields(&fields)?;
605-
let fields = UnionFields::new(ids, fields);
609+
let union_fields = UnionFields::try_new(ids, fields).map_err(|e| {
610+
DataFusionError::from(e).context("Deserializing Union ScalarValue")
611+
})?;
606612
let v_id = val.value_id as i8;
607613
let val = match &val.value {
608614
None => None,
@@ -614,7 +620,7 @@ impl TryFrom<&protobuf::ScalarValue> for ScalarValue {
614620
Some((v_id, Box::new(val)))
615621
}
616622
};
617-
Self::Union(val, fields, mode)
623+
Self::Union(val, union_fields, mode)
618624
}
619625
Value::FixedSizeBinaryValue(v) => {
620626
Self::FixedSizeBinary(v.length, Some(v.clone().values))

datafusion/proto/tests/cases/roundtrip_logical_plan.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,18 +1780,19 @@ fn round_trip_datatype() {
17801780
),
17811781
])),
17821782
DataType::Union(
1783-
UnionFields::new(
1783+
UnionFields::try_new(
17841784
vec![7, 5, 3],
17851785
vec![
17861786
Field::new("nullable", DataType::Boolean, false),
17871787
Field::new("name", DataType::Utf8, false),
17881788
Field::new("datatype", DataType::Binary, false),
17891789
],
1790-
),
1790+
)
1791+
.unwrap(),
17911792
UnionMode::Sparse,
17921793
),
17931794
DataType::Union(
1794-
UnionFields::new(
1795+
UnionFields::try_new(
17951796
vec![5, 8, 1],
17961797
vec![
17971798
Field::new("nullable", DataType::Boolean, false),
@@ -1807,7 +1808,8 @@ fn round_trip_datatype() {
18071808
true,
18081809
),
18091810
],
1810-
),
1811+
)
1812+
.unwrap(),
18111813
UnionMode::Dense,
18121814
),
18131815
DataType::Dictionary(

datafusion/sqllogictest/src/test_context.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,14 +436,15 @@ fn create_example_udf() -> ScalarUDF {
436436

437437
fn register_union_table(ctx: &SessionContext) {
438438
let union = UnionArray::try_new(
439-
UnionFields::new(
439+
UnionFields::try_new(
440440
// typeids: 3 for int, 1 for string
441441
vec![3, 1],
442442
vec![
443443
Field::new("int", DataType::Int32, false),
444444
Field::new("string", DataType::Utf8, false),
445445
],
446-
),
446+
)
447+
.unwrap(),
447448
ScalarBuffer::from(vec![3, 1, 3]),
448449
None,
449450
vec![

0 commit comments

Comments
 (0)