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 2019/12/09 01:20:53 UTC

[GitHub] [incubator-iceberg] rdblue commented on a change in pull request #227: ORC column map fix

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

 ##########
 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:
   It looks like these test cases are actually testing `buildOrcProjection` and not schema evolution. I think it would be more clear to put them in a test suite specific to `buildOrcProjection`.
   
   Also, it may help to produce your evolved schema by using the `SchemaUpdate` class. Then you'd be able to write like this:
   
   ```java
   Schema evolvedSchema = new SchemaUpdate(originalSchema, 2)
       .deleteColumn("a")
       .renameColumn("b", "a")
       .addColumn("c", DateType.get())
       .apply();
   ```

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


With regards,
Apache Git Services

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