Parse number in sql string, convert to Expr::Literal
(
&self,
unsigned_number: &str,
negative: bool,
)
| 70 | |
| 71 | /// Parse number in sql string, convert to Expr::Literal |
| 72 | pub(super) fn parse_sql_number( |
| 73 | &self, |
| 74 | unsigned_number: &str, |
| 75 | negative: bool, |
| 76 | ) -> Result<Expr> { |
| 77 | let signed_number: Cow<str> = if negative { |
| 78 | Cow::Owned(format!("-{unsigned_number}")) |
| 79 | } else { |
| 80 | Cow::Borrowed(unsigned_number) |
| 81 | }; |
| 82 | |
| 83 | // Try to parse as i64 first, then u64 if negative is false, then decimal or f64 |
| 84 | |
| 85 | if let Ok(n) = signed_number.parse::<i64>() { |
| 86 | return Ok(lit(n)); |
| 87 | } |
| 88 | |
| 89 | if !negative && let Ok(n) = unsigned_number.parse::<u64>() { |
| 90 | return Ok(lit(n)); |
| 91 | } |
| 92 | |
| 93 | if self.options.parse_float_as_decimal { |
| 94 | parse_decimal(unsigned_number, negative) |
| 95 | } else { |
| 96 | signed_number.parse::<f64>().map(lit).map_err(|_| { |
| 97 | DataFusionError::from(ParserError(format!( |
| 98 | "Cannot parse {signed_number} as f64" |
| 99 | ))) |
| 100 | }) |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | /// Create a placeholder expression |
| 105 | /// Both named (`$foo`) and positional (`$1`, `$2`, ...) placeholder styles are supported. |
no test coverage detected