You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "alamb (via GitHub)" <gi...@apache.org> on 2023/03/08 18:30:51 UTC
[GitHub] [arrow-rs] alamb commented on a diff in pull request #3801: Faster timestamp parsing (~70-90% faster)
alamb commented on code in PR #3801:
URL: https://github.com/apache/arrow-rs/pull/3801#discussion_r1129867567
##########
arrow-cast/src/parse.rs:
##########
@@ -15,11 +15,117 @@
// specific language governing permissions and limitations
// under the License.
+use arrow_array::timezone::Tz;
use arrow_array::types::*;
use arrow_array::ArrowPrimitiveType;
use arrow_schema::ArrowError;
use chrono::prelude::*;
+/// Helper for parsing timestamps
+struct TimestampParser {
+ digits: [u8; 32],
+ mask: u32,
+}
+
+impl TimestampParser {
+ fn new(bytes: &[u8]) -> Self {
+ let mut digits = [0; 32];
+ let mut mask = 0;
+
+ for (idx, (o, i)) in digits.iter_mut().zip(bytes).enumerate() {
+ *o = i.wrapping_sub(b'0');
+ mask |= ((*o < 10) as u32) << idx
+ }
+
+ Self { digits, mask }
+ }
+
+ /// Returns true if the byte at `idx` equals `b`
Review Comment:
```suggestion
/// Returns true if the byte at `idx` represents the ASCII character with the numeric value of `b`.
/// This is intended to quickly check for numerals like `'0'`, `'1'`, `'2'`, etc
///
/// given "12foo"
/// test(0, 1) -> true
/// test(0, 2) -> false
/// test(4, 0) -> false
```
##########
arrow-cast/src/parse.rs:
##########
@@ -15,11 +15,117 @@
// specific language governing permissions and limitations
// under the License.
+use arrow_array::timezone::Tz;
use arrow_array::types::*;
use arrow_array::ArrowPrimitiveType;
use arrow_schema::ArrowError;
use chrono::prelude::*;
+/// Helper for parsing timestamps
+struct TimestampParser {
+ digits: [u8; 32],
+ mask: u32,
Review Comment:
Can we please document what mask represents? I think it is a bitmask of digits ?
##########
arrow-cast/src/parse.rs:
##########
@@ -565,11 +637,11 @@ mod tests {
// Test parsing invalid formats
// It would be nice to make these messages better
- expect_timestamp_parse_error("", "Error parsing '' as timestamp");
- expect_timestamp_parse_error("SS", "Error parsing 'SS' as timestamp");
+ expect_timestamp_parse_error("", "Error parsing timestamp from '': timestamp must contain at least 10 characters");
Review Comment:
Can we also add some tests for invalid timestamps
Cases:
1. timzone with bad characters `00: 4` (aka put a space in there),
2. timezones without `:`, such as `+00`
3. extra content after the timestamp
Perhaps the explictly stated unsupported formats:
```
/// "2023-01-01 040506 America/Los_Angeles",
/// "2023-01-01 04:05:06.789 +07:30:00",
/// "2023-01-01 040506 +07:30:00",
/// "2023-01-01 04:05:06.789 PST",
/// "2023-01-01 04:05:06.789 -08",
```
--
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-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org