goldmedal commented on code in PR #16610:
URL: https://github.com/apache/datafusion/pull/16610#discussion_r2174859892
##########
datafusion/sql/tests/cases/plan_to_sql.rs:
##########
@@ -2596,3 +2600,36 @@ fn test_not_ilike_filter_with_escape() {
@"SELECT person.first_name FROM person WHERE person.first_name NOT
ILIKE 'A!_%' ESCAPE '!'"
);
}
+
+#[test]
+fn test_struct_expr() {
+ let statement = generate_round_trip_statement(
+ GenericDialect {},
+ r#"WITH test AS (SELECT STRUCT(STRUCT(STRUCT('Product Name' as name))
as product) AS metadata) SELECT metadata.product FROM test WHERE
metadata.product.name = 'Product Name'"#,
Review Comment:
I think this test case is wrong. If I try to select `metadata.product.name`
like:
```sql
WITH
test AS (
SELECT
STRUCT (
STRUCT (STRUCT ('Product Name' as name)) as product
) AS metadata
)
SELECT
metadata.product.name
FROM
test
```
We will get the following error message:
```
called `Result::unwrap()` on an `Err` value: Plan("Field name not found in
struct")
```
Because you create an unnamed struct as `product`:
```
STRUCT (STRUCT ('Product Name' as name)) as product
```
It creates the structure like `product.c0.name` here, actually.
I guess what you really want is:
```suggestion
r#"WITH test AS (SELECT STRUCT(STRUCT('Product Name' as name) as
product) AS metadata) SELECT metadata.product FROM test WHERE
metadata.product.name = 'Product Name'"#,
```
It will create a column called `metadata` which is a 2-dim struct
`product.name`.
--
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]