Skip to content

Conversation

@aihuaxu
Copy link
Contributor

@aihuaxu aihuaxu commented Dec 22, 2024

This PR adds the implementation to build a variant for primitive, object and array.

The usage:

  • Build from Json
    VariantBuilder.parseJson(json_string);

  • build a primitive

VariantBuilder builder = new VariantBuilder();
VariantPrimitiveBuilder primBuilder = builder.createPrimitive();
Variant variant = primBuilder.writeNumeric(10).build();

  • build an object
 VariantBuilder builder = new VariantBuilder();
 VariantObjectBuilder objBuilder = builder.startObject();
 objBuilder.writeString("key1", "value1").writeNumeric("key2", 3).endObject();
 Variant variant = builder.build();
  • build an array
 VariantBuilder builder = new VariantBuilder();
 VariantArrayBuilder arrBuilder = builder.createArray();
 arrBuilder.writerNumeric(10).writerNumeric(20).endArray();
 Variant variant = builder.build();

Nested arrays and objects can be supported as well. Please see the test cases for the usage. Compared to build from JSON string, we also support some additional types such as timestamp, date.

Part of: #10392

@github-actions github-actions bot added the core label Dec 22, 2024
@aihuaxu aihuaxu marked this pull request as ready for review December 22, 2024 20:11
@aihuaxu aihuaxu force-pushed the variant-add-writer-impl branch 6 times, most recently from f8f8e8f to d806c66 Compare December 24, 2024 03:54
@aihuaxu aihuaxu force-pushed the variant-add-writer-impl branch from d806c66 to 16210a0 Compare January 6, 2025 22:26
@aihuaxu
Copy link
Contributor Author

aihuaxu commented Jan 6, 2025

@rdblue, @RussellSpitzer Please help review. Thanks.

@aihuaxu aihuaxu force-pushed the variant-add-writer-impl branch from 16210a0 to d4f1d0e Compare January 6, 2025 22:57
Preconditions.checkArgument(
json != null && !json.isEmpty(), "Input JSON string cannot be null or empty.");

try (JsonParser parser = new JsonFactory().createParser(json)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There are existing utilities in JSONUtil for a lot of the boilerplate around parsing and generating JSON. Is there a reason not to use the same approach here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to parse the JSON token by token so we can encode them in binary. Seems we only have the version to parse the JSON string into a full JSONNode and then create the object.

@aihuaxu aihuaxu force-pushed the variant-add-writer-impl branch 2 times, most recently from 9cba102 to 86bf18b Compare February 2, 2025 03:59
@aihuaxu aihuaxu force-pushed the variant-add-writer-impl branch 3 times, most recently from fa34686 to 3ad94d3 Compare February 3, 2025 19:10
@aihuaxu aihuaxu requested a review from rdblue February 3, 2025 19:17
@aihuaxu aihuaxu force-pushed the variant-add-writer-impl branch from 3ad94d3 to 38e6f2f Compare February 3, 2025 19:18
@aihuaxu aihuaxu force-pushed the variant-add-writer-impl branch from 38e6f2f to 6062741 Compare February 10, 2025 17:43
@aihuaxu aihuaxu requested a review from xxubai February 10, 2025 17:45
@aihuaxu aihuaxu force-pushed the variant-add-writer-impl branch from 6062741 to cc91ec0 Compare February 11, 2025 21:07
}

protected void writeNullInternal() {
valueBuffer.writePrimitive(Variants.PhysicalType.NULL, null);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
valueBuffer.writePrimitive(Variants.PhysicalType.NULL, null);
valueBuffer.writePrimitive(PhysicalType.NULL, null);

@github-actions
Copy link

This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions.

@github-actions github-actions bot added the stale label Mar 17, 2025
@github-actions
Copy link

This pull request has been closed due to lack of activity. This is not a judgement on the merit of the PR in any way. It is just a way of keeping the PR queue manageable. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.

@github-actions github-actions bot closed this Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants