You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by am...@apache.org on 2024/09/30 16:22:02 UTC
(iceberg) branch main updated: Core: Improve error handling when parsing view representations (#11236)
This is an automated email from the ASF dual-hosted git repository.
amoghj pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg.git
The following commit(s) were added to refs/heads/main by this push:
new 9454927ddb Core: Improve error handling when parsing view representations (#11236)
9454927ddb is described below
commit 9454927ddb62d675d9f78843341a81ff2f3d946f
Author: Eduard Tudenhoefner <et...@gmail.com>
AuthorDate: Mon Sep 30 18:21:56 2024 +0200
Core: Improve error handling when parsing view representations (#11236)
---
.../org/apache/iceberg/view/ViewVersionParser.java | 10 ++++++----
.../org/apache/iceberg/view/TestViewVersionParser.java | 18 ++++++++++++++++++
2 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/core/src/main/java/org/apache/iceberg/view/ViewVersionParser.java b/core/src/main/java/org/apache/iceberg/view/ViewVersionParser.java
index 2645e40d94..06ee3b2648 100644
--- a/core/src/main/java/org/apache/iceberg/view/ViewVersionParser.java
+++ b/core/src/main/java/org/apache/iceberg/view/ViewVersionParser.java
@@ -84,12 +84,14 @@ public class ViewVersionParser {
long timestamp = JsonUtil.getLong(TIMESTAMP_MS, node);
Map<String, String> summary = JsonUtil.getStringMap(SUMMARY, node);
- JsonNode serializedRepresentations = node.get(REPRESENTATIONS);
+ JsonNode serializedRepresentations = JsonUtil.get(REPRESENTATIONS, node);
+ Preconditions.checkArgument(
+ serializedRepresentations.isArray(),
+ "Cannot parse representations from non-array: %s",
+ serializedRepresentations);
ImmutableList.Builder<ViewRepresentation> representations = ImmutableList.builder();
for (JsonNode serializedRepresentation : serializedRepresentations) {
- ViewRepresentation representation =
- ViewRepresentationParser.fromJson(serializedRepresentation);
- representations.add(representation);
+ representations.add(ViewRepresentationParser.fromJson(serializedRepresentation));
}
String defaultCatalog = JsonUtil.getStringOrNull(DEFAULT_CATALOG, node);
diff --git a/core/src/test/java/org/apache/iceberg/view/TestViewVersionParser.java b/core/src/test/java/org/apache/iceberg/view/TestViewVersionParser.java
index 1d115c04c3..a68b99a679 100644
--- a/core/src/test/java/org/apache/iceberg/view/TestViewVersionParser.java
+++ b/core/src/test/java/org/apache/iceberg/view/TestViewVersionParser.java
@@ -129,4 +129,22 @@ public class TestViewVersionParser {
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Cannot parse missing field: default-namespace");
}
+
+ @Test
+ public void invalidRepresentations() {
+ String invalidRepresentations =
+ "{\"version-id\":1, \"timestamp-ms\":12345, \"schema-id\":1, \"summary\":{\"user\":\"some-user\"}, \"representations\": 23, \"default-namespace\":[\"one\",\"two\"]}";
+ assertThatThrownBy(() -> ViewVersionParser.fromJson(invalidRepresentations))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage("Cannot parse representations from non-array: 23");
+ }
+
+ @Test
+ public void missingRepresentations() {
+ String missingRepresentations =
+ "{\"version-id\":1, \"timestamp-ms\":12345, \"schema-id\":1, \"summary\":{\"user\":\"some-user\"}, \"default-namespace\":[\"one\",\"two\"]}";
+ assertThatThrownBy(() -> ViewVersionParser.fromJson(missingRepresentations))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage("Cannot parse missing field: representations");
+ }
}