Skip to content

Commit 952070e

Browse files
authored
Merge pull request #9205 from lichuang/truncate_ts
fix: truncate reset ts location
2 parents 4123682 + 8b3873c commit 952070e

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/query/service/tests/it/storages/fuse/operations/analyze.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
use common_base::base::tokio;
1616
use common_exception::Result;
17+
use common_storages_factory::Table;
18+
use common_storages_fuse::FuseTable;
19+
use common_storages_fuse::TableContext;
1720

1821
use crate::storages::fuse::table_test_fixture::check_data_dir;
1922
use crate::storages::fuse::table_test_fixture::execute_command;
@@ -38,6 +41,53 @@ async fn test_fuse_snapshot_analyze() -> Result<()> {
3841
.await
3942
}
4043

44+
#[tokio::test]
45+
async fn test_fuse_snapshot_analyze_and_truncate() -> Result<()> {
46+
let fixture = TestFixture::new().await;
47+
let db = fixture.default_db_name();
48+
let tbl = fixture.default_table_name();
49+
let case_name = "test_fuse_snapshot_analyze_and_truncate";
50+
51+
// insert some data
52+
do_insertions(&fixture).await?;
53+
54+
// analyze the table
55+
{
56+
let qry = format!("Analyze table {}.{}", db, tbl);
57+
58+
let ctx = fixture.ctx();
59+
execute_command(ctx, &qry).await?;
60+
61+
check_data_dir(&fixture, case_name, 3, 1, 2, 2, 2, None, Some(())).await?;
62+
}
63+
64+
// truncate table
65+
{
66+
let ctx = fixture.ctx();
67+
let catalog = ctx.get_catalog(fixture.default_catalog_name().as_str())?;
68+
let table = catalog
69+
.get_table(ctx.get_tenant().as_str(), &db, &tbl)
70+
.await?;
71+
let fuse_table = FuseTable::try_from_table(table.as_ref())?;
72+
fuse_table.truncate(ctx, false).await?;
73+
}
74+
75+
// optimize after truncate table, ts file location will become None
76+
{
77+
let ctx = fixture.ctx();
78+
let catalog = ctx.get_catalog(fixture.default_catalog_name().as_str())?;
79+
let table = catalog
80+
.get_table(ctx.get_tenant().as_str(), &db, &tbl)
81+
.await?;
82+
let fuse_table = FuseTable::try_from_table(table.as_ref())?;
83+
let snapshot_opt = fuse_table.read_table_snapshot().await?;
84+
assert!(snapshot_opt.is_some());
85+
assert!(snapshot_opt.unwrap().table_statistics_location.is_none());
86+
}
87+
88+
Ok(())
89+
}
90+
4191
#[tokio::test]
4292
async fn test_fuse_snapshot_analyze_purge() -> Result<()> {
4393
let fixture = TestFixture::new().await;

src/query/storages/fuse/fuse/src/operations/truncate.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ impl FuseTable {
4141
Default::default(),
4242
vec![],
4343
self.cluster_key_meta.clone(),
44-
prev_snapshot.table_statistics_location.clone(),
44+
// truncate MUST reset ts location
45+
None,
4546
);
4647
let loc = self.meta_location_generator();
4748
let new_snapshot_loc =

0 commit comments

Comments
 (0)