mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-07 22:02:56 +00:00
feat: Implement SHOW STATUS (#4050)
* show status returning empty contents * return an empty set instead of affected rows * chore: Update src/query/src/sql.rs --------- Co-authored-by: Yingwen <realevenyag@gmail.com>
This commit is contained in:
@@ -554,6 +554,7 @@ pub fn check_permission(
|
||||
Statement::ShowIndex(stmt) => {
|
||||
validate_db_permission!(stmt, query_ctx);
|
||||
}
|
||||
Statement::ShowStatus(_stmt) => {}
|
||||
Statement::DescribeTable(stmt) => {
|
||||
validate_param(stmt.name(), query_ctx)?;
|
||||
}
|
||||
|
||||
@@ -263,6 +263,7 @@ impl StatementExecutor {
|
||||
self.show_columns(show_columns, query_ctx).await
|
||||
}
|
||||
Statement::ShowIndex(show_index) => self.show_index(show_index, query_ctx).await,
|
||||
Statement::ShowStatus(_) => self.show_status(query_ctx).await,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -117,6 +117,13 @@ impl StatementExecutor {
|
||||
.await
|
||||
.context(error::ExecuteStatementSnafu)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all)]
|
||||
pub async fn show_status(&self, query_ctx: QueryContextRef) -> Result<Output> {
|
||||
query::sql::show_status(query_ctx)
|
||||
.await
|
||||
.context(error::ExecuteStatementSnafu)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn create_partitions_stmt(partitions: Vec<PartitionInfo>) -> Result<Option<Partitions>> {
|
||||
|
||||
@@ -564,6 +564,22 @@ pub fn show_variable(stmt: ShowVariables, query_ctx: QueryContextRef) -> Result<
|
||||
Ok(Output::new_with_record_batches(records))
|
||||
}
|
||||
|
||||
pub async fn show_status(_query_ctx: QueryContextRef) -> Result<Output> {
|
||||
let schema = Arc::new(Schema::new(vec![
|
||||
ColumnSchema::new("Variable_name", ConcreteDataType::string_datatype(), false),
|
||||
ColumnSchema::new("Value", ConcreteDataType::string_datatype(), true),
|
||||
]));
|
||||
let records = RecordBatches::try_from_columns(
|
||||
schema,
|
||||
vec![
|
||||
Arc::new(StringVector::from(Vec::<&str>::new())) as _,
|
||||
Arc::new(StringVector::from(Vec::<&str>::new())) as _,
|
||||
],
|
||||
)
|
||||
.context(error::CreateRecordBatchSnafu)?;
|
||||
Ok(Output::new_with_record_batches(records))
|
||||
}
|
||||
|
||||
pub fn show_create_table(
|
||||
table: TableRef,
|
||||
partitions: Option<Partitions>,
|
||||
|
||||
@@ -19,7 +19,8 @@ use sqlparser::tokenizer::Token;
|
||||
use crate::error::{self, InvalidDatabaseNameSnafu, InvalidTableNameSnafu, Result};
|
||||
use crate::parser::ParserContext;
|
||||
use crate::statements::show::{
|
||||
ShowColumns, ShowCreateTable, ShowDatabases, ShowIndex, ShowKind, ShowTables, ShowVariables,
|
||||
ShowColumns, ShowCreateTable, ShowDatabases, ShowIndex, ShowKind, ShowStatus, ShowTables,
|
||||
ShowVariables,
|
||||
};
|
||||
use crate::statements::statement::Statement;
|
||||
|
||||
@@ -82,6 +83,8 @@ impl<'a> ParserContext<'a> {
|
||||
actual: self.peek_token_as_string(),
|
||||
})?;
|
||||
Ok(Statement::ShowVariables(ShowVariables { variable }))
|
||||
} else if self.consume_token("STATUS") {
|
||||
Ok(Statement::ShowStatus(ShowStatus {}))
|
||||
} else {
|
||||
self.unsupported(self.peek_token_as_string())
|
||||
}
|
||||
|
||||
@@ -145,6 +145,16 @@ impl Display for ShowVariables {
|
||||
}
|
||||
}
|
||||
|
||||
/// SQL structure for "SHOW STATUS"
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Visit, VisitMut)]
|
||||
pub struct ShowStatus {}
|
||||
|
||||
impl Display for ShowStatus {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "SHOW STATUS")
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::assert_matches::assert_matches;
|
||||
|
||||
@@ -31,7 +31,8 @@ use crate::statements::insert::Insert;
|
||||
use crate::statements::query::Query;
|
||||
use crate::statements::set_variables::SetVariables;
|
||||
use crate::statements::show::{
|
||||
ShowColumns, ShowCreateTable, ShowDatabases, ShowIndex, ShowKind, ShowTables, ShowVariables,
|
||||
ShowColumns, ShowCreateTable, ShowDatabases, ShowIndex, ShowKind, ShowStatus, ShowTables,
|
||||
ShowVariables,
|
||||
};
|
||||
use crate::statements::tql::Tql;
|
||||
use crate::statements::truncate::TruncateTable;
|
||||
@@ -80,6 +81,8 @@ pub enum Statement {
|
||||
ShowIndex(ShowIndex),
|
||||
// SHOW CREATE TABLE
|
||||
ShowCreateTable(ShowCreateTable),
|
||||
// SHOW STATUS
|
||||
ShowStatus(ShowStatus),
|
||||
// DESCRIBE TABLE
|
||||
DescribeTable(DescribeTable),
|
||||
// EXPLAIN QUERY
|
||||
@@ -115,6 +118,7 @@ impl Display for Statement {
|
||||
Statement::ShowColumns(s) => s.fmt(f),
|
||||
Statement::ShowIndex(s) => s.fmt(f),
|
||||
Statement::ShowCreateTable(s) => s.fmt(f),
|
||||
Statement::ShowStatus(s) => s.fmt(f),
|
||||
Statement::DescribeTable(s) => s.fmt(f),
|
||||
Statement::Explain(s) => s.fmt(f),
|
||||
Statement::Copy(s) => s.fmt(f),
|
||||
|
||||
Reference in New Issue
Block a user