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 2020/07/23 03:15:00 UTC

[GitHub] [iceberg] shardulm94 commented on a change in pull request #1208: ORC: Add name mapping support

shardulm94 commented on a change in pull request #1208:
URL: https://github.com/apache/iceberg/pull/1208#discussion_r459193057



##########
File path: orc/src/test/java/org/apache/iceberg/orc/TestORCSchemaUtil.java
##########
@@ -269,4 +278,68 @@ public void testSkipNonIcebergColumns() {
     );
     assertEquals("Schemas must match.", expectedSchema2.asStruct(), icebergSchema2.asStruct());
   }
+
+  @Test
+  public void testHasIds() {
+    Schema schema = new Schema(
+        optional(1, "data", Types.StructType.of(
+            optional(10, "entries", Types.MapType.ofOptional(11, 12, Types.StringType.get(), Types.DateType.get()))
+        )),
+        optional(2, "intCol", Types.IntegerType.get()),
+        optional(3, "longCol", Types.LongType.get()),
+        optional(4, "listCol", Types.ListType.ofOptional(40, Types.DoubleType.get()))
+    );
+
+    TypeDescription orcSchema = ORCSchemaUtil.removeIds(ORCSchemaUtil.convert(schema));
+    assertFalse("Should not have Ids", ORCSchemaUtil.hasIds(orcSchema));
+
+    TypeDescription map2Col = TypeDescription.createMap(TypeDescription.createString(), TypeDescription.createBinary());
+    map2Col.setAttribute(ICEBERG_ID_ATTRIBUTE, "4");
+    orcSchema.addField("map2Col", map2Col);
+    assertTrue("Should have Ids after adding one type with Id", ORCSchemaUtil.hasIds(orcSchema));
+  }
+
+  @Test
+  public void tetsAssignIdsByNameMapping() {
+    Types.StructType structType = Types.StructType.of(
+        required(0, "id", Types.LongType.get()),
+        optional(1, "list_of_maps",
+            Types.ListType.ofOptional(2, Types.MapType.ofOptional(3, 4,
+                Types.StringType.get(),
+                SUPPORTED_PRIMITIVES))),
+        optional(5, "map_of_lists",
+            Types.MapType.ofOptional(6, 7,
+                Types.StringType.get(),
+                Types.ListType.ofOptional(8, SUPPORTED_PRIMITIVES))),
+        required(9, "list_of_lists",
+            Types.ListType.ofOptional(10, Types.ListType.ofOptional(11, SUPPORTED_PRIMITIVES))),
+        required(12, "map_of_maps",
+            Types.MapType.ofOptional(13, 14,
+                Types.StringType.get(),
+                Types.MapType.ofOptional(15, 16,
+                    Types.StringType.get(),
+                    SUPPORTED_PRIMITIVES))),
+        required(17, "list_of_struct_of_nested_types", Types.ListType.ofOptional(19, Types.StructType.of(
+            Types.NestedField.required(20, "m1", Types.MapType.ofOptional(21, 22,
+                Types.StringType.get(),
+                SUPPORTED_PRIMITIVES)),
+            Types.NestedField.optional(23, "l1", Types.ListType.ofRequired(24, SUPPORTED_PRIMITIVES)),
+            Types.NestedField.required(25, "l2", Types.ListType.ofRequired(26, SUPPORTED_PRIMITIVES)),
+            Types.NestedField.optional(27, "m2", Types.MapType.ofOptional(28, 29,
+                Types.StringType.get(),
+                SUPPORTED_PRIMITIVES))
+        )))
+    );
+
+    Schema schema = new Schema(TypeUtil.assignFreshIds(structType, new AtomicInteger(0)::incrementAndGet)
+        .asStructType().fields());
+
+    NameMapping nameMapping = MappingUtil.create(schema);
+    TypeDescription typeDescriptionWithIds = ORCSchemaUtil.convert(schema);
+    TypeDescription typeDescriptionWithIdsFromNameMapping = ORCSchemaUtil
+        .applyNameMapping(ORCSchemaUtil.removeIds(typeDescriptionWithIds), nameMapping);
+
+    assertTrue("TypeDescription schemas should be equal, not comparing Attributes",
+        typeDescriptionWithIds.equals(typeDescriptionWithIdsFromNameMapping, false /* checkAttributes */));

Review comment:
       If we are not comparing the attributes here, is there any value to adding this assert? Seems like name mapping's effect (assign ids) is not actually being tested in this case. 




----------------------------------------------------------------
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.

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