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/02/14 17:59:50 UTC
[GitHub] [iceberg] haizhou-zhao opened a new pull request #4120: Schema projection fix for list and map
haizhou-zhao opened a new pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120
https://github.com/apache/iceberg/issues/4072
Purpose: Keeping the ID properties for list and map node when projecting
@russell-spitzer
--
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
[GitHub] [iceberg] haizhou-zhao commented on a change in pull request #4120: Avro: Fix BuildAvroProjection list and map handling to preserve field IDs
Posted by GitBox <gi...@apache.org>.
haizhou-zhao commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r806351900
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,23 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ /**
+ * @param schema an Avro Schema
Review comment:
I tried to follow some examples I saw under the [Catalog.class](https://github.com/apache/iceberg/blob/master/api/src/main/java/org/apache/iceberg/catalog/Catalog.java#L57), basically, a general description, then followed by `param`, `return`, `throws`. Let me know if I'm missing some components in this java doc.
--
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
[GitHub] [iceberg] haizhou-zhao commented on a change in pull request #4120: Avro: Fix BuildAvroProjection list and map handling to preserve field IDs
Posted by GitBox <gi...@apache.org>.
haizhou-zhao commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r806350000
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,23 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ /**
+ * @param schema an Avro Schema
+ * @return true/false based on whether any of the nodes in the provided schema is missing an
+ * ID property recognizable by Iceberg core API. To have an ID recognizable by Iceberg core API:
+ * <ul>
+ * <li>a field node under struct (record) schema should have {@link FIELD_ID_PROP} property
+ * <li>an element node under list (array) schema should have {@link ELEMENT_ID_PROP} property
+ * <li>a pair of key and value node under map schema should have {@link KEY_ID_PROP} and
+ * {@link VALUE_ID_PROP} respectively
+ * <li>a primitive node is not assigned any ID related properties
+ * </ul>
Review comment:
Moved out of return section and before `param` or `return` in a general description.
--
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
[GitHub] [iceberg] rdblue commented on a change in pull request #4120: Avro: Fix BuildAvroProjection list and map handling to preserve field IDs
Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r806315422
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,23 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ /**
+ * @param schema an Avro Schema
+ * @return true/false based on whether any of the nodes in the provided schema is missing an
+ * ID property recognizable by Iceberg core API. To have an ID recognizable by Iceberg core API:
+ * <ul>
+ * <li>a field node under struct (record) schema should have {@link FIELD_ID_PROP} property
+ * <li>an element node under list (array) schema should have {@link ELEMENT_ID_PROP} property
+ * <li>a pair of key and value node under map schema should have {@link KEY_ID_PROP} and
+ * {@link VALUE_ID_PROP} respectively
+ * <li>a primitive node is not assigned any ID related properties
+ * </ul>
+ * @implNote see {@link MissingIds} for more details
Review comment:
This is an internal class, so it shouldn't be referenced in Javadoc. Anything that is relevant should be noted here since this is the public facing part.
--
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
[GitHub] [iceberg] rdblue commented on a change in pull request #4120: Avro: Fix BuildAvroProjection list and map handling to preserve field IDs
Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r806315554
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,23 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ /**
+ * @param schema an Avro Schema
Review comment:
Can you add a description like the other methods have?
--
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
[GitHub] [iceberg] haizhou-zhao commented on a change in pull request #4120: Avro: Fix BuildAvroProjection list and map handling to preserve field IDs
Posted by GitBox <gi...@apache.org>.
haizhou-zhao commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r808299844
##########
File path: core/src/test/java/org/apache/iceberg/avro/TestBuildAvroProjection.java
##########
@@ -0,0 +1,244 @@
+/*
+ * 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 java.util.Collections;
+import java.util.function.Supplier;
+import org.apache.avro.SchemaBuilder;
+import org.apache.iceberg.types.Type;
+import org.apache.iceberg.types.Types;
+import org.junit.Test;
+
+import static org.apache.iceberg.types.Types.NestedField.optional;
+import static org.junit.Assert.assertEquals;
+
+public class TestBuildAvroProjection {
+
+ @Test
+ public void projectArrayWithElementSchemaUnchanged() {
+
+ final Type icebergType = Types.ListType.ofRequired(0,
+ Types.StructType.of(
+ optional(1, "int1", Types.IntegerType.get()),
+ optional(2, "string1", Types.StringType.get())
+ )
+ );
+
+ final org.apache.avro.Schema expected = SchemaBuilder.array().prop(AvroSchemaUtil.ELEMENT_ID_PROP, "0")
+ .items(
+ SchemaBuilder.record("elem").namespace("unit.test").fields()
+ .name("int1").prop(AvroSchemaUtil.FIELD_ID_PROP, "1").type().nullable().intType().noDefault()
+ .name("string1").prop(AvroSchemaUtil.FIELD_ID_PROP, "2").type().nullable().stringType().noDefault()
+ .endRecord());
+
+ final BuildAvroProjection testSubject = new BuildAvroProjection(icebergType, Collections.emptyMap());
+
+ final Supplier<org.apache.avro.Schema> supplier = expected::getElementType;
+
+ final org.apache.avro.Schema actual = testSubject.array(expected, supplier);
+
+ assertEquals(expected, actual);
+ assertEquals(0, Integer.valueOf(actual.getProp(AvroSchemaUtil.ELEMENT_ID_PROP)).intValue());
+ }
+
+ @Test
+ public void projectArrayWithExtraFieldInElementSchema() {
+
+ final Type icebergType = Types.ListType.ofRequired(0,
+ Types.StructType.of(
+ optional(1, "int1", Types.IntegerType.get()),
+ optional(2, "string1", Types.StringType.get())
+ )
+ );
+
+ final org.apache.avro.Schema extraField = SchemaBuilder.array().prop(AvroSchemaUtil.ELEMENT_ID_PROP, "0")
+ .items(
+ SchemaBuilder.record("elem").namespace("unit.test").fields()
+ .name("int1").prop(AvroSchemaUtil.FIELD_ID_PROP, "1").type().nullable().intType().noDefault()
+ .name("string1").prop(AvroSchemaUtil.FIELD_ID_PROP, "2").type().nullable().stringType().noDefault()
+ .name("float1").prop(AvroSchemaUtil.FIELD_ID_PROP, "3").type().nullable().floatType().noDefault()
+ .endRecord());
+
+ // once projected onto iceberg schema, the avro schema will lose the extra float field
+ final org.apache.avro.Schema expected = SchemaBuilder.array().prop(AvroSchemaUtil.ELEMENT_ID_PROP, "0")
+ .items(
+ SchemaBuilder.record("elem").namespace("unit.test").fields()
+ .name("int1").prop(AvroSchemaUtil.FIELD_ID_PROP, "1").type().nullable().intType().noDefault()
+ .name("string1").prop(AvroSchemaUtil.FIELD_ID_PROP, "2").type().nullable().stringType().noDefault()
+ .endRecord());
+
+ final BuildAvroProjection testSubject = new BuildAvroProjection(icebergType, Collections.emptyMap());
+
+ final Supplier<org.apache.avro.Schema> supplier = expected::getElementType;
+
+ final org.apache.avro.Schema actual = testSubject.array(extraField, supplier);
+
+ assertEquals(expected, actual);
+ assertEquals(0, Integer.valueOf(actual.getProp(AvroSchemaUtil.ELEMENT_ID_PROP)).intValue());
+ }
+
+ @Test
+ public void projectArrayWithLessFieldInElementSchema() {
+
+ final Type icebergType = Types.ListType.ofRequired(0,
+ Types.StructType.of(
+ optional(1, "int1", Types.IntegerType.get()),
+ optional(2, "string1", Types.StringType.get())
+ )
+ );
+
+ final org.apache.avro.Schema lessField = SchemaBuilder.array().prop(AvroSchemaUtil.ELEMENT_ID_PROP, "0")
+ .items(
+ SchemaBuilder.record("elem").namespace("unit.test").fields()
+ .name("int1").prop(AvroSchemaUtil.FIELD_ID_PROP, "1").type().nullable().intType().noDefault()
+ .endRecord());
+
+ // once projected onto iceberg schema, the avro schema will have an extra string column
+ final org.apache.avro.Schema expected = SchemaBuilder.array().prop(AvroSchemaUtil.ELEMENT_ID_PROP, "0")
+ .items(
+ SchemaBuilder.record("elem").namespace("unit.test").fields()
+ .name("int1").prop(AvroSchemaUtil.FIELD_ID_PROP, "1").type().nullable().intType().noDefault()
+ .name("string1_r").prop(AvroSchemaUtil.FIELD_ID_PROP, "2").type().nullable().stringType().noDefault()
+ .endRecord());
+
+ final BuildAvroProjection testSubject = new BuildAvroProjection(icebergType, Collections.emptyMap());
+
+ final Supplier<org.apache.avro.Schema> supplier = expected::getElementType;
+
+ final org.apache.avro.Schema actual = testSubject.array(lessField, supplier);
+
+ assertEquals(expected, actual);
+ assertEquals(0, Integer.valueOf(actual.getProp(AvroSchemaUtil.ELEMENT_ID_PROP)).intValue());
+ }
+
+ @Test
+ public void projectMapWithValueSchemaUnchanged() {
+
+ final Type icebergType = Types.MapType.ofRequired(0, 1,
+ Types.StringType.get(),
+ Types.StructType.of(
+ optional(2, "int1", Types.IntegerType.get()),
+ optional(3, "string1", Types.StringType.get())
+ )
+ );
+
+ final org.apache.avro.Schema expected = SchemaBuilder.map()
+ .prop(AvroSchemaUtil.KEY_ID_PROP, "0")
+ .prop(AvroSchemaUtil.VALUE_ID_PROP, "1")
+ .values(
+ SchemaBuilder.record("value").namespace("unit.test").fields()
+ .name("int1").prop(AvroSchemaUtil.FIELD_ID_PROP, "1").type().nullable().intType().noDefault()
+ .name("string1").prop(AvroSchemaUtil.FIELD_ID_PROP, "2").type().nullable().stringType().noDefault()
+ .endRecord());
+
+ final BuildAvroProjection testSubject = new BuildAvroProjection(icebergType, Collections.emptyMap());
+
+ final Supplier<org.apache.avro.Schema> supplier = expected::getValueType;
+
+ final org.apache.avro.Schema actual = testSubject.map(expected, supplier);
+
+ assertEquals(expected, actual);
+ assertEquals(0, Integer.valueOf(actual.getProp(AvroSchemaUtil.KEY_ID_PROP)).intValue());
+ assertEquals(1, Integer.valueOf(actual.getProp(AvroSchemaUtil.VALUE_ID_PROP)).intValue());
+ }
+
+ @Test
+ public void projectMapWithExtraFieldInValueSchema() {
+
+ final Type icebergType = Types.MapType.ofRequired(0, 1,
+ Types.StringType.get(),
+ Types.StructType.of(
+ optional(2, "int1", Types.IntegerType.get()),
+ optional(3, "string1", Types.StringType.get())
+ )
+ );
+
+ final org.apache.avro.Schema extraField = SchemaBuilder.map()
+ .prop(AvroSchemaUtil.KEY_ID_PROP, "0")
+ .prop(AvroSchemaUtil.VALUE_ID_PROP, "1")
+ .values(
+ SchemaBuilder.record("value").namespace("unit.test").fields()
+ .name("int1").prop(AvroSchemaUtil.FIELD_ID_PROP, "1").type().nullable().intType().noDefault()
+ .name("string1").prop(AvroSchemaUtil.FIELD_ID_PROP, "2").type().nullable().stringType().noDefault()
+ .name("float1").prop(AvroSchemaUtil.FIELD_ID_PROP, "3").type().nullable().floatType().noDefault()
+ .endRecord());
+
+ // once projected onto iceberg schema, the avro schema will lose the extra float field
+ final org.apache.avro.Schema expected = SchemaBuilder.map()
+ .prop(AvroSchemaUtil.KEY_ID_PROP, "0")
+ .prop(AvroSchemaUtil.VALUE_ID_PROP, "1")
+ .values(
+ SchemaBuilder.record("value").namespace("unit.test").fields()
+ .name("int1").prop(AvroSchemaUtil.FIELD_ID_PROP, "1").type().nullable().intType().noDefault()
+ .name("string1").prop(AvroSchemaUtil.FIELD_ID_PROP, "2").type().nullable().stringType().noDefault()
+ .endRecord());
+
+ final BuildAvroProjection testSubject = new BuildAvroProjection(icebergType, Collections.emptyMap());
+
+ final Supplier<org.apache.avro.Schema> supplier = expected::getValueType;
+
+ final org.apache.avro.Schema actual = testSubject.map(extraField, supplier);
+
+ assertEquals(expected, actual);
+ assertEquals(0, Integer.valueOf(actual.getProp(AvroSchemaUtil.KEY_ID_PROP)).intValue());
Review comment:
Added message for all asserts added.
--
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
[GitHub] [iceberg] haizhou-zhao commented on a change in pull request #4120: Avro: Fix BuildAvroProjection list and map handling to preserve field IDs
Posted by GitBox <gi...@apache.org>.
haizhou-zhao commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r808266934
##########
File path: core/src/main/java/org/apache/iceberg/avro/MissingIds.java
##########
@@ -0,0 +1,80 @@
+/*
+ * 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 java.util.List;
+import java.util.function.Supplier;
+import org.apache.avro.Schema;
+
+/**
+ * Returns true once the first node is found with ID property missing. Reverse of {@link HasIds}
+ * <p>
+ * Note: To use {@link AvroSchemaUtil#toIceberg(Schema)} on an avro schema, the avro schema need to be either
+ * have IDs on every node or not have IDs at all. Invoke {@link AvroSchemaUtil#hasIds(Schema)} only proves
+ * that the schema has at least one ID, and not sufficient condition for invoking
+ * {@link AvroSchemaUtil#toIceberg(Schema)} on the schema.
+ */
+class MissingIds extends AvroCustomOrderSchemaVisitor<Boolean, Boolean> {
+ @Override
+ public Boolean record(Schema record, List<String> names, Iterable<Boolean> fields) {
+ for (Boolean field : fields) {
+ if (field) {
+ return true;
Review comment:
No prob, I can switch to use guava's `any`, if we don't see style differences between this class and `HasIds` as problem. I can also change things for `HasIds` as well if you think that's proper.
--
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
[GitHub] [iceberg] rdblue commented on a change in pull request #4120: Avro: Fix BuildAvroProjection list and map handling to preserve field IDs
Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r807017036
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,25 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ /**
+ * Check if any of the nodes in a given avro schema is missing an ID recognizable by Iceberg core API
+ *
Review comment:
To separate paragraphs in Javadoc, add `<p>` to this line. No need for a closing paragraph tag.
--
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
[GitHub] [iceberg] rdblue merged pull request #4120: Avro: Fix BuildAvroProjection list and map handling to preserve field IDs
Posted by GitBox <gi...@apache.org>.
rdblue merged pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120
--
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
[GitHub] [iceberg] rdblue commented on a change in pull request #4120: Schema projection fix for list and map
Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r806219718
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -357,6 +361,26 @@ static Schema copyRecord(Schema record, List<Schema.Field> newFields, String new
return copy;
}
+ static Schema copyArray(Schema array, Schema elementSchema) {
+ Preconditions.checkArgument(array.getType() == org.apache.avro.Schema.Type.ARRAY,
+ "Cannot invoke copyArray on non array schema");
+ Schema copy = Schema.createArray(elementSchema);
+ for (Map.Entry<String, Object> prop : array.getObjectProps().entrySet()) {
+ copy.addProp(prop.getKey(), prop.getValue());
+ }
+ return copy;
+ }
+
+ static Schema copyMap(Schema map, Schema valueSchema) {
+ Preconditions.checkArgument(map.getType() == org.apache.avro.Schema.Type.MAP,
+ "Cannot invoke copyMap on non map schema");
Review comment:
I think this should include the problem schema for debugging.
--
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
[GitHub] [iceberg] haizhou-zhao commented on a change in pull request #4120: Avro: Fix BuildAvroProjection list and map handling to preserve field IDs
Posted by GitBox <gi...@apache.org>.
haizhou-zhao commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r806351900
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,23 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ /**
+ * @param schema an Avro Schema
Review comment:
I tried to follow some example I saw under the [Catalog.class](https://github.com/apache/iceberg/blob/master/api/src/main/java/org/apache/iceberg/catalog/Catalog.java#L57), basically, a general description, then followed by `param`, `return`, `throws`. Let me know if I'm missing some components in this java doc.
--
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
[GitHub] [iceberg] haizhou-zhao commented on a change in pull request #4120: Avro: Fix BuildAvroProjection list and map handling to preserve field IDs
Posted by GitBox <gi...@apache.org>.
haizhou-zhao commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r807097100
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,25 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ /**
+ * Check if any of the nodes in a given avro schema is missing an ID recognizable by Iceberg core API
+ *
Review comment:
Added
--
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
[GitHub] [iceberg] rdblue commented on a change in pull request #4120: Avro: Fix BuildAvroProjection list and map handling to preserve field IDs
Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r807017581
##########
File path: core/src/main/java/org/apache/iceberg/avro/MissingIds.java
##########
@@ -0,0 +1,80 @@
+/*
+ * 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 java.util.List;
+import java.util.function.Supplier;
+import org.apache.avro.Schema;
+
+/**
+ * Returns true once the first node is found with ID property missing. Reverse of {@link HasIds}
+ * <p>
+ * Note: To use {@link AvroSchemaUtil#toIceberg(Schema)} on an avro schema, the avro schema need to be either
+ * have IDs on every node or not have IDs at all. Invoke {@link AvroSchemaUtil#hasIds(Schema)} only proves
+ * that the schema has at least one ID, and not sufficient condition for invoking
+ * {@link AvroSchemaUtil#toIceberg(Schema)} on the schema.
+ */
+public class MissingIds extends AvroCustomOrderSchemaVisitor<Boolean, Boolean> {
Review comment:
This can be package-private right?
--
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
[GitHub] [iceberg] rdblue commented on a change in pull request #4120: Avro: Fix BuildAvroProjection list and map handling to preserve field IDs
Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r807016714
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,25 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ /**
+ * Check if any of the nodes in a given avro schema is missing an ID recognizable by Iceberg core API
Review comment:
This is the Iceberg core API, so it doesn't make sense to refer to it as something else. You can just say "Check if the schema is missing any ID properties." And below, you can clarify which IDs are considered.
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,25 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ /**
+ * Check if any of the nodes in a given avro schema is missing an ID recognizable by Iceberg core API
+ *
Review comment:
To separate paragraphs in Javadoc, add `<p>` to this line. No need for closing tags.
--
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
[GitHub] [iceberg] rdblue commented on a change in pull request #4120: Schema projection fix for list and map
Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r806222904
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -357,6 +361,26 @@ static Schema copyRecord(Schema record, List<Schema.Field> newFields, String new
return copy;
}
+ static Schema copyArray(Schema array, Schema elementSchema) {
Review comment:
I don't think that `copy` is quite the correct verb here because this is not actually copying the array. It is replacing the element. What about `replaceElement` and `replaceValue`?
--
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
[GitHub] [iceberg] haizhou-zhao commented on a change in pull request #4120: Avro: Fix BuildAvroProjection list and map handling to preserve field IDs
Posted by GitBox <gi...@apache.org>.
haizhou-zhao commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r807096737
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,23 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ /**
+ * @param schema an Avro Schema
+ * @return true/false based on whether any of the nodes in the provided schema is missing an
+ * ID property recognizable by Iceberg core API. To have an ID recognizable by Iceberg core API:
+ * <ul>
+ * <li>a field node under struct (record) schema should have {@link FIELD_ID_PROP} property
+ * <li>an element node under list (array) schema should have {@link ELEMENT_ID_PROP} property
+ * <li>a pair of key and value node under map schema should have {@link KEY_ID_PROP} and
+ * {@link VALUE_ID_PROP} respectively
+ * <li>a primitive node is not assigned any ID related properties
+ * </ul>
+ * @implNote see {@link MissingIds} for more details
Review comment:
removed `public`
--
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
[GitHub] [iceberg] rdblue commented on a change in pull request #4120: Avro: Fix BuildAvroProjection list and map handling to preserve field IDs
Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r806316193
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,23 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ /**
+ * @param schema an Avro Schema
+ * @return true/false based on whether any of the nodes in the provided schema is missing an
+ * ID property recognizable by Iceberg core API. To have an ID recognizable by Iceberg core API:
+ * <ul>
+ * <li>a field node under struct (record) schema should have {@link FIELD_ID_PROP} property
+ * <li>an element node under list (array) schema should have {@link ELEMENT_ID_PROP} property
+ * <li>a pair of key and value node under map schema should have {@link KEY_ID_PROP} and
+ * {@link VALUE_ID_PROP} respectively
+ * <li>a primitive node is not assigned any ID related properties
+ * </ul>
Review comment:
This long content is better suited for the main description, rather than in the return. `@return` should be a short summary, like "@return true if the schema has at least one field ID property, false otherwise"
The details about what "field ID property" could be should be above.
--
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
[GitHub] [iceberg] rdblue commented on a change in pull request #4120: Schema projection fix for list and map
Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r806222195
##########
File path: core/src/main/java/org/apache/iceberg/avro/BuildAvroProjection.java
##########
@@ -49,6 +49,11 @@
this.current = expectedSchema.asStruct();
}
+ BuildAvroProjection(org.apache.iceberg.types.Type expectedType, Map<String, String> renames) {
Review comment:
Is this for testing? What guarantees that the expected type is correct?
--
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
[GitHub] [iceberg] haizhou-zhao commented on a change in pull request #4120: Schema projection fix for list and map
Posted by GitBox <gi...@apache.org>.
haizhou-zhao commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r806294795
##########
File path: core/src/main/java/org/apache/iceberg/avro/BuildAvroProjection.java
##########
@@ -49,6 +49,11 @@
this.current = expectedSchema.asStruct();
}
+ BuildAvroProjection(org.apache.iceberg.types.Type expectedType, Map<String, String> renames) {
Review comment:
This is for testing only.
--
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
[GitHub] [iceberg] szehon-ho commented on a change in pull request #4120: Avro: Fix BuildAvroProjection list and map handling to preserve field IDs
Posted by GitBox <gi...@apache.org>.
szehon-ho commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r808273960
##########
File path: core/src/main/java/org/apache/iceberg/avro/MissingIds.java
##########
@@ -0,0 +1,80 @@
+/*
+ * 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 java.util.List;
+import java.util.function.Supplier;
+import org.apache.avro.Schema;
+
+/**
+ * Returns true once the first node is found with ID property missing. Reverse of {@link HasIds}
+ * <p>
+ * Note: To use {@link AvroSchemaUtil#toIceberg(Schema)} on an avro schema, the avro schema need to be either
+ * have IDs on every node or not have IDs at all. Invoke {@link AvroSchemaUtil#hasIds(Schema)} only proves
+ * that the schema has at least one ID, and not sufficient condition for invoking
+ * {@link AvroSchemaUtil#toIceberg(Schema)} on the schema.
+ */
+class MissingIds extends AvroCustomOrderSchemaVisitor<Boolean, Boolean> {
+ @Override
+ public Boolean record(Schema record, List<String> names, Iterable<Boolean> fields) {
+ for (Boolean field : fields) {
+ if (field) {
+ return true;
Review comment:
Yea no worries, don't want to make you do unnecessary changes :). I'll leave to @rdblue if there was any initial reason not to use guava 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
[GitHub] [iceberg] haizhou-zhao commented on a change in pull request #4120: Avro: Fix BuildAvroProjection list and map handling to preserve field IDs
Posted by GitBox <gi...@apache.org>.
haizhou-zhao commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r807441358
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,25 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ /**
+ * Check if any of the nodes in a given avro schema is missing an ID
+ * <p>
+ * To have an ID recognizable by Iceberg core API:
Review comment:
Ack, removed.
--
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
[GitHub] [iceberg] haizhou-zhao commented on a change in pull request #4120: Schema projection fix for list and map
Posted by GitBox <gi...@apache.org>.
haizhou-zhao commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r806294592
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,10 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ static boolean missingIds(Schema schema) {
Review comment:
Added.
--
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
[GitHub] [iceberg] haizhou-zhao commented on a change in pull request #4120: Avro: Fix BuildAvroProjection list and map handling to preserve field IDs
Posted by GitBox <gi...@apache.org>.
haizhou-zhao commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r806350186
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,23 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ /**
+ * @param schema an Avro Schema
+ * @return true/false based on whether any of the nodes in the provided schema is missing an
+ * ID property recognizable by Iceberg core API. To have an ID recognizable by Iceberg core API:
+ * <ul>
+ * <li>a field node under struct (record) schema should have {@link FIELD_ID_PROP} property
+ * <li>an element node under list (array) schema should have {@link ELEMENT_ID_PROP} property
+ * <li>a pair of key and value node under map schema should have {@link KEY_ID_PROP} and
+ * {@link VALUE_ID_PROP} respectively
+ * <li>a primitive node is not assigned any ID related properties
+ * </ul>
+ * @implNote see {@link MissingIds} for more details
Review comment:
Make sense, removed.
--
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
[GitHub] [iceberg] rdblue commented on a change in pull request #4120: Avro: Fix BuildAvroProjection list and map handling to preserve field IDs
Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r807105658
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,25 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ /**
+ * Check if any of the nodes in a given avro schema is missing an ID
+ * <p>
+ * To have an ID recognizable by Iceberg core API:
Review comment:
This still references the "Iceberg core API"
--
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
[GitHub] [iceberg] haizhou-zhao commented on a change in pull request #4120: Schema projection fix for list and map
Posted by GitBox <gi...@apache.org>.
haizhou-zhao commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r806294592
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,10 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ static boolean missingIds(Schema schema) {
Review comment:
Added.
##########
File path: core/src/main/java/org/apache/iceberg/avro/BuildAvroProjection.java
##########
@@ -49,6 +49,11 @@
this.current = expectedSchema.asStruct();
}
+ BuildAvroProjection(org.apache.iceberg.types.Type expectedType, Map<String, String> renames) {
Review comment:
This is for testing only.
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -357,6 +361,26 @@ static Schema copyRecord(Schema record, List<Schema.Field> newFields, String new
return copy;
}
+ static Schema copyArray(Schema array, Schema elementSchema) {
+ Preconditions.checkArgument(array.getType() == org.apache.avro.Schema.Type.ARRAY,
+ "Cannot invoke copyArray on non array schema");
+ Schema copy = Schema.createArray(elementSchema);
+ for (Map.Entry<String, Object> prop : array.getObjectProps().entrySet()) {
+ copy.addProp(prop.getKey(), prop.getValue());
+ }
+ return copy;
+ }
+
+ static Schema copyMap(Schema map, Schema valueSchema) {
+ Preconditions.checkArgument(map.getType() == org.apache.avro.Schema.Type.MAP,
+ "Cannot invoke copyMap on non map schema");
Review comment:
Added
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -357,6 +361,26 @@ static Schema copyRecord(Schema record, List<Schema.Field> newFields, String new
return copy;
}
+ static Schema copyArray(Schema array, Schema elementSchema) {
Review comment:
Adopted `replaceElement` and `replaceValue`
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,23 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ /**
+ * @param schema an Avro Schema
+ * @return true/false based on whether any of the nodes in the provided schema is missing an
+ * ID property recognizable by Iceberg core API. To have an ID recognizable by Iceberg core API:
+ * <ul>
+ * <li>a field node under struct (record) schema should have {@link FIELD_ID_PROP} property
+ * <li>an element node under list (array) schema should have {@link ELEMENT_ID_PROP} property
+ * <li>a pair of key and value node under map schema should have {@link KEY_ID_PROP} and
+ * {@link VALUE_ID_PROP} respectively
+ * <li>a primitive node is not assigned any ID related properties
+ * </ul>
Review comment:
Moved out of return section and before `param` or `return` in a general description.
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,23 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ /**
+ * @param schema an Avro Schema
+ * @return true/false based on whether any of the nodes in the provided schema is missing an
+ * ID property recognizable by Iceberg core API. To have an ID recognizable by Iceberg core API:
+ * <ul>
+ * <li>a field node under struct (record) schema should have {@link FIELD_ID_PROP} property
+ * <li>an element node under list (array) schema should have {@link ELEMENT_ID_PROP} property
+ * <li>a pair of key and value node under map schema should have {@link KEY_ID_PROP} and
+ * {@link VALUE_ID_PROP} respectively
+ * <li>a primitive node is not assigned any ID related properties
+ * </ul>
+ * @implNote see {@link MissingIds} for more details
Review comment:
Make sense, removed.
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,23 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ /**
+ * @param schema an Avro Schema
Review comment:
I tried to follow some example I saw under the [Catalog.class](https://github.com/apache/iceberg/blob/master/api/src/main/java/org/apache/iceberg/catalog/Catalog.java#L57), basically, a general description, then followed by `param`, `return`, `throws`. Let me know if I'm missing some components in this java doc.
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,23 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ /**
+ * @param schema an Avro Schema
Review comment:
I tried to follow some examples I saw under the [Catalog.class](https://github.com/apache/iceberg/blob/master/api/src/main/java/org/apache/iceberg/catalog/Catalog.java#L57), basically, a general description, then followed by `param`, `return`, `throws`. Let me know if I'm missing some components in this java doc.
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,23 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ /**
+ * @param schema an Avro Schema
+ * @return true/false based on whether any of the nodes in the provided schema is missing an
+ * ID property recognizable by Iceberg core API. To have an ID recognizable by Iceberg core API:
+ * <ul>
+ * <li>a field node under struct (record) schema should have {@link FIELD_ID_PROP} property
+ * <li>an element node under list (array) schema should have {@link ELEMENT_ID_PROP} property
+ * <li>a pair of key and value node under map schema should have {@link KEY_ID_PROP} and
+ * {@link VALUE_ID_PROP} respectively
+ * <li>a primitive node is not assigned any ID related properties
+ * </ul>
+ * @implNote see {@link MissingIds} for more details
Review comment:
removed `public`
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,25 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ /**
+ * Check if any of the nodes in a given avro schema is missing an ID recognizable by Iceberg core API
+ *
Review comment:
Added
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,25 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ /**
+ * Check if any of the nodes in a given avro schema is missing an ID recognizable by Iceberg core API
Review comment:
Make sense. Changed.
##########
File path: core/src/main/java/org/apache/iceberg/avro/MissingIds.java
##########
@@ -0,0 +1,80 @@
+/*
+ * 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 java.util.List;
+import java.util.function.Supplier;
+import org.apache.avro.Schema;
+
+/**
+ * Returns true once the first node is found with ID property missing. Reverse of {@link HasIds}
+ * <p>
+ * Note: To use {@link AvroSchemaUtil#toIceberg(Schema)} on an avro schema, the avro schema need to be either
+ * have IDs on every node or not have IDs at all. Invoke {@link AvroSchemaUtil#hasIds(Schema)} only proves
+ * that the schema has at least one ID, and not sufficient condition for invoking
+ * {@link AvroSchemaUtil#toIceberg(Schema)} on the schema.
+ */
+public class MissingIds extends AvroCustomOrderSchemaVisitor<Boolean, Boolean> {
Review comment:
Removed `public`
--
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
[GitHub] [iceberg] rdblue commented on a change in pull request #4120: Schema projection fix for list and map
Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r806219718
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -357,6 +361,26 @@ static Schema copyRecord(Schema record, List<Schema.Field> newFields, String new
return copy;
}
+ static Schema copyArray(Schema array, Schema elementSchema) {
+ Preconditions.checkArgument(array.getType() == org.apache.avro.Schema.Type.ARRAY,
+ "Cannot invoke copyArray on non array schema");
+ Schema copy = Schema.createArray(elementSchema);
+ for (Map.Entry<String, Object> prop : array.getObjectProps().entrySet()) {
+ copy.addProp(prop.getKey(), prop.getValue());
+ }
+ return copy;
+ }
+
+ static Schema copyMap(Schema map, Schema valueSchema) {
+ Preconditions.checkArgument(map.getType() == org.apache.avro.Schema.Type.MAP,
+ "Cannot invoke copyMap on non map schema");
Review comment:
I think this should include the problem schema for debugging.
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,10 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ static boolean missingIds(Schema schema) {
Review comment:
This needs Javadoc.
##########
File path: core/src/main/java/org/apache/iceberg/avro/BuildAvroProjection.java
##########
@@ -49,6 +49,11 @@
this.current = expectedSchema.asStruct();
}
+ BuildAvroProjection(org.apache.iceberg.types.Type expectedType, Map<String, String> renames) {
Review comment:
Is this for testing? What guarantees that the expected type is correct?
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -357,6 +361,26 @@ static Schema copyRecord(Schema record, List<Schema.Field> newFields, String new
return copy;
}
+ static Schema copyArray(Schema array, Schema elementSchema) {
Review comment:
I don't think that `copy` is quite the correct verb here because this is not actually copying the array. It is replacing the element. What about `replaceElement` and `replaceValue`?
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,23 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ /**
+ * @param schema an Avro Schema
+ * @return true/false based on whether any of the nodes in the provided schema is missing an
+ * ID property recognizable by Iceberg core API. To have an ID recognizable by Iceberg core API:
+ * <ul>
+ * <li>a field node under struct (record) schema should have {@link FIELD_ID_PROP} property
+ * <li>an element node under list (array) schema should have {@link ELEMENT_ID_PROP} property
+ * <li>a pair of key and value node under map schema should have {@link KEY_ID_PROP} and
+ * {@link VALUE_ID_PROP} respectively
+ * <li>a primitive node is not assigned any ID related properties
+ * </ul>
+ * @implNote see {@link MissingIds} for more details
Review comment:
This is an internal class, so it shouldn't be referenced in Javadoc. Anything that is relevant should be noted here since this is the public facing part.
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,23 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ /**
+ * @param schema an Avro Schema
Review comment:
Can you add a description like the other methods have?
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,23 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ /**
+ * @param schema an Avro Schema
+ * @return true/false based on whether any of the nodes in the provided schema is missing an
+ * ID property recognizable by Iceberg core API. To have an ID recognizable by Iceberg core API:
+ * <ul>
+ * <li>a field node under struct (record) schema should have {@link FIELD_ID_PROP} property
+ * <li>an element node under list (array) schema should have {@link ELEMENT_ID_PROP} property
+ * <li>a pair of key and value node under map schema should have {@link KEY_ID_PROP} and
+ * {@link VALUE_ID_PROP} respectively
+ * <li>a primitive node is not assigned any ID related properties
+ * </ul>
Review comment:
This long content is better suited for the main description, rather than in the return. `@return` should be a short summary, like "@return true if the schema has at least one field ID property, false otherwise"
The details about what "field ID property" could be should be above.
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,25 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ /**
+ * Check if any of the nodes in a given avro schema is missing an ID recognizable by Iceberg core API
Review comment:
This is the Iceberg core API, so it doesn't make sense to refer to it as something else. You can just say "Check if the schema is missing any ID properties." And below, you can clarify which IDs are considered.
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,25 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ /**
+ * Check if any of the nodes in a given avro schema is missing an ID recognizable by Iceberg core API
+ *
Review comment:
To separate paragraphs in Javadoc, add `<p>` to this line. No need for closing tags.
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,25 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ /**
+ * Check if any of the nodes in a given avro schema is missing an ID recognizable by Iceberg core API
+ *
Review comment:
To separate paragraphs in Javadoc, add `<p>` to this line. No need for a closing paragraph tag.
##########
File path: core/src/main/java/org/apache/iceberg/avro/MissingIds.java
##########
@@ -0,0 +1,80 @@
+/*
+ * 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 java.util.List;
+import java.util.function.Supplier;
+import org.apache.avro.Schema;
+
+/**
+ * Returns true once the first node is found with ID property missing. Reverse of {@link HasIds}
+ * <p>
+ * Note: To use {@link AvroSchemaUtil#toIceberg(Schema)} on an avro schema, the avro schema need to be either
+ * have IDs on every node or not have IDs at all. Invoke {@link AvroSchemaUtil#hasIds(Schema)} only proves
+ * that the schema has at least one ID, and not sufficient condition for invoking
+ * {@link AvroSchemaUtil#toIceberg(Schema)} on the schema.
+ */
+public class MissingIds extends AvroCustomOrderSchemaVisitor<Boolean, Boolean> {
Review comment:
This can be package-private right?
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,25 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ /**
+ * Check if any of the nodes in a given avro schema is missing an ID
+ * <p>
+ * To have an ID recognizable by Iceberg core API:
Review comment:
This still references the "Iceberg core API"
--
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
[GitHub] [iceberg] szehon-ho commented on a change in pull request #4120: Avro: Fix BuildAvroProjection list and map handling to preserve field IDs
Posted by GitBox <gi...@apache.org>.
szehon-ho commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r808273960
##########
File path: core/src/main/java/org/apache/iceberg/avro/MissingIds.java
##########
@@ -0,0 +1,80 @@
+/*
+ * 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 java.util.List;
+import java.util.function.Supplier;
+import org.apache.avro.Schema;
+
+/**
+ * Returns true once the first node is found with ID property missing. Reverse of {@link HasIds}
+ * <p>
+ * Note: To use {@link AvroSchemaUtil#toIceberg(Schema)} on an avro schema, the avro schema need to be either
+ * have IDs on every node or not have IDs at all. Invoke {@link AvroSchemaUtil#hasIds(Schema)} only proves
+ * that the schema has at least one ID, and not sufficient condition for invoking
+ * {@link AvroSchemaUtil#toIceberg(Schema)} on the schema.
+ */
+class MissingIds extends AvroCustomOrderSchemaVisitor<Boolean, Boolean> {
+ @Override
+ public Boolean record(Schema record, List<String> names, Iterable<Boolean> fields) {
+ for (Boolean field : fields) {
+ if (field) {
+ return true;
Review comment:
Yea no worries, don't want to make you do unnecessary changes :). I'll leave to @rdblue if there was any initial reason not to use guava in "HasIds" class
--
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
[GitHub] [iceberg] haizhou-zhao commented on a change in pull request #4120: Schema projection fix for list and map
Posted by GitBox <gi...@apache.org>.
haizhou-zhao commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r806295052
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -357,6 +361,26 @@ static Schema copyRecord(Schema record, List<Schema.Field> newFields, String new
return copy;
}
+ static Schema copyArray(Schema array, Schema elementSchema) {
+ Preconditions.checkArgument(array.getType() == org.apache.avro.Schema.Type.ARRAY,
+ "Cannot invoke copyArray on non array schema");
+ Schema copy = Schema.createArray(elementSchema);
+ for (Map.Entry<String, Object> prop : array.getObjectProps().entrySet()) {
+ copy.addProp(prop.getKey(), prop.getValue());
+ }
+ return copy;
+ }
+
+ static Schema copyMap(Schema map, Schema valueSchema) {
+ Preconditions.checkArgument(map.getType() == org.apache.avro.Schema.Type.MAP,
+ "Cannot invoke copyMap on non map schema");
Review comment:
Added
--
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
[GitHub] [iceberg] haizhou-zhao commented on a change in pull request #4120: Schema projection fix for list and map
Posted by GitBox <gi...@apache.org>.
haizhou-zhao commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r806295376
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -357,6 +361,26 @@ static Schema copyRecord(Schema record, List<Schema.Field> newFields, String new
return copy;
}
+ static Schema copyArray(Schema array, Schema elementSchema) {
Review comment:
Adopted `replaceElement` and `replaceValue`
--
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
[GitHub] [iceberg] rdblue commented on a change in pull request #4120: Schema projection fix for list and map
Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r806221763
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,10 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ static boolean missingIds(Schema schema) {
Review comment:
This needs Javadoc.
--
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
[GitHub] [iceberg] szehon-ho commented on a change in pull request #4120: Avro: Fix BuildAvroProjection list and map handling to preserve field IDs
Posted by GitBox <gi...@apache.org>.
szehon-ho commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r807563588
##########
File path: core/src/test/java/org/apache/iceberg/avro/TestBuildAvroProjection.java
##########
@@ -0,0 +1,244 @@
+/*
+ * 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 java.util.Collections;
+import java.util.function.Supplier;
+import org.apache.avro.SchemaBuilder;
+import org.apache.iceberg.types.Type;
+import org.apache.iceberg.types.Types;
+import org.junit.Test;
+
+import static org.apache.iceberg.types.Types.NestedField.optional;
+import static org.junit.Assert.assertEquals;
+
+public class TestBuildAvroProjection {
+
+ @Test
+ public void projectArrayWithElementSchemaUnchanged() {
+
+ final Type icebergType = Types.ListType.ofRequired(0,
+ Types.StructType.of(
+ optional(1, "int1", Types.IntegerType.get()),
+ optional(2, "string1", Types.StringType.get())
+ )
+ );
+
+ final org.apache.avro.Schema expected = SchemaBuilder.array().prop(AvroSchemaUtil.ELEMENT_ID_PROP, "0")
+ .items(
+ SchemaBuilder.record("elem").namespace("unit.test").fields()
+ .name("int1").prop(AvroSchemaUtil.FIELD_ID_PROP, "1").type().nullable().intType().noDefault()
+ .name("string1").prop(AvroSchemaUtil.FIELD_ID_PROP, "2").type().nullable().stringType().noDefault()
+ .endRecord());
+
+ final BuildAvroProjection testSubject = new BuildAvroProjection(icebergType, Collections.emptyMap());
+
+ final Supplier<org.apache.avro.Schema> supplier = expected::getElementType;
+
+ final org.apache.avro.Schema actual = testSubject.array(expected, supplier);
+
+ assertEquals(expected, actual);
+ assertEquals(0, Integer.valueOf(actual.getProp(AvroSchemaUtil.ELEMENT_ID_PROP)).intValue());
+ }
+
+ @Test
+ public void projectArrayWithExtraFieldInElementSchema() {
+
+ final Type icebergType = Types.ListType.ofRequired(0,
+ Types.StructType.of(
+ optional(1, "int1", Types.IntegerType.get()),
+ optional(2, "string1", Types.StringType.get())
+ )
+ );
+
+ final org.apache.avro.Schema extraField = SchemaBuilder.array().prop(AvroSchemaUtil.ELEMENT_ID_PROP, "0")
+ .items(
+ SchemaBuilder.record("elem").namespace("unit.test").fields()
+ .name("int1").prop(AvroSchemaUtil.FIELD_ID_PROP, "1").type().nullable().intType().noDefault()
+ .name("string1").prop(AvroSchemaUtil.FIELD_ID_PROP, "2").type().nullable().stringType().noDefault()
+ .name("float1").prop(AvroSchemaUtil.FIELD_ID_PROP, "3").type().nullable().floatType().noDefault()
+ .endRecord());
+
+ // once projected onto iceberg schema, the avro schema will lose the extra float field
+ final org.apache.avro.Schema expected = SchemaBuilder.array().prop(AvroSchemaUtil.ELEMENT_ID_PROP, "0")
+ .items(
+ SchemaBuilder.record("elem").namespace("unit.test").fields()
+ .name("int1").prop(AvroSchemaUtil.FIELD_ID_PROP, "1").type().nullable().intType().noDefault()
+ .name("string1").prop(AvroSchemaUtil.FIELD_ID_PROP, "2").type().nullable().stringType().noDefault()
+ .endRecord());
+
+ final BuildAvroProjection testSubject = new BuildAvroProjection(icebergType, Collections.emptyMap());
+
+ final Supplier<org.apache.avro.Schema> supplier = expected::getElementType;
+
+ final org.apache.avro.Schema actual = testSubject.array(extraField, supplier);
+
+ assertEquals(expected, actual);
+ assertEquals(0, Integer.valueOf(actual.getProp(AvroSchemaUtil.ELEMENT_ID_PROP)).intValue());
+ }
+
+ @Test
+ public void projectArrayWithLessFieldInElementSchema() {
+
+ final Type icebergType = Types.ListType.ofRequired(0,
+ Types.StructType.of(
+ optional(1, "int1", Types.IntegerType.get()),
+ optional(2, "string1", Types.StringType.get())
+ )
+ );
+
+ final org.apache.avro.Schema lessField = SchemaBuilder.array().prop(AvroSchemaUtil.ELEMENT_ID_PROP, "0")
+ .items(
+ SchemaBuilder.record("elem").namespace("unit.test").fields()
+ .name("int1").prop(AvroSchemaUtil.FIELD_ID_PROP, "1").type().nullable().intType().noDefault()
+ .endRecord());
+
+ // once projected onto iceberg schema, the avro schema will have an extra string column
+ final org.apache.avro.Schema expected = SchemaBuilder.array().prop(AvroSchemaUtil.ELEMENT_ID_PROP, "0")
+ .items(
+ SchemaBuilder.record("elem").namespace("unit.test").fields()
+ .name("int1").prop(AvroSchemaUtil.FIELD_ID_PROP, "1").type().nullable().intType().noDefault()
+ .name("string1_r").prop(AvroSchemaUtil.FIELD_ID_PROP, "2").type().nullable().stringType().noDefault()
+ .endRecord());
+
+ final BuildAvroProjection testSubject = new BuildAvroProjection(icebergType, Collections.emptyMap());
+
+ final Supplier<org.apache.avro.Schema> supplier = expected::getElementType;
+
+ final org.apache.avro.Schema actual = testSubject.array(lessField, supplier);
+
+ assertEquals(expected, actual);
+ assertEquals(0, Integer.valueOf(actual.getProp(AvroSchemaUtil.ELEMENT_ID_PROP)).intValue());
+ }
+
+ @Test
+ public void projectMapWithValueSchemaUnchanged() {
+
+ final Type icebergType = Types.MapType.ofRequired(0, 1,
+ Types.StringType.get(),
+ Types.StructType.of(
+ optional(2, "int1", Types.IntegerType.get()),
+ optional(3, "string1", Types.StringType.get())
+ )
+ );
+
+ final org.apache.avro.Schema expected = SchemaBuilder.map()
+ .prop(AvroSchemaUtil.KEY_ID_PROP, "0")
+ .prop(AvroSchemaUtil.VALUE_ID_PROP, "1")
+ .values(
+ SchemaBuilder.record("value").namespace("unit.test").fields()
+ .name("int1").prop(AvroSchemaUtil.FIELD_ID_PROP, "1").type().nullable().intType().noDefault()
+ .name("string1").prop(AvroSchemaUtil.FIELD_ID_PROP, "2").type().nullable().stringType().noDefault()
+ .endRecord());
+
+ final BuildAvroProjection testSubject = new BuildAvroProjection(icebergType, Collections.emptyMap());
+
+ final Supplier<org.apache.avro.Schema> supplier = expected::getValueType;
+
+ final org.apache.avro.Schema actual = testSubject.map(expected, supplier);
+
+ assertEquals(expected, actual);
+ assertEquals(0, Integer.valueOf(actual.getProp(AvroSchemaUtil.KEY_ID_PROP)).intValue());
+ assertEquals(1, Integer.valueOf(actual.getProp(AvroSchemaUtil.VALUE_ID_PROP)).intValue());
+ }
+
+ @Test
+ public void projectMapWithExtraFieldInValueSchema() {
+
+ final Type icebergType = Types.MapType.ofRequired(0, 1,
+ Types.StringType.get(),
+ Types.StructType.of(
+ optional(2, "int1", Types.IntegerType.get()),
+ optional(3, "string1", Types.StringType.get())
+ )
+ );
+
+ final org.apache.avro.Schema extraField = SchemaBuilder.map()
+ .prop(AvroSchemaUtil.KEY_ID_PROP, "0")
+ .prop(AvroSchemaUtil.VALUE_ID_PROP, "1")
+ .values(
+ SchemaBuilder.record("value").namespace("unit.test").fields()
+ .name("int1").prop(AvroSchemaUtil.FIELD_ID_PROP, "1").type().nullable().intType().noDefault()
+ .name("string1").prop(AvroSchemaUtil.FIELD_ID_PROP, "2").type().nullable().stringType().noDefault()
+ .name("float1").prop(AvroSchemaUtil.FIELD_ID_PROP, "3").type().nullable().floatType().noDefault()
+ .endRecord());
+
+ // once projected onto iceberg schema, the avro schema will lose the extra float field
+ final org.apache.avro.Schema expected = SchemaBuilder.map()
+ .prop(AvroSchemaUtil.KEY_ID_PROP, "0")
+ .prop(AvroSchemaUtil.VALUE_ID_PROP, "1")
+ .values(
+ SchemaBuilder.record("value").namespace("unit.test").fields()
+ .name("int1").prop(AvroSchemaUtil.FIELD_ID_PROP, "1").type().nullable().intType().noDefault()
+ .name("string1").prop(AvroSchemaUtil.FIELD_ID_PROP, "2").type().nullable().stringType().noDefault()
+ .endRecord());
+
+ final BuildAvroProjection testSubject = new BuildAvroProjection(icebergType, Collections.emptyMap());
+
+ final Supplier<org.apache.avro.Schema> supplier = expected::getValueType;
+
+ final org.apache.avro.Schema actual = testSubject.map(extraField, supplier);
+
+ assertEquals(expected, actual);
+ assertEquals(0, Integer.valueOf(actual.getProp(AvroSchemaUtil.KEY_ID_PROP)).intValue());
Review comment:
I think most of the Iceberg unit test use asserts with a message so it's slightly more clear what fails.
##########
File path: core/src/main/java/org/apache/iceberg/avro/MissingIds.java
##########
@@ -0,0 +1,80 @@
+/*
+ * 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 java.util.List;
+import java.util.function.Supplier;
+import org.apache.avro.Schema;
+
+/**
+ * Returns true once the first node is found with ID property missing. Reverse of {@link HasIds}
+ * <p>
+ * Note: To use {@link AvroSchemaUtil#toIceberg(Schema)} on an avro schema, the avro schema need to be either
+ * have IDs on every node or not have IDs at all. Invoke {@link AvroSchemaUtil#hasIds(Schema)} only proves
+ * that the schema has at least one ID, and not sufficient condition for invoking
+ * {@link AvroSchemaUtil#toIceberg(Schema)} on the schema.
+ */
+class MissingIds extends AvroCustomOrderSchemaVisitor<Boolean, Boolean> {
+ @Override
+ public Boolean record(Schema record, List<String> names, Iterable<Boolean> fields) {
+ for (Boolean field : fields) {
+ if (field) {
+ return true;
Review comment:
I was going to say we should use guava's 'Iterables.any' for these checks, but seems the hasIds class was also this way as well, oh well..
--
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
[GitHub] [iceberg] haizhou-zhao commented on a change in pull request #4120: Avro: Fix BuildAvroProjection list and map handling to preserve field IDs
Posted by GitBox <gi...@apache.org>.
haizhou-zhao commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r807097972
##########
File path: core/src/main/java/org/apache/iceberg/avro/MissingIds.java
##########
@@ -0,0 +1,80 @@
+/*
+ * 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 java.util.List;
+import java.util.function.Supplier;
+import org.apache.avro.Schema;
+
+/**
+ * Returns true once the first node is found with ID property missing. Reverse of {@link HasIds}
+ * <p>
+ * Note: To use {@link AvroSchemaUtil#toIceberg(Schema)} on an avro schema, the avro schema need to be either
+ * have IDs on every node or not have IDs at all. Invoke {@link AvroSchemaUtil#hasIds(Schema)} only proves
+ * that the schema has at least one ID, and not sufficient condition for invoking
+ * {@link AvroSchemaUtil#toIceberg(Schema)} on the schema.
+ */
+public class MissingIds extends AvroCustomOrderSchemaVisitor<Boolean, Boolean> {
Review comment:
Removed `public`
--
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
[GitHub] [iceberg] haizhou-zhao commented on a change in pull request #4120: Avro: Fix BuildAvroProjection list and map handling to preserve field IDs
Posted by GitBox <gi...@apache.org>.
haizhou-zhao commented on a change in pull request #4120:
URL: https://github.com/apache/iceberg/pull/4120#discussion_r807097587
##########
File path: core/src/main/java/org/apache/iceberg/avro/AvroSchemaUtil.java
##########
@@ -90,6 +90,25 @@ static boolean hasIds(Schema schema) {
return AvroCustomOrderSchemaVisitor.visit(schema, new HasIds());
}
+ /**
+ * Check if any of the nodes in a given avro schema is missing an ID recognizable by Iceberg core API
Review comment:
Make sense. Changed.
--
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