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