Skip to content

Commit 21d580f

Browse files
committed
Tweak DeclareSignature for TConvert class
1 parent 12870c7 commit 21d580f

File tree

1 file changed

+50
-8
lines changed

1 file changed

+50
-8
lines changed

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

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,15 +1264,57 @@ TUnboxedValuePod DoAddYears(const TUnboxedValuePod& date, i64 years, const NUdf:
12641264
}
12651265
END_SIMPLE_ARROW_UDF(TMakeTzTimestamp, TMakeDateKernelExec<TTzTimestamp>::Do);
12661266

1267+
class TConvert: public ::NYql::NUdf::TBoxedValue {
1268+
public:
1269+
explicit TConvert(TSourcePosition pos)
1270+
: Pos_(pos)
1271+
{}
12671272

1268-
SIMPLE_STRICT_UDF(TConvert, TResource<TM64ResourceName>(TAutoMap<TResource<TMResourceName>>)) {
1269-
Y_UNUSED(valueBuilder);
1270-
TUnboxedValuePod result(0);
1271-
auto& arg = Reference<TMResourceName>(args[0]);
1272-
auto& storage = Reference<TM64ResourceName>(result);
1273-
storage.From(arg);
1274-
return result;
1275-
}
1273+
static const ::NYql::NUdf::TStringRef& Name() {
1274+
static auto name = TStringRef::Of("Convert");
1275+
return name;
1276+
}
1277+
1278+
static bool DeclareSignature(
1279+
const ::NYql::NUdf::TStringRef& name,
1280+
::NYql::NUdf::TType*,
1281+
::NYql::NUdf::IFunctionTypeInfoBuilder& builder,
1282+
bool typesOnly)
1283+
{
1284+
if (Name() != name) {
1285+
return false;
1286+
}
1287+
1288+
// Convert is emitted in scope of type annotation phase to
1289+
// implicitly cast basic DateTime resource to the extended
1290+
// one. Extended dates can't be handled by MKQL prior to
1291+
// runtime version 51, hence Convert has to be nop for the
1292+
// versions older than 51 in case the YQL frontend emitted
1293+
// Convert call.
1294+
if constexpr (MKQL_RUNTIME_VERSION < 51U) {
1295+
builder.SimpleSignature<NYql::NUdf::TResource<TMResourceName>(NYql::NUdf::TAutoMap<NYql::NUdf::TResource<TMResourceName>>)>()
1296+
.IsStrict();
1297+
} else {
1298+
builder.SimpleSignature<NYql::NUdf::TResource<TM64ResourceName>(NYql::NUdf::TAutoMap<NYql::NUdf::TResource<TMResourceName>>)>()
1299+
.IsStrict();
1300+
}
1301+
if (!typesOnly) {
1302+
builder.Implementation(new TConvert(builder.GetSourcePosition()));
1303+
}
1304+
return true;
1305+
}
1306+
private:
1307+
TUnboxedValue Run(const IValueBuilder* valueBuilder, const TUnboxedValuePod* args) const final {
1308+
Y_UNUSED(valueBuilder);
1309+
TUnboxedValuePod result(0);
1310+
auto& arg = Reference<TMResourceName>(args[0]);
1311+
auto& storage = Reference<TM64ResourceName>(result);
1312+
storage.From(arg);
1313+
return result;
1314+
}
1315+
1316+
const TSourcePosition Pos_;
1317+
};
12761318

12771319
SIMPLE_STRICT_UDF(TMakeDate32, TDate32(TAutoMap<TResource<TM64ResourceName>>)) {
12781320
auto& storage = Reference<TM64ResourceName>(args[0]);

0 commit comments

Comments
 (0)