14
14
15
15
use common_base:: base:: tokio;
16
16
use common_exception:: Result ;
17
+ use common_storages_factory:: Table ;
18
+ use common_storages_fuse:: FuseTable ;
19
+ use common_storages_fuse:: TableContext ;
17
20
18
21
use crate :: storages:: fuse:: table_test_fixture:: check_data_dir;
19
22
use crate :: storages:: fuse:: table_test_fixture:: execute_command;
@@ -38,6 +41,53 @@ async fn test_fuse_snapshot_analyze() -> Result<()> {
38
41
. await
39
42
}
40
43
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
+
41
91
#[ tokio:: test]
42
92
async fn test_fuse_snapshot_analyze_purge ( ) -> Result < ( ) > {
43
93
let fixture = TestFixture :: new ( ) . await ;
0 commit comments