-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Implement Decimal from/to bytes represents #665
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Xuanwo <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The values in the tests match what I'd expect from converting manually 👍🏼
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Xuanwo for fixing this, generally LGTM! Left some minor points to fix.
PrimitiveLiteral::Int128(_) => todo!(), | ||
PrimitiveLiteral::Int128(val) => { | ||
let PrimitiveType::Decimal { precision, .. } = self.r#type else { | ||
unreachable!( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we return error here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're right @liurenjie1024 . I don't see a way that a malformed Datum
could be created anywhere right now but this may not always be true as the project continues to evolve.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we will change Datum::to_bytes
's return value into Result<ByteBuf>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we will change Datum::to_bytes's return value into Result?
Looks good to me.
// It's required by iceberg spec that we must keep the minimum | ||
// number of bytes for the value | ||
let required_bytes = Type::decimal_required_bytes(precision) | ||
.expect("PrimitiveType must has valid precision") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
@@ -3031,6 +3061,31 @@ mod tests { | |||
check_avro_bytes_serde(bytes, Datum::string("iceberg"), &PrimitiveType::String); | |||
} | |||
|
|||
#[test] | |||
fn avro_bytes_decimal() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we check add more tests for different precision?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
Close #663
This PR will implement Decimal from/to bytes represents.