summaryrefslogtreecommitdiffstats
path: root/yql/essentials/udfs/examples
diff options
context:
space:
mode:
authorvvvv <[email protected]>2025-10-06 13:26:25 +0300
committervvvv <[email protected]>2025-10-06 14:06:25 +0300
commiteca8ce9cb1613d5c983185c4e43c20651a9638aa (patch)
tree61ee5ae779948e61af9a7691d19eaa2c09869121 /yql/essentials/udfs/examples
parent4adf7eecae16a9b228b28cc5f64c27ef69ad5ec2 (diff)
YQL-20086 udfs
init commit_hash:f9684778bf1ea956965f2360b80b91edb7d4ffbe
Diffstat (limited to 'yql/essentials/udfs/examples')
-rw-r--r--yql/essentials/udfs/examples/callables/callables_udf.cpp65
-rw-r--r--yql/essentials/udfs/examples/callables/ya.make2
-rw-r--r--yql/essentials/udfs/examples/dicts/dicts_udf.cpp38
-rw-r--r--yql/essentials/udfs/examples/dicts/ya.make2
-rw-r--r--yql/essentials/udfs/examples/dummylog/dummylog_udf.cpp68
-rw-r--r--yql/essentials/udfs/examples/dummylog/ya.make2
-rw-r--r--yql/essentials/udfs/examples/linear/linear_udf.cpp9
-rw-r--r--yql/essentials/udfs/examples/linear/ya.make2
-rw-r--r--yql/essentials/udfs/examples/lists/lists_udf.cpp44
-rw-r--r--yql/essentials/udfs/examples/lists/ya.make2
-rw-r--r--yql/essentials/udfs/examples/structs/structs_udf.cpp57
-rw-r--r--yql/essentials/udfs/examples/structs/ya.make2
-rw-r--r--yql/essentials/udfs/examples/tagged/tagged_udf.cpp168
-rw-r--r--yql/essentials/udfs/examples/tagged/ya.make2
-rw-r--r--yql/essentials/udfs/examples/type_inspection/type_inspection_udf.cpp43
-rw-r--r--yql/essentials/udfs/examples/type_inspection/ya.make2
16 files changed, 223 insertions, 285 deletions
diff --git a/yql/essentials/udfs/examples/callables/callables_udf.cpp b/yql/essentials/udfs/examples/callables/callables_udf.cpp
index 6d8f1c27d9a..e367c3b990c 100644
--- a/yql/essentials/udfs/examples/callables/callables_udf.cpp
+++ b/yql/essentials/udfs/examples/callables/callables_udf.cpp
@@ -5,7 +5,6 @@
#include <util/generic/yexception.h>
#include <util/string/cast.h>
-
using namespace NKikimr;
using namespace NUdf;
@@ -14,8 +13,7 @@ namespace {
//////////////////////////////////////////////////////////////////////////////
// TFromString
//////////////////////////////////////////////////////////////////////////////
-class TFromString: public TBoxedValue
-{
+class TFromString: public TBoxedValue {
public:
static TStringRef Name() {
static auto name = TStringRef::Of("FromString");
@@ -24,9 +22,8 @@ public:
private:
TUnboxedValue Run(
- const IValueBuilder* valueBuilder,
- const TUnboxedValuePod* args) const override
- {
+ const IValueBuilder* valueBuilder,
+ const TUnboxedValuePod* args) const override {
Y_UNUSED(valueBuilder);
auto str = args[0].AsStringRef();
int val = FromString<int>(str);
@@ -37,8 +34,7 @@ private:
//////////////////////////////////////////////////////////////////////////////
// TSum
//////////////////////////////////////////////////////////////////////////////
-class TSum: public TBoxedValue
-{
+class TSum: public TBoxedValue {
public:
static TStringRef Name() {
static auto name = TStringRef::Of("Sum");
@@ -47,9 +43,8 @@ public:
private:
TUnboxedValue Run(
- const IValueBuilder* valueBuilder,
- const TUnboxedValuePod* args) const override
- {
+ const IValueBuilder* valueBuilder,
+ const TUnboxedValuePod* args) const override {
int sum = 0;
auto it = args[0].GetListIterator();
@@ -65,8 +60,7 @@ private:
//////////////////////////////////////////////////////////////////////////////
// TMul
//////////////////////////////////////////////////////////////////////////////
-class TMul: public TBoxedValue
-{
+class TMul: public TBoxedValue {
public:
static TStringRef Name() {
static auto name = TStringRef::Of("Mul");
@@ -75,9 +69,8 @@ public:
private:
TUnboxedValue Run(
- const IValueBuilder* valueBuilder,
- const TUnboxedValuePod* args) const override
- {
+ const IValueBuilder* valueBuilder,
+ const TUnboxedValuePod* args) const override {
int mul = 1;
const auto it = args[0].GetListIterator();
@@ -106,9 +99,8 @@ public:
private:
TUnboxedValue Run(
- const IValueBuilder* valueBuilder,
- const TUnboxedValuePod* args) const override
- {
+ const IValueBuilder* valueBuilder,
+ const TUnboxedValuePod* args) const override {
Y_UNUSED(valueBuilder);
auto res = args[0] ? args[0].Get<i32>() : 123;
return TUnboxedValuePod(res + 1);
@@ -127,9 +119,8 @@ public:
}
TUnboxedValue Run(
- const IValueBuilder* valueBuilder,
- const TUnboxedValuePod* args) const override
- {
+ const IValueBuilder* valueBuilder,
+ const TUnboxedValuePod* args) const override {
Y_UNUSED(valueBuilder);
Y_UNUSED(args);
return TUnboxedValuePod(new TNamedArgUdf());
@@ -139,14 +130,14 @@ public:
//////////////////////////////////////////////////////////////////////////////
// TCallablesModule
//////////////////////////////////////////////////////////////////////////////
-class TCallablesModule: public IUdfModule
-{
+class TCallablesModule: public IUdfModule {
public:
TStringRef Name() const {
return TStringRef::Of("Callables");
}
- void CleanupOnTerminate() const final {}
+ void CleanupOnTerminate() const final {
+ }
void GetAllFunctions(IFunctionsSink& sink) const final {
sink.Add(TFromString::Name());
@@ -155,12 +146,11 @@ public:
}
void BuildFunctionTypeInfo(
- const TStringRef& name,
- TType* userType,
- const TStringRef& typeConfig,
- ui32 flags,
- IFunctionTypeInfoBuilder& builder) const final
- {
+ const TStringRef& name,
+ TType* userType,
+ const TStringRef& typeConfig,
+ ui32 flags,
+ IFunctionTypeInfoBuilder& builder) const final {
try {
Y_UNUSED(userType);
Y_UNUSED(typeConfig);
@@ -176,25 +166,20 @@ public:
if (!typesOnly) {
builder.Implementation(new TFromString);
}
- }
- else if (TSum::Name() == name) {
+ } else if (TSum::Name() == name) {
// function signature:
// int (ListOf(String), int(*)(String))
// run config: void
- builder.Returns<int>().Args()->
- Add(builder.List()->Item<char*>())
- .Add(builder.Callable()->Returns<int>().Arg<char*>())
- .Done();
+ builder.Returns<int>().Args()->Add(builder.List()->Item<char*>()).Add(builder.Callable()->Returns<int>().Arg<char*>()).Done();
if (!typesOnly) {
builder.Implementation(new TSum);
}
- }
- else if (TMul::Name() == name) {
+ } else if (TMul::Name() == name) {
// function signature:
// int (ListOf(String), int(*)(String))
// run config: void
- using TFuncType = int(*)(char*);
+ using TFuncType = int (*)(char*);
builder.SimpleSignature<int(TListType<char*>, TFuncType)>();
if (!typesOnly) {
diff --git a/yql/essentials/udfs/examples/callables/ya.make b/yql/essentials/udfs/examples/callables/ya.make
index 63e19657996..67b6cecbb68 100644
--- a/yql/essentials/udfs/examples/callables/ya.make
+++ b/yql/essentials/udfs/examples/callables/ya.make
@@ -1,6 +1,8 @@
YQL_UDF_CONTRIB(callables_udf)
YQL_ABI_VERSION(2 38 0)
+ENABLE(YQL_STYLE_CPP)
+
SRCS(
callables_udf.cpp
)
diff --git a/yql/essentials/udfs/examples/dicts/dicts_udf.cpp b/yql/essentials/udfs/examples/dicts/dicts_udf.cpp
index 69231f01b13..2ce8c509a6e 100644
--- a/yql/essentials/udfs/examples/dicts/dicts_udf.cpp
+++ b/yql/essentials/udfs/examples/dicts/dicts_udf.cpp
@@ -13,8 +13,7 @@ namespace {
//////////////////////////////////////////////////////////////////////////////
// TStrToInt
//////////////////////////////////////////////////////////////////////////////
-class TStrToInt: public TBoxedValue
-{
+class TStrToInt: public TBoxedValue {
public:
explicit TStrToInt(TType* dictType)
: DictType_(dictType)
@@ -28,9 +27,8 @@ public:
private:
TUnboxedValue Run(
- const IValueBuilder* valueBuilder,
- const TUnboxedValuePod* args) const override
- {
+ const IValueBuilder* valueBuilder,
+ const TUnboxedValuePod* args) const override {
auto kind = args[0].AsStringRef();
ui32 flags = 0;
@@ -40,18 +38,7 @@ private:
flags |= TDictFlags::Sorted;
}
- return valueBuilder->NewDict(DictType_, flags)->
- Add(valueBuilder->NewString("zero"), TUnboxedValuePod((ui32) 0))
- .Add(valueBuilder->NewString("one"), TUnboxedValuePod((ui32) 1))
- .Add(valueBuilder->NewString("two"), TUnboxedValuePod((ui32) 2))
- .Add(valueBuilder->NewString("three"), TUnboxedValuePod((ui32) 3))
- .Add(valueBuilder->NewString("four"), TUnboxedValuePod((ui32) 4))
- .Add(valueBuilder->NewString("five"), TUnboxedValuePod((ui32) 5))
- .Add(valueBuilder->NewString("six"), TUnboxedValuePod((ui32) 6))
- .Add(valueBuilder->NewString("seven"), TUnboxedValuePod((ui32) 7))
- .Add(valueBuilder->NewString("eight"), TUnboxedValuePod((ui32) 8))
- .Add(valueBuilder->NewString("nine"), TUnboxedValuePod((ui32) 9))
- .Build();
+ return valueBuilder->NewDict(DictType_, flags)->Add(valueBuilder->NewString("zero"), TUnboxedValuePod((ui32)0)).Add(valueBuilder->NewString("one"), TUnboxedValuePod((ui32)1)).Add(valueBuilder->NewString("two"), TUnboxedValuePod((ui32)2)).Add(valueBuilder->NewString("three"), TUnboxedValuePod((ui32)3)).Add(valueBuilder->NewString("four"), TUnboxedValuePod((ui32)4)).Add(valueBuilder->NewString("five"), TUnboxedValuePod((ui32)5)).Add(valueBuilder->NewString("six"), TUnboxedValuePod((ui32)6)).Add(valueBuilder->NewString("seven"), TUnboxedValuePod((ui32)7)).Add(valueBuilder->NewString("eight"), TUnboxedValuePod((ui32)8)).Add(valueBuilder->NewString("nine"), TUnboxedValuePod((ui32)9)).Build();
}
TType* DictType_;
@@ -60,26 +47,25 @@ private:
//////////////////////////////////////////////////////////////////////////////
// TDictsModule
//////////////////////////////////////////////////////////////////////////////
-class TDictsModule: public IUdfModule
-{
+class TDictsModule: public IUdfModule {
public:
TStringRef Name() const {
return TStringRef::Of("Dicts");
}
- void CleanupOnTerminate() const final {}
+ void CleanupOnTerminate() const final {
+ }
void GetAllFunctions(IFunctionsSink& sink) const final {
sink.Add(TStrToInt::Name());
}
void BuildFunctionTypeInfo(
- const TStringRef& name,
- TType* userType,
- const TStringRef& typeConfig,
- ui32 flags,
- IFunctionTypeInfoBuilder& builder) const final
- {
+ const TStringRef& name,
+ TType* userType,
+ const TStringRef& typeConfig,
+ ui32 flags,
+ IFunctionTypeInfoBuilder& builder) const final {
try {
Y_UNUSED(userType);
Y_UNUSED(typeConfig);
diff --git a/yql/essentials/udfs/examples/dicts/ya.make b/yql/essentials/udfs/examples/dicts/ya.make
index 4dd62e36e9d..f7a7ff40c85 100644
--- a/yql/essentials/udfs/examples/dicts/ya.make
+++ b/yql/essentials/udfs/examples/dicts/ya.make
@@ -1,6 +1,8 @@
YQL_UDF_CONTRIB(dicts_udf)
YQL_ABI_VERSION(2 9 0)
+ENABLE(YQL_STYLE_CPP)
+
SRCS(
dicts_udf.cpp
)
diff --git a/yql/essentials/udfs/examples/dummylog/dummylog_udf.cpp b/yql/essentials/udfs/examples/dummylog/dummylog_udf.cpp
index e3e227f1303..fd1dcb5970b 100644
--- a/yql/essentials/udfs/examples/dummylog/dummylog_udf.cpp
+++ b/yql/essentials/udfs/examples/dummylog/dummylog_udf.cpp
@@ -10,32 +10,28 @@ using namespace NUdf;
namespace {
-struct TRecordInfo
-{
+struct TRecordInfo {
ui32 Key;
ui32 Subkey;
ui32 Value;
static constexpr ui32 FieldsCount = 3U;
};
-
//////////////////////////////////////////////////////////////////////////////
// TDummyLog
//////////////////////////////////////////////////////////////////////////////
-class TDummyLog: public TBoxedValue
-{
+class TDummyLog: public TBoxedValue {
public:
explicit TDummyLog(
- const TRecordInfo& fieldIndexes)
+ const TRecordInfo& fieldIndexes)
: RecordInfo_(fieldIndexes)
{
}
private:
TUnboxedValue Run(
- const IValueBuilder* valueBuilder,
- const TUnboxedValuePod* args) const override
- {
+ const IValueBuilder* valueBuilder,
+ const TUnboxedValuePod* args) const override {
auto keyData = args[0].GetElement(RecordInfo_.Key);
auto subkeyData = args[0].GetElement(RecordInfo_.Subkey);
auto valueData = args[0].GetElement(RecordInfo_.Value);
@@ -55,21 +51,20 @@ private:
const TRecordInfo RecordInfo_;
};
-class TDummyLog2 : public TBoxedValue
-{
+class TDummyLog2: public TBoxedValue {
public:
- class TFactory : public TBoxedValue {
+ class TFactory: public TBoxedValue {
public:
TFactory(const TRecordInfo& inputInfo, const TRecordInfo& outputInfo)
: InputInfo_(inputInfo)
, OutputInfo_(outputInfo)
- {}
+ {
+ }
-private:
+ private:
TUnboxedValue Run(
const IValueBuilder* valueBuilder,
- const TUnboxedValuePod* args) const override
- {
+ const TUnboxedValuePod* args) const override {
Y_UNUSED(valueBuilder);
return TUnboxedValuePod(new TDummyLog2(args[0], InputInfo_, OutputInfo_));
}
@@ -81,8 +76,7 @@ private:
explicit TDummyLog2(
const TUnboxedValuePod& runConfig,
const TRecordInfo& inputInfo,
- const TRecordInfo& outputInfo
- )
+ const TRecordInfo& outputInfo)
: Prefix_(runConfig.AsStringRef())
, InputInfo_(inputInfo)
, OutputInfo_(outputInfo)
@@ -92,8 +86,7 @@ private:
private:
TUnboxedValue Run(
const IValueBuilder* valueBuilder,
- const TUnboxedValuePod* args) const override
- {
+ const TUnboxedValuePod* args) const override {
auto keyData = args[0].GetElement(InputInfo_.Key);
auto valueData = args[0].GetElement(InputInfo_.Value);
@@ -115,14 +108,14 @@ private:
//////////////////////////////////////////////////////////////////////////////
// TDummyLogModule
//////////////////////////////////////////////////////////////////////////////
-class TDummyLogModule: public IUdfModule
-{
+class TDummyLogModule: public IUdfModule {
public:
TStringRef Name() const {
return TStringRef::Of("DummyLog");
}
- void CleanupOnTerminate() const final {}
+ void CleanupOnTerminate() const final {
+ }
void GetAllFunctions(IFunctionsSink& sink) const final {
sink.Add(TStringRef::Of("ReadRecord"));
@@ -130,12 +123,11 @@ public:
}
void BuildFunctionTypeInfo(
- const TStringRef& name,
- TType* userType,
- const TStringRef& typeConfig,
- ui32 flags,
- IFunctionTypeInfoBuilder& builder) const final
- {
+ const TStringRef& name,
+ TType* userType,
+ const TStringRef& typeConfig,
+ ui32 flags,
+ IFunctionTypeInfoBuilder& builder) const final {
try {
Y_UNUSED(userType);
Y_UNUSED(typeConfig);
@@ -144,11 +136,7 @@ public:
if (TStringRef::Of("ReadRecord") == name) {
TRecordInfo recordInfo;
- auto recordType = builder.Struct(recordInfo.FieldsCount)->
- AddField<char*>("key", &recordInfo.Key)
- .AddField<char*>("subkey", &recordInfo.Subkey)
- .AddField<char*>("value", &recordInfo.Value)
- .Build();
+ auto recordType = builder.Struct(recordInfo.FieldsCount)->AddField<char*>("key", &recordInfo.Key).AddField<char*>("subkey", &recordInfo.Subkey).AddField<char*>("value", &recordInfo.Value).Build();
builder.Returns(recordType).Args()->Add(recordType).Done();
@@ -162,18 +150,10 @@ public:
builder.SetError(TStringRef::Of("Only AAA is valid type config"));
}
TRecordInfo inputInfo;
- auto inputType = builder.Struct(inputInfo.FieldsCount)->
- AddField<char*>("key", &inputInfo.Key)
- .AddField<char*>("subkey", &inputInfo.Subkey)
- .AddField<char*>("value", &inputInfo.Value)
- .Build();
+ auto inputType = builder.Struct(inputInfo.FieldsCount)->AddField<char*>("key", &inputInfo.Key).AddField<char*>("subkey", &inputInfo.Subkey).AddField<char*>("value", &inputInfo.Value).Build();
TRecordInfo outputInfo;
- auto outputType = builder.Struct(2U)->
- AddField<char*>("key", &outputInfo.Key)
- .AddField<char*>("value", &outputInfo.Value)
- .Build();
-
+ auto outputType = builder.Struct(2U)->AddField<char*>("key", &outputInfo.Key).AddField<char*>("value", &outputInfo.Value).Build();
builder.Returns(outputType).Args()->Add(inputType).Done();
builder.RunConfig<char*>();
diff --git a/yql/essentials/udfs/examples/dummylog/ya.make b/yql/essentials/udfs/examples/dummylog/ya.make
index d1acd15945b..2a74a5767e9 100644
--- a/yql/essentials/udfs/examples/dummylog/ya.make
+++ b/yql/essentials/udfs/examples/dummylog/ya.make
@@ -1,6 +1,8 @@
YQL_UDF_CONTRIB(dummylog)
YQL_ABI_VERSION(2 9 0)
+ENABLE(YQL_STYLE_CPP)
+
SRCS(
dummylog_udf.cpp
)
diff --git a/yql/essentials/udfs/examples/linear/linear_udf.cpp b/yql/essentials/udfs/examples/linear/linear_udf.cpp
index 006ee817446..8696799a865 100644
--- a/yql/essentials/udfs/examples/linear/linear_udf.cpp
+++ b/yql/essentials/udfs/examples/linear/linear_udf.cpp
@@ -10,7 +10,7 @@ SIMPLE_UDF(TProducer, TLinear<i32>(i32)) {
return TUnboxedValuePod(args[0].Get<i32>());
}
-using TExchangeRet = TTuple<TLinear<i32>,i32>;
+using TExchangeRet = TTuple<TLinear<i32>, i32>;
SIMPLE_UDF(TExchange, TExchangeRet(TLinear<i32>, i32)) {
TUnboxedValue* items;
TUnboxedValue ret = valueBuilder->NewArray(2, items);
@@ -19,7 +19,7 @@ SIMPLE_UDF(TExchange, TExchangeRet(TLinear<i32>, i32)) {
return ret;
}
-class TUnsafeConsumer : public TBoxedValue {
+class TUnsafeConsumer: public TBoxedValue {
public:
typedef bool TTypeAwareMarker;
@@ -78,8 +78,7 @@ public:
}
return true;
- }
- else {
+ } else {
return false;
}
}
@@ -87,6 +86,6 @@ public:
SIMPLE_MODULE(TLinearModule, TProducer, TUnsafeConsumer, TExchange)
-}
+} // namespace
REGISTER_MODULES(TLinearModule)
diff --git a/yql/essentials/udfs/examples/linear/ya.make b/yql/essentials/udfs/examples/linear/ya.make
index 961bc48b82e..fb38acaf8f6 100644
--- a/yql/essentials/udfs/examples/linear/ya.make
+++ b/yql/essentials/udfs/examples/linear/ya.make
@@ -1,6 +1,8 @@
YQL_UDF(linear_udf)
YQL_ABI_VERSION(2 44 0)
+ENABLE(YQL_STYLE_CPP)
+
SRCS(
linear_udf.cpp
)
diff --git a/yql/essentials/udfs/examples/lists/lists_udf.cpp b/yql/essentials/udfs/examples/lists/lists_udf.cpp
index 35dbb57dfa3..e310cde3e3b 100644
--- a/yql/essentials/udfs/examples/lists/lists_udf.cpp
+++ b/yql/essentials/udfs/examples/lists/lists_udf.cpp
@@ -15,8 +15,7 @@ namespace {
//////////////////////////////////////////////////////////////////////////////
// TNumbersList
//////////////////////////////////////////////////////////////////////////////
-class TNumbers: public TBoxedValue
-{
+class TNumbers: public TBoxedValue {
public:
static TStringRef Name() {
static auto name = TStringRef::Of("Numbers");
@@ -25,9 +24,8 @@ public:
private:
TUnboxedValue Run(
- const IValueBuilder* valueBuilder,
- const TUnboxedValuePod* args) const override
- {
+ const IValueBuilder* valueBuilder,
+ const TUnboxedValuePod* args) const override {
const auto appendPrepend = args[0].AsStringRef();
const auto count = args[1].Get<ui32>();
std::vector<TUnboxedValue> list(count);
@@ -36,8 +34,7 @@ private:
for (auto it = list.begin(); list.end() != it; ++it) {
*it = TUnboxedValuePod(i++);
}
- }
- else if (TStringRef::Of("Prepend") == appendPrepend) {
+ } else if (TStringRef::Of("Prepend") == appendPrepend) {
for (auto it = list.rbegin(); list.rend() != it; ++it) {
*it = TUnboxedValuePod(i++);
}
@@ -50,8 +47,7 @@ private:
//////////////////////////////////////////////////////////////////////////////
// TExtend
//////////////////////////////////////////////////////////////////////////////
-class TExtend: public TBoxedValue
-{
+class TExtend: public TBoxedValue {
public:
static TStringRef Name() {
static auto name = TStringRef::Of("Extend");
@@ -60,9 +56,8 @@ public:
private:
TUnboxedValue Run(
- const IValueBuilder* valueBuilder,
- const TUnboxedValuePod* args) const override
- {
+ const IValueBuilder* valueBuilder,
+ const TUnboxedValuePod* args) const override {
std::array<TUnboxedValue, 2U> list = {{TUnboxedValuePod(args[0]), TUnboxedValuePod(args[1])}};
return valueBuilder->NewList(list.data(), list.size());
}
@@ -71,14 +66,14 @@ private:
//////////////////////////////////////////////////////////////////////////////
// TListsModule
//////////////////////////////////////////////////////////////////////////////
-class TListsModule: public IUdfModule
-{
+class TListsModule: public IUdfModule {
public:
TStringRef Name() const {
return TStringRef::Of("Lists");
}
- void CleanupOnTerminate() const final {}
+ void CleanupOnTerminate() const final {
+ }
void GetAllFunctions(IFunctionsSink& sink) const final {
sink.Add(TNumbers::Name());
@@ -86,12 +81,11 @@ public:
}
void BuildFunctionTypeInfo(
- const TStringRef& name,
- TType* userType,
- const TStringRef& typeConfig,
- ui32 flags,
- IFunctionTypeInfoBuilder& builder) const final
- {
+ const TStringRef& name,
+ TType* userType,
+ const TStringRef& typeConfig,
+ ui32 flags,
+ IFunctionTypeInfoBuilder& builder) const final {
try {
Y_UNUSED(userType);
Y_UNUSED(typeConfig);
@@ -107,14 +101,16 @@ public:
if (!typesOnly) {
builder.Implementation(new TNumbers);
}
- }
- else if (TExtend::Name() == name) {
+ } else if (TExtend::Name() == name) {
// function signature:
// List<ui32> Numbers(List<ui32>, List<ui32>)
// runConfig: void
auto listType = builder.List()->Item<ui32>().Build();
builder.Returns(listType)
- .Args()->Add(listType).Add(listType).Done();
+ .Args()
+ ->Add(listType)
+ .Add(listType)
+ .Done();
if (!typesOnly) {
builder.Implementation(new TExtend);
diff --git a/yql/essentials/udfs/examples/lists/ya.make b/yql/essentials/udfs/examples/lists/ya.make
index 3fa002c7800..dac2ee92dd9 100644
--- a/yql/essentials/udfs/examples/lists/ya.make
+++ b/yql/essentials/udfs/examples/lists/ya.make
@@ -1,6 +1,8 @@
YQL_UDF_CONTRIB(lists_udf)
YQL_ABI_VERSION(2 9 0)
+ENABLE(YQL_STYLE_CPP)
+
SRCS(
lists_udf.cpp
)
diff --git a/yql/essentials/udfs/examples/structs/structs_udf.cpp b/yql/essentials/udfs/examples/structs/structs_udf.cpp
index 38ea115eaf6..3d8e89c4ff6 100644
--- a/yql/essentials/udfs/examples/structs/structs_udf.cpp
+++ b/yql/essentials/udfs/examples/structs/structs_udf.cpp
@@ -11,8 +11,7 @@ using namespace NUdf;
namespace {
-struct TPersonInfo
-{
+struct TPersonInfo {
ui32 FirstName = 0;
ui32 LastName = 0;
ui32 Age = 0;
@@ -26,8 +25,7 @@ struct TPersonInfo
//////////////////////////////////////////////////////////////////////////////
// TPersonMember
//////////////////////////////////////////////////////////////////////////////
-class TPersonMember: public TBoxedValue
-{
+class TPersonMember: public TBoxedValue {
public:
explicit TPersonMember(ui32 memberIndex)
: MemberIndex_(memberIndex)
@@ -36,9 +34,8 @@ public:
private:
TUnboxedValue Run(
- const IValueBuilder* valueBuilder,
- const TUnboxedValuePod* args) const override
- {
+ const IValueBuilder* valueBuilder,
+ const TUnboxedValuePod* args) const override {
Y_UNUSED(valueBuilder);
return args[0].GetElement(MemberIndex_);
}
@@ -49,8 +46,7 @@ private:
//////////////////////////////////////////////////////////////////////////////
// TNewPerson
//////////////////////////////////////////////////////////////////////////////
-class TNewPerson: public TBoxedValue
-{
+class TNewPerson: public TBoxedValue {
public:
explicit TNewPerson(const TPersonInfo& personIndexes)
: Info_(personIndexes)
@@ -59,9 +55,8 @@ public:
private:
TUnboxedValue Run(
- const IValueBuilder* valueBuilder,
- const TUnboxedValuePod* args) const override
- {
+ const IValueBuilder* valueBuilder,
+ const TUnboxedValuePod* args) const override {
TUnboxedValue name, surname, age;
if (Info_.RemapKSV) {
name = args->GetElement(Info_.Key);
@@ -88,14 +83,14 @@ private:
//////////////////////////////////////////////////////////////////////////////
// TPersonModule
//////////////////////////////////////////////////////////////////////////////
-class TPersonModule: public IUdfModule
-{
+class TPersonModule: public IUdfModule {
public:
TStringRef Name() const {
return TStringRef::Of("Person");
}
- void CleanupOnTerminate() const final {}
+ void CleanupOnTerminate() const final {
+ }
void GetAllFunctions(IFunctionsSink& sink) const final {
sink.Add(TStringRef::Of("FirstName"));
@@ -105,22 +100,17 @@ public:
}
void BuildFunctionTypeInfo(
- const TStringRef& name,
- TType* userType,
- const TStringRef& typeConfig,
- ui32 flags,
- IFunctionTypeInfoBuilder& builder) const final
- {
+ const TStringRef& name,
+ TType* userType,
+ const TStringRef& typeConfig,
+ ui32 flags,
+ IFunctionTypeInfoBuilder& builder) const final {
Y_UNUSED(userType);
try {
bool typesOnly = (flags & TFlags::TypesOnly);
TPersonInfo personInfo;
- auto personType = builder.Struct(personInfo.FieldsCount)->
- AddField<char*>("FirstName", &personInfo.FirstName)
- .AddField<char*>("LastName", &personInfo.LastName)
- .AddField<ui32>("Age", &personInfo.Age)
- .Build();
+ auto personType = builder.Struct(personInfo.FieldsCount)->AddField<char*>("FirstName", &personInfo.FirstName).AddField<char*>("LastName", &personInfo.LastName).AddField<ui32>("Age", &personInfo.Age).Build();
if (TStringRef::Of("FirstName") == name) {
// function signature: String FirstName(PersonStruct p)
@@ -130,8 +120,7 @@ public:
if (!typesOnly) {
builder.Implementation(new TPersonMember(personInfo.FirstName));
}
- }
- else if (TStringRef::Of("LastName") == name) {
+ } else if (TStringRef::Of("LastName") == name) {
// function signature: String LastName(PersonStruct p)
// runConfig: void
builder.Returns<char*>().Args()->Add(personType).Done();
@@ -139,8 +128,7 @@ public:
if (!typesOnly) {
builder.Implementation(new TPersonMember(personInfo.LastName));
}
- }
- else if (TStringRef::Of("Age") == name) {
+ } else if (TStringRef::Of("Age") == name) {
// function signature: ui32 Age(PersonStruct p)
// runConfig: void
builder.Returns<ui32>().Args()->Add(personType).Done();
@@ -148,19 +136,14 @@ public:
if (!typesOnly) {
builder.Implementation(new TPersonMember(personInfo.Age));
}
- }
- else if (TStringRef::Of("New") == name) {
+ } else if (TStringRef::Of("New") == name) {
// function signature:
// PersonStruct New(String firstName, String lastName, ui32 age)
// runConfig: void
builder.Returns(personType);
if (TStringRef::Of("RemapKSV") == typeConfig) {
personInfo.RemapKSV = true;
- auto inputType = builder.Struct(personInfo.FieldsCount)->
- AddField<char*>("key", &personInfo.Key)
- .AddField<char*>("subkey", &personInfo.Subkey)
- .AddField<char*>("value", &personInfo.Value)
- .Build();
+ auto inputType = builder.Struct(personInfo.FieldsCount)->AddField<char*>("key", &personInfo.Key).AddField<char*>("subkey", &personInfo.Subkey).AddField<char*>("value", &personInfo.Value).Build();
builder.Args()->Add(inputType);
} else {
builder.Args()->Add<char*>().Add<char*>().Add<ui32>();
diff --git a/yql/essentials/udfs/examples/structs/ya.make b/yql/essentials/udfs/examples/structs/ya.make
index 2339cf0b272..00dacb1545a 100644
--- a/yql/essentials/udfs/examples/structs/ya.make
+++ b/yql/essentials/udfs/examples/structs/ya.make
@@ -1,6 +1,8 @@
YQL_UDF_CONTRIB(structs_udf)
YQL_ABI_VERSION(2 9 0)
+ENABLE(YQL_STYLE_CPP)
+
SRCS(
structs_udf.cpp
)
diff --git a/yql/essentials/udfs/examples/tagged/tagged_udf.cpp b/yql/essentials/udfs/examples/tagged/tagged_udf.cpp
index 0f85c3e968e..29e2c51540d 100644
--- a/yql/essentials/udfs/examples/tagged/tagged_udf.cpp
+++ b/yql/essentials/udfs/examples/tagged/tagged_udf.cpp
@@ -4,100 +4,100 @@ using namespace NKikimr;
using namespace NUdf;
namespace {
- extern const char TagFoo[] = "foo";
- extern const char TagBar[] = "bar";
- extern const char TagBaz[] = "baz";
- using TTaggedFoo = TTagged<i32, TagFoo>;
- using TTaggedBar = TTagged<i32, TagBar>;
- using TTaggedBaz = TTagged<i32, TagBaz>;
-
- SIMPLE_UDF(TExample, TTaggedBaz(TTaggedFoo, TTaggedBar)) {
- Y_UNUSED(valueBuilder);
- const auto input1 = args[0].Get<i32>();
- const auto input2 = args[1].Get<i32>();
- return TUnboxedValuePod(input1 + input2);
+extern const char TagFoo[] = "foo";
+extern const char TagBar[] = "bar";
+extern const char TagBaz[] = "baz";
+using TTaggedFoo = TTagged<i32, TagFoo>;
+using TTaggedBar = TTagged<i32, TagBar>;
+using TTaggedBaz = TTagged<i32, TagBaz>;
+
+SIMPLE_UDF(TExample, TTaggedBaz(TTaggedFoo, TTaggedBar)) {
+ Y_UNUSED(valueBuilder);
+ const auto input1 = args[0].Get<i32>();
+ const auto input2 = args[1].Get<i32>();
+ return TUnboxedValuePod(input1 + input2);
+}
+
+class TGenericTag: public TBoxedValue {
+public:
+ typedef bool TTypeAwareMarker;
+
+ TUnboxedValue Run(const IValueBuilder* valueBuilder, const TUnboxedValuePod* args) const final {
+ auto tagStr = valueBuilder->NewString(Tag_);
+ return valueBuilder->ConcatStrings(args[0], static_cast<const TUnboxedValuePod&>(tagStr));
}
- class TGenericTag : public TBoxedValue {
- public:
- typedef bool TTypeAwareMarker;
+ static const TStringRef& Name() {
+ static auto name = TStringRef::Of("GenericTag");
+ return name;
+ }
- TUnboxedValue Run(const IValueBuilder* valueBuilder, const TUnboxedValuePod* args) const final {
- auto tagStr = valueBuilder->NewString(Tag_);
- return valueBuilder->ConcatStrings(args[0], static_cast<const TUnboxedValuePod&>(tagStr));
- }
+ TGenericTag(TStringRef tag)
+ : Tag_(tag)
+ {
+ }
- static const TStringRef& Name() {
- static auto name = TStringRef::Of("GenericTag");
- return name;
- }
+ static bool DeclareSignature(const TStringRef& name, TType* userType, IFunctionTypeInfoBuilder& builder, bool typesOnly) {
+ if (Name() == name) {
+ if (!userType) {
+ builder.SetError("Missing user type.");
+ return true;
+ }
+
+ builder.UserType(userType);
+ const auto typeHelper = builder.TypeInfoHelper();
+ const auto userTypeInspector = TTupleTypeInspector(*typeHelper, userType);
+ if (!userTypeInspector || userTypeInspector.GetElementsCount() < 1) {
+ builder.SetError("Invalid user type.");
+ return true;
+ }
- TGenericTag(TStringRef tag)
- : Tag_(tag)
- {}
-
- static bool DeclareSignature(const TStringRef& name, TType* userType, IFunctionTypeInfoBuilder& builder, bool typesOnly) {
- if (Name() == name) {
- if (!userType) {
- builder.SetError("Missing user type.");
- return true;
- }
-
- builder.UserType(userType);
- const auto typeHelper = builder.TypeInfoHelper();
- const auto userTypeInspector = TTupleTypeInspector(*typeHelper, userType);
- if (!userTypeInspector || userTypeInspector.GetElementsCount() < 1) {
- builder.SetError("Invalid user type.");
- return true;
- }
-
- const auto argsTypeTuple = userTypeInspector.GetElementType(0);
- const auto argsTypeInspector = TTupleTypeInspector(*typeHelper, argsTypeTuple);
- if (!argsTypeInspector) {
- builder.SetError("Invalid user type - expected tuple.");
- return true;
- }
-
- if (const auto argsCount = argsTypeInspector.GetElementsCount(); argsCount != 1) {
- ::TStringBuilder sb;
- sb << "Invalid user type - expected one argument, got: " << argsCount;
- builder.SetError(sb);
- return true;
- }
-
- const auto inputType = argsTypeInspector.GetElementType(0);
- const auto tagged = TTaggedTypeInspector(*typeHelper, inputType);
- if (!tagged) {
- ::TStringBuilder sb;
- sb << "Expected tagged string";
- builder.SetError(sb);
- return true;
- }
-
- const auto data = TDataTypeInspector(*typeHelper, tagged.GetBaseType());
- if (!data || data.GetTypeId() != TDataType<const char*>::Id) {
- ::TStringBuilder sb;
- sb << "Expected tagged string";
- builder.SetError(sb);
- return true;
- }
-
- builder.Args()->Add(inputType).Done().Returns(inputType);
- if (!typesOnly) {
- builder.Implementation(new TGenericTag(tagged.GetTag()));
- }
+ const auto argsTypeTuple = userTypeInspector.GetElementType(0);
+ const auto argsTypeInspector = TTupleTypeInspector(*typeHelper, argsTypeTuple);
+ if (!argsTypeInspector) {
+ builder.SetError("Invalid user type - expected tuple.");
return true;
}
- else {
- return false;
+
+ if (const auto argsCount = argsTypeInspector.GetElementsCount(); argsCount != 1) {
+ ::TStringBuilder sb;
+ sb << "Invalid user type - expected one argument, got: " << argsCount;
+ builder.SetError(sb);
+ return true;
+ }
+
+ const auto inputType = argsTypeInspector.GetElementType(0);
+ const auto tagged = TTaggedTypeInspector(*typeHelper, inputType);
+ if (!tagged) {
+ ::TStringBuilder sb;
+ sb << "Expected tagged string";
+ builder.SetError(sb);
+ return true;
+ }
+
+ const auto data = TDataTypeInspector(*typeHelper, tagged.GetBaseType());
+ if (!data || data.GetTypeId() != TDataType<const char*>::Id) {
+ ::TStringBuilder sb;
+ sb << "Expected tagged string";
+ builder.SetError(sb);
+ return true;
+ }
+
+ builder.Args()->Add(inputType).Done().Returns(inputType);
+ if (!typesOnly) {
+ builder.Implementation(new TGenericTag(tagged.GetTag()));
}
+ return true;
+ } else {
+ return false;
}
- private:
- TStringRef Tag_;
- };
+ }
+private:
+ TStringRef Tag_;
+};
- SIMPLE_MODULE(TTaggedModule, TExample, TGenericTag)
-}
+SIMPLE_MODULE(TTaggedModule, TExample, TGenericTag)
+} // namespace
REGISTER_MODULES(TTaggedModule)
diff --git a/yql/essentials/udfs/examples/tagged/ya.make b/yql/essentials/udfs/examples/tagged/ya.make
index 2afb4f4d42e..7209cbfbe56 100644
--- a/yql/essentials/udfs/examples/tagged/ya.make
+++ b/yql/essentials/udfs/examples/tagged/ya.make
@@ -1,6 +1,8 @@
YQL_UDF_CONTRIB(tagged_udf)
YQL_ABI_VERSION(2 21 0)
+ENABLE(YQL_STYLE_CPP)
+
SRCS(
tagged_udf.cpp
)
diff --git a/yql/essentials/udfs/examples/type_inspection/type_inspection_udf.cpp b/yql/essentials/udfs/examples/type_inspection/type_inspection_udf.cpp
index b4b3e4709e1..07ad4f724fd 100644
--- a/yql/essentials/udfs/examples/type_inspection/type_inspection_udf.cpp
+++ b/yql/essentials/udfs/examples/type_inspection/type_inspection_udf.cpp
@@ -6,7 +6,6 @@
#include <util/generic/yexception.h>
-
using namespace NKikimr;
using namespace NUdf;
@@ -15,8 +14,7 @@ namespace {
//////////////////////////////////////////////////////////////////////////////
// TZip
//////////////////////////////////////////////////////////////////////////////
-class TZip: public TBoxedValue
-{
+class TZip: public TBoxedValue {
public:
static TStringRef Name() {
static auto name = TStringRef::Of("Zip");
@@ -25,15 +23,15 @@ public:
private:
TUnboxedValue Run(
- const IValueBuilder* valueBuilder,
- const TUnboxedValuePod* args) const override
- {
+ const IValueBuilder* valueBuilder,
+ const TUnboxedValuePod* args) const override {
const auto it1 = args[0].GetListIterator();
const auto it2 = args[1].GetListIterator();
std::vector<TUnboxedValue> list;
- if (args[0].HasFastListLength() && args[1].HasFastListLength())
+ if (args[0].HasFastListLength() && args[1].HasFastListLength()) {
list.reserve(std::min(args[0].GetListLength(), args[1].GetListLength()));
+ }
for (TUnboxedValue one, two, *items = nullptr; it1.Next(one) && it2.Next(two);) {
auto tuple = valueBuilder->NewArray(2U, items);
items[0] = std::move(one);
@@ -48,8 +46,7 @@ private:
//////////////////////////////////////////////////////////////////////////////
// TFold
//////////////////////////////////////////////////////////////////////////////
-class TFold : public TBoxedValue
-{
+class TFold: public TBoxedValue {
public:
static TStringRef Name() {
static auto name = TStringRef::Of("Fold");
@@ -59,8 +56,7 @@ public:
private:
TUnboxedValue Run(
const IValueBuilder* valueBuilder,
- const TUnboxedValuePod* args) const override
- {
+ const TUnboxedValuePod* args) const override {
const auto it = args[0].GetListIterator();
TUnboxedValue state = TUnboxedValuePod(args[1]);
auto func = args[2];
@@ -76,10 +72,9 @@ private:
//////////////////////////////////////////////////////////////////////////////
// TInterleave
//////////////////////////////////////////////////////////////////////////////
-class TInterleave : public TBoxedValue
-{
+class TInterleave: public TBoxedValue {
public:
- class TValue : public TBoxedValue {
+ class TValue: public TBoxedValue {
public:
TValue(const IValueBuilder* valueBuilder, const TUnboxedValuePod& left, const TUnboxedValuePod& right)
: ValueBuilder_(valueBuilder)
@@ -121,8 +116,7 @@ public:
private:
TUnboxedValue Run(
const IValueBuilder* valueBuilder,
- const TUnboxedValuePod* args) const override
- {
+ const TUnboxedValuePod* args) const override {
return TUnboxedValuePod(new TValue(valueBuilder, args[0], args[1]));
}
};
@@ -130,14 +124,14 @@ private:
//////////////////////////////////////////////////////////////////////////////
// TTypeInspectionModule
//////////////////////////////////////////////////////////////////////////////
-class TTypeInspectionModule: public IUdfModule
-{
+class TTypeInspectionModule: public IUdfModule {
public:
TStringRef Name() const {
return TStringRef::Of("TypeInspection");
}
- void CleanupOnTerminate() const final {}
+ void CleanupOnTerminate() const final {
+ }
void GetAllFunctions(IFunctionsSink& sink) const final {
sink.Add(TZip::Name())->SetTypeAwareness();
@@ -146,12 +140,11 @@ public:
}
void BuildFunctionTypeInfo(
- const TStringRef& name,
- TType* userType,
- const TStringRef& typeConfig,
- ui32 flags,
- IFunctionTypeInfoBuilder& builder) const final
- {
+ const TStringRef& name,
+ TType* userType,
+ const TStringRef& typeConfig,
+ ui32 flags,
+ IFunctionTypeInfoBuilder& builder) const final {
try {
Y_UNUSED(typeConfig);
diff --git a/yql/essentials/udfs/examples/type_inspection/ya.make b/yql/essentials/udfs/examples/type_inspection/ya.make
index 7ce6c1b26dc..bbe8e26e0ae 100644
--- a/yql/essentials/udfs/examples/type_inspection/ya.make
+++ b/yql/essentials/udfs/examples/type_inspection/ya.make
@@ -1,6 +1,8 @@
YQL_UDF_CONTRIB(type_inspection_udf)
YQL_ABI_VERSION(2 9 0)
+ENABLE(YQL_STYLE_CPP)
+
SRCS(
type_inspection_udf.cpp
)