Skip to content

Commit 1cf95a5

Browse files
authored
Make Datetime UDF backward compatible for incremental upgrade (#18920)
2 parents 8f60223 + ac47d74 commit 1cf95a5

File tree

33 files changed

+152
-4574
lines changed

33 files changed

+152
-4574
lines changed

yql/essentials/sql/v1/builtin.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <yql/essentials/public/issue/yql_issue_id.h>
1313
#include <yql/essentials/parser/pg_catalog/catalog.h>
1414

15+
#include <yql/essentials/minikql/mkql_runtime_version.h>
16+
1517
#include <library/cpp/charset/ci_string.h>
1618
#include <library/cpp/yson/node/node_io.h>
1719
#include <util/string/builder.h>
@@ -3471,6 +3473,12 @@ TNodePtr BuildBuiltinFunc(TContext& ctx, TPosition pos, TString name, const TVec
34713473
}
34723474
} else if (ns == "datetime2" && (name == "Parse")) {
34733475
return BuildUdf(ctx, pos, nameSpace, name, args);
3476+
} else if (MKQL_RUNTIME_VERSION < 51U && ns == "datetime2" && name == "Format") {
3477+
// FIXME: The condition above is required to untie the
3478+
// Gordian knot with the upgrade, when two MiniKQL
3479+
// runtimes with different versions are being used.
3480+
// See YQL-19967 for more info.
3481+
return BuildUdf(ctx, pos, nameSpace, name, args);
34743482
} else if (ns == "pg" || ns == "pgagg" || ns == "pgproc") {
34753483
bool isAggregateFunc = NYql::NPg::HasAggregation(name, NYql::NPg::EAggKind::Normal);
34763484
bool isNormalFunc = NYql::NPg::HasProc(name, NYql::NPg::EProcKind::Function);

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

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <yql/essentials/minikql/datetime/datetime.h>
55
#include <yql/essentials/minikql/datetime/datetime64.h>
66

7+
#include <yql/essentials/minikql/mkql_runtime_version.h>
8+
79
#include <yql/essentials/public/udf/arrow/udf_arrow_helpers.h>
810

911
#include <util/datetime/base.h>
@@ -314,6 +316,18 @@ struct TGetTimeComponent {
314316

315317
const auto features = NUdf::GetDataTypeInfo(NUdf::GetDataSlot(data.GetTypeId())).Features;
316318
if (features & NUdf::BigDateType) {
319+
// FIXME: The condition below is required to untie the
320+
// Gordian knot with the upgrade, when two MiniKQL
321+
// runtimes with different versions are being used.
322+
// See YQL-19967 for more info.
323+
if (MKQL_RUNTIME_VERSION < 51U && typesOnly) {
324+
::TStringBuilder sb;
325+
sb << "Invalid argument type: got ";
326+
TTypePrinter(*typeInfoHelper, argType).Out(sb.Out);
327+
sb << ", but Resource<" << TMResourceName << "> expected";
328+
builder.SetError(sb);
329+
return true;
330+
}
317331
BuildSignature<TFieldStorage, TM64ResourceName, WAccessor>(builder, typesOnly);
318332
return true;
319333
}
@@ -383,6 +397,16 @@ struct TGetTimeComponent {
383397
Y_ENSURE(!block);
384398

385399
if (resource.GetTag() == TStringRef::Of(TM64ResourceName)) {
400+
// FIXME: The condition below is required to untie the
401+
// Gordian knot with the upgrade, when two MiniKQL
402+
// runtimes with different versions are being used.
403+
// See YQL-19967 for more info.
404+
if (MKQL_RUNTIME_VERSION < 51U && typesOnly) {
405+
::TStringBuilder sb;
406+
sb << "Unexpected Resource tag: got '" << resource.GetTag() << "'";
407+
builder.SetError(sb);
408+
return true;
409+
}
386410
BuildSignature<TFieldStorage, TM64ResourceName, WAccessor>(builder, typesOnly);
387411
return true;
388412
}
@@ -1146,6 +1170,18 @@ class TGetDateComponent: public ::NYql::NUdf::TBoxedValue {
11461170

11471171
const auto features = NUdf::GetDataTypeInfo(NUdf::GetDataSlot(data.GetTypeId())).Features;
11481172
if (features & NUdf::BigDateType) {
1173+
// FIXME: The condition below is required to untie the
1174+
// Gordian knot with the upgrade, when two MiniKQL
1175+
// runtimes with different versions are being used.
1176+
// See YQL-19967 for more info.
1177+
if (MKQL_RUNTIME_VERSION < 51U && typesOnly) {
1178+
::TStringBuilder sb;
1179+
sb << "Invalid argument type: got ";
1180+
TTypePrinter(*typeInfoHelper, argType).Out(sb.Out);
1181+
sb << ", but Resource<" << TMResourceName << "> expected";
1182+
builder.SetError(sb);
1183+
return true;
1184+
}
11491185
BuildSignature<TResultWType, TM64ResourceName, WAccessor>(builder, typesOnly);
11501186
return true;
11511187
}
@@ -1164,6 +1200,16 @@ class TGetDateComponent: public ::NYql::NUdf::TBoxedValue {
11641200
}
11651201

11661202
if (resource.GetTag() == TStringRef::Of(TM64ResourceName)) {
1203+
// FIXME: The condition below is required to untie the
1204+
// Gordian knot with the upgrade, when two MiniKQL
1205+
// runtimes with different versions are being used.
1206+
// See YQL-19967 for more info.
1207+
if (MKQL_RUNTIME_VERSION < 51U && typesOnly) {
1208+
::TStringBuilder sb;
1209+
sb << "Unexpected Resource tag: got '" << resource.GetTag() << "'";
1210+
builder.SetError(sb);
1211+
return true;
1212+
}
11671213
BuildSignature<TResultWType, TM64ResourceName, WAccessor>(builder, typesOnly);
11681214
return true;
11691215
}
@@ -1260,6 +1306,18 @@ class TGetDateComponentName: public ::NYql::NUdf::TBoxedValue {
12601306

12611307
const auto features = NUdf::GetDataTypeInfo(NUdf::GetDataSlot(data.GetTypeId())).Features;
12621308
if (features & NUdf::BigDateType) {
1309+
// FIXME: The condition below is required to untie the
1310+
// Gordian knot with the upgrade, when two MiniKQL
1311+
// runtimes with different versions are being used.
1312+
// See YQL-19967 for more info.
1313+
if (MKQL_RUNTIME_VERSION < 51U && typesOnly) {
1314+
::TStringBuilder sb;
1315+
sb << "Invalid argument type: got ";
1316+
TTypePrinter(*typeInfoHelper, argType).Out(sb.Out);
1317+
sb << ", but Resource<" << TMResourceName << "> expected";
1318+
builder.SetError(sb);
1319+
return true;
1320+
}
12631321
BuildSignature<TM64ResourceName, WAccessor>(builder, typesOnly);
12641322
return true;
12651323
}
@@ -1278,6 +1336,16 @@ class TGetDateComponentName: public ::NYql::NUdf::TBoxedValue {
12781336
}
12791337

12801338
if (resource.GetTag() == TStringRef::Of(TM64ResourceName)) {
1339+
// FIXME: The condition below is required to untie the
1340+
// Gordian knot with the upgrade, when two MiniKQL
1341+
// runtimes with different versions are being used.
1342+
// See YQL-19967 for more info.
1343+
if (MKQL_RUNTIME_VERSION < 51U && typesOnly) {
1344+
::TStringBuilder sb;
1345+
sb << "Unexpected Resource tag: got '" << resource.GetTag() << "'";
1346+
builder.SetError(sb);
1347+
return true;
1348+
}
12811349
BuildSignature<TM64ResourceName, WAccessor>(builder, typesOnly);
12821350
return true;
12831351
}
@@ -1500,6 +1568,18 @@ TUnboxedValue GetTimezoneName(const IValueBuilder* valueBuilder, const TUnboxedV
15001568

15011569
const auto features = NUdf::GetDataTypeInfo(NUdf::GetDataSlot(data.GetTypeId())).Features;
15021570
if (features & NUdf::BigDateType) {
1571+
// FIXME: The condition below is required to untie the
1572+
// Gordian knot with the upgrade, when two MiniKQL
1573+
// runtimes with different versions are being used.
1574+
// See YQL-19967 for more info.
1575+
if (MKQL_RUNTIME_VERSION < 51U && typesOnly) {
1576+
::TStringBuilder sb;
1577+
sb << "Invalid argument type: got ";
1578+
TTypePrinter(*typeInfoHelper, argType).Out(sb.Out);
1579+
sb << ", but Resource<" << TMResourceName << "> expected";
1580+
builder.SetError(sb);
1581+
return true;
1582+
}
15031583
BuildSignature<TM64ResourceName>(builder, typesOnly);
15041584
return true;
15051585
}
@@ -1513,6 +1593,16 @@ TUnboxedValue GetTimezoneName(const IValueBuilder* valueBuilder, const TUnboxedV
15131593
}
15141594

15151595
if (resource.GetTag() == TStringRef::Of(TM64ResourceName)) {
1596+
// FIXME: The condition below is required to untie the
1597+
// Gordian knot with the upgrade, when two MiniKQL
1598+
// runtimes with different versions are being used.
1599+
// See YQL-19967 for more info.
1600+
if (MKQL_RUNTIME_VERSION < 51U && typesOnly) {
1601+
::TStringBuilder sb;
1602+
sb << "Unexpected Resource tag: got '" << resource.GetTag() << "'";
1603+
builder.SetError(sb);
1604+
return true;
1605+
}
15161606
BuildSignature<TM64ResourceName>(builder, typesOnly);
15171607
return true;
15181608
}
@@ -1802,6 +1892,18 @@ class TBoundaryOf: public ::NYql::NUdf::TBoxedValue {
18021892

18031893
const auto features = NUdf::GetDataTypeInfo(NUdf::GetDataSlot(data.GetTypeId())).Features;
18041894
if (features & NUdf::BigDateType) {
1895+
// FIXME: The condition below is required to untie the
1896+
// Gordian knot with the upgrade, when two MiniKQL
1897+
// runtimes with different versions are being used.
1898+
// See YQL-19967 for more info.
1899+
if (MKQL_RUNTIME_VERSION < 51U && typesOnly) {
1900+
::TStringBuilder sb;
1901+
sb << "Invalid argument type: got ";
1902+
TTypePrinter(*typeInfoHelper, argType).Out(sb.Out);
1903+
sb << ", but Resource<" << TMResourceName << "> expected";
1904+
builder.SetError(sb);
1905+
return true;
1906+
}
18051907
BuildSignature<TM64ResourceName, WBoundary>(builder, typesOnly);
18061908
return true;
18071909
}
@@ -1815,6 +1917,16 @@ class TBoundaryOf: public ::NYql::NUdf::TBoxedValue {
18151917
}
18161918

18171919
if (resource.GetTag() == TStringRef::Of(TM64ResourceName)) {
1920+
// FIXME: The condition below is required to untie the
1921+
// Gordian knot with the upgrade, when two MiniKQL
1922+
// runtimes with different versions are being used.
1923+
// See YQL-19967 for more info.
1924+
if (MKQL_RUNTIME_VERSION < 51U && typesOnly) {
1925+
::TStringBuilder sb;
1926+
sb << "Unexpected Resource tag: got '" << resource.GetTag() << "'";
1927+
builder.SetError(sb);
1928+
return true;
1929+
}
18181930
BuildSignature<TM64ResourceName, WBoundary>(builder, typesOnly);
18191931
return true;
18201932
}
@@ -2183,6 +2295,18 @@ class TShift : public TBoxedValue {
21832295

21842296
const auto features = NUdf::GetDataTypeInfo(NUdf::GetDataSlot(data.GetTypeId())).Features;
21852297
if (features & NUdf::BigDateType) {
2298+
// FIXME: The condition below is required to untie the
2299+
// Gordian knot with the upgrade, when two MiniKQL
2300+
// runtimes with different versions are being used.
2301+
// See YQL-19967 for more info.
2302+
if (MKQL_RUNTIME_VERSION < 51U && typesOnly) {
2303+
::TStringBuilder sb;
2304+
sb << "Invalid argument type: got ";
2305+
TTypePrinter(*typeInfoHelper, argType).Out(sb.Out);
2306+
sb << ", but Resource<" << TMResourceName << "> expected";
2307+
builder.SetError(sb);
2308+
return true;
2309+
}
21862310
BuildSignature<TM64ResourceName, WShifter>(builder, typesOnly);
21872311
return true;
21882312
}
@@ -2196,6 +2320,16 @@ class TShift : public TBoxedValue {
21962320
}
21972321

21982322
if (resource.GetTag() == TStringRef::Of(TM64ResourceName)) {
2323+
// FIXME: The condition below is required to untie the
2324+
// Gordian knot with the upgrade, when two MiniKQL
2325+
// runtimes with different versions are being used.
2326+
// See YQL-19967 for more info.
2327+
if (MKQL_RUNTIME_VERSION < 51U && typesOnly) {
2328+
::TStringBuilder sb;
2329+
sb << "Unexpected Resource tag: got '" << resource.GetTag() << "'";
2330+
builder.SetError(sb);
2331+
return true;
2332+
}
21992333
BuildSignature<TM64ResourceName, WShifter>(builder, typesOnly);
22002334
return true;
22012335
}
@@ -2293,6 +2427,16 @@ class TShift : public TBoxedValue {
22932427

22942428
auto resourceType = builder.Resource(TMResourceName);
22952429

2430+
// FIXME: The condition below is required to untie the
2431+
// Gordian knot with the upgrade, when two MiniKQL
2432+
// runtimes with different versions are being used.
2433+
// See YQL-19967 for more info.
2434+
if (MKQL_RUNTIME_VERSION < 51U && typesOnly) {
2435+
builder.Args()->Add(resourceType).Flags(ICallablePayload::TArgumentFlags::AutoMap);
2436+
builder.RunConfig<char*>().Returns<char*>();
2437+
return true;
2438+
}
2439+
22962440
auto stringType = builder.SimpleType<char*>();
22972441

22982442
auto boolType = builder.SimpleType<bool>();

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@
3434
"uri": "file://test.test_EndOf_/results.txt"
3535
}
3636
],
37-
"test.test[FormatMicroseconds]": [
38-
{
39-
"uri": "file://test.test_FormatMicroseconds_/results.txt"
40-
}
41-
],
4237
"test.test[Format]": [
4338
{
4439
"uri": "file://test.test_Format_/results.txt"

yql/essentials/udfs/common/datetime2/test/canondata/test.test_FormatMicroseconds_/results.txt

Lines changed: 0 additions & 98 deletions
This file was deleted.

yql/essentials/udfs/common/datetime2/test/cases/FormatMicroseconds.sql

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)