Skip to content

Add Iceberg-style API for defining schemas with field IDs #1385

@murali-db

Description

@murali-db

Currently, creating schemas with field IDs requires verbose boilerplate:

StructType::new_unchecked([
    create_field_with_id("id", DataType::LONG, false, 1),
    create_field_with_id("name", DataType::STRING, true, 2),
]);

// Helper function needed:
fn create_field_with_id(name: &str, data_type: DataType, nullable: bool, id: i64) -> StructField {
    StructField::new(name, data_type, nullable)
        .add_metadata([
            ("delta.columnMapping.id", MetadataValue::Number(id)),
            ("delta.columnMapping.physicalName", MetadataValue::String(format!("col_{}", id))),
        ])
}

Proposal

Add a builder-style API similar to Iceberg for ergonomic schema construction with field IDs:

  StructType::builder()
      .field("id", DataType::LONG).required().id(1).build()
      .field("name", DataType::STRING).nullable().id(2).build()
      .build()

Or method chaining on StructField:

  StructField::new("id", DataType::LONG, false)
      .with_id(1)
      .with_physical_name("col_1")

This would improve readability and reduce boilerplate when working with column mapping, especially in tests and schema evolution scenarios.

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