iffyio commented on code in PR #1724:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/1724#discussion_r1952866285


##########
src/ast/query.rs:
##########
@@ -2205,31 +2205,50 @@ pub enum JoinConstraint {
 #[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
 #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
 #[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
-pub struct OrderBy {
-    pub exprs: Vec<OrderByExpr>,
-    /// Optional: `INTERPOLATE`
-    /// Supported by [ClickHouse syntax]
+pub enum OrderBy {

Review Comment:
   Would it make sense to use this representation instead?
   ```rust
   enum OrderByKind {
       Expr(Vec<OrderByExpr>),
       All
   }
   struct OrderBy {
       pub kind: OrderByKind,
       pub interpolate: Option<Interpolate>,
   }
   ```
   thinking in order to avoid duplicating interpolate (and other shared) 
parameters



##########
src/parser/mod.rs:
##########
@@ -9183,17 +9183,19 @@ impl<'a> Parser<'a> {
 
     pub fn parse_optional_order_by(&mut self) -> Result<Option<OrderBy>, 
ParserError> {
         if self.parse_keywords(&[Keyword::ORDER, Keyword::BY]) {
-            let order_by_exprs = 
self.parse_comma_separated(Parser::parse_order_by_expr)?;
-            let interpolate = if dialect_of!(self is ClickHouseDialect | 
GenericDialect) {
-                self.parse_interpolations()?
+            let order_by = if self.parse_keyword(Keyword::ALL) {

Review Comment:
   could we introduce a dialect method `self.dialect.supports_order_by_all()` 
and guard this behavior with it? since it would be incorrect behavior if this 
branch returns true for a dialect that does not support this feature



##########
src/ast/query.rs:
##########
@@ -2205,31 +2205,50 @@ pub enum JoinConstraint {
 #[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
 #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
 #[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
-pub struct OrderBy {
-    pub exprs: Vec<OrderByExpr>,
-    /// Optional: `INTERPOLATE`
-    /// Supported by [ClickHouse syntax]
+pub enum OrderBy {
+    /// ALL syntax of [DuckDB] and [ClickHouse].
     ///
-    /// [ClickHouse syntax]: 
<https://clickhouse.com/docs/en/sql-reference/statements/select/order-by#order-by-expr-with-fill-modifier>
-    pub interpolate: Option<Interpolate>,
+    /// [DuckDB]:  <https://duckdb.org/docs/sql/query_syntax/orderby>
+    /// [ClickHouse]: 
<https://clickhouse.com/docs/en/sql-reference/statements/select/order-by>
+    All(OrderByAll),
+
+    /// Expressions
+    Expressions(OrderByExprsWithInterpolate),
 }
 
 impl fmt::Display for OrderBy {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         write!(f, "ORDER BY")?;
-        if !self.exprs.is_empty() {
-            write!(f, " {}", display_comma_separated(&self.exprs))?;
-        }
-        if let Some(ref interpolate) = self.interpolate {
-            match &interpolate.exprs {
-                Some(exprs) => write!(f, " INTERPOLATE ({})", 
display_comma_separated(exprs))?,
-                None => write!(f, " INTERPOLATE")?,
+        match self {
+            OrderBy::Expressions(exprs) => {
+                write!(f, "{}", exprs)?;
+            }
+            OrderBy::All(all) => {
+                write!(f, " ALL{}", all)?;
             }
         }
+
         Ok(())
     }
 }
 
+impl OrderBy {
+    pub fn get_exprs(&self) -> Option<&Vec<OrderByExpr>> {
+        match self {
+            OrderBy::Expressions(exprs_with_interpolate) => 
Some(&exprs_with_interpolate.exprs),
+            OrderBy::All(_) => None,
+        }
+    }
+    pub fn get_interpolate(&self) -> Option<&Interpolate> {
+        match self {
+            OrderBy::Expressions(exprs_with_interpolate) => {
+                exprs_with_interpolate.interpolate.as_ref()
+            }
+            OrderBy::All(_) => None,
+        }
+    }
+}

Review Comment:
   I'm thinking we would rather avoid these methods to avoid more api breakage 
than necessary when things change. Did we introduce them primarily for the 
tests? if so I think we could as usual have the test match the expected expr 
variant



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to