Skip to content

Commit ef5c9a9

Browse files
committed
fix(graph): remove CTE name requirements
1 parent c96c0c6 commit ef5c9a9

File tree

1 file changed

+0
-44
lines changed

1 file changed

+0
-44
lines changed

graph/src/amp/sql/query_builder/parser.rs

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use sqlparser_latest::{
1616
/// - The SQL query cannot be parsed
1717
/// - The SQL query contains multiple SQL statements
1818
/// - The SQL query is not a `SELECT` query
19-
/// - The SQL query contains CTEs with quoted names
2019
///
2120
/// The returned error is deterministic.
2221
pub(super) fn parse_query(s: impl AsRef<str>) -> Result<ast::Query> {
@@ -35,10 +34,6 @@ pub(super) fn parse_query(s: impl AsRef<str>) -> Result<ast::Query> {
3534
return Err(e);
3635
}
3736

38-
if let ControlFlow::Break(e) = query.visit(&mut AllowOnlyUnquotedCtes) {
39-
return Err(e);
40-
}
41-
4237
Ok(query)
4338
}
4439

@@ -76,41 +71,6 @@ impl Visitor for AllowOnlySelectQueries {
7671
}
7772
}
7873

79-
/// Validates that CTE names in the SQL query AST do not use quotes.
80-
///
81-
/// This is a temporary solution that allows proper identification of table references.
82-
struct AllowOnlyUnquotedCtes;
83-
84-
impl AllowOnlyUnquotedCtes {
85-
/// Returns an error if the `query` contains CTEs with quoted names.
86-
fn visit_query(&self, query: &ast::Query) -> Result<()> {
87-
let Some(with) = &query.with else {
88-
return Ok(());
89-
};
90-
91-
for cte_table in &with.cte_tables {
92-
let cte_name = &cte_table.alias.name;
93-
94-
if cte_name.quote_style.is_some() {
95-
bail!("invalid CTE {cte_name}: CTE names with quotes are not allowed");
96-
}
97-
}
98-
99-
Ok(())
100-
}
101-
}
102-
103-
impl Visitor for AllowOnlyUnquotedCtes {
104-
type Break = anyhow::Error;
105-
106-
fn pre_visit_query(&mut self, query: &ast::Query) -> ControlFlow<Self::Break> {
107-
match self.visit_query(query) {
108-
Ok(()) => ControlFlow::Continue(()),
109-
Err(e) => ControlFlow::Break(e),
110-
}
111-
}
112-
}
113-
11474
#[cfg(test)]
11575
mod tests {
11676
use super::*;
@@ -151,9 +111,5 @@ mod tests {
151111
valid_query: "SELECT a FROM b" => Ok("SELECT a FROM b"),
152112
valid_query_with_cte: "WITH a AS (SELECT b FROM c) SELECT * FROM a" => Ok("WITH a AS (SELECT b FROM c) SELECT * FROM a"),
153113
valid_query_with_join: "SELECT a FROM b INNER JOIN c ON c.c = b.b" => Ok("SELECT a FROM b INNER JOIN c ON c.c = b.b"),
154-
155-
single_quoted_ctes_not_allowed: "WITH 'a' AS (SELECT * FROM b) SELECT * FROM a" => Err("invalid CTE 'a': CTE names with quotes are not allowed"),
156-
double_quoted_ctes_not_allowed: r#"WITH "a" AS (SELECT * FROM b) SELECT * FROM a"# => Err(r#"invalid CTE "a": CTE names with quotes are not allowed"#),
157-
backticked_ctes_not_allowed: "WITH `a` AS (SELECT * FROM b) SELECT * FROM a" => Err("invalid CTE `a`: CTE names with quotes are not allowed"),
158114
}
159115
}

0 commit comments

Comments
 (0)