adriangb opened a new issue, #27491:
URL: https://github.com/apache/datafusion/issues/27491

   ### Describe the bug
   
   `Unparser::arrow_dtype_to_ast_dtype` maps `DataType::Float32` to 
`ast::DataType::Float` for every dialect, and `Float16` uses the same type. 
With `BigQueryDialect`, a cast to `Float32` unparses as `CAST(... AS FLOAT)`. 
BigQuery rejects that SQL:
   
   ```
   SELECT CAST('Infinity' AS FLOAT) AS v
   -- Type not found: FLOAT at [1:27]
   ```
   
   The `Dialect` trait has `float64_ast_dtype`, which `BigQueryDialect` 
overrides to `FLOAT64`. It has no matching hook for `Float32`.
   
   ### To Reproduce
   
   ```rust
   use arrow::datatypes::DataType;
   use datafusion_expr::{cast, col};
   use datafusion_sql::unparser::{Unparser, dialect::BigQueryDialect};
   
   let expr = cast(col("a"), DataType::Float32);
   let sql = Unparser::new(&BigQueryDialect {}).expr_to_sql(&expr)?;
   println!("{sql}"); // CAST(`a` AS FLOAT)
   ```
   
   Non-finite `Float32` and `Float16` literals hit this too after #27478, 
because the unparser now writes them as `CAST('Infinity' AS FLOAT)`.
   
   ### Expected behavior
   
   `BigQueryDialect` renders the cast with a type that BigQuery accepts. 
BigQuery SQL has only `FLOAT64`. So the likely fix is a `float32_ast_dtype` 
hook (default `FLOAT`), which `BigQueryDialect` overrides to `FLOAT64`. 
Widening `Float32` to `FLOAT64` keeps the value, because every `Float32` value 
is exact in `FLOAT64`.
   
   ### Additional context
   
   Checked in BigQuery: `CAST('Infinity' AS FLOAT64)`, `CAST('-Infinity' AS 
FLOAT64)`, and `CAST('NaN' AS FLOAT64)` all work. `CAST(... AS FLOAT)` fails 
with `Type not found: FLOAT`.
   


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