Skip to content

Commit 4e29835

Browse files
retikulumalamb
andauthored
Implement serialization for ScalarValue::FixedSizeBinary (apache#3943)
* Implement serialization for ScalarValue::FixedSizeBinary * correct test * fix formatting * add none test case for non zero length Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org> * resolve conflict Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
1 parent 97ff345 commit 4e29835

4 files changed

Lines changed: 23 additions & 3 deletions

File tree

datafusion/proto/proto/datafusion.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,11 @@ message StructValue {
770770
repeated Field fields = 3;
771771
}
772772

773+
message ScalarFixedSizeBinary{
774+
bytes values = 1;
775+
int32 length = 2;
776+
}
777+
773778
message ScalarValue{
774779
// was PrimitiveScalarType null_value = 19;
775780
reserved 19;
@@ -808,6 +813,7 @@ message ScalarValue{
808813
int64 time64_value = 30;
809814
IntervalMonthDayNanoValue interval_month_day_nano = 31;
810815
StructValue struct_value = 32;
816+
ScalarFixedSizeBinary fixed_size_binary_value = 34;
811817
}
812818
}
813819

datafusion/proto/src/from_proto.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,9 @@ impl TryFrom<&protobuf::ScalarValue> for ScalarValue {
651651

652652
Self::Struct(values, Box::new(fields))
653653
}
654+
Value::FixedSizeBinaryValue(v) => {
655+
Self::FixedSizeBinary(v.length, Some(v.clone().values))
656+
}
654657
})
655658
}
656659
}

datafusion/proto/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,12 @@ mod roundtrip_tests {
682682
Field::new("a", DataType::Boolean, false),
683683
]),
684684
),
685+
ScalarValue::FixedSizeBinary(
686+
b"bar".to_vec().len() as i32,
687+
Some(b"bar".to_vec()),
688+
),
689+
ScalarValue::FixedSizeBinary(0, None),
690+
ScalarValue::FixedSizeBinary(5, None),
685691
];
686692

687693
for test_case in should_pass.into_iter() {

datafusion/proto/src/to_proto.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,9 +1033,14 @@ impl TryFrom<&ScalarValue> for protobuf::ScalarValue {
10331033
Value::LargeBinaryValue(s.to_owned())
10341034
})
10351035
}
1036-
scalar::ScalarValue::FixedSizeBinary(_, _) => Err(Error::General(
1037-
"FixedSizeBinary is not yet implemented".to_owned(),
1038-
)),
1036+
scalar::ScalarValue::FixedSizeBinary(length, val) => {
1037+
create_proto_scalar(val, &data_type, |s| {
1038+
Value::FixedSizeBinaryValue(protobuf::ScalarFixedSizeBinary {
1039+
values: s.to_owned(),
1040+
length: *length,
1041+
})
1042+
})
1043+
}
10391044

10401045
datafusion::scalar::ScalarValue::Time64(v) => {
10411046
create_proto_scalar(v, &data_type, |v| Value::Time64Value(*v))

0 commit comments

Comments
 (0)