Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Reassign field ids for schema #615

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

c-thiel
Copy link
Contributor

@c-thiel c-thiel commented Sep 8, 2024

Required for TableMetadataBuilder (#587).

When new TableMetadata is created, field ids should be reassign to ensure that field numbering is normalized and started from 0.

@c-thiel c-thiel changed the title Feat: Reassign field ids for schema feat: Reassign field ids for schema Sep 8, 2024
@c-thiel c-thiel mentioned this pull request Sep 8, 2024
/// If not provided, it will start from 0.
///
/// All specified aliases and identifier fields will be updated to the new field-ids.
pub fn with_reassigned_field_ids(mut self, start_from: Option<i32>) -> Self {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please elaborate on the circumstances under which the user wants to set this? I used to think users always need to start with 0.

///
/// All specified aliases and identifier fields will be updated to the new field-ids.
pub fn with_reassigned_field_ids(mut self, start_from: Option<i32>) -> Self {
self.reassign_field_ids_from = Some(start_from.unwrap_or(0));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we always set Some(v) here, how about just using i32 for reassign_field_ids_from with default value 0?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically you would pass in last-column-id from the table metadata. In the case of a CREATE TABLE this will be zero, in the case of a REPLACE TABLE it will be last-column-id where all columns get a new ID and you ensure they are not used before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Xuanwo only doubt with the i32 is that people might input 1 as something is required - and it's shorter than Default::default().
The rust tests are quite a good example that this can happen: We have many tests where field numbering starts from 1, so I had to re-write them to be compatible with the new builder.

I am OK with the i32 as well, just wanted to bring up that a None is probably more verbose.

@Xuanwo
Copy link
Member

Xuanwo commented Sep 10, 2024

cc @liurenjie1024 would you like to take a look too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants