Skip to content

Commit 9bc214b

Browse files
committed
YQL-20093: Change DateTime::IntervalFromSeconds signature
As `DateTime::ToSeconds(Interval)` returns `Int64` since `2025.03`, then a reverse function should be changed as well. Also added support for block `UDF`s at `TLangForked`. commit_hash:24fdaa28ef016ee10b9c5772aa8d4e8ba28ee6c4
1 parent 0385586 commit 9bc214b

File tree

15 files changed

+137
-5
lines changed

15 files changed

+137
-5
lines changed

yql/essentials/docs/en/changelog/2025.03.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
## Changes in DateTime module {#datetime-module}
1010

11-
* Changed a return type of the `DateTime::ToSeconds(Interval)` to `Int64` intead of `Int32`.
11+
* Changed a return type of the `DateTime::ToSeconds(Interval)` to `Int64` instead of `Int32`.
12+
* Changed an argument type of the `DateTime::IntervalFromSeconds` to `Int64` instead of `Int32`.
1213

1314
## Changes in SELECT syntax
1415

yql/essentials/docs/en/udf/list/datetime.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ Conversions between `Interval` and various time units.
185185
* `DateTime::Interval64FromHours(Int64{Flags:AutoMap}) -> Interval64`
186186
* `DateTime::IntervalFromMinutes(Int32{Flags:AutoMap}) -> Interval`
187187
* `DateTime::Interval64FromMinutes(Int64{Flags:AutoMap}) -> Interval64`
188-
* `DateTime::IntervalFromSeconds(Int32{Flags:AutoMap}) -> Interval`
188+
* `DateTime::IntervalFromSeconds(Int32{Flags:AutoMap}) -> Interval` Until [2025.03](../../changelog/2025.03.md)
189+
* `DateTime::IntervalFromSeconds(Int64{Flags:AutoMap}) -> Interval` Since [2025.03](../../changelog/2025.03.md)
189190
* `DateTime::Interval64FromSeconds(Int64{Flags:AutoMap}) -> Interval64`
190191
* `DateTime::IntervalFromMilliseconds(Int64{Flags:AutoMap}) -> Interval`
191192
* `DateTime::Interval64FromMilliseconds(Int64{Flags:AutoMap}) -> Interval64`

yql/essentials/docs/ru/changelog/2025.03.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
## Изменения в модуле DateTime {#datetime-module}
1010

1111
* Изменен возващаемый тип `DateTime::ToSeconds(Interval)` на `Int64` вместо `Int32`.
12+
* Изменён тип аргумента `DateTime::IntervalFromSeconds` на `Int64` вместо `Int32`.
1213

1314
## Изменения в синтаксисе SELECT
1415

yql/essentials/docs/ru/udf/list/datetime.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ SELECT
185185
* `DateTime::Interval64FromHours(Int64{Flags:AutoMap}) -> Interval64`
186186
* `DateTime::IntervalFromMinutes(Int32{Flags:AutoMap}) -> Interval`
187187
* `DateTime::Interval64FromMinutes(Int64{Flags:AutoMap}) -> Interval64`
188-
* `DateTime::IntervalFromSeconds(Int32{Flags:AutoMap}) -> Interval`
188+
* `DateTime::IntervalFromSeconds(Int32{Flags:AutoMap}) -> Interval` - до версии [2025.03](../../changelog/2025.03.md)
189+
* `DateTime::IntervalFromSeconds(Int64{Flags:AutoMap}) -> Interval` - с версии [2025.03](../../changelog/2025.03.md)
189190
* `DateTime::Interval64FromSeconds(Int64{Flags:AutoMap}) -> Interval64`
190191
* `DateTime::IntervalFromMilliseconds(Int64{Flags:AutoMap}) -> Interval`
191192
* `DateTime::Interval64FromMilliseconds(Int64{Flags:AutoMap}) -> Interval64`

