hmadison opened a new issue, #16607:
URL: https://github.com/apache/datafusion/issues/16607
### Describe the bug
When attempting to invoke `plan_to_sql` on a plan which includes accessing a
field inside of a nested structure, the invocation fails with the following
error:
```
Error: Custom { kind: Other, error: Internal("get_field expects first
argument to be column, but received: ScalarFunction(ScalarFunction { func:
ScalarUDF { inner: GetFieldFunc { signature: Signature { type_signature:
Any(2), volatility: Immutable } } }, args: [Column(Column { relation: Some(Bare
{ table: \"query\" }), name: \"metadata\" }), Literal(Utf8(\"product\"), None)]
})") }
```
### To Reproduce
Given `query.json` as:
```json
{"metadata": {"product": {"name": "Product Name"}}}
```
The following test case reproduces the error:
```rust
use std::io::Error;
use datafusion::prelude::{NdJsonReadOptions, SessionContext};
use datafusion::sql::unparser::plan_to_sql;
#[tokio::test]
async fn test_plan_to_sql() -> Result<(), Error> {
let ctx = SessionContext::new();
ctx.register_json("query", "tests/fixtures/query.json",
NdJsonReadOptions::default()).await?;
let df = ctx.sql(r#"SELECT query."message" FROM query WHERE
metadata['product']['name'] = 'Product Name'"#).await?;
let sql_ast = plan_to_sql(df.logical_plan())?;
assert_eq!(r#"SELECT "query".message FROM "query" WHERE
("query"."metadata".product.name = 'Product Name')"#, sql_ast.to_string());
Ok(())
}
```
### Expected behavior
The expectation would be that the `plan_to_sql` call succeeds and generates
a SQL expression similar to:
```sql
SELECT "query".message FROM "query" WHERE ("query"."metadata".product.name =
'Product Name')
```
### Additional context
While I'm not too familiar with the code base, my best guess is that the
problem seems to be in
[`get_field_to_sql`](https://github.com/apache/datafusion/blob/0143b20de3f9e25ab8d87ef4b96b78c28e462bee/datafusion/sql/src/unparser/expr.rs#L619).
If I'm understanding the logic correctly, the implementation assumes a column
/ field pair.
--
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]