Skip to content

Commit 795789f

Browse files
committed
Add update statistics
1 parent e488f45 commit 795789f

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
@@ -20,6 +20,7 @@
2020
mod append;
2121
mod snapshot;
2222
mod sort_order;
23+
mod update_statistics;
2324

2425
use std::cmp::Ordering;
2526
use std::collections::HashMap;
@@ -34,6 +35,7 @@ use crate::spec::FormatVersion;
3435
use crate::table::Table;
3536
use crate::transaction::append::FastAppendAction;
3637
use crate::transaction::sort_order::ReplaceSortOrderAction;
38+
use crate::transaction::update_statistics::UpdateStatistics;
3739
use crate::{Catalog, Error, ErrorKind, TableCommit, TableRequirement, TableUpdate};
3840

3941
/// Table transaction.
@@ -189,6 +191,11 @@ impl<'a> Transaction<'a> {
189191
Ok(self)
190192
}
191193

194+
/// Update the statistics of table
195+
pub fn update_statistics(self) -> UpdateStatistics<'a> {
196+
UpdateStatistics::new(self)
197+
}
198+
192199
/// Commit transaction.
193200
pub async fn commit(self, catalog: &dyn Catalog) -> Result<Table> {
194201
let table_commit = TableCommit::builder()
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)