File tree Expand file tree Collapse file tree 8 files changed +101
-13
lines changed Expand file tree Collapse file tree 8 files changed +101
-13
lines changed Original file line number Diff line number Diff line change @@ -33,4 +33,8 @@ impl Dialect for ClickHouseDialect {
33
33
fn supports_select_wildcard_except ( & self ) -> bool {
34
34
true
35
35
}
36
+
37
+ fn describe_requires_table_keyword ( & self ) -> bool {
38
+ true
39
+ }
36
40
}
Original file line number Diff line number Diff line change @@ -488,6 +488,16 @@ pub trait Dialect: Debug + Any {
488
488
fn prec_unknown ( & self ) -> u8 {
489
489
0
490
490
}
491
+
492
+ /// Returns true if this dialect requires the `TABLE keyword after `DESCRIBE`
493
+ ///
494
+ /// Defaults to false.
495
+ ///
496
+ /// If true, the following statement is valid: `DESCRIBE TABLE my_table`
497
+ /// If false, the following statement is valid: `DESCRIBE my_table`
498
+ fn describe_requires_table_keyword ( & self ) -> bool {
499
+ false
500
+ }
491
501
}
492
502
493
503
/// This represents the operators for which precedence must be defined
Original file line number Diff line number Diff line change @@ -154,6 +154,10 @@ impl Dialect for SnowflakeDialect {
154
154
_ => None ,
155
155
}
156
156
}
157
+
158
+ fn describe_requires_table_keyword ( & self ) -> bool {
159
+ true
160
+ }
157
161
}
158
162
159
163
/// Parse snowflake create table statement.
Original file line number Diff line number Diff line change @@ -8185,15 +8185,20 @@ impl<'a> Parser<'a> {
8185
8185
format,
8186
8186
} ) ,
8187
8187
_ => {
8188
- let mut hive_format = None ;
8189
- match self . parse_one_of_keywords ( & [ Keyword :: EXTENDED , Keyword :: FORMATTED ] ) {
8190
- Some ( Keyword :: EXTENDED ) => hive_format = Some ( HiveDescribeFormat :: Extended ) ,
8191
- Some ( Keyword :: FORMATTED ) => hive_format = Some ( HiveDescribeFormat :: Formatted ) ,
8192
- _ => { }
8193
- }
8188
+ let hive_format =
8189
+ match self . parse_one_of_keywords ( & [ Keyword :: EXTENDED , Keyword :: FORMATTED ] ) {
8190
+ Some ( Keyword :: EXTENDED ) => Some ( HiveDescribeFormat :: Extended ) ,
8191
+ Some ( Keyword :: FORMATTED ) => Some ( HiveDescribeFormat :: Formatted ) ,
8192
+ _ => None ,
8193
+ } ;
8194
+
8195
+ let has_table_keyword = if self . dialect . describe_requires_table_keyword ( ) {
8196
+ // only allow to use TABLE keyword for DESC|DESCRIBE statement
8197
+ self . parse_keyword ( Keyword :: TABLE )
8198
+ } else {
8199
+ false
8200
+ } ;
8194
8201
8195
- // only allow to use TABLE keyword for DESC|DESCRIBE statement
8196
- let has_table_keyword = self . parse_keyword ( Keyword :: TABLE ) ;
8197
8202
let table_name = self . parse_object_name ( false ) ?;
8198
8203
Ok ( Statement :: ExplainTable {
8199
8204
describe_alias,
Original file line number Diff line number Diff line change @@ -1376,6 +1376,36 @@ fn parse_select_table_function_settings() {
1376
1376
}
1377
1377
}
1378
1378
1379
+ #[ test]
1380
+ fn explain_describe ( ) {
1381
+ clickhouse ( ) . verified_stmt ( "DESCRIBE test.table" ) ;
1382
+ clickhouse ( ) . verified_stmt ( "DESCRIBE TABLE test.table" ) ;
1383
+ }
1384
+
1385
+ #[ test]
1386
+ fn explain_desc ( ) {
1387
+ clickhouse ( ) . verified_stmt ( "DESC test.table" ) ;
1388
+ clickhouse ( ) . verified_stmt ( "DESC TABLE test.table" ) ;
1389
+ }
1390
+
1391
+ #[ test]
1392
+ fn parse_explain_table ( ) {
1393
+ match clickhouse ( ) . verified_stmt ( "EXPLAIN TABLE test_identifier" ) {
1394
+ Statement :: ExplainTable {
1395
+ describe_alias,
1396
+ hive_format,
1397
+ has_table_keyword,
1398
+ table_name,
1399
+ } => {
1400
+ pretty_assertions:: assert_eq!( describe_alias, DescribeAlias :: Explain ) ;
1401
+ pretty_assertions:: assert_eq!( hive_format, None ) ;
1402
+ pretty_assertions:: assert_eq!( has_table_keyword, true ) ;
1403
+ pretty_assertions:: assert_eq!( "test_identifier" , table_name. to_string( ) ) ;
1404
+ }
1405
+ _ => panic ! ( "Unexpected Statement, must be ExplainTable" ) ,
1406
+ }
1407
+ }
1408
+
1379
1409
fn clickhouse ( ) -> TestedDialects {
1380
1410
TestedDialects {
1381
1411
dialects : vec ! [ Box :: new( ClickHouseDialect { } ) ] ,
Original file line number Diff line number Diff line change @@ -4317,13 +4317,11 @@ fn parse_explain_table() {
4317
4317
#[ test]
4318
4318
fn explain_describe ( ) {
4319
4319
verified_stmt ( "DESCRIBE test.table" ) ;
4320
- verified_stmt ( "DESCRIBE TABLE test.table" ) ;
4321
4320
}
4322
4321
4323
4322
#[ test]
4324
4323
fn explain_desc ( ) {
4325
4324
verified_stmt ( "DESC test.table" ) ;
4326
- verified_stmt ( "DESC TABLE test.table" ) ;
4327
4325
}
4328
4326
4329
4327
#[ test]
Original file line number Diff line number Diff line change @@ -44,9 +44,9 @@ fn generic(options: Option<ParserOptions>) -> TestedDialects {
44
44
45
45
#[ test]
46
46
fn parse_describe ( ) {
47
- let describe = r#"DESCRIBE namespace.`table`"# ;
48
- hive ( ) . verified_stmt ( describe ) ;
49
- generic ( None ) . verified_stmt ( describe ) ;
47
+ hive_and_generic ( ) . verified_stmt ( r#"DESCRIBE namespace.`table`"# ) ;
48
+ hive_and_generic ( ) . verified_stmt ( r#"DESCRIBE namespace.table"# ) ;
49
+ hive_and_generic ( ) . verified_stmt ( r#"DESCRIBE table"# ) ;
50
50
}
51
51
52
52
#[ test]
@@ -414,3 +414,10 @@ fn hive() -> TestedDialects {
414
414
options : None ,
415
415
}
416
416
}
417
+
418
+ fn hive_and_generic ( ) -> TestedDialects {
419
+ TestedDialects {
420
+ dialects : vec ! [ Box :: new( HiveDialect { } ) , Box :: new( GenericDialect { } ) ] ,
421
+ options : None ,
422
+ }
423
+ }
Original file line number Diff line number Diff line change @@ -2292,3 +2292,33 @@ fn test_parse_position() {
2292
2292
snowflake ( ) . verified_query ( "SELECT position('an', 'banana', 1)" ) ;
2293
2293
snowflake ( ) . verified_query ( "SELECT n, h, POSITION(n IN h) FROM pos" ) ;
2294
2294
}
2295
+
2296
+ #[ test]
2297
+ fn explain_describe ( ) {
2298
+ snowflake ( ) . verified_stmt ( "DESCRIBE test.table" ) ;
2299
+ snowflake ( ) . verified_stmt ( "DESCRIBE TABLE test.table" ) ;
2300
+ }
2301
+
2302
+ #[ test]
2303
+ fn explain_desc ( ) {
2304
+ snowflake ( ) . verified_stmt ( "DESC test.table" ) ;
2305
+ snowflake ( ) . verified_stmt ( "DESC TABLE test.table" ) ;
2306
+ }
2307
+
2308
+ #[ test]
2309
+ fn parse_explain_table ( ) {
2310
+ match snowflake ( ) . verified_stmt ( "EXPLAIN TABLE test_identifier" ) {
2311
+ Statement :: ExplainTable {
2312
+ describe_alias,
2313
+ hive_format,
2314
+ has_table_keyword,
2315
+ table_name,
2316
+ } => {
2317
+ assert_eq ! ( describe_alias, DescribeAlias :: Explain ) ;
2318
+ assert_eq ! ( hive_format, None ) ;
2319
+ assert_eq ! ( has_table_keyword, true ) ;
2320
+ assert_eq ! ( "test_identifier" , table_name. to_string( ) ) ;
2321
+ }
2322
+ _ => panic ! ( "Unexpected Statement, must be ExplainTable" ) ,
2323
+ }
2324
+ }
You can’t perform that action at this time.
0 commit comments