From f6f7f0f220b56828c068d6117e656715293f9787 Mon Sep 17 00:00:00 2001 From: Jack Kleeman Date: Thu, 27 Apr 2023 22:41:19 +0100 Subject: [PATCH 1/2] Support uint64 literals It should be possible to compare numeric types to uint64 literals. Currently for anything above the int64 max, it will become a float or a decimal128 depending on config. The float conversion is lossy, and the decimal type is currently not comparable with uint64, so both of these are problematic. --- datafusion/sql/src/expr/value.rs | 2 ++ datafusion/sql/tests/integration_test.rs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/datafusion/sql/src/expr/value.rs b/datafusion/sql/src/expr/value.rs index c936313e208f..9adcf1b935cf 100644 --- a/datafusion/sql/src/expr/value.rs +++ b/datafusion/sql/src/expr/value.rs @@ -56,6 +56,8 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> { )) } else if let Ok(n) = n.parse::() { Ok(lit(n)) + } else if let Ok(n) = n.parse::() { + Ok(lit(n)) } else if self.options.parse_float_as_decimal { // remove leading zeroes let str = n.trim_start_matches('0'); diff --git a/datafusion/sql/tests/integration_test.rs b/datafusion/sql/tests/integration_test.rs index 64ca85b72d98..9975a78996f8 100644 --- a/datafusion/sql/tests/integration_test.rs +++ b/datafusion/sql/tests/integration_test.rs @@ -56,6 +56,8 @@ fn parse_decimals() { "10000000000000000000.00", "Decimal128(Some(1000000000000000000000),22,2)", ), + ("18446744073709551615", "UInt64(18446744073709551615)"), + ("18446744073709551616", "Decimal128(Some(18446744073709551616),38,0)"), ]; for (a, b) in test_data { let sql = format!("SELECT {a}"); From bf0e0b6c559cf9cd7b6a80b52e2af36ac214438d Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Sun, 30 Apr 2023 06:45:22 -0400 Subject: [PATCH 2/2] fix: fmt --- datafusion/sql/tests/integration_test.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/datafusion/sql/tests/integration_test.rs b/datafusion/sql/tests/integration_test.rs index 9975a78996f8..a69a824a3eea 100644 --- a/datafusion/sql/tests/integration_test.rs +++ b/datafusion/sql/tests/integration_test.rs @@ -57,7 +57,10 @@ fn parse_decimals() { "Decimal128(Some(1000000000000000000000),22,2)", ), ("18446744073709551615", "UInt64(18446744073709551615)"), - ("18446744073709551616", "Decimal128(Some(18446744073709551616),38,0)"), + ( + "18446744073709551616", + "Decimal128(Some(18446744073709551616),38,0)", + ), ]; for (a, b) in test_data { let sql = format!("SELECT {a}");