-
Notifications
You must be signed in to change notification settings - Fork 3k
Views: Fix SQL view representation field name #7417
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,6 @@ | |
| import java.util.Map; | ||
| import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; | ||
| import org.apache.iceberg.util.JsonUtil; | ||
|
|
||
| class ViewVersionParser { | ||
|
|
@@ -40,24 +39,25 @@ private ViewVersionParser() {} | |
| static void toJson(ViewVersion version, JsonGenerator generator) throws IOException { | ||
| Preconditions.checkArgument(version != null, "Cannot serialize null view version"); | ||
| generator.writeStartObject(); | ||
|
|
||
| generator.writeNumberField(VERSION_ID, version.versionId()); | ||
| generator.writeNumberField(TIMESTAMP_MS, version.timestampMillis()); | ||
|
|
||
| generator.writeObjectFieldStart(SUMMARY); | ||
| generator.writeStringField(OPERATION, version.operation()); | ||
| for (Map.Entry<String, String> summaryEntry : version.summary().entrySet()) { | ||
| if (!summaryEntry.getKey().equals(OPERATION)) { | ||
| generator.writeStringField(summaryEntry.getKey(), summaryEntry.getValue()); | ||
| } | ||
| } | ||
|
|
||
| generator.writeEndObject(); | ||
|
|
||
| generator.writeArrayFieldStart(REPRESENTATIONS); | ||
| for (ViewRepresentation representation : version.representations()) { | ||
| ViewRepresentationParser.toJson(representation, generator); | ||
| } | ||
|
|
||
| generator.writeEndArray(); | ||
|
|
||
| generator.writeEndObject(); | ||
| } | ||
|
|
||
|
|
@@ -80,22 +80,7 @@ static ViewVersion fromJson(JsonNode node) { | |
| long timestamp = JsonUtil.getLong(TIMESTAMP_MS, node); | ||
| Map<String, String> summary = JsonUtil.getStringMap(SUMMARY, node); | ||
| Preconditions.checkArgument( | ||
| summary != null, "Cannot parse view version with missing required field: %s", SUMMARY); | ||
|
|
||
| String operation = null; | ||
| ImmutableMap.Builder<String, String> versionSummary = ImmutableMap.builder(); | ||
| for (Map.Entry<String, String> summaryEntry : summary.entrySet()) { | ||
| if (summaryEntry.getKey().equals(OPERATION)) { | ||
| operation = summaryEntry.getValue(); | ||
| } else { | ||
| versionSummary.put(summaryEntry.getKey(), summaryEntry.getValue()); | ||
| } | ||
| } | ||
|
|
||
| Preconditions.checkArgument( | ||
| operation != null, | ||
| "Cannot parse view version summary with missing required field: %s", | ||
| OPERATION); | ||
| summary.containsKey(OPERATION), "Invalid view version summary, missing %s", OPERATION); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. one issue with this is unfortunately that we're only checking for the existence of @rdblue I have opened #7428 to move the check to |
||
|
|
||
| JsonNode serializedRepresentations = node.get(REPRESENTATIONS); | ||
| ImmutableList.Builder<ViewRepresentation> representations = ImmutableList.builder(); | ||
|
|
@@ -108,8 +93,7 @@ static ViewVersion fromJson(JsonNode node) { | |
| return ImmutableViewVersion.builder() | ||
| .versionId(versionId) | ||
| .timestampMillis(timestamp) | ||
| .summary(versionSummary.build()) | ||
| .operation(operation) | ||
| .summary(summary) | ||
| .representations(representations.build()) | ||
| .build(); | ||
| } | ||
|
|
||
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.
Nice, Derived is way cleaner. We don't need any of the special parsing logic for operation and derived also prevents manually setting the operation field, so there is no ambiguity in which is the real "operation"