Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13958,7 +13958,7 @@ impl<'a> Parser<'a> {
closing_paren_token: closing_paren_token.into(),
}
};
if self.parse_keyword(Keyword::FROM) {
if dialect_of!(self is HiveDialect) && self.parse_keyword(Keyword::FROM) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I follow the intent of the PR, is it rather that hive should support supports_from_first_select (i.e. what's the difference in behavior from hive vs other dialects)?

cte.from = Some(self.parse_identifier()?);
}
Ok(cte)
Expand Down
123 changes: 123 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16073,6 +16073,129 @@ fn test_select_from_first() {
}
}

#[test]
fn test_select_from_first_with_cte() {
let dialects = all_dialects_where(|d| d.supports_from_first_select());
let q = "WITH test AS (FROM t SELECT a) FROM test SELECT 1";

let ast = dialects.verified_query(q);

let expected = Query {
with: Some(With {
with_token: AttachedToken::empty(),
recursive: false,
cte_tables: vec![Cte {
alias: TableAlias {
explicit: false,
name: Ident {
value: "test".to_string(),
quote_style: None,
span: Span::empty(),
},
columns: vec![],
},
query: Box::new(Query {
with: None,
body: Box::new(SetExpr::Select(Box::new(Select {
select_token: AttachedToken::empty(),
optimizer_hints: vec![],
distinct: None,
select_modifiers: None,
top: None,
projection: vec![SelectItem::UnnamedExpr(Expr::Identifier(Ident {
value: "a".to_string(),
quote_style: None,
span: Span::empty(),
}))],
exclude: None,
top_before_distinct: false,
into: None,
from: vec![TableWithJoins {
relation: table_from_name(ObjectName::from(vec![Ident {
value: "t".to_string(),
quote_style: None,
span: Span::empty(),
}])),
joins: vec![],
}],
lateral_views: vec![],
prewhere: None,
selection: None,
group_by: GroupByExpr::Expressions(vec![], vec![]),
cluster_by: vec![],
distribute_by: vec![],
sort_by: vec![],
having: None,
named_window: vec![],
window_before_qualify: false,
qualify: None,
value_table_mode: None,
connect_by: vec![],
flavor: SelectFlavor::FromFirst,
}))),
order_by: None,
limit_clause: None,
fetch: None,
locks: vec![],
for_clause: None,
settings: None,
format_clause: None,
pipe_operators: vec![],
}),
from: None,
materialized: None,
closing_paren_token: AttachedToken::empty(),
}],
}),
body: Box::new(SetExpr::Select(Box::new(Select {
select_token: AttachedToken::empty(),
optimizer_hints: vec![],
distinct: None,
select_modifiers: None,
top: None,
projection: vec![SelectItem::UnnamedExpr(Expr::Value(ValueWithSpan {
value: test_utils::number("1"),
span: Span::empty(),
}))],
exclude: None,
top_before_distinct: false,
into: None,
from: vec![TableWithJoins {
relation: table_from_name(ObjectName::from(vec![Ident {
value: "test".to_string(),
quote_style: None,
span: Span::empty(),
}])),
joins: vec![],
}],
lateral_views: vec![],
prewhere: None,
selection: None,
group_by: GroupByExpr::Expressions(vec![], vec![]),
cluster_by: vec![],
distribute_by: vec![],
sort_by: vec![],
having: None,
named_window: vec![],
window_before_qualify: false,
qualify: None,
value_table_mode: None,
connect_by: vec![],
flavor: SelectFlavor::FromFirst,
}))),
order_by: None,
limit_clause: None,
fetch: None,
locks: vec![],
for_clause: None,
settings: None,
format_clause: None,
pipe_operators: vec![],
};
assert_eq!(expected, ast);
assert_eq!(ast.to_string(), q);
}

#[test]
fn test_geometric_unary_operators() {
// Number of points in path or polygon
Expand Down