Skip to content

Commit e871b90

Browse files
committed
Fix parsing W and D components ofinterval literals
commit_hash:59642f0b610a45880a53087b4b6d1f0e97cf2f6e (cherry picked from commit f82809e)
1 parent 1a82965 commit e871b90

File tree

2 files changed

+59
-18
lines changed

2 files changed

+59
-18
lines changed

yql/essentials/minikql/mkql_type_ops.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2263,10 +2263,13 @@ NUdf::TUnboxedValuePod ParseInterval(const std::string_view& buf) {
22632263
return NUdf::TUnboxedValuePod();
22642264
}
22652265

2266-
std::optional<ui64> days, hours, minutes, seconds, microseconds;
2266+
std::optional<ui64> weeks, days, hours, minutes, seconds, microseconds;
22672267
ui64 num;
22682268

2269-
if (*pos != 'T') {
2269+
while (buf.cend() != pos) {
2270+
if (*pos == 'T') {
2271+
break;
2272+
}
22702273
// Estimated upper bound for number of digits in the
22712274
// numeric representation of days (weeks need less).
22722275
// * Interval: MAX_DATE (49673) = 5 digits.
@@ -2278,13 +2281,27 @@ NUdf::TUnboxedValuePod ParseInterval(const std::string_view& buf) {
22782281
}
22792282

22802283
switch (*pos++) {
2281-
case 'D': days = num; break;
2282-
case 'W': days = 7U * num; break;
2284+
case 'W':
2285+
if (weeks || days) {
2286+
return NUdf::TUnboxedValuePod();
2287+
}
2288+
weeks = num;
2289+
break;
2290+
case 'D':
2291+
if (days) {
2292+
return NUdf::TUnboxedValuePod();
2293+
}
2294+
days = num;
2295+
break;
22832296
default: return NUdf::TUnboxedValuePod();
22842297
}
22852298
}
22862299

2287-
if (days > MaxDays) {
2300+
const ui32 dvalue
2301+
= weeks.value_or(0U) * 7ull
2302+
+ days.value_or(0U);
2303+
2304+
if (dvalue > MaxDays) {
22882305
return NUdf::TUnboxedValuePod();
22892306
}
22902307

@@ -2342,7 +2359,7 @@ NUdf::TUnboxedValuePod ParseInterval(const std::string_view& buf) {
23422359
}
23432360

23442361
const ui64 value
2345-
= days.value_or(0U) * 86400000000ull
2362+
= dvalue * 86400000000ull
23462363
+ hours.value_or(0U) * 3600000000ull
23472364
+ minutes.value_or(0U) * 60000000ull
23482365
+ seconds.value_or(0U) * 1000000ull

yql/essentials/udfs/common/datetime2/test_bigdates/canondata/test.test_To_/results.txt

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -474,12 +474,24 @@
474474
]
475475
];
476476
[
477-
#;
478-
#;
479-
#;
480-
#;
481-
#;
482-
#;
477+
[
478+
"8"
479+
];
480+
[
481+
"193"
482+
];
483+
[
484+
"11581"
485+
];
486+
[
487+
"694861"
488+
];
489+
[
490+
"694861000"
491+
];
492+
[
493+
"694861000001"
494+
];
483495
[
484496
"-86400"
485497
];
@@ -610,12 +622,24 @@
610622
]
611623
];
612624
[
613-
#;
614-
#;
615-
#;
616-
#;
617-
#;
618-
#;
625+
[
626+
"9"
627+
];
628+
[
629+
"219"
630+
];
631+
[
632+
"13144"
633+
];
634+
[
635+
"788645"
636+
];
637+
[
638+
"788645678"
639+
];
640+
[
641+
"788645678912"
642+
];
619643
[
620644
"1735689600"
621645
];

0 commit comments

Comments
 (0)