Skip to content

Commit a7a824a

Browse files
authored
Add support for protobuf serialisation of Arrow Map type (#5359)
* Add protobuf serialisation support for Arrow Map type * Add protobuf serialisation support for Arrow Map type
1 parent cb09142 commit a7a824a

File tree

6 files changed

+163
-4
lines changed

6 files changed

+163
-4
lines changed

datafusion/proto/proto/datafusion.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,11 @@ message Struct{
743743
repeated Field sub_field_types = 1;
744744
}
745745

746+
message Map {
747+
Field field_type = 1;
748+
bool keys_sorted = 2;
749+
}
750+
746751
enum UnionMode{
747752
sparse = 0;
748753
dense = 1;
@@ -894,6 +899,7 @@ message ArrowType{
894899
Struct STRUCT = 28;
895900
Union UNION = 29;
896901
Dictionary DICTIONARY = 30;
902+
Map MAP = 33;
897903
}
898904
}
899905

datafusion/proto/src/generated/pbjson.rs

Lines changed: 123 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

datafusion/proto/src/generated/prost.rs

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

datafusion/proto/src/logical_plan/from_proto.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,12 @@ impl TryFrom<&protobuf::arrow_type::ArrowTypeEnum> for DataType {
351351
let value_datatype = dict.as_ref().value.as_deref().required("value")?;
352352
DataType::Dictionary(Box::new(key_datatype), Box::new(value_datatype))
353353
}
354+
arrow_type::ArrowTypeEnum::Map(map) => {
355+
let field: Field =
356+
map.as_ref().field_type.as_deref().required("field_type")?;
357+
let keys_sorted = map.keys_sorted;
358+
DataType::Map(Box::new(field), keys_sorted)
359+
}
354360
})
355361
}
356362
}

datafusion/proto/src/logical_plan/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2212,6 +2212,17 @@ mod roundtrip_tests {
22122212
4,
22132213
)),
22142214
),
2215+
DataType::Map(
2216+
new_box_field(
2217+
"entries",
2218+
DataType::Struct(vec![
2219+
Field::new("keys", DataType::Utf8, false),
2220+
Field::new("values", DataType::Int32, true),
2221+
]),
2222+
true,
2223+
),
2224+
false,
2225+
),
22152226
];
22162227

22172228
for test_case in test_cases.into_iter() {

datafusion/proto/src/logical_plan/to_proto.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,12 @@ impl TryFrom<&DataType> for protobuf::arrow_type::ArrowTypeEnum {
218218
DataType::Decimal256(_, _) => {
219219
return Err(Error::General("Proto serialization error: The Decimal256 data type is not yet supported".to_owned()))
220220
}
221-
DataType::Map(_, _) => {
222-
return Err(Error::General(
223-
"Proto serialization error: The Map data type is not yet supported".to_owned()
221+
DataType::Map(field, sorted) => {
222+
Self::Map(Box::new(
223+
protobuf::Map {
224+
field_type: Some(Box::new(field.as_ref().try_into()?)),
225+
keys_sorted: *sorted,
226+
}
224227
))
225228
}
226229
DataType::RunEndEncoded(_, _) => {

0 commit comments

Comments
 (0)