rdsr commented on a change in pull request #207: Add external schema mappings 
for files written with name-based schemas #40
URL: https://github.com/apache/incubator-iceberg/pull/207#discussion_r333785084
 
 

 ##########
 File path: core/src/test/java/org/apache/iceberg/avro/TestAvroNameMapping.java
 ##########
 @@ -0,0 +1,261 @@
+/*
+ * 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.avro;
+
+import com.google.common.collect.Lists;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Set;
+import org.apache.avro.SchemaNormalization;
+import org.apache.avro.generic.GenericData;
+import org.apache.iceberg.AssertHelpers;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.mapping.MappedField;
+import org.apache.iceberg.mapping.MappedFields;
+import org.apache.iceberg.mapping.MappingUtil;
+import org.apache.iceberg.mapping.NameMapping;
+import org.apache.iceberg.types.TypeUtil;
+import org.apache.iceberg.types.Types;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestAvroNameMapping extends TestAvroReadProjection {
+  @Override
+  protected GenericData.Record writeAndRead(String desc,
+                                            Schema writeSchema,
+                                            Schema readSchema,
+                                            GenericData.Record inputRecord) 
throws IOException {
+
+    // Use all existing TestAvroReadProjection tests to verify that
+    // we get the same projected (Avro) read schema whether we use
+    // NameMapping together with file schema without field-ids or we
+    // use a file schema having field-ids
+    GenericData.Record record = super.writeAndRead(desc, writeSchema, 
readSchema, inputRecord);
+    org.apache.avro.Schema expected = record.getSchema();
+    org.apache.avro.Schema actual = projectWithNameMapping(writeSchema, 
readSchema, MappingUtil.create(writeSchema));
+    Assert.assertEquals(expected, actual);
+    return record;
+  }
+
+  @Test
+  public void testNameMappingProjections() {
+    Schema fileSchema = new Schema(
+        Types.NestedField.required(0, "id", Types.LongType.get()),
+        Types.NestedField.optional(5, "locations", Types.MapType.ofOptional(6, 
7,
+            Types.StringType.get(),
+            Types.StructType.of(
+                Types.NestedField.required(1, "lat", Types.FloatType.get()),
+                Types.NestedField.required(2, "long", Types.FloatType.get())
+            )
+        )));
+
+    // Table mapping does not project `locations` map
+    NameMapping nameMapping = MappingUtil.create(new Schema(
+        Types.NestedField.required(0, "id", Types.LongType.get())));
+
+    // Table read schema projects `locations` map's value
+    Schema readSchema = new Schema(
+        Types.NestedField.required(0, "id", Types.LongType.get()),
+        Types.NestedField.optional(5, "locations", Types.MapType.ofOptional(6, 
7,
+            Types.StringType.get(),
+            Types.StructType.of(
+                Types.NestedField.required(2, "long", Types.FloatType.get())
+            )
+        )));
+
+    check(fileSchema, readSchema, nameMapping);
 
 Review comment:
   > This test case, for example, will project null values for all of the 
locations map
   
   ...
   
   > In this case, that locations is null.
   
   Doesn't it depend upon the file schema? The `locations` field is optional in 
the file schema. If the file has data for the `locations` column it will be 
returned, since the read/projected schema has the column projected.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

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

Reply via email to