mirror of
				https://github.com/apache/datafusion-sqlparser-rs.git
				synced 2025-10-31 15:17:41 +00:00 
			
		
		
		
	ClickHouse: create view with fields and data types (#1292)
This commit is contained in:
		
							parent
							
								
									029a999645
								
							
						
					
					
						commit
						375742d1fa
					
				
					 5 changed files with 60 additions and 2 deletions
				
			
		|  | @ -815,7 +815,7 @@ impl fmt::Display for ColumnDef { | |||
| ///
 | ||||
| /// Syntax
 | ||||
| /// ```markdown
 | ||||
| /// <name> [OPTIONS(option, ...)]
 | ||||
| /// <name> [data_type][OPTIONS(option, ...)]
 | ||||
| ///
 | ||||
| /// option: <name> = <value>
 | ||||
| /// ```
 | ||||
|  | @ -824,18 +824,23 @@ impl fmt::Display for ColumnDef { | |||
| /// ```sql
 | ||||
| /// name
 | ||||
| /// age OPTIONS(description = "age column", tag = "prod")
 | ||||
| /// created_at DateTime64
 | ||||
| /// ```
 | ||||
| #[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] | ||||
| #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||||
| #[cfg_attr(feature = "visitor", derive(Visit, VisitMut))] | ||||
| pub struct ViewColumnDef { | ||||
|     pub name: Ident, | ||||
|     pub data_type: Option<DataType>, | ||||
|     pub options: Option<Vec<SqlOption>>, | ||||
| } | ||||
| 
 | ||||
| impl fmt::Display for ViewColumnDef { | ||||
|     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||||
|         write!(f, "{}", self.name)?; | ||||
|         if let Some(data_type) = self.data_type.as_ref() { | ||||
|             write!(f, " {}", data_type)?; | ||||
|         } | ||||
|         if let Some(options) = self.options.as_ref() { | ||||
|             write!( | ||||
|                 f, | ||||
|  |  | |||
|  | @ -7282,7 +7282,16 @@ impl<'a> Parser<'a> { | |||
|         } else { | ||||
|             None | ||||
|         }; | ||||
|         Ok(ViewColumnDef { name, options }) | ||||
|         let data_type = if dialect_of!(self is ClickHouseDialect) { | ||||
|             Some(self.parse_data_type()?) | ||||
|         } else { | ||||
|             None | ||||
|         }; | ||||
|         Ok(ViewColumnDef { | ||||
|             name, | ||||
|             data_type, | ||||
|             options, | ||||
|         }) | ||||
|     } | ||||
| 
 | ||||
|     /// Parse a parenthesized comma-separated list of unqualified, possibly quoted identifiers
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Aleksei Piianin
						Aleksei Piianin