leung-ming commented on code in PR #1914: URL: https://github.com/apache/datafusion-comet/pull/1914#discussion_r2163128943
########## native/spark-expr/src/conversion_funcs/cast.rs: ########## @@ -1298,6 +1298,7 @@ where }); } else { cast_array.append_null(); + continue; Review Comment: > Thanks for catching the bug @leung-ming - the code can currently append both a null and a value, which is incorrect. > > However, using `continue` does not seem to be the correct fix because if will terminate the `for` loop and stop processing the remaining data in the vector. > > I think we just need an `else` condition instead: > > ```rust > if Decimal128Type::validate_decimal_precision(v, precision).is_err() { > if eval_mode == EvalMode::Ansi { > return Err(SparkError::NumericValueOutOfRange { > value: input_value.to_string(), > precision, > scale, > }); > } else { > cast_array.append_null(); > } > } else { > cast_array.append_value(v); > } > ``` Sorry, I really don't understand, I am new to Rust. Your words make sense to me if there is a `break` instead of `continue`. If you mean code quality/style, how about the follow one: ```rust for i in 0..input.len() { if input.is_null(i) { cast_array.append_null(); continue; } let input_value = input.value(i).as_(); if let Some(v) = (input_value * mul).round().to_i128() { if Decimal128Type::validate_decimal_precision(v, precision).is_ok() { cast_array.append_value(v); continue; } }; if eval_mode == EvalMode::Ansi { return Err(SparkError::NumericValueOutOfRange { value: input_value.to_string(), precision, scale, }); } cast_array.append_null(); } ``` I think all three should do the same things. -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org