@@ -2218,30 +2218,50 @@ pub enum JoinConstraint {
22182218 None ,
22192219}
22202220
2221+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
2222+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
2223+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
2224+ pub enum OrderByKind {
2225+ /// ALL syntax of [DuckDB] and [ClickHouse].
2226+ ///
2227+ /// [DuckDB]: <https://duckdb.org/docs/sql/query_syntax/orderby>
2228+ /// [ClickHouse]: <https://clickhouse.com/docs/en/sql-reference/statements/select/order-by>
2229+ All ( OrderByOptions ) ,
2230+
2231+ /// Expressions
2232+ Expressions ( Vec < OrderByExpr > ) ,
2233+ }
2234+
22212235#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
22222236#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
22232237#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
22242238pub struct OrderBy {
2225- pub exprs : Vec < OrderByExpr > ,
2239+ pub kind : OrderByKind ,
2240+
22262241 /// Optional: `INTERPOLATE`
22272242 /// Supported by [ClickHouse syntax]
2228- ///
2229- /// [ClickHouse syntax]: <https://clickhouse.com/docs/en/sql-reference/statements/select/order-by#order-by-expr-with-fill-modifier>
22302243 pub interpolate : Option < Interpolate > ,
22312244}
22322245
22332246impl fmt:: Display for OrderBy {
22342247 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
22352248 write ! ( f, "ORDER BY" ) ?;
2236- if !self . exprs . is_empty ( ) {
2237- write ! ( f, " {}" , display_comma_separated( & self . exprs) ) ?;
2249+ match & self . kind {
2250+ OrderByKind :: Expressions ( exprs) => {
2251+ write ! ( f, " {}" , display_comma_separated( exprs) ) ?;
2252+ }
2253+ OrderByKind :: All ( all) => {
2254+ write ! ( f, " ALL{}" , all) ?;
2255+ }
22382256 }
2257+
22392258 if let Some ( ref interpolate) = self . interpolate {
22402259 match & interpolate. exprs {
22412260 Some ( exprs) => write ! ( f, " INTERPOLATE ({})" , display_comma_separated( exprs) ) ?,
22422261 None => write ! ( f, " INTERPOLATE" ) ?,
22432262 }
22442263 }
2264+
22452265 Ok ( ( ) )
22462266 }
22472267}
@@ -2252,28 +2272,15 @@ impl fmt::Display for OrderBy {
22522272#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
22532273pub struct OrderByExpr {
22542274 pub expr : Expr ,
2255- /// Optional `ASC` or `DESC`
2256- pub asc : Option < bool > ,
2257- /// Optional `NULLS FIRST` or `NULLS LAST`
2258- pub nulls_first : Option < bool > ,
2275+ pub options : OrderByOptions ,
22592276 /// Optional: `WITH FILL`
22602277 /// Supported by [ClickHouse syntax]: <https://clickhouse.com/docs/en/sql-reference/statements/select/order-by#order-by-expr-with-fill-modifier>
22612278 pub with_fill : Option < WithFill > ,
22622279}
22632280
22642281impl fmt:: Display for OrderByExpr {
22652282 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
2266- write ! ( f, "{}" , self . expr) ?;
2267- match self . asc {
2268- Some ( true ) => write ! ( f, " ASC" ) ?,
2269- Some ( false ) => write ! ( f, " DESC" ) ?,
2270- None => ( ) ,
2271- }
2272- match self . nulls_first {
2273- Some ( true ) => write ! ( f, " NULLS FIRST" ) ?,
2274- Some ( false ) => write ! ( f, " NULLS LAST" ) ?,
2275- None => ( ) ,
2276- }
2283+ write ! ( f, "{}{}" , self . expr, self . options) ?;
22772284 if let Some ( ref with_fill) = self . with_fill {
22782285 write ! ( f, " {}" , with_fill) ?
22792286 }
@@ -2339,6 +2346,32 @@ impl fmt::Display for InterpolateExpr {
23392346 }
23402347}
23412348
2349+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
2350+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
2351+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
2352+ pub struct OrderByOptions {
2353+ /// Optional `ASC` or `DESC`
2354+ pub asc : Option < bool > ,
2355+ /// Optional `NULLS FIRST` or `NULLS LAST`
2356+ pub nulls_first : Option < bool > ,
2357+ }
2358+
2359+ impl fmt:: Display for OrderByOptions {
2360+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
2361+ match self . asc {
2362+ Some ( true ) => write ! ( f, " ASC" ) ?,
2363+ Some ( false ) => write ! ( f, " DESC" ) ?,
2364+ None => ( ) ,
2365+ }
2366+ match self . nulls_first {
2367+ Some ( true ) => write ! ( f, " NULLS FIRST" ) ?,
2368+ Some ( false ) => write ! ( f, " NULLS LAST" ) ?,
2369+ None => ( ) ,
2370+ }
2371+ Ok ( ( ) )
2372+ }
2373+ }
2374+
23422375#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
23432376#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
23442377#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
0 commit comments