mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-03 20:02:54 +00:00
feat: support desc [table] <table_name> (#1944)
* feat: support desc [table] Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * refine style Signed-off-by: Ruihang Xia <waynestxia@gmail.com> --------- Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
This commit is contained in:
@@ -261,10 +261,8 @@ impl<'a> ParserContext<'a> {
|
||||
fn parse_describe(&mut self) -> Result<Statement> {
|
||||
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<Statement> {
|
||||
@@ -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;");
|
||||
}
|
||||
}
|
||||
|
||||
58
tests/cases/standalone/common/describe/describe_table.result
Normal file
58
tests/cases/standalone/common/describe/describe_table.result
Normal file
@@ -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
|
||||
|
||||
17
tests/cases/standalone/common/describe/describe_table.sql
Normal file
17
tests/cases/standalone/common/describe/describe_table.sql
Normal file
@@ -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;
|
||||
Reference in New Issue
Block a user