Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Xuanwo
Copy link
Member

@Xuanwo Xuanwo commented Oct 12, 2024

Close #663

This PR will implement Decimal from/to bytes represents.

Signed-off-by: Xuanwo <github@xuanwo.io>
Copy link
Contributor

@sdd sdd left a 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 👍🏼

Copy link
Collaborator

@liurenjie1024 liurenjie1024 left a 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!(
Copy link
Collaborator

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?

Copy link
Contributor

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.

Copy link
Member Author

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>?

Copy link
Collaborator

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")
Copy link
Collaborator

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() {
Copy link
Collaborator

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

chenzl25 added a commit to risingwavelabs/iceberg-rust that referenced this pull request Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: Allow reading data type Decimal
3 participants