GitHub user JeonDaehong added a comment to the discussion: Are we able to avoid 
reassign field-id when building TableMetadata?

`TableMetadataBuilder::new` always reassigns ids 
([table_metadata_builder.rs#L89](https://github.com/apache/iceberg-rust/blob/697abcee75b503fc106f445dae8bcfc401524dcc/crates/iceberg/src/spec/table_metadata_builder.rs#L89)).
 That's intended and matches Java's `TableMetadata.newTableMetadata`. The 
reasoning is in #1499.

`add_schema` / `add_current_schema` keep the field ids you pass in, though. So 
you can create the table first and then switch to your own schema:

```rust
let metadata = TableMetadataBuilder::new(schema.clone(), spec.clone(), 
sort_order, location, FormatVersion::V2, props)?
    .add_current_schema(schema.clone())?      // keeps your field ids
    .add_default_partition_spec(spec.clone())? // re-bind the spec to your ids
    .build()?
    .metadata;

// optional: drop the throwaway schema/spec created by new()
let metadata = metadata
    .into_builder(None)
    .remove_schemas(&[0])?
    .remove_partition_specs(&[0])?
    .build()?
    .metadata;
```

I ran this on current main with a schema using ids 10/20/30 and a `day(ts)` 
spec. The result has current schema ids `[10, 20, 30]`, `last_column_id = 30`, 
and the spec source id `20`, and it survives a JSON round trip.

The builder doesn't validate the ids for you. Make sure they are unique and 
match the ids in your data files.

GitHub link: 
https://github.com/apache/iceberg-rust/discussions/1668#discussioncomment-18986904

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to