Skip to content

Commit fc29baa

Browse files
committed
Fix clippy due to UnionFields::new is deprecated
1 parent 206dc33 commit fc29baa

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
@@ -8894,7 +8894,7 @@ mod tests {
88948894
.unwrap(),
88958895
ScalarValue::try_new_null(&DataType::Map(map_field_ref, false)).unwrap(),
88968896
ScalarValue::try_new_null(&DataType::Union(
8897-
UnionFields::new(vec![42], vec![field_ref]),
8897+
UnionFields::try_new(vec![42], vec![field_ref]).unwrap(),
88988898
UnionMode::Dense,
88998899
))
89008900
.unwrap(),
@@ -8997,13 +8997,14 @@ mod tests {
89978997
}
89988998

89998999
// Test union type
9000-
let union_fields = UnionFields::new(
9000+
let union_fields = UnionFields::try_new(
90019001
vec![0, 1],
90029002
vec![
90039003
Field::new("i32", DataType::Int32, false),
90049004
Field::new("f64", DataType::Float64, false),
90059005
],
9006-
);
9006+
)
9007+
.unwrap();
90079008
let union_result = ScalarValue::new_default(&DataType::Union(
90089009
union_fields.clone(),
90099010
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
@@ -1773,18 +1773,19 @@ fn round_trip_datatype() {
17731773
),
17741774
])),
17751775
DataType::Union(
1776-
UnionFields::new(
1776+
UnionFields::try_new(
17771777
vec![7, 5, 3],
17781778
vec![
17791779
Field::new("nullable", DataType::Boolean, false),
17801780
Field::new("name", DataType::Utf8, false),
17811781
Field::new("datatype", DataType::Binary, false),
17821782
],
1783-
),
1783+
)
1784+
.unwrap(),
17841785
UnionMode::Sparse,
17851786
),
17861787
DataType::Union(
1787-
UnionFields::new(
1788+
UnionFields::try_new(
17881789
vec![5, 8, 1],
17891790
vec![
17901791
Field::new("nullable", DataType::Boolean, false),
@@ -1800,7 +1801,8 @@ fn round_trip_datatype() {
18001801
true,
18011802
),
18021803
],
1803-
),
1804+
)
1805+
.unwrap(),
18041806
UnionMode::Dense,
18051807
),
18061808
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)