yql/essentials/public/udf/udf_helpers.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,24 @@ namespace NUdf {
2626

2727
template <ui32 V, CUDF TLegacyUDF, CUDF TActualUDF>
2828
class TLangVerForked {
29+
private:
30+
Y_HAS_SUBTYPE(TBlockType);
31+
2932
public:
3033
using TTypeAwareMarker = bool;
3134

35+
using TBlockType = decltype([] {
36+
static_assert(THasTBlockType<TLegacyUDF>::value == THasTBlockType<TActualUDF>::value);
37+
if constexpr (THasTBlockType<TActualUDF>::value) {
38+
return TLangVerForked<
39+
V,
40+
typename TLegacyUDF::TBlockType,
41+
typename TActualUDF::TBlockType>();
42+
} else {
43+
return;
44+
}
45+
}());
46+
3247
static const TStringRef& Name() {
3348
Y_ENSURE(TLegacyUDF::Name() == TActualUDF::Name());
3449
return TActualUDF::Name();

yql/essentials/udfs/common/datetime2/datetime_udf.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,6 +1856,11 @@ TUnboxedValue GetTimezoneName(const IValueBuilder* valueBuilder, const TUnboxedV
18561856
\
18571857
END_SIMPLE_ARROW_UDF(T##name, (TFromConverterKernel<argType, retType, usecMultiplier>::Do))
18581858

1859+
#define DATETIME_FROM_CONVERTER_UDF_N(space, name, retType, argType, usecMultiplier) \
1860+
namespace N##space { \
1861+
DATETIME_FROM_CONVERTER_UDF(name, retType, argType, usecMultiplier); \
1862+
}
1863+
18591864
DATETIME_FROM_CONVERTER_UDF(FromSeconds, TTimestamp, ui32, UsecondsInSecond);
18601865
DATETIME_FROM_CONVERTER_UDF(FromMilliseconds, TTimestamp, ui64, UsecondsInMilliseconds);
18611866
DATETIME_FROM_CONVERTER_UDF(FromMicroseconds, TTimestamp, ui64, 1);
@@ -1867,7 +1872,8 @@ TUnboxedValue GetTimezoneName(const IValueBuilder* valueBuilder, const TUnboxedV
18671872
DATETIME_FROM_CONVERTER_UDF(IntervalFromDays, TInterval, i32, UsecondsInDay);
18681873
DATETIME_FROM_CONVERTER_UDF(IntervalFromHours, TInterval, i32, UsecondsInHour);
18691874
DATETIME_FROM_CONVERTER_UDF(IntervalFromMinutes, TInterval, i32, UsecondsInMinute);
1870-
DATETIME_FROM_CONVERTER_UDF(IntervalFromSeconds, TInterval, i32, UsecondsInSecond);
1875+
DATETIME_FROM_CONVERTER_UDF_N(Legacy, IntervalFromSeconds, TInterval, i32, UsecondsInSecond);
1876+
DATETIME_FROM_CONVERTER_UDF_N(Actual, IntervalFromSeconds, TInterval, i64, UsecondsInSecond);
18711877
DATETIME_FROM_CONVERTER_UDF(IntervalFromMilliseconds, TInterval, i64, UsecondsInMilliseconds);
18721878
DATETIME_FROM_CONVERTER_UDF(IntervalFromMicroseconds, TInterval, i64, 1);
18731879

@@ -3465,7 +3471,12 @@ class TShift : public TBoxedValue {
34653471
TIntervalFromDays,
34663472
TIntervalFromHours,
34673473
TIntervalFromMinutes,
3468-
TIntervalFromSeconds,
3474+
3475+
TLangVerForked<
3476+
NYql::MakeLangVersion(2025, 03),
3477+
NLegacy::TIntervalFromSeconds,
3478+
NActual::TIntervalFromSeconds>,
3479+
34693480
TIntervalFromMilliseconds,
34703481
TIntervalFromMicroseconds,
34713482

yql/essentials/udfs/common/datetime2/test/canondata/result.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@
4949
"uri": "file://test.test_Format_/results.txt"
5050
}
5151
],
52+
"test.test[FromSeconds_2025.02]": [
53+
{
54+
"uri": "file://test.test_FromSeconds_2025.02_/extracted"
55+
}
56+
],
57+
"test.test[FromSeconds_2025.03]": [
58+
{
59+
"uri": "file://test.test_FromSeconds_2025.03_/results.txt"
60+
}
61+
],
5262
"test.test[From]": [
5363
{
5464
"uri": "file://test.test_From_/results.txt"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<tmp_path>/program.sql:<main>: Error: Type annotation
2+
3+
<tmp_path>/program.sql:<main>:4:1: Error: At function: RemovePrefixMembers, At function: Unordered, At function: PersistableRepr, At function: OrderedSqlProject, At tuple, At function: SqlProjectItem, At lambda
4+
select
5+
^
6+
<tmp_path>/program.sql:<main>:6:15: Error: At function: Apply, Callable is produced by Udf: DateTime2.IntervalFromSeconds
7+
DateTime::IntervalFromSeconds(`seconds`) as interval_from_seconds
8+
^
9+
<tmp_path>/program.sql:<main>:6:35: Error: Mismatch type argument #1, type diff: Int32!=Optional<Int64>
10+
DateTime::IntervalFromSeconds(`seconds`) as interval_from_seconds
11+
^
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[
2+
{
3+
"Write" = [
4+
{
5+
"Type" = [
6+
"ListType";
7+
[
8+
"StructType";
9+
[
10+
[
11+
"interval_from_seconds";
12+
[
13+
"OptionalType";
14+
[
15+
"DataType";
16+
"Interval"
17+
]
18+
]
19+
]
20+
]
21+
]
22+
];
23+
"Data" = [
24+
[
25+
[
26+
"1542844800000000"
27+
]
28+
];
29+
[
30+
[
31+
"2160000000000000"
32+
]
33+
]
34+
]
35+
}
36+
]
37+
}
38+
]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"fseconds"="1542844800";
3+
};
4+
{
5+
"fseconds"="2160000000";
6+
};

0 commit comments

Comments
 (0)