mirror of
				https://github.com/apache/datafusion-sqlparser-rs.git
				synced 2025-10-28 05:59:48 +00:00 
			
		
		
		
	fix: only require DESCRIBE TABLE for Snowflake and ClickHouse dialect (#1386)
				
					
				
			This commit is contained in:
		
							parent
							
								
									8c4d30bb6d
								
							
						
					
					
						commit
						dd78084ca0
					
				
					 8 changed files with 103 additions and 32 deletions
				
			
		|  | @ -33,4 +33,8 @@ impl Dialect for ClickHouseDialect { | |||
|     fn supports_select_wildcard_except(&self) -> bool { | ||||
|         true | ||||
|     } | ||||
| 
 | ||||
|     fn describe_requires_table_keyword(&self) -> bool { | ||||
|         true | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -485,9 +485,20 @@ pub trait Dialect: Debug + Any { | |||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /// Returns the precedence when the precedence is otherwise unknown
 | ||||
|     fn prec_unknown(&self) -> u8 { | ||||
|         0 | ||||
|     } | ||||
| 
 | ||||
|     /// Returns true if this dialect requires the `TABLE` keyword after `DESCRIBE`
 | ||||
|     ///
 | ||||
|     /// Defaults to false.
 | ||||
|     ///
 | ||||
|     /// If true, the following statement is valid: `DESCRIBE TABLE my_table`
 | ||||
|     /// If false, the following statements are valid: `DESCRIBE my_table` and `DESCRIBE table`
 | ||||
|     fn describe_requires_table_keyword(&self) -> bool { | ||||
|         false | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| /// This represents the operators for which precedence must be defined
 | ||||
|  |  | |||
|  | @ -154,6 +154,10 @@ impl Dialect for SnowflakeDialect { | |||
|             _ => None, | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     fn describe_requires_table_keyword(&self) -> bool { | ||||
|         true | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| /// Parse snowflake create table statement.
 | ||||
|  |  | |||
|  | @ -8185,15 +8185,20 @@ impl<'a> Parser<'a> { | |||
|                 format, | ||||
|             }), | ||||
|             _ => { | ||||
|                 let mut hive_format = None; | ||||
|                 match self.parse_one_of_keywords(&[Keyword::EXTENDED, Keyword::FORMATTED]) { | ||||
|                     Some(Keyword::EXTENDED) => hive_format = Some(HiveDescribeFormat::Extended), | ||||
|                     Some(Keyword::FORMATTED) => hive_format = Some(HiveDescribeFormat::Formatted), | ||||
|                     _ => {} | ||||
|                 } | ||||
|                 let hive_format = | ||||
|                     match self.parse_one_of_keywords(&[Keyword::EXTENDED, Keyword::FORMATTED]) { | ||||
|                         Some(Keyword::EXTENDED) => Some(HiveDescribeFormat::Extended), | ||||
|                         Some(Keyword::FORMATTED) => Some(HiveDescribeFormat::Formatted), | ||||
|                         _ => None, | ||||
|                     }; | ||||
| 
 | ||||
|                 let has_table_keyword = if self.dialect.describe_requires_table_keyword() { | ||||
|                     // only allow to use TABLE keyword for DESC|DESCRIBE statement
 | ||||
|                     self.parse_keyword(Keyword::TABLE) | ||||
|                 } else { | ||||
|                     false | ||||
|                 }; | ||||
| 
 | ||||
|                 // only allow to use TABLE keyword for DESC|DESCRIBE statement
 | ||||
|                 let has_table_keyword = self.parse_keyword(Keyword::TABLE); | ||||
|                 let table_name = self.parse_object_name(false)?; | ||||
|                 Ok(Statement::ExplainTable { | ||||
|                     describe_alias, | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andrew Lamb
						Andrew Lamb