waitingkuo commented on code in PR #3101:
URL: https://github.com/apache/arrow-rs/pull/3101#discussion_r1022272744
##########
arrow-cast/src/parse.rs:
##########
@@ -199,10 +199,123 @@ impl Parser for TimestampSecondType {
}
}
-parser_primitive!(Time64NanosecondType);
-parser_primitive!(Time64MicrosecondType);
-parser_primitive!(Time32MillisecondType);
-parser_primitive!(Time32SecondType);
+impl Parser for Time64NanosecondType {
+ fn parse(string: &str) -> Option<Self::Native> {
+ [
+ "%I:%M:%S%.9f %P",
+ "%I:%M:%S%.9f %p",
+ "%l:%M:%S%.9f %P",
+ "%l:%M:%S%.9f %p",
+ "%H:%M:%S%.9f",
Review Comment:
I'll suggest that move this as the first place as this is our default
display (`23:59:59.123456789`)
##########
arrow-cast/src/parse.rs:
##########
@@ -199,10 +199,123 @@ impl Parser for TimestampSecondType {
}
}
-parser_primitive!(Time64NanosecondType);
-parser_primitive!(Time64MicrosecondType);
-parser_primitive!(Time32MillisecondType);
-parser_primitive!(Time32SecondType);
+impl Parser for Time64NanosecondType {
+ fn parse(string: &str) -> Option<Self::Native> {
+ [
+ "%I:%M:%S%.9f %P",
+ "%I:%M:%S%.9f %p",
+ "%l:%M:%S%.9f %P",
+ "%l:%M:%S%.9f %p",
+ "%H:%M:%S%.9f",
+ "%k:%M:%S%.9f",
+ "%I:%M:%S %P",
+ "%I:%M:%S %p",
+ "%l:%M:%S %P",
+ "%l:%M:%S %p",
+ "%H:%M:%S",
+ "%k:%M:%S",
+ "%I:%M %P",
+ "%I:%M %p",
+ "%l:%M %P",
+ "%l:%M %p",
+ "%H:%M",
+ "%k:%M",
+ ]
+ .iter()
+ .find_map(|f| NaiveTime::parse_from_str(string, f).ok())
+ .map(|nt| {
+ nt.num_seconds_from_midnight() as i64 * 1_000_000_000 +
nt.nanosecond() as i64
+ })
+ .or_else(|| string.parse::<Self::Native>().ok())
+ }
+}
+
+impl Parser for Time64MicrosecondType {
+ fn parse(string: &str) -> Option<Self::Native> {
+ [
+ "%I:%M:%S%.6f %P",
+ "%I:%M:%S%.6f %p",
+ "%l:%M:%S%.6f %P",
+ "%l:%M:%S%.6f %p",
+ "%H:%M:%S%.6f",
+ "%k:%M:%S%.6f",
+ "%I:%M:%S %P",
+ "%I:%M:%S %p",
+ "%l:%M:%S %P",
+ "%l:%M:%S %p",
+ "%H:%M:%S",
+ "%k:%M:%S",
+ "%I:%M %P",
+ "%I:%M %p",
+ "%l:%M %P",
+ "%l:%M %p",
+ "%H:%M",
+ "%k:%M",
+ ]
+ .iter()
+ .find_map(|f| NaiveTime::parse_from_str(string, f).ok())
+ .map(|nt| {
+ nt.num_seconds_from_midnight() as i64 * 1_000_000
+ + (nt.nanosecond() as i64) / 1_000
+ })
Review Comment:
we could consider whether to support leap second `23:59:60`
`%S` already captured `Second number (00–60), zero-padded to 2 digits.
`22:59:60` is parsed as `82800000000000 nanos` which works.
`23:59:60` is parsed as `86400000000000 nanos` which overflows while we
construct the array by `Time64NanosecondArray::from(vec![86400000000000]);` so
it'll return a `null`
--
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]