Skip to content

Commit

Permalink
add converting from Substrait Struct type
Browse files Browse the repository at this point in the history
  • Loading branch information
Blizzara committed May 22, 2024
1 parent 06fd5d7 commit bd964f8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions datafusion/substrait/src/logical_plan/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,15 @@ pub(crate) fn from_substrait_type(dt: &substrait::proto::Type) -> Result<DataTyp
"Unsupported Substrait type variation {v} of type {s_kind:?}"
),
},
r#type::Kind::Struct(s) => {
let mut fields = vec![];
for (i, f) in s.types.iter().enumerate() {
let field =
Field::new(&format!("c{i}"), from_substrait_type(f)?, true);
fields.push(field);
}
Ok(DataType::Struct(fields.into()))
}
_ => not_impl_err!("Unsupported Substrait type: {s_kind:?}"),
},
_ => not_impl_err!("`None` Substrait kind is not supported"),
Expand Down
7 changes: 7 additions & 0 deletions datafusion/substrait/src/logical_plan/producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2194,6 +2194,13 @@ mod test {
round_trip_type(DataType::LargeList(
Field::new_list_field(DataType::Int32, true).into(),
))?;
round_trip_type(DataType::Struct(
vec![
Field::new("c0", DataType::Int32, true),
Field::new("c1", DataType::Utf8, true),
]
.into(),
))?;

Ok(())
}
Expand Down

0 comments on commit bd964f8

Please sign in to comment.