adriangb commented on code in PR #27478:
URL: https://github.com/apache/datafusion/pull/27478#discussion_r4590346548


##########
datafusion/sql/src/unparser/expr.rs:
##########
@@ -1307,6 +1307,28 @@ impl Unparser<'_> {
         }
     }
 
+    /// Renders a non-finite float as `CAST('NaN' | 'Infinity' | '-Infinity' 
AS <type>)`.
+    ///
+    /// A bare `inf` or `NaN` number token parses back as an identifier. The 
sign
+    /// stays inside the string, so the cast folds to one negative literal and 
not
+    /// to a negation of a cast.
+    fn non_finite_float_to_sql(&self, f: f64, data_type: DataType) -> 
Result<ast::Expr> {
+        let value = if f.is_nan() {
+            "NaN"
+        } else if f.is_sign_positive() {
+            "Infinity"
+        } else {
+            "-Infinity"
+        };
+        Ok(ast::Expr::Cast {
+            kind: ast::CastKind::Cast,
+            expr: 
Box::new(ast::Expr::value(SingleQuotedString(value.to_string()))),
+            data_type: self
+                
.arrow_dtype_to_ast_dtype(&data_type.into_nullable_field_ref())?,

Review Comment:
   Fixed in 84ec976. A new `Dialect::non_finite_float_to_sql` hook keeps the 
cast by default. `SqliteDialect` renders infinity as `9e999` / `-9e999`, which 
SQLite reads as infinity, and returns a not-implemented error for NaN, which 
SQLite cannot represent. `test_sqlite_non_finite_float_scalar_to_expr` covers 
both.
   
   _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_



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