Skip to content

Losing "element-id" after calling BuildAvroProjection #4072

Description

@haizhou-zhao

Hello,

We are using iceberg 0.11.x, and we had an issue with assembling an iceberg schema from the result of AvroSchemaUtil.buildAvroProjection.

First, couple words on the overall architecture of our operation: we manage iceberg tables for our customers and accept schema evolution requests from them in the format of Avro. This is our schema compatibility check:

Given: [avro.Schema] currentSchema, [avro.Schema] updatedSchema

step 1: currentIcebergSchema = AvroSchemaUtil.toIceberg(currentSchema)

step 2: projectedIds = TypeUtil.getProjectedIds(currentIcebergSchema)

step 3: nameMapping = MappingUtil.create(currentIcebergSchema)

step 4: prunedSchema = AvroSchemaUtil.pruneColumns(updatedSchema, projectedIds, nameMapping)

step 5: projectionSchema = AvroSchemaUtil.buildAvroProjection(prunedSchema, currentIcebergSchema, HashMap.empty())

step 6: updatedIcebergSchema = AvroSchemaUtil.toIceberg(projectionSchema)

step 7: CheckCompatibility.writeCompatibilityErrors(currentIcebergSchema, updatedIcebergSchema)

Recently, one of our customer submitted a schema change where they want to add more optional fields to the element type of an array column.

<excerpt of schema change>
{
    "type": "record",
    "name": "top-level",
    "fields": [
         {
               "type": "array",
               "items":  {
                       "type": "record",
                       "name": "element-record",
                       "fields": [
                           {
                                  "name": "field1",
                                  "type": ["null", "int"],
                           },
+                           {
+                                  "name": "field2",
+                                  "type": ["null", "string"],
+                           },
                       ]
                }
         }
    ]
}

Then our compatibility check breaks at step 6 (java.lang.IllegalArgumentException: Multiple entries with same key:). What we've discovered so far are:

  1. each of the Avro node is assigned an id after step 5 for prunedSchema
  2. the "top-level.element" node lost its assigned id from the prunedSchema after step 6 in projectionSchema reference
  3. when reassembling an Iceberg schema out of projectionSchema at step 7, the "top-level.element" node, as it does not have "element-id" property, is assigned a generated id that happens to collide its id with another node reference

The questions are:

  1. When projecting schema of array type, even if the underlying schema differs, should the "element-id" property be preserved? Reference
  2. If not, then is there an Iceberg API/Util that performs projection (column reordering, etc.) while preserving ids of all node from the projected schema?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions