Skip to content

Commit 93b8d1e

Browse files
committed
Add update statistics
1 parent 772ae1a commit 93b8d1e

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

crates/iceberg/src/transaction/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ mod sort_order;
2727
mod update_location;
2828
mod update_properties;
2929
mod upgrade_format_version;
30+
mod update_statistics;
3031

3132
use std::sync::Arc;
3233

@@ -38,6 +39,7 @@ use crate::transaction::sort_order::ReplaceSortOrderAction;
3839
use crate::transaction::update_location::UpdateLocationAction;
3940
use crate::transaction::update_properties::UpdatePropertiesAction;
4041
use crate::transaction::upgrade_format_version::UpgradeFormatVersionAction;
42+
use crate::transaction::update_statistics::UpdateStatistics;
4143
use crate::{Catalog, TableCommit, TableRequirement, TableUpdate};
4244

4345
/// Table transaction.
@@ -112,6 +114,11 @@ impl Transaction {
112114
UpdateLocationAction::new()
113115
}
114116

117+
/// Update the statistics of table
118+
pub fn update_statistics(self) -> UpdateStatistics<'a> {
119+
UpdateStatistics::new(self)
120+
}
121+
115122
/// Commit transaction.
116123
pub async fn commit(mut self, catalog: &dyn Catalog) -> Result<Table> {
117124
if self.actions.is_empty() {
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
use crate::spec::StatisticsFile;
19+
use crate::transaction::Transaction;
20+
use crate::{Error, TableUpdate};
21+
22+
pub struct UpdateStatistics<'a> {
23+
tx: Transaction<'a>,
24+
updates: Vec<TableUpdate>,
25+
}
26+
27+
impl<'a> UpdateStatistics<'a> {
28+
pub fn new(tx: Transaction<'a>) -> Self {
29+
UpdateStatistics {
30+
tx,
31+
updates: Vec::new(),
32+
}
33+
}
34+
35+
pub fn set_statistics(&mut self, statistics: StatisticsFile) -> Result<&mut Self, Error> {
36+
self.updates.push(TableUpdate::SetStatistics { statistics });
37+
38+
Ok(self)
39+
}
40+
41+
pub fn remove_statistics(&mut self, snapshot_id: i64) -> Result<&mut Self, Error> {
42+
self.updates
43+
.push(TableUpdate::RemoveStatistics { snapshot_id });
44+
45+
Ok(self)
46+
}
47+
48+
pub fn apply(mut self) -> Result<Transaction<'a>, Error> {
49+
self.tx.apply(self.updates, vec![])?;
50+
51+
Ok(self.tx)
52+
}
53+
}

0 commit comments

Comments
 (0)