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:
Ruihang Xia
2023-07-12 14:41:31 +08:00
committed by GitHub
parent 5422224530
commit 4fa8340572
3 changed files with 92 additions and 3 deletions

View File

@@ -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;");
}
}

View 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

View 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;