@@ -808,6 +808,23 @@ pub enum Expr {
808808 } ,
809809 /// Scalar function call e.g. `LEFT(foo, 5)`
810810 Function ( Function ) ,
811+ /// Arbitrary expr method call
812+ ///
813+ /// Syntax:
814+ ///
815+ /// `<arbitrary-expr>.<function-call>.<function-call-expr>...`
816+ ///
817+ /// > `arbitrary-expr` can be any expression including a function call.
818+ ///
819+ /// Example:
820+ ///
821+ /// ```sql
822+ /// SELECT (SELECT ',' + name FROM sys.objects FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)')
823+ /// SELECT CONVERT(XML,'<Book>abc</Book>').value('.','NVARCHAR(MAX)').value('.','NVARCHAR(MAX)')
824+ /// ```
825+ ///
826+ /// (mssql): <https://learn.microsoft.com/en-us/sql/t-sql/xml/xml-data-type-methods?view=sql-server-ver16>
827+ Method ( Method ) ,
811828 /// `CASE [<operand>] WHEN <condition> THEN <result> ... [ELSE <result>] END`
812829 ///
813830 /// Note we only recognize a complete single expression as `<condition>`,
@@ -1464,6 +1481,7 @@ impl fmt::Display for Expr {
14641481 write ! ( f, " '{}'" , & value:: escape_single_quote_string( value) )
14651482 }
14661483 Expr :: Function ( fun) => write ! ( f, "{fun}" ) ,
1484+ Expr :: Method ( method) => write ! ( f, "{method}" ) ,
14671485 Expr :: Case {
14681486 operand,
14691487 conditions,
@@ -3329,6 +3347,22 @@ pub enum Statement {
33293347 channel : Ident ,
33303348 payload : Option < String > ,
33313349 } ,
3350+ /// ```sql
3351+ /// LOAD DATA [LOCAL] INPATH 'filepath' [OVERWRITE] INTO TABLE tablename
3352+ /// [PARTITION (partcol1=val1, partcol2=val2 ...)]
3353+ /// [INPUTFORMAT 'inputformat' SERDE 'serde']
3354+ /// ```
3355+ /// Loading files into tables
3356+ ///
3357+ /// See Hive <https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=27362036#LanguageManualDML-Loadingfilesintotables>
3358+ LoadData {
3359+ local : bool ,
3360+ inpath : String ,
3361+ overwrite : bool ,
3362+ table_name : ObjectName ,
3363+ partitioned : Option < Vec < Expr > > ,
3364+ table_format : Option < HiveLoadDataFormat > ,
3365+ } ,
33323366}
33333367
33343368impl fmt:: Display for Statement {
@@ -3931,6 +3965,36 @@ impl fmt::Display for Statement {
39313965 Ok ( ( ) )
39323966 }
39333967 Statement :: CreateTable ( create_table) => create_table. fmt ( f) ,
3968+ Statement :: LoadData {
3969+ local,
3970+ inpath,
3971+ overwrite,
3972+ table_name,
3973+ partitioned,
3974+ table_format,
3975+ } => {
3976+ write ! (
3977+ f,
3978+ "LOAD DATA {local}INPATH '{inpath}' {overwrite}INTO TABLE {table_name}" ,
3979+ local = if * local { "LOCAL " } else { "" } ,
3980+ inpath = inpath,
3981+ overwrite = if * overwrite { "OVERWRITE " } else { "" } ,
3982+ table_name = table_name,
3983+ ) ?;
3984+ if let Some ( ref parts) = & partitioned {
3985+ if !parts. is_empty ( ) {
3986+ write ! ( f, " PARTITION ({})" , display_comma_separated( parts) ) ?;
3987+ }
3988+ }
3989+ if let Some ( HiveLoadDataFormat {
3990+ serde,
3991+ input_format,
3992+ } ) = & table_format
3993+ {
3994+ write ! ( f, " INPUTFORMAT {input_format} SERDE {serde}" ) ?;
3995+ }
3996+ Ok ( ( ) )
3997+ }
39343998 Statement :: CreateVirtualTable {
39353999 name,
39364000 if_not_exists,
@@ -5609,6 +5673,27 @@ impl fmt::Display for FunctionArgumentClause {
56095673 }
56105674}
56115675
5676+ /// A method call
5677+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
5678+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
5679+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
5680+ pub struct Method {
5681+ pub expr : Box < Expr > ,
5682+ // always non-empty
5683+ pub method_chain : Vec < Function > ,
5684+ }
5685+
5686+ impl fmt:: Display for Method {
5687+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
5688+ write ! (
5689+ f,
5690+ "{}.{}" ,
5691+ self . expr,
5692+ display_separated( & self . method_chain, "." )
5693+ )
5694+ }
5695+ }
5696+
56125697#[ derive( Debug , Copy , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
56135698#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
56145699#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
@@ -5816,6 +5901,14 @@ pub enum HiveRowFormat {
58165901 DELIMITED { delimiters : Vec < HiveRowDelimiter > } ,
58175902}
58185903
5904+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
5905+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
5906+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
5907+ pub struct HiveLoadDataFormat {
5908+ pub serde : Expr ,
5909+ pub input_format : Expr ,
5910+ }
5911+
58195912#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
58205913#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
58215914#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
0 commit comments