iffyio commented on code in PR #2024:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2024#discussion_r2348297077
##########
src/dialect/mod.rs:
##########
@@ -596,6 +596,20 @@ pub trait Dialect: Debug + Any {
false
}
+ /// Returns true if the dialect supports Common Scalar Expressions in
`SELECT`.
+ ///
+ /// For example:
+ /// ```sql
+ /// WITH
+ /// toDate('2000-01-01') AS start_date
+ /// SELECT * from tbl WHERE col1 > start_date;
+ /// ```
+ ///
+ ///
[ClickHouse](https://clickhouse.com/docs/sql-reference/statements/select/with#common-scalar-expressions)
+ fn supports_common_scalar_expressions(&self) -> bool {
+ false
+ }
Review Comment:
In general [we try to add support for new syntax to the generic
dialect](https://github.com/apache/datafusion-sqlparser-rs?tab=readme-ov-file#new-syntax)
as long as the syntax doesn't conflict with existing syntax support on the
dialect
##########
src/ast/query.rs:
##########
@@ -641,6 +641,56 @@ impl fmt::Display for CteAsMaterialized {
}
}
+#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
+#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
+#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
+pub enum CteOrCse {
+ Cte(Cte),
+ Cse(Cse),
+}
+
+impl CteOrCse {
+ pub fn cte(&self) -> Option<&Cte> {
+ match self {
+ CteOrCse::Cte(cte) => Some(cte),
+ CteOrCse::Cse(_) => None,
+ }
+ }
+
+ pub fn cse(&self) -> Option<&Cse> {
+ match self {
+ CteOrCse::Cte(_) => None,
+ CteOrCse::Cse(cse) => Some(cse),
+ }
+ }
+}
Review Comment:
I think this is okay to skip, users can match directly on the enum when
needed similar to other nodes in the AST
##########
src/parser/mod.rs:
##########
@@ -12260,6 +12260,27 @@ impl<'a> Parser<'a> {
})
}
+ /// Parse a CTE or CSE.
+ pub fn parse_cte_or_cse(&mut self) -> Result<CteOrCse, ParserError> {
+ Ok(if dialect_of!(self is ClickHouseDialect) {
+ if let Some(cse) = self.maybe_parse(Parser::parse_cse)? {
+ CteOrCse::Cse(cse)
+ } else {
+ CteOrCse::Cte(self.parse_cte()?)
+ }
+ } else {
+ CteOrCse::Cte(self.parse_cte()?)
+ })
+ }
+
+ /// Parse a CSE (`<expr> AS <ident>`).
+ pub fn parse_cse(&mut self) -> Result<Cse, ParserError> {
Review Comment:
I think it should be fine to leave them as public APIs in this case!
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]