Skip to content

Commit

Permalink
feat(query): add created_time column to processes table (databendlabs…
Browse files Browse the repository at this point in the history
  • Loading branch information
TCeason authored May 9, 2024
1 parent 1bf37ce commit 3b1b239
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ DB.Table: 'system'.'columns', Table: columns-table_id:1, ver:0, Engine: SystemCo
| 'created_on' | 'system' | 'views' | 'Timestamp' | 'TIMESTAMP' | '' | '' | 'NO' | '' |
| 'created_on' | 'system' | 'views_with_history' | 'Timestamp' | 'TIMESTAMP' | '' | '' | 'NO' | '' |
| 'created_on' | 'system' | 'virtual_columns' | 'Timestamp' | 'TIMESTAMP' | '' | '' | 'NO' | '' |
| 'created_time' | 'system' | 'processes' | 'Timestamp' | 'TIMESTAMP' | '' | '' | 'NO' | '' |
| 'creator' | 'system' | 'background_jobs' | 'Nullable(String)' | 'VARCHAR' | '' | '' | 'YES' | '' |
| 'creator' | 'system' | 'background_tasks' | 'Nullable(String)' | 'VARCHAR' | '' | '' | 'YES' | '' |
| 'creator' | 'system' | 'stages' | 'Nullable(String)' | 'VARCHAR' | '' | '' | 'YES' | '' |
Expand Down
10 changes: 10 additions & 0 deletions src/query/storages/system/src/processes_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use std::sync::Arc;
use std::time::Duration;

use chrono::DateTime;
use chrono::Utc;
use databend_common_catalog::table::Table;
use databend_common_catalog::table_context::TableContext;
use databend_common_exception::Result;
Expand All @@ -23,6 +25,7 @@ use databend_common_expression::types::number::UInt32Type;
use databend_common_expression::types::number::UInt64Type;
use databend_common_expression::types::NumberDataType;
use databend_common_expression::types::StringType;
use databend_common_expression::types::TimestampType;
use databend_common_expression::utils::FromData;
use databend_common_expression::DataBlock;
use databend_common_expression::TableDataType;
Expand Down Expand Up @@ -69,11 +72,15 @@ impl SyncSystemTable for ProcessesTable {
let mut processes_scan_progress_read_bytes = Vec::with_capacity(processes_info.len());
let mut processes_mysql_connection_id = Vec::with_capacity(processes_info.len());
let mut processes_time = Vec::with_capacity(processes_info.len());
let mut processes_created_time = Vec::with_capacity(processes_info.len());
let mut processes_status = Vec::with_capacity(processes_info.len());

for process_info in &processes_info {
let data_metrics = &process_info.data_metrics;
let scan_progress = process_info.scan_progress_value.clone().unwrap_or_default();

let created_time: DateTime<Utc> = process_info.created_time.into();
let created_time = created_time.timestamp_micros();
let time = process_info
.created_time
.elapsed()
Expand All @@ -96,6 +103,7 @@ impl SyncSystemTable for ProcessesTable {
processes_scan_progress_read_bytes.push(scan_progress.bytes as u64);
processes_mysql_connection_id.push(process_info.mysql_connection_id);
processes_time.push(time);
processes_created_time.push(created_time);

if let Some(data_metrics) = data_metrics {
processes_data_read_bytes.push(data_metrics.get_read_bytes() as u64);
Expand Down Expand Up @@ -125,6 +133,7 @@ impl SyncSystemTable for ProcessesTable {
UInt64Type::from_data(processes_scan_progress_read_bytes),
UInt32Type::from_opt_data(processes_mysql_connection_id),
UInt64Type::from_data(processes_time),
TimestampType::from_data(processes_created_time),
StringType::from_data(processes_status),
]))
}
Expand Down Expand Up @@ -166,6 +175,7 @@ impl ProcessesTable {
TableDataType::Nullable(Box::new(TableDataType::Number(NumberDataType::UInt32))),
),
TableField::new("time", TableDataType::Number(NumberDataType::UInt64)),
TableField::new("created_time", TableDataType::Timestamp),
TableField::new("status", TableDataType::String),
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ select count() >= 1 from system.processes where type='HTTPQuery' and host='127.0
1

statement error
SHOW PROCESSLIST WHERE tt='default' LIMIT 2
SHOW PROCESSLIST WHERE tt='default' LIMIT 2

statement ok
select created_time from system.processes limit 1;

0 comments on commit 3b1b239

Please sign in to comment.