You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/06/20 07:42:49 UTC

[GitHub] [iceberg] nastra commented on a diff in pull request #5067: API: Support composite types in Accessors

nastra commented on code in PR #5067:
URL: https://github.com/apache/iceberg/pull/5067#discussion_r901348454


##########
api/src/test/java/org/apache/iceberg/TestAccessors.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * Licensed 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;
+
+import java.math.BigDecimal;
+import java.nio.ByteBuffer;
+import java.util.UUID;
+import org.apache.iceberg.TestHelpers.Row;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.types.Type;
+import org.apache.iceberg.types.Types;
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.apache.iceberg.types.Types.NestedField.optional;
+import static org.apache.iceberg.types.Types.NestedField.required;
+
+public class TestAccessors {
+
+  private static Accessor<StructLike> direct(Type type) {
+    Schema schema = new Schema(required(17, "field_" + type.typeId(), type));
+    return schema.accessorForField(17);
+  }
+
+  private static Accessor<StructLike> nested1(Type type) {
+    Schema schema = new Schema(required(11, "struct1", Types.StructType.of(
+        Types.NestedField.required(17, "field_" + type.typeId(), type))));
+    return schema.accessorForField(17);
+  }
+
+  private static Accessor<StructLike> nested2(Type type) {
+    Schema schema = new Schema(required(11, "s", Types.StructType.of(
+        Types.NestedField.required(22, "s2", Types.StructType.of(
+            Types.NestedField.required(17, "field_" + type.typeId(), type))))));
+    return schema.accessorForField(17);
+  }
+
+  private static Accessor<StructLike> nested3(Type type) {
+    Schema schema = new Schema(required(11, "s", Types.StructType.of(
+        Types.NestedField.required(22, "s2", Types.StructType.of(
+            Types.NestedField.required(33, "s3", Types.StructType.of(
+                Types.NestedField.required(17, "field_" + type.typeId(), type))))))));
+    return schema.accessorForField(17);
+  }
+
+  private static Accessor<StructLike> nested3optional(Type type) {
+    Schema schema = new Schema(optional(11, "s", Types.StructType.of(
+        Types.NestedField.optional(22, "s2", Types.StructType.of(
+            Types.NestedField.optional(33, "s3", Types.StructType.of(
+                Types.NestedField.optional(17, "field_" + type.typeId(), type))))))));
+    return schema.accessorForField(17);
+  }
+
+  private static Accessor<StructLike> nested4(Type type) {
+    Schema schema = new Schema(required(11, "s", Types.StructType.of(
+        Types.NestedField.required(22, "s2", Types.StructType.of(
+            Types.NestedField.required(33, "s3", Types.StructType.of(
+                Types.NestedField.required(44, "s4", Types.StructType.of(
+                    Types.NestedField.required(17, "field_" + type.typeId(), type))))))))));
+    return schema.accessorForField(17);
+  }
+
+  private void assertAccessorReturns(Type type, Object value) {
+    Assert.assertEquals(value, direct(type).get(Row.of(value)));
+
+    Assert.assertEquals(value, nested1(type).get(Row.of(Row.of(value))));
+    Assert.assertEquals(value, nested2(type).get(Row.of(Row.of(Row.of(value)))));
+    Assert.assertEquals(value, nested3(type).get(Row.of(Row.of(Row.of(Row.of(value))))));
+    Assert.assertEquals(value, nested4(type).get(Row.of(Row.of(Row.of(Row.of(Row.of(value)))))));
+
+    Assert.assertEquals(value, nested3optional(type).get(Row.of(Row.of(Row.of(Row.of(value))))));
+  }
+
+  @Test
+  public void testBoolean() {
+    assertAccessorReturns(Types.IntegerType.get(), 123);

Review Comment:
   should probably test a boolean here



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org