Skip to content

Commit

Permalink
feat: show dropped table and data_retention_time_in_hours in fuse_tim… (
Browse files Browse the repository at this point in the history
#17015)

* feat: show dropped table and data_retention_time_in_hours in fuse_time_travel_size()

* fix test
  • Loading branch information
SkyFan2002 authored Dec 11, 2024
1 parent daa5b9b commit a71d8cb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String>,
Expand Down Expand Up @@ -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),
Expand All @@ -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()),
])
}
Expand All @@ -102,8 +109,10 @@ impl SimpleArgFunc for FuseTimeTravelSize {
) -> Result<DataBlock> {
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 {
Expand All @@ -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();
Expand All @@ -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
}
Expand All @@ -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::<u64>())
.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));
Expand All @@ -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),
]))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
<<<<
Original file line number Diff line number Diff line change
Expand Up @@ -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')"


0 comments on commit a71d8cb

Please sign in to comment.