-
Notifications
You must be signed in to change notification settings - Fork 711
Only parse FROM identifier in CTE if using Hive #2241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder are we asserting something specific about the AST? It would be good to skip the assertion since the struct is quite verbose - thinking if its sufficient to only assert that the query parses and round trip. Otherwise if we can rewrite/split the assertion to only assert the components we're interested in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I simplified to only assert the query body's projection and from clauses. |
||
| 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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this should be needed given
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I followed the existing |
||
| } | ||
|
|
||
| #[test] | ||
| fn test_geometric_unary_operators() { | ||
| // Number of points in path or polygon | ||
|
|
||
There was a problem hiding this comment.
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)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave more context in the issue I created; I'm not knowledgeable enough about Hive to understand if it should support FROM first selects, and it is unclear (see also #235 (comment)) why this
FROMtoken parsing was introduced here. Maybe the intent was indeed to support FROM first selects, but I'd rather not break things here so that's why I only gated thisFROMparsing for Hive.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, oh yeah afaict it seems to be the case that from the link the syntax was misinterpreted, the
FROMdoesn't belong to the CTE, rather its a variant of from_first (at least for insert statements).I think ideally we would introduce a
self.dialect.supports_from_first_insertmethod that hive flags and thefrombeing set here moves from the cte to the insert statement. The latter might be out of scope for the MR however, so maybe we can just add a comment in the hive dialect method on the former mentioning that its incomplete/incorrect?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with this option, I can also create a follow up issue along with the comment (or just the comment if you are happy with it).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An issue sounds great as well thanks!