@@ -2205,31 +2205,50 @@ pub enum JoinConstraint {
22052205#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
22062206#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
22072207#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
2208- pub struct OrderBy {
2209- pub exprs : Vec < OrderByExpr > ,
2210- /// Optional: `INTERPOLATE`
2211- /// Supported by [ClickHouse syntax]
2208+ pub enum OrderBy {
2209+ /// ALL syntax of [DuckDB] and [ClickHouse].
22122210 ///
2213- /// [ClickHouse syntax]: <https://clickhouse.com/docs/en/sql-reference/statements/select/order-by#order-by-expr-with-fill-modifier>
2214- pub interpolate : Option < Interpolate > ,
2211+ /// [DuckDB]: <https://duckdb.org/docs/sql/query_syntax/orderby>
2212+ /// [ClickHouse]: <https://clickhouse.com/docs/en/sql-reference/statements/select/order-by>
2213+ All ( OrderByAll ) ,
2214+
2215+ /// Expressions
2216+ Expressions ( OrderByExprsWithInterpolate ) ,
22152217}
22162218
22172219impl fmt:: Display for OrderBy {
22182220 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
22192221 write ! ( f, "ORDER BY" ) ?;
2220- if !self . exprs . is_empty ( ) {
2221- write ! ( f, " {}" , display_comma_separated( & self . exprs) ) ?;
2222- }
2223- if let Some ( ref interpolate) = self . interpolate {
2224- match & interpolate. exprs {
2225- Some ( exprs) => write ! ( f, " INTERPOLATE ({})" , display_comma_separated( exprs) ) ?,
2226- None => write ! ( f, " INTERPOLATE" ) ?,
2222+ match self {
2223+ OrderBy :: Expressions ( exprs) => {
2224+ write ! ( f, "{}" , exprs) ?;
2225+ }
2226+ OrderBy :: All ( all) => {
2227+ write ! ( f, " ALL{}" , all) ?;
22272228 }
22282229 }
2230+
22292231 Ok ( ( ) )
22302232 }
22312233}
22322234
2235+ impl OrderBy {
2236+ pub fn get_exprs ( & self ) -> Option < & Vec < OrderByExpr > > {
2237+ match self {
2238+ OrderBy :: Expressions ( exprs_with_interpolate) => Some ( & exprs_with_interpolate. exprs ) ,
2239+ OrderBy :: All ( _) => None ,
2240+ }
2241+ }
2242+ pub fn get_interpolate ( & self ) -> Option < & Interpolate > {
2243+ match self {
2244+ OrderBy :: Expressions ( exprs_with_interpolate) => {
2245+ exprs_with_interpolate. interpolate . as_ref ( )
2246+ }
2247+ OrderBy :: All ( _) => None ,
2248+ }
2249+ }
2250+ }
2251+
22332252/// An `ORDER BY` expression
22342253#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
22352254#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
@@ -2323,6 +2342,61 @@ impl fmt::Display for InterpolateExpr {
23232342 }
23242343}
23252344
2345+ /// `ORDER BY` expressions with interpolate
2346+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
2347+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
2348+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
2349+ pub struct OrderByExprsWithInterpolate {
2350+ pub exprs : Vec < OrderByExpr > ,
2351+ /// Expressions
2352+ /// Optional: `INTERPOLATE`
2353+ /// Supported by [ClickHouse syntax]
2354+ /// [ClickHouse syntax]: <https://clickhouse.com/docs/en/sql-reference/statements/select/order-by#order-by-expr-with-fill-modifier>
2355+ pub interpolate : Option < Interpolate > ,
2356+ }
2357+
2358+ impl fmt:: Display for OrderByExprsWithInterpolate {
2359+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
2360+ if !self . exprs . is_empty ( ) {
2361+ write ! ( f, " {}" , display_comma_separated( & self . exprs) ) ?;
2362+ }
2363+ if let Some ( ref interpolate) = self . interpolate {
2364+ match & interpolate. exprs {
2365+ Some ( exprs) => write ! ( f, " INTERPOLATE ({})" , display_comma_separated( exprs) ) ?,
2366+ None => write ! ( f, " INTERPOLATE" ) ?,
2367+ }
2368+ }
2369+ Ok ( ( ) )
2370+ }
2371+ }
2372+
2373+ /// 'ORDER BY ALL' clause
2374+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
2375+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
2376+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
2377+ pub struct OrderByAll {
2378+ /// Optional `ASC` or `DESC`
2379+ pub asc : Option < bool > ,
2380+ /// Optional `NULLS FIRST` or `NULLS LAST`
2381+ pub nulls_first : Option < bool > ,
2382+ }
2383+
2384+ impl fmt:: Display for OrderByAll {
2385+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
2386+ match self . asc {
2387+ Some ( true ) => write ! ( f, " ASC" ) ?,
2388+ Some ( false ) => write ! ( f, " DESC" ) ?,
2389+ None => ( ) ,
2390+ }
2391+ match self . nulls_first {
2392+ Some ( true ) => write ! ( f, " NULLS FIRST" ) ?,
2393+ Some ( false ) => write ! ( f, " NULLS LAST" ) ?,
2394+ None => ( ) ,
2395+ }
2396+ Ok ( ( ) )
2397+ }
2398+ }
2399+
23262400#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
23272401#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
23282402#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
0 commit comments