comphead commented on code in PR #5150: URL: https://github.com/apache/datafusion-comet/pull/5150#discussion_r3686789250
########## native/spark-expr/src/conversion_funcs/trim.rs: ########## @@ -0,0 +1,196 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! Whitespace trimming for parsing from string. +//! +//! Spark's string casts do not all agree on what "whitespace" means. There are exactly two +//! regimes, and neither of them matches Rust's `str::trim` (which trims Unicode whitespace) or +//! `<[u8]>::trim_ascii` (which omits `0x0B`): +//! +//! | Regime | Trimmed bytes | Cast targets | +//! |----------------------|--------------------------|-------------------------------------------------------| +//! | [`trim_all`] | `0x00`-`0x20` and `0x7F` | boolean, byte, short, int, long, date, timestamp \* | +//! | [`trim_java_string`] | `0x00`-`0x20` | float, double, decimal | +//! +//! Crucially, **neither regime trims any non-ASCII whitespace**. `U+0085`, `U+00A0`, `U+1680`, +//! `U+2000`-`U+200A`, `U+2028`, `U+2029`, `U+202F`, `U+205F` and `U+3000` all leave Spark +//! returning NULL (or raising under ANSI) for every cast target, so using `str::trim` here +//! silently produces a value where Spark produces none. +//! +//! The two regimes differ only in `0x7F` (DELETE), which the `trimAll` set removes and the +//! `String.trim` set does not. That single byte is why a shared helper cannot be applied +//! uniformly: trimming it in the float/double/decimal paths would introduce a new divergence. +//! +//! \* `timestamp` and `timestamp_ntz` are listed for what Spark does; the Comet parsers for +//! those two targets still use `str::trim` and have not been migrated to these helpers Review Comment: I feel the comments are too verbose 🤔 -- 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]
