Skip to content

bug: schema does not reject multiple field ids #593

@twuebi

Description

@twuebi

Bug

We allow this:

sc := iceberg.NewSchema(0,
	        ...
		iceberg.NestedField{
			Type: &iceberg.StructType{
				FieldList: []iceberg.NestedField{
					{
						Type: typ,
						ID:   6,
						Name: "inner_op",
					},
					{
						Type:     typ,
						ID:       6,
						Name:     "inner_req",
						Required: true,
					},
					...
				},
			},
			ID:       5,
			Name:     "struct",
			Required: true,
		},
                ...
	)

while java rejects this:

new Schema(
        Types.NestedField.required(1, "id", Types.LongType.get()),
        Types.NestedField.optional(2, "top", type),
        Types.NestedField.optional(3, "arr", Types.ListType.ofRequired(4, type)),
        Types.NestedField.required(
            5,
            "struct",
            Types.StructType.of(
                Types.NestedField.optional(6, "inner_op", type),
                Types.NestedField.required(6, "inner_req", type),
                Types.NestedField.optional(
                    8,
                    "struct_arr",
                    Types.StructType.of(Types.NestedField.optional(9, "deep", type))))));
  java.lang.IllegalArgumentException: Multiple entries with same key: 6=struct.inner_req and 6=struct.inner_op
...
	at org.apache.iceberg.types.IndexByName.byId(IndexByName.java:81)
	at org.apache.iceberg.types.TypeUtil.indexNameById(TypeUtil.java:174)
	at org.apache.iceberg.Schema.lazyIdToName(Schema.java:225)
	at org.apache.iceberg.Schema.<init>(Schema.java:154)

We could probably verify this in the same place as java, in schema.init()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions