edgarRd commented on a change in pull request #227: ORC column map fix
URL: https://github.com/apache/incubator-iceberg/pull/227#discussion_r363438198
 
 

 ##########
 File path: orc/src/test/java/org/apache/iceberg/orc/TestORCSchemaUtil.java
 ##########
 @@ -0,0 +1,231 @@
+/*
+ * 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.orc;
+
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.types.Types;
+import org.apache.orc.TypeDescription;
+import org.junit.Test;
+
+import static org.apache.iceberg.AssertHelpers.assertThrows;
+import static org.apache.iceberg.types.Types.NestedField.optional;
+import static org.apache.iceberg.types.Types.NestedField.required;
+import static org.junit.Assert.assertEquals;
+
+public class TestORCSchemaUtil {
+
+  @Test
+  public void testRoundtripConversionPrimitive() {
+    Schema expectedSchema = new Schema(
+        optional(1, "intCol", Types.IntegerType.get()),
+        optional(3, "longCol", Types.LongType.get()),
+        optional(6, "intCol2", Types.IntegerType.get()),
+        optional(20, "intCol3", Types.IntegerType.get()),
+        required(9, "doubleCol", Types.DoubleType.get()),
+        required(10, "uuidCol", Types.UUIDType.get()),
+        optional(2, "booleanCol", Types.BooleanType.get()),
+        optional(21, "fixedCol", Types.FixedType.ofLength(4096)),
+        required(22, "binaryCol", Types.BinaryType.get()),
+        required(23, "stringCol", Types.StringType.get()),
+        required(24, "decimalCol", Types.DecimalType.of(15, 3)),
+        required(25, "floatCol", Types.FloatType.get()),
+        optional(30, "dateCol", Types.DateType.get()),
+        required(32, "timeCol", Types.TimeType.get()),
+        required(34, "timestampCol", Types.TimestampType.withZone())
+    );
+    TypeDescription orcSchema = ORCSchemaUtil.convert(expectedSchema);
+    assertEquals(expectedSchema.asStruct(), 
ORCSchemaUtil.convert(orcSchema).asStruct());
+  }
+
+  @Test
+  public void testRoundtripConversionNested() {
+    Types.StructType leafStructType = Types.StructType.of(
+        optional(6, "leafLongCol", Types.LongType.get()),
+        optional(7, "leafBinaryCol", Types.BinaryType.get())
+    );
+    Types.StructType nestedStructType = Types.StructType.of(
+        optional(4, "longCol", Types.LongType.get()),
+        optional(5, "leafStructCol", leafStructType)
+    );
+    // all fields in expected iceberg schema will be optional since we don't 
have a column mapping
+    Schema expectedSchema = new Schema(
+        optional(1, "intCol", Types.IntegerType.get()),
+        optional(2, "longCol", Types.LongType.get()),
+        optional(3, "nestedStructCol", nestedStructType),
+        optional(8, "intCol3", Types.IntegerType.get()),
+        optional(9, "doubleCol", Types.DoubleType.get()),
+        required(10, "uuidCol", Types.UUIDType.get()),
+        optional(20, "booleanCol", Types.BooleanType.get()),
+        optional(21, "fixedCol", Types.FixedType.ofLength(4096)),
+        required(22, "binaryCol", Types.BinaryType.get()),
+        required(23, "stringCol", Types.StringType.get()),
+        required(24, "decimalCol", Types.DecimalType.of(15, 3)),
+        required(25, "floatCol", Types.FloatType.get()),
+        optional(30, "dateCol", Types.DateType.get()),
+        required(32, "timeCol", Types.TimeType.get()),
+        required(34, "timestampCol", Types.TimestampType.withZone())
+    );
+    TypeDescription orcSchema = ORCSchemaUtil.convert(expectedSchema);
+    assertEquals(expectedSchema.asStruct(), 
ORCSchemaUtil.convert(orcSchema).asStruct());
+  }
+
+  @Test
+  public void testSchemaEvolutionPrimitiveNoOp() {
+    Schema originalSchema = new Schema(
+        optional(1, "a", Types.IntegerType.get()),
+        optional(2, "b", Types.StringType.get())
+    );
+
+    // Original mapping (stored in ORC)
+    TypeDescription orcSchema = ORCSchemaUtil.convert(originalSchema);
+    assertEquals(2, orcSchema.getChildren().size());
+    assertEquals(1, orcSchema.findSubtype("a").getId());
+    assertEquals(TypeDescription.Category.INT, 
orcSchema.findSubtype("a").getCategory());
+    assertEquals(2, orcSchema.findSubtype("b").getId());
+    assertEquals(TypeDescription.Category.STRING, 
orcSchema.findSubtype("b").getCategory());
+  }
+
+  @Test
+  public void testSchemaEvolutionPrimitive() {
 
 Review comment:
   I split these tests into their own test suite for build ORC projection. I 
looked into using `SchemaUpdate` however it is not a public class and seems to 
only be accessible via `Table` with the schema evolution API. I'm not sure I'd 
want to change the access modifier for this class nor create a Table for this 
test (seems overkill) but I'm open to suggestions. Thanks!

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to