diff --git a/src/sql/src/parser.rs b/src/sql/src/parser.rs index eb8fc4ac30..4da3328f8b 100644 --- a/src/sql/src/parser.rs +++ b/src/sql/src/parser.rs @@ -261,10 +261,8 @@ impl<'a> ParserContext<'a> { fn parse_describe(&mut self) -> Result { if self.matches_keyword(Keyword::TABLE) { let _ = self.parser.next_token(); - self.parse_describe_table() - } else { - self.unsupported(self.peek_token_as_string()) } + self.parse_describe_table() } fn parse_describe_table(&mut self) -> Result { @@ -677,4 +675,20 @@ mod tests { ParserContext::parse_function("current_timestamp()", &GreptimeDbDialect {}).unwrap(); assert!(matches!(expr, Expr::Function(_))); } + + fn assert_describe_table(sql: &str) { + let stmt = ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}) + .unwrap() + .pop() + .unwrap(); + assert!(matches!(stmt, Statement::DescribeTable(_))) + } + + #[test] + fn test_parse_describe_table() { + assert_describe_table("desc table t;"); + assert_describe_table("describe table t;"); + assert_describe_table("desc t;"); + assert_describe_table("describe t;"); + } } diff --git a/tests/cases/standalone/common/describe/describe_table.result b/tests/cases/standalone/common/describe/describe_table.result new file mode 100644 index 0000000000..e23a6f836e --- /dev/null +++ b/tests/cases/standalone/common/describe/describe_table.result @@ -0,0 +1,58 @@ +create table host_load1( + ts timestamp time index, + collector string, + host string, + val double, + primary key (collector, host) +); + +Affected Rows: 0 + +describe table host_load1; + ++-----------+----------------------+------+---------+---------------+ +| Field | Type | Null | Default | Semantic Type | ++-----------+----------------------+------+---------+---------------+ +| ts | TimestampMillisecond | NO | | TIME INDEX | +| collector | String | YES | | PRIMARY KEY | +| host | String | YES | | PRIMARY KEY | +| val | Float64 | YES | | FIELD | ++-----------+----------------------+------+---------+---------------+ + +describe host_load1; + ++-----------+----------------------+------+---------+---------------+ +| Field | Type | Null | Default | Semantic Type | ++-----------+----------------------+------+---------+---------------+ +| ts | TimestampMillisecond | NO | | TIME INDEX | +| collector | String | YES | | PRIMARY KEY | +| host | String | YES | | PRIMARY KEY | +| val | Float64 | YES | | FIELD | ++-----------+----------------------+------+---------+---------------+ + +desc table host_load1; + ++-----------+----------------------+------+---------+---------------+ +| Field | Type | Null | Default | Semantic Type | ++-----------+----------------------+------+---------+---------------+ +| ts | TimestampMillisecond | NO | | TIME INDEX | +| collector | String | YES | | PRIMARY KEY | +| host | String | YES | | PRIMARY KEY | +| val | Float64 | YES | | FIELD | ++-----------+----------------------+------+---------+---------------+ + +desc host_load1; + ++-----------+----------------------+------+---------+---------------+ +| Field | Type | Null | Default | Semantic Type | ++-----------+----------------------+------+---------+---------------+ +| ts | TimestampMillisecond | NO | | TIME INDEX | +| collector | String | YES | | PRIMARY KEY | +| host | String | YES | | PRIMARY KEY | +| val | Float64 | YES | | FIELD | ++-----------+----------------------+------+---------+---------------+ + +drop table host_load1; + +Affected Rows: 1 + diff --git a/tests/cases/standalone/common/describe/describe_table.sql b/tests/cases/standalone/common/describe/describe_table.sql new file mode 100644 index 0000000000..49d7edda12 --- /dev/null +++ b/tests/cases/standalone/common/describe/describe_table.sql @@ -0,0 +1,17 @@ +create table host_load1( + ts timestamp time index, + collector string, + host string, + val double, + primary key (collector, host) +); + +describe table host_load1; + +describe host_load1; + +desc table host_load1; + +desc host_load1; + +drop table host_load1;