Copilot commented on code in PR #27478:
URL: https://github.com/apache/datafusion/pull/27478#discussion_r4590295336
##########
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:
With `SqliteDialect`, these casts silently turn infinity and NaN into zero
for both `DOUBLE` and `FLOAT`, producing executable SQL with incorrect results.
For example, SQLite evaluates `1.0 < CAST('Infinity' AS DOUBLE)` as false
instead of true. Make non-finite literal rendering dialect-aware, using a
supported representation or returning an unsupported-value error, and add a
SQLite regression test.
--
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]