Skip to content

Commit

Permalink
Implement serialization for ScalarValue::FixedSizeBinary (#3943)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
retikulum and alamb authored Oct 26, 2022
1 parent 97ff345 commit 4e29835
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
6 changes: 6 additions & 0 deletions datafusion/proto/proto/datafusion.proto
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,11 @@ message StructValue {
repeated Field fields = 3;
}

message ScalarFixedSizeBinary{
bytes values = 1;
int32 length = 2;
}

message ScalarValue{
// was PrimitiveScalarType null_value = 19;
reserved 19;
Expand Down Expand Up @@ -808,6 +813,7 @@ message ScalarValue{
int64 time64_value = 30;
IntervalMonthDayNanoValue interval_month_day_nano = 31;
StructValue struct_value = 32;
ScalarFixedSizeBinary fixed_size_binary_value = 34;
}
}

Expand Down
3 changes: 3 additions & 0 deletions datafusion/proto/src/from_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,9 @@ impl TryFrom<&protobuf::ScalarValue> for ScalarValue {

Self::Struct(values, Box::new(fields))
}
Value::FixedSizeBinaryValue(v) => {
Self::FixedSizeBinary(v.length, Some(v.clone().values))
}
})
}
}
Expand Down
6 changes: 6 additions & 0 deletions datafusion/proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,12 @@ mod roundtrip_tests {
Field::new("a", DataType::Boolean, false),
]),
),
ScalarValue::FixedSizeBinary(
b"bar".to_vec().len() as i32,
Some(b"bar".to_vec()),
),
ScalarValue::FixedSizeBinary(0, None),
ScalarValue::FixedSizeBinary(5, None),
];

for test_case in should_pass.into_iter() {
Expand Down
11 changes: 8 additions & 3 deletions datafusion/proto/src/to_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1033,9 +1033,14 @@ impl TryFrom<&ScalarValue> for protobuf::ScalarValue {
Value::LargeBinaryValue(s.to_owned())
})
}
scalar::ScalarValue::FixedSizeBinary(_, _) => Err(Error::General(
"FixedSizeBinary is not yet implemented".to_owned(),
)),
scalar::ScalarValue::FixedSizeBinary(length, val) => {
create_proto_scalar(val, &data_type, |s| {
Value::FixedSizeBinaryValue(protobuf::ScalarFixedSizeBinary {
values: s.to_owned(),
length: *length,
})
})
}

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

0 comments on commit 4e29835

Please sign in to comment.