Viicos commented on code in PR #2241:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/2241#discussion_r3080067084


##########
tests/sqlparser_common.rs:
##########
@@ -16118,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);

Review Comment:
   I followed the existing 
[`test_select_from_first()`](https://github.com/apache/datafusion-sqlparser-rs/blob/67d684b1a0cf0a9da149fb7733fbdeecf70cf7f1/tests/sqlparser_common.rs#L16162)
 test for this one, but this makes sense. I removed the assertion from both 
tests.



##########
tests/sqlparser_common.rs:
##########
@@ -16118,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 {

Review Comment:
   I simplified to only assert the query body's projection and from clauses.



-- 
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]

Reply via email to