Skip to content

PartitionData cannot handle nested field names in PartitionSpec schema #216

Closed

Description

@rdsr

The following test will throw an exception when parsing the partition's Iceberg schema to Avro schema

Test: rdsr@95b95b0

The problem is that the Avro parser cannot handle dots in the field name and throws an exception

 org.apache.avro.SchemaParseException: Illegal character in: a_struct.a_primitive
	at org.apache.avro.Schema.validateName(Schema.java:1151)
	at org.apache.avro.Schema.access$200(Schema.java:81)
	at org.apache.avro.Schema$Field.<init>(Schema.java:403)
	at org.apache.avro.Schema$Field.<init>(Schema.java:423)
	at org.apache.avro.Schema$Field.<init>(Schema.java:415)
	at org.apache.iceberg.avro.TypeToSchema.struct(TypeToSchema.java:91)
	at org.apache.iceberg.avro.TypeToSchema.struct(TypeToSchema.java:33)
	at org.apache.iceberg.types.TypeUtil.visit(TypeUtil.java:238)
	at org.apache.iceberg.avro.AvroSchemaUtil.convert(AvroSchemaUtil.java:71)
	at org.apache.iceberg.avro.AvroSchemaUtil.convert(AvroSchemaUtil.java:67)
	at org.apache.iceberg.PartitionData.partitionDataSchema(PartitionData.java:42)
	at org.apache.iceberg.PartitionData.<init>(PartitionData.java:71)
	at org.apache.iceberg.TestPartitionData.testNestedField(TestPartitionData.java:16)

AFAICT from the spec nested fields are allowed for partitioning

Activity

  1. changed the title [-]`PartitionData` cannot handle nested field names in `PartitionSpec` schema[/-] [+]PartitionData cannot handle nested field names in PartitionSpec schema[/+] on Jun 14, 2019
  2. rdsr commented on Jun 14, 2019

    @rdsr
    ContributorAuthor

    @rdblue , as per the spec

    The source column, selected by id, must be a primitive type and cannot be contained in a map or list, but may be nested in a struct

    So we can possibly have 2 ways to address this.

    1. Automatically replace the dot with underscore
    2. Allow user to specify the target column name in the partition field
  3. rdblue commented on Jun 14, 2019

    @rdblue
    Contributor

    Iceberg supports special characters in names, looks like the failure is in Avro. I think Iceberg should sanitize special characters from the names when creating an Avro schema.

  4. rdsr commented on Jun 14, 2019

    @rdsr
    ContributorAuthor

    The special char can only be DOT though right?
    Also it seems like you are suggesting that we should handle the sanitization in TypeToSchema visitor. That makes sense to me.

  5. rdblue commented on Jun 14, 2019

    @rdblue
    Contributor

    I think it could be anything since we allow users to pass strings into UpdateSchema. We should probably sanitize any character that isn't allowed by Avro, assuming that they might creep in.

    By the way, because we project based on ID and not by name, the names used in Avro files don't really matter. So this should be safe to change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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