andygrove commented on code in PR #453:
URL: https://github.com/apache/datafusion-comet/pull/453#discussion_r1607254539


##########
core/src/execution/datafusion/expressions/cast.rs:
##########
@@ -1029,34 +1021,22 @@ fn do_cast_string_to_int<
     type_name: &str,
     min_value: T,
 ) -> CometResult<Option<T>> {
-    let len = str.len();
-    if str.is_empty() {
+    let trimmed_str = str.trim();
+    if trimmed_str.is_empty() {
         return none_or_err(eval_mode, type_name, str);
     }
-
+    let len = trimmed_str.len();
     let mut result: T = T::zero();
     let mut negative = false;
     let radix = T::from(10);
     let stop_value = min_value / radix;
-    let mut state = State::SkipLeadingWhiteSpace;
-    let mut parsed_sign = false;
-
-    for (i, ch) in str.char_indices() {
-        // skip leading whitespace
-        if state == State::SkipLeadingWhiteSpace {
-            if ch.is_whitespace() {
-                // consume this char
-                continue;
-            }
-            // change state and fall through to next section
-            state = State::ParseSignAndDigits;
-        }
+    let mut parse_sign_and_digits = true;
 
-        if state == State::ParseSignAndDigits {
-            if !parsed_sign {
+    for (i, ch) in trimmed_str.char_indices() {

Review Comment:
   We process the trimmed string here and we no longer need the logic for 
skipping leading and trailing whitespace



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

Reply via email to