You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "CTTY (via GitHub)" <gi...@apache.org> on 2025/05/21 00:20:18 UTC
[PR] feat(transaction): Add update statistics [iceberg-rust]
CTTY opened a new pull request, #1359:
URL: https://github.com/apache/iceberg-rust/pull/1359
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
- Closes #1358
## What changes are included in this PR?
<!--
Provide a summary of the modifications in this PR. List the main changes such as new features, bug fixes, refactoring, or any other updates.
-->
- Add new transaction api to update statistics
## Are these changes tested?
<!--
Specify what test covers (unit test, integration test, etc.).
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
will add uts
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat(transaction): Add UpdateStatisticsAction [iceberg-rust]
Posted by "liurenjie1024 (via GitHub)" <gi...@apache.org>.
liurenjie1024 commented on code in PR #1359:
URL: https://github.com/apache/iceberg-rust/pull/1359#discussion_r2168147739
##########
crates/iceberg/src/transaction/update_statistics.rs:
##########
@@ -0,0 +1,174 @@
+// 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 std::collections::HashMap;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+
+use crate::spec::StatisticsFile;
+use crate::table::Table;
+use crate::transaction::{ActionCommit, TransactionAction};
+use crate::{Result, TableUpdate};
+
+/// A transactional action for updating statistics files in a table
+pub struct UpdateStatisticsAction {
+ statistics_to_set: HashMap<i64, Option<StatisticsFile>>,
+}
+
+impl UpdateStatisticsAction {
+ pub fn new() -> Self {
+ Self {
+ statistics_to_set: HashMap::default(),
+ }
+ }
+
+ /// Set the table's statistics file for given snapshot, replacing the previous statistics file for
+ /// the snapshot if any exists. The snapshot id of the statistics file will be used.
+ ///
+ /// # Arguments
+ ///
+ /// * `statistics_file` - The [`StatisticsFile`] to associate with its corresponding snapshot ID.
+ ///
+ /// # Returns
+ ///
+ /// An updated [`UpdateStatisticsAction`] with the new statistics file applied.
+ pub fn set_statistics(mut self, statistics_file: StatisticsFile) -> Self {
+ self.statistics_to_set
+ .insert(statistics_file.snapshot_id, Some(statistics_file));
+ self
+ }
+
+ /// Remove the table's statistics file for given snapshot.
+ ///
+ /// # Arguments
+ ///
+ /// * `snapshot_id` - The ID of the snapshot whose statistics file should be removed.
+ ///
+ /// # Returns
+ ///
+ /// An updated [`UpdateStatisticsAction`] with the removal operation recorded.
+ pub fn remove_statistics(mut self, snapshot_id: i64) -> Self {
+ self.statistics_to_set.insert(snapshot_id, None);
+ self
+ }
+}
+
+impl Default for UpdateStatisticsAction {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
+#[async_trait]
+impl TransactionAction for UpdateStatisticsAction {
+ async fn commit(self: Arc<Self>, _table: &Table) -> Result<ActionCommit> {
+ let mut updates: Vec<TableUpdate> = vec![];
+
+ self.statistics_to_set
+ .iter()
+ .for_each(|(snapshot_id, statistic_file)| {
+ if let Some(statistics) = statistic_file {
+ updates.push(TableUpdate::SetStatistics {
+ statistics: statistics.clone(),
+ })
+ } else {
+ updates.push(TableUpdate::RemoveStatistics {
+ snapshot_id: *snapshot_id,
+ })
+ }
+ });
+
+ Ok(ActionCommit::new(updates, vec![]))
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use std::collections::HashMap;
+
+ use as_any::Downcast;
+
+ use crate::spec::{BlobMetadata, StatisticsFile};
+ use crate::transaction::tests::make_v2_table;
+ use crate::transaction::update_statistics::UpdateStatisticsAction;
+ use crate::transaction::{ApplyTransactionAction, Transaction};
+
+ #[test]
+ fn test_update_statistics() {
Review Comment:
Sounds reasonable to me, also I think it's currently blocked by https://github.com/apache/iceberg-rust/issues/1467
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat(transaction): Add update statistics [iceberg-rust]
Posted by "CTTY (via GitHub)" <gi...@apache.org>.
CTTY commented on PR #1359:
URL: https://github.com/apache/iceberg-rust/pull/1359#issuecomment-2954187575
I'm converting this to draft and will rebase this on the new transaction API later: https://github.com/apache/iceberg-rust/pull/1400
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat(transaction): Add UpdateStatisticsAction [iceberg-rust]
Posted by "CTTY (via GitHub)" <gi...@apache.org>.
CTTY commented on code in PR #1359:
URL: https://github.com/apache/iceberg-rust/pull/1359#discussion_r2167850949
##########
crates/iceberg/src/transaction/update_statistics.rs:
##########
@@ -0,0 +1,174 @@
+// 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 std::collections::HashMap;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+
+use crate::spec::StatisticsFile;
+use crate::table::Table;
+use crate::transaction::{ActionCommit, TransactionAction};
+use crate::{Result, TableUpdate};
+
+/// A transactional action for updating statistics files in a table
+pub struct UpdateStatisticsAction {
+ statistics_to_set: HashMap<i64, Option<StatisticsFile>>,
+}
+
+impl UpdateStatisticsAction {
+ pub fn new() -> Self {
+ Self {
+ statistics_to_set: HashMap::default(),
+ }
+ }
+
+ /// Set the table's statistics file for given snapshot, replacing the previous statistics file for
+ /// the snapshot if any exists. The snapshot id of the statistics file will be used.
+ ///
+ /// # Arguments
+ ///
+ /// * `statistics_file` - The [`StatisticsFile`] to associate with its corresponding snapshot ID.
+ ///
+ /// # Returns
+ ///
+ /// An updated [`UpdateStatisticsAction`] with the new statistics file applied.
+ pub fn set_statistics(mut self, statistics_file: StatisticsFile) -> Self {
+ self.statistics_to_set
+ .insert(statistics_file.snapshot_id, Some(statistics_file));
+ self
+ }
+
+ /// Remove the table's statistics file for given snapshot.
+ ///
+ /// # Arguments
+ ///
+ /// * `snapshot_id` - The ID of the snapshot whose statistics file should be removed.
+ ///
+ /// # Returns
+ ///
+ /// An updated [`UpdateStatisticsAction`] with the removal operation recorded.
+ pub fn remove_statistics(mut self, snapshot_id: i64) -> Self {
+ self.statistics_to_set.insert(snapshot_id, None);
+ self
+ }
+}
+
+impl Default for UpdateStatisticsAction {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
+#[async_trait]
+impl TransactionAction for UpdateStatisticsAction {
+ async fn commit(self: Arc<Self>, _table: &Table) -> Result<ActionCommit> {
+ let mut updates: Vec<TableUpdate> = vec![];
+
+ self.statistics_to_set
+ .iter()
+ .for_each(|(snapshot_id, statistic_file)| {
+ if let Some(statistics) = statistic_file {
+ updates.push(TableUpdate::SetStatistics {
+ statistics: statistics.clone(),
+ })
+ } else {
+ updates.push(TableUpdate::RemoveStatistics {
+ snapshot_id: *snapshot_id,
+ })
+ }
+ });
+
+ Ok(ActionCommit::new(updates, vec![]))
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use std::collections::HashMap;
+
+ use as_any::Downcast;
+
+ use crate::spec::{BlobMetadata, StatisticsFile};
+ use crate::transaction::tests::make_v2_table;
+ use crate::transaction::update_statistics::UpdateStatisticsAction;
+ use crate::transaction::{ApplyTransactionAction, Transaction};
+
+ #[test]
+ fn test_update_statistics() {
Review Comment:
Yes, I'm thinking the same, but I'm planning to create another issue to track this and other tx API tests improvement for others to ramp up, wdyt?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat(transaction): Add UpdateStatisticsAction [iceberg-rust]
Posted by "liurenjie1024 (via GitHub)" <gi...@apache.org>.
liurenjie1024 merged PR #1359:
URL: https://github.com/apache/iceberg-rust/pull/1359
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat(transaction): Add UpdateStatisticsAction [iceberg-rust]
Posted by "liurenjie1024 (via GitHub)" <gi...@apache.org>.
liurenjie1024 commented on code in PR #1359:
URL: https://github.com/apache/iceberg-rust/pull/1359#discussion_r2166304074
##########
crates/iceberg/src/transaction/update_statistics.rs:
##########
@@ -0,0 +1,174 @@
+// 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 std::collections::HashMap;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+
+use crate::spec::StatisticsFile;
+use crate::table::Table;
+use crate::transaction::{ActionCommit, TransactionAction};
+use crate::{Result, TableUpdate};
+
+/// A transactional action for updating statistics files in a table
+pub struct UpdateStatisticsAction {
+ statistics_to_set: HashMap<i64, Option<StatisticsFile>>,
+}
+
+impl UpdateStatisticsAction {
+ pub fn new() -> Self {
+ Self {
+ statistics_to_set: HashMap::default(),
+ }
+ }
+
+ /// Set the table's statistics file for given snapshot, replacing the previous statistics file for
+ /// the snapshot if any exists. The snapshot id of the statistics file will be used.
+ ///
+ /// # Arguments
+ ///
+ /// * `statistics_file` - The [`StatisticsFile`] to associate with its corresponding snapshot ID.
+ ///
+ /// # Returns
+ ///
+ /// An updated [`UpdateStatisticsAction`] with the new statistics file applied.
+ pub fn set_statistics(mut self, statistics_file: StatisticsFile) -> Self {
+ self.statistics_to_set
+ .insert(statistics_file.snapshot_id, Some(statistics_file));
+ self
+ }
+
+ /// Remove the table's statistics file for given snapshot.
+ ///
+ /// # Arguments
+ ///
+ /// * `snapshot_id` - The ID of the snapshot whose statistics file should be removed.
+ ///
+ /// # Returns
+ ///
+ /// An updated [`UpdateStatisticsAction`] with the removal operation recorded.
+ pub fn remove_statistics(mut self, snapshot_id: i64) -> Self {
+ self.statistics_to_set.insert(snapshot_id, None);
+ self
+ }
+}
+
+impl Default for UpdateStatisticsAction {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
+#[async_trait]
+impl TransactionAction for UpdateStatisticsAction {
+ async fn commit(self: Arc<Self>, _table: &Table) -> Result<ActionCommit> {
+ let mut updates: Vec<TableUpdate> = vec![];
+
+ self.statistics_to_set
+ .iter()
+ .for_each(|(snapshot_id, statistic_file)| {
+ if let Some(statistics) = statistic_file {
+ updates.push(TableUpdate::SetStatistics {
+ statistics: statistics.clone(),
+ })
+ } else {
+ updates.push(TableUpdate::RemoveStatistics {
+ snapshot_id: *snapshot_id,
+ })
+ }
+ });
+
+ Ok(ActionCommit::new(updates, vec![]))
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use std::collections::HashMap;
+
+ use as_any::Downcast;
+
+ use crate::spec::{BlobMetadata, StatisticsFile};
+ use crate::transaction::tests::make_v2_table;
+ use crate::transaction::update_statistics::UpdateStatisticsAction;
+ use crate::transaction::{ApplyTransactionAction, Transaction};
+
+ #[test]
+ fn test_update_statistics() {
Review Comment:
Since we could apply tx action now, how about test table metadata result against `MemoryCatalog`?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org