@@ -2205,25 +2205,48 @@ 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 enum OrderBy {
2208+ pub enum OrderByKind {
22092209 /// ALL syntax of [DuckDB] and [ClickHouse].
22102210 ///
22112211 /// [DuckDB]: <https://duckdb.org/docs/sql/query_syntax/orderby>
22122212 /// [ClickHouse]: <https://clickhouse.com/docs/en/sql-reference/statements/select/order-by>
22132213 All ( OrderByAll ) ,
22142214
22152215 /// Expressions
2216- Expressions ( OrderByExprsWithInterpolate ) ,
2216+ Expressions ( Vec < OrderByExpr > ) ,
2217+ }
2218+
2219+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
2220+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
2221+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
2222+ pub struct OrderBy {
2223+ pub kind : OrderByKind ,
2224+
2225+ /// Optional: `INTERPOLATE`
2226+ /// Supported by [ClickHouse syntax]
2227+ /// Note that when combined with `OrderByKind::All`, it should be None, as ClickHouse doesn't support using them together.
2228+ ///
2229+ /// [ClickHouse syntax]: <https://clickhouse.com/docs/en/sql-reference/statements/select/order-by#order-by-expr-with-fill-modifier>
2230+ pub interpolate : Option < Interpolate > ,
22172231}
22182232
22192233impl fmt:: Display for OrderBy {
22202234 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
22212235 write ! ( f, "ORDER BY" ) ?;
2222- match self {
2223- OrderBy :: Expressions ( exprs) => {
2224- write ! ( f, "{}" , exprs) ?;
2236+ match & self . kind {
2237+ OrderByKind :: Expressions ( exprs) => {
2238+ write ! ( f, " {}" , display_comma_separated( exprs) ) ?;
2239+
2240+ if let Some ( ref interpolate) = self . interpolate {
2241+ match & interpolate. exprs {
2242+ Some ( exprs) => {
2243+ write ! ( f, " INTERPOLATE ({})" , display_comma_separated( exprs) ) ?
2244+ }
2245+ None => write ! ( f, " INTERPOLATE" ) ?,
2246+ }
2247+ }
22252248 }
2226- OrderBy :: All ( all) => {
2249+ OrderByKind :: All ( all) => {
22272250 write ! ( f, " ALL{}" , all) ?;
22282251 }
22292252 }
@@ -2232,23 +2255,6 @@ impl fmt::Display for OrderBy {
22322255 }
22332256}
22342257
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-
22522258/// An `ORDER BY` expression
22532259#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
22542260#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
@@ -2342,34 +2348,6 @@ impl fmt::Display for InterpolateExpr {
23422348 }
23432349}
23442350
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-
23732351/// 'ORDER BY ALL' clause
23742352#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
23752353#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
0 commit comments