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

refactor: Removing type infromation in Struct literal. #103

Closed
wants to merge 5 commits into from

Conversation

mobley-trent
Copy link

Closes #96

@@ -554,13 +554,14 @@ impl From<&Literal> for JsonValue {
PrimitiveLiteral::Decimal(_) => todo!(),
},
Literal::Struct(s) => {
Copy link
Author

Choose a reason for hiding this comment

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

Hey @liurenjie1024 how should we design this method ? Since the iterator only return the value instead of the (id, value, name) tuple. I'm having trouble setting up the test for this method.

Copy link
Author

Choose a reason for hiding this comment

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

Update: I used enumerate to account for the id property in the json object. I don't know if this is the correct procedure.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for late reply. Is this method really useful? I think we should expose this method

Copy link
Author

Choose a reason for hiding this comment

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

Isn't the this Struct method supposed to return a hashmap ? The StructType for iceberg requires a NestedField with the id and value.

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 it's supposed to return an json object, and the field names should match struct field names. But this is not feasible without schema. This method is the correct approach I think.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I mean we should remove the total implementation of From<&Literal> for JsonValue. Since we have decided to remove type info for Struct, this method signature is incorrect. The conversion from/to json should delegate to ser/de module.

Copy link
Author

@mobley-trent mobley-trent Nov 25, 2023

Choose a reason for hiding this comment

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

serde_json doesn't seem to have a method to extract the JsonValue from the Literal. This was only possible through From<&Literal> for JsonValue

This line raises a compiler error when I removed From<&Literal> for JsonValue

fn check_json_serde(json: &str, expected_literal: Literal, expected_type: &Type) {
    ...
    let expected_json_value: JsonValue = (&expected_literal).into(); // error raised here

Error:

^^^^ the trait `From<&values::Literal>` is not implemented for `serde_json::Value`

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, after removing this, directly ser/de from json no longer works. The correct way to do this is to ser/de is using the ser/de module, you can see this method as example. It delegates ser/de to serializaiton/deserialization system.

Copy link
Author

@mobley-trent mobley-trent Dec 2, 2023

Choose a reason for hiding this comment

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

So you are saying I should refactor check_json_serde to follow the structure of check_convert_with_avro ?

Also just a reminder, but the code doesn't build when I remove From<&values::Literal> so I don't think removing it entirely will work @liurenjie1024

Copy link
Contributor

@liurenjie1024 liurenjie1024 Dec 4, 2023

Choose a reason for hiding this comment

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

Hi, @mobley-trent Yes, we are planning to delegate conversion between literal values and json values to ser/de module, just like what we did with avro. You're right complete removing From<&values::Literal> will not work before that. I think we can hold on this pr before that the json conversion was finished.

@liurenjie1024
Copy link
Contributor

cc @mobley-trent Could we close this? The issue has been resolve by #120

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.

refactor: Remove type infromation in Struct literal.
2 participants