Jefffrey commented on code in PR #10374:
URL: https://github.com/apache/arrow-rs/pull/10374#discussion_r3610043658
##########
arrow-cast/src/parse.rs:
##########
@@ -453,23 +454,45 @@ impl Parser for Float16Type {
impl Parser for Float32Type {
fn parse(string: &str) -> Option<f32> {
+ let string = truncate_white_space(string);
lexical_core::parse(string.as_bytes()).ok()
}
}
impl Parser for Float64Type {
fn parse(string: &str) -> Option<f64> {
+ let string = truncate_white_space(string);
lexical_core::parse(string.as_bytes()).ok()
}
}
+#[inline]
+fn truncate_white_space(string: &str) -> &str {
+ if string
+ .as_bytes()
+ .first()
+ .is_some_and(|first_byte| !first_byte.is_ascii_digit())
+ {
+ string.trim_ascii_start()
+ } else {
+ string
+ }
+}
macro_rules! parser_primitive {
($t:ty) => {
impl Parser for $t {
fn parse(string: &str) -> Option<Self::Native> {
+ let mut string = string;
Review Comment:
```suggestion
fn parse(mut string: &str) -> Option<Self::Native> {
```
##########
arrow-cast/src/parse.rs:
##########
@@ -2872,4 +2895,19 @@ mod tests {
assert_eq!(interval.days, 0);
assert_eq!(interval.nanoseconds, NANOS_PER_SECOND);
}
+ #[test]
+ fn test_parse_prefix_white_space() {
Review Comment:
lets add a negative case like ` a1.5` etc.
--
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]