Rich-T-kid opened a new pull request, #10374:
URL: https://github.com/apache/arrow-rs/pull/10374

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and 
enhancements and this helps us generate change logs for our releases. You can 
link an issue to this PR using the GitHub syntax.
   -->
   
   - Closes half of #9538.
   
   # Rationale for this change
   currently parsing ints and floats with white space prefiing the number 
caused the cast to fail
   ```rust
   assert_eq!(Float64Type::parse("\n\t\n\t\n40.5123"), Some(40.5123));
   assert_eq!(Float64Type::parse(" 1.5"), Some(1.5));
   assert_eq!(Int32Type::parse(" 3"), Some(3));
   assert_eq!(Int32Type::parse("          30"), Some(30));
   ```
   
   <!--
   Why are you proposing this change? If this is already explained clearly in 
the issue then this section is not needed.
   Explaining clearly why changes are proposed helps reviewers understand your 
changes and offer better suggestions for fixes.
   -->
   
   # What changes are included in this PR?
   this PR adds a check to the string before parsing. it checks the first byte, 
if its not an ascii digit it will trim the left side of the string. 
   
   Performance was a consideration to avoid regressions here — see 
https://github.com/apache/arrow-rs/pull/9537#issuecomment-4085626688. In the 
worst case where a string doesn't need trimming (no leading whitespace), the 
cost is just one slice operation to grab the first byte plus a range comparison 
to check if it's an ASCII digit.
   
   benchmarks show no significant change
   <img width="1155" height="493" alt="Image 7-18-26 at 1 02 PM" 
src="https://github.com/user-attachments/assets/911560a4-bc4f-4dde-83a0-858e4a470bf8";
 />
   
   
   <!--
   There is no need to duplicate the description in the issue here but it is 
sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # Are these changes tested?
   yes. I created a test with 12 assertiosn to validate behavoir 
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are 
they covered by existing tests)?
   
   If this PR claims a performance improvement, please include evidence such as 
benchmark results.
   -->
   
   # Are there any user-facing changes?
   yes. arrow-rs/datafusion cast operations will no longer fail when a number 
is prefixed with white space.
   <!--
   If there are user-facing changes then we may require documentation to be 
updated before approving the PR.
   
   If there are any breaking changes to public APIs, please call them out.
   -->
   


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

Reply via email to