xanderbailey commented on code in PR #3066: URL: https://github.com/apache/iceberg-rust/pull/3066#discussion_r4109012640
########## crates/iceberg/src/spec/schema/assign_fresh_ids.rs: ########## @@ -0,0 +1,407 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use super::utils::try_insert_field; +use super::*; + +pub(crate) fn assign_fresh_ids(schema: Schema, base: &Schema, start_from: i32) -> Result<Schema> { + let mut assigner = AssignFreshIds::new(&schema, base, start_from); + let Schema { + r#struct, + schema_id, + identifier_field_ids, + alias_to_id, + .. + } = schema; + let fields = assigner.assign_fields(r#struct.fields().to_vec())?; + let identifier_field_ids = assigner.apply_to_identifier_fields(identifier_field_ids)?; + let alias_to_id = assigner.apply_to_aliases(alias_to_id)?; + + Schema::builder() + .with_schema_id(schema_id) + .with_fields(fields) + .with_identifier_field_ids(identifier_field_ids) + .with_alias(alias_to_id) + .build() +} + +struct AssignFreshIds { + next_field_id: i32, + target_names: HashMap<i32, String>, + base_ids: HashMap<String, i32>, + old_to_new_id: HashMap<i32, i32>, +} + +impl AssignFreshIds { + fn new(target: &Schema, base: &Schema, start_from: i32) -> Self { + Self { + next_field_id: start_from, + target_names: target.field_id_to_name_map().clone(), Review Comment: https://github.com/apache/iceberg-rust/pull/3066/commits/0566b90b3adc8bf6f2f0cb377d63a5b8c19d1b07 ########## crates/iceberg/src/spec/schema/assign_fresh_ids.rs: ########## @@ -0,0 +1,407 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use super::utils::try_insert_field; +use super::*; + +pub(crate) fn assign_fresh_ids(schema: Schema, base: &Schema, start_from: i32) -> Result<Schema> { + let mut assigner = AssignFreshIds::new(&schema, base, start_from); + let Schema { + r#struct, + schema_id, + identifier_field_ids, + alias_to_id, + .. + } = schema; + let fields = assigner.assign_fields(r#struct.fields().to_vec())?; + let identifier_field_ids = assigner.apply_to_identifier_fields(identifier_field_ids)?; + let alias_to_id = assigner.apply_to_aliases(alias_to_id)?; + + Schema::builder() + .with_schema_id(schema_id) + .with_fields(fields) + .with_identifier_field_ids(identifier_field_ids) + .with_alias(alias_to_id) + .build() +} + +struct AssignFreshIds { + next_field_id: i32, + target_names: HashMap<i32, String>, + base_ids: HashMap<String, i32>, + old_to_new_id: HashMap<i32, i32>, +} + +impl AssignFreshIds { + fn new(target: &Schema, base: &Schema, start_from: i32) -> Self { + Self { + next_field_id: start_from, + target_names: target.field_id_to_name_map().clone(), + base_ids: base + .field_id_to_name_map() + .iter() + .map(|(id, name)| (name.clone(), *id)) + .collect(), + old_to_new_id: HashMap::new(), + } + } + + fn id_for(&mut self, old_id: i32) -> Result<i32> { Review Comment: https://github.com/apache/iceberg-rust/pull/3066/commits/29423629e60896f35df20b7b10e5b96f90977e2f ########## crates/iceberg/src/spec/schema/assign_fresh_ids.rs: ########## @@ -0,0 +1,407 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use super::utils::try_insert_field; +use super::*; + +pub(crate) fn assign_fresh_ids(schema: Schema, base: &Schema, start_from: i32) -> Result<Schema> { + let mut assigner = AssignFreshIds::new(&schema, base, start_from); + let Schema { + r#struct, + schema_id, + identifier_field_ids, + alias_to_id, + .. + } = schema; + let fields = assigner.assign_fields(r#struct.fields().to_vec())?; + let identifier_field_ids = assigner.apply_to_identifier_fields(identifier_field_ids)?; + let alias_to_id = assigner.apply_to_aliases(alias_to_id)?; + + Schema::builder() + .with_schema_id(schema_id) Review Comment: https://github.com/apache/iceberg-rust/pull/3066/commits/29423629e60896f35df20b7b10e5b96f90977e2f https://github.com/apache/iceberg-rust/pull/3066/commits/c7b2fa97e7bfaf32dd344d09528346aa19ad1a0a -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
