diff --git a/src/query/storages/fuse/src/table_functions/fuse_time_travel_size.rs b/src/query/storages/fuse/src/table_functions/fuse_time_travel_size.rs index f4e4d360ec80..5c41a62cad92 100644 --- a/src/query/storages/fuse/src/table_functions/fuse_time_travel_size.rs +++ b/src/query/storages/fuse/src/table_functions/fuse_time_travel_size.rs @@ -20,6 +20,7 @@ use databend_common_catalog::table_args::TableArgs; use databend_common_catalog::table_context::TableContext; use databend_common_exception::ErrorCode; use databend_common_exception::Result; +use databend_common_expression::types::BooleanType; use databend_common_expression::types::NumberDataType; use databend_common_expression::types::StringType; use databend_common_expression::types::UInt64Type; @@ -40,6 +41,7 @@ use crate::table_functions::string_literal; use crate::table_functions::SimpleArgFunc; use crate::table_functions::SimpleArgFuncTemplate; use crate::FuseTable; +use crate::FUSE_OPT_KEY_DATA_RETENTION_PERIOD_IN_HOURS; pub struct FuseTimeTravelSizeArgs { pub database_name: Option, @@ -82,6 +84,7 @@ impl SimpleArgFunc for FuseTimeTravelSize { TableSchemaRefExt::create(vec![ TableField::new("database_name", TableDataType::String), TableField::new("table_name", TableDataType::String), + TableField::new("is_dropped", TableDataType::Boolean), TableField::new( "time_travel_size", TableDataType::Number(NumberDataType::UInt64), @@ -90,6 +93,10 @@ impl SimpleArgFunc for FuseTimeTravelSize { "latest_snapshot_size", TableDataType::Number(NumberDataType::UInt64).wrap_nullable(), ), + TableField::new( + "data_retention_period_in_hours", + TableDataType::Number(NumberDataType::UInt64).wrap_nullable(), + ), TableField::new("error", TableDataType::String.wrap_nullable()), ]) } @@ -102,8 +109,10 @@ impl SimpleArgFunc for FuseTimeTravelSize { ) -> Result { let mut database_names = Vec::new(); let mut table_names = Vec::new(); + let mut is_droppeds = Vec::new(); let mut sizes = Vec::new(); let mut latest_snapshot_sizes = Vec::new(); + let mut data_retention_period_in_hours = Vec::new(); let mut errors = Vec::new(); let catalog = ctx.get_default_catalog()?; let dbs = match &args.database_name { @@ -123,6 +132,9 @@ impl SimpleArgFunc for FuseTimeTravelSize { } }; for db in dbs { + if db.name() == "system" || db.name() == "information_schema" { + continue; + } let tables = match &args.table_name { Some(table_name) => { let start = std::time::Instant::now(); @@ -132,7 +144,7 @@ impl SimpleArgFunc for FuseTimeTravelSize { } None => { let start = std::time::Instant::now(); - let tables = db.list_tables().await?; + let tables = db.list_tables_history().await?; info!("list_tables cost: {:?}", start.elapsed()); tables } @@ -147,9 +159,19 @@ impl SimpleArgFunc for FuseTimeTravelSize { continue; } let (time_travel_size, latest_snapshot_size) = calc_tbl_size(fuse_table).await?; + let data_retention_period_in_hour = fuse_table + .table_info + .meta + .options + .get(FUSE_OPT_KEY_DATA_RETENTION_PERIOD_IN_HOURS) + .map(|v| v.parse::()) + .transpose()?; + let is_dropped = fuse_table.table_info.meta.drop_on.is_some(); database_names.push(db.name().to_string()); table_names.push(tbl.name().to_string()); + is_droppeds.push(is_dropped); sizes.push(time_travel_size); + data_retention_period_in_hours.push(data_retention_period_in_hour); match latest_snapshot_size { Ok(size) => { latest_snapshot_sizes.push(Some(size)); @@ -165,8 +187,10 @@ impl SimpleArgFunc for FuseTimeTravelSize { Ok(DataBlock::new_from_columns(vec![ StringType::from_data(database_names), StringType::from_data(table_names), + BooleanType::from_data(is_droppeds), UInt64Type::from_data(sizes), UInt64Type::from_opt_data(latest_snapshot_sizes), + UInt64Type::from_opt_data(data_retention_period_in_hours), StringType::from_opt_data(errors), ])) } diff --git a/tests/suites/0_stateless/20+_others/20_0020_fuse_time_travel_size.result b/tests/suites/0_stateless/20+_others/20_0020_fuse_time_travel_size.result index aed5d2c63e51..d6b42d45015c 100644 --- a/tests/suites/0_stateless/20+_others/20_0020_fuse_time_travel_size.result +++ b/tests/suites/0_stateless/20+_others/20_0020_fuse_time_travel_size.result @@ -2,3 +2,11 @@ >>>> create table test_fuse_time_travel_size.t(c int) 'fs:///tmp/test_fuse_time_travel_size/' >>>> insert into test_fuse_time_travel_size.t values (1),(2) Size difference is less than 10 bytes +>>>> alter table test_fuse_time_travel_size.t SET OPTIONS (data_retention_period_in_hours = 240); +>>>> drop table test_fuse_time_travel_size.t +>>>> select is_dropped from fuse_time_travel_size('test_fuse_time_travel_size') +true +<<<< +>>>> select data_retention_period_in_hours from fuse_time_travel_size('test_fuse_time_travel_size') +240 +<<<< diff --git a/tests/suites/0_stateless/20+_others/20_0020_fuse_time_travel_size.sh b/tests/suites/0_stateless/20+_others/20_0020_fuse_time_travel_size.sh index bda278331efa..d7bab996b847 100755 --- a/tests/suites/0_stateless/20+_others/20_0020_fuse_time_travel_size.sh +++ b/tests/suites/0_stateless/20+_others/20_0020_fuse_time_travel_size.sh @@ -26,4 +26,12 @@ else exit 1 fi +stmt "alter table test_fuse_time_travel_size.t SET OPTIONS (data_retention_period_in_hours = 240);" + +stmt "drop table test_fuse_time_travel_size.t" + +query "select is_dropped from fuse_time_travel_size('test_fuse_time_travel_size')" + +query "select data_retention_period_in_hours from fuse_time_travel_size('test_fuse_time_travel_size')" +