You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by bl...@apache.org on 2019/09/13 16:49:27 UTC
[incubator-iceberg] branch master updated: Throw exception in
ReassignIds when a field is missing (#438)
This is an automated email from the ASF dual-hosted git repository.
blue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-iceberg.git
The following commit(s) were added to refs/heads/master by this push:
new c554282 Throw exception in ReassignIds when a field is missing (#438)
c554282 is described below
commit c5542826e3267b156591d65c95df221c56ad2dca
Author: Shardul Mahadik <sh...@somaiya.edu>
AuthorDate: Fri Sep 13 09:49:23 2019 -0700
Throw exception in ReassignIds when a field is missing (#438)
---
.../java/org/apache/iceberg/types/ReassignIds.java | 3 ++
.../org/apache/iceberg/types/TestTypeUtil.java | 42 ++++++++++++++++++++++
2 files changed, 45 insertions(+)
diff --git a/api/src/main/java/org/apache/iceberg/types/ReassignIds.java b/api/src/main/java/org/apache/iceberg/types/ReassignIds.java
index 2a73145..1609949 100644
--- a/api/src/main/java/org/apache/iceberg/types/ReassignIds.java
+++ b/api/src/main/java/org/apache/iceberg/types/ReassignIds.java
@@ -73,6 +73,9 @@ class ReassignIds extends TypeUtil.CustomOrderSchemaVisitor<Type> {
Types.StructType sourceStruct = sourceType.asStructType();
Types.NestedField sourceField = sourceStruct.field(field.name());
+ if (sourceField == null) {
+ throw new IllegalArgumentException("Field " + field.name() + " not found in source schema");
+ }
this.sourceType = sourceField.type();
try {
diff --git a/api/src/test/java/org/apache/iceberg/types/TestTypeUtil.java b/api/src/test/java/org/apache/iceberg/types/TestTypeUtil.java
new file mode 100644
index 0000000..1d22e2f
--- /dev/null
+++ b/api/src/test/java/org/apache/iceberg/types/TestTypeUtil.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.iceberg.types;
+
+import org.apache.iceberg.Schema;
+import org.junit.Test;
+
+import static org.apache.iceberg.types.Types.NestedField.required;
+
+
+public class TestTypeUtil {
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testReassignIdsIllegalArgumentException() {
+ Schema schema = new Schema(
+ required(1, "a", Types.IntegerType.get()),
+ required(2, "b", Types.IntegerType.get())
+ );
+ Schema sourceSchema = new Schema(
+ required(1, "a", Types.IntegerType.get())
+ );
+ TypeUtil.reassignIds(schema, sourceSchema);
+ }
+}