Skip to content

Commit 52e48f7

Browse files
author
Vadim Averin
authored
Add IListBuilder to UDF ABI (#8914)
1 parent 10c0003 commit 52e48f7

File tree

6 files changed

+85
-16
lines changed

6 files changed

+85
-16
lines changed

ydb/library/yql/minikql/computation/mkql_computation_node_holders.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2909,6 +2909,40 @@ class TDictValueBuilder: public NUdf::IDictValueBuilder
29092909
TKeyPayloadPairVector Items_;
29102910
};
29112911

2912+
///////////////////////////////////////////////////////////////////////////////
2913+
// TListValueBuilder
2914+
///////////////////////////////////////////////////////////////////////////////
2915+
class TListValueBuilder: public NUdf::IListValueBuilder {
2916+
public:
2917+
explicit TListValueBuilder(const THolderFactory& HolderFactory)
2918+
: HolderFactory_(HolderFactory)
2919+
{}
2920+
2921+
// Destroys (moves out from) the element
2922+
IListValueBuilder& Add(NUdf::TUnboxedValue&& element) final {
2923+
List_.emplace_back(element);
2924+
return *this;
2925+
}
2926+
2927+
// Destroys (moves out from) the elements
2928+
IListValueBuilder& AddMany(const NUdf::TUnboxedValue* elements, size_t count) final {
2929+
std::copy_n(std::make_move_iterator(elements), count, std::back_inserter(List_));
2930+
return *this;
2931+
}
2932+
2933+
NUdf::TUnboxedValue Build() final {
2934+
if (List_.empty()) {
2935+
return HolderFactory_.GetEmptyContainerLazy();
2936+
}
2937+
2938+
return HolderFactory_.VectorAsVectorHolder(std::move(List_));
2939+
}
2940+
2941+
private:
2942+
const NMiniKQL::THolderFactory& HolderFactory_;
2943+
TUnboxedValueVector List_;
2944+
};
2945+
29122946
//////////////////////////////////////////////////////////////////////////////
29132947
// THolderFactory
29142948
//////////////////////////////////////////////////////////////////////////////
@@ -3450,6 +3484,10 @@ NUdf::IDictValueBuilder::TPtr THolderFactory::NewDict(
34503484
GetCompare(*keyType, useIHash));
34513485
}
34523486

3487+
NUdf::IListValueBuilder::TPtr THolderFactory::NewList() const {
3488+
return new TListValueBuilder(*this);
3489+
}
3490+
34533491
#define DEFINE_HASHED_SINGLE_FIXED_MAP_OPT(xType) \
34543492
template NUdf::TUnboxedValuePod THolderFactory::CreateDirectHashedSingleFixedMapHolder<xType, true> \
34553493
(TValuesDictHashSingleFixedMap<xType>&& map, std::optional<NUdf::TUnboxedValue>&& nullPayload) const;

ydb/library/yql/minikql/computation/mkql_computation_node_holders.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,8 @@ class THolderFactory: private TNonCopyable
948948
const NUdf::TType* dictType,
949949
ui32 flags) const;
950950

951+
NUdf::IListValueBuilder::TPtr NewList() const;
952+
951953
NUdf::TUnboxedValuePod Cloned(const NUdf::TUnboxedValuePod& it) const;
952954
NUdf::TUnboxedValuePod Reversed(const NUdf::TUnboxedValuePod& it) const;
953955

ydb/library/yql/minikql/computation/mkql_value_builder.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,23 +87,15 @@ NUdf::TUnboxedValue TDefaultValueBuilder::SubString(NUdf::TUnboxedValuePod value
8787
}
8888

8989
NUdf::TUnboxedValue TDefaultValueBuilder::NewList(NUdf::TUnboxedValue* items, ui64 count) const {
90-
if (!items || !count)
90+
if (items == nullptr || count == 0) {
9191
return HolderFactory_.GetEmptyContainerLazy();
92-
93-
if (count < Max<ui32>()) {
94-
NUdf::TUnboxedValue* inplace = nullptr;
95-
auto array = HolderFactory_.CreateDirectArrayHolder(count, inplace);
96-
for (ui64 i = 0; i < count; ++i)
97-
*inplace++ = std::move(*items++);
98-
return std::move(array);
9992
}
10093

101-
TDefaultListRepresentation list;
102-
for (ui64 i = 0; i < count; ++i) {
103-
list = list.Append(std::move(*items++));
104-
}
94+
NUdf::TUnboxedValue* inplace = nullptr;
95+
auto array = HolderFactory_.CreateDirectArrayHolder(count, inplace);
96+
std::copy_n(std::make_move_iterator(items), count, inplace);
10597

106-
return HolderFactory_.CreateDirectListHolder(std::move(list));
98+
return array;
10799
}
108100

109101
NUdf::TUnboxedValue TDefaultValueBuilder::ReverseList(const NUdf::TUnboxedValuePod& list) const
@@ -331,5 +323,9 @@ bool TDefaultValueBuilder::GetSecureParam(NUdf::TStringRef key, NUdf::TStringRef
331323
return false;
332324
}
333325

326+
NUdf::IListValueBuilder::TPtr TDefaultValueBuilder::NewListBuilder() const {
327+
return HolderFactory_.NewList();
328+
}
329+
334330
} // namespace NMiniKQL
335331
} // namespace Nkikimr

ydb/library/yql/minikql/computation/mkql_value_builder.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class TDefaultValueBuilder final: public NUdf::IValueBuilder, private TNonCopyab
3737
NUdf::TUnboxedValue PrependString(const NUdf::TStringRef& ref,NUdf::TUnboxedValuePod value) const final;
3838

3939
NUdf::TUnboxedValue SubString(NUdf::TUnboxedValuePod value, ui32 offset, ui32 size) const final;
40-
NUdf::TUnboxedValue NewList(NUdf::TUnboxedValue* items, ui64 count) const final;
40+
NUdf::TUnboxedValue NewList(NUdf::TUnboxedValue* items, ui64 count) const final; // Destroys (moves out from) items
4141

4242
NUdf::TUnboxedValue NewString(const NUdf::TStringRef& ref) const final;
4343

@@ -91,6 +91,8 @@ class TDefaultValueBuilder final: public NUdf::IValueBuilder, private TNonCopyab
9191

9292
NUdf::TUnboxedValue NewArray64(ui64 count, NUdf::TUnboxedValue*& itemsPtr) const final;
9393

94+
NUdf::IListValueBuilder::TPtr NewListBuilder() const final;
95+
9496
private:
9597
const THolderFactory& HolderFactory_;
9698
NUdf::EValidatePolicy Policy_;

ydb/library/yql/public/udf/udf_value_builder.h

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@ class IDictValueBuilder
4242

4343
UDF_ASSERT_TYPE_SIZE(IDictValueBuilder, 8);
4444

45+
class IListValueBuilder {
46+
public:
47+
using TPtr = TUniquePtr<IListValueBuilder>;
48+
49+
public:
50+
virtual ~IListValueBuilder() = default;
51+
52+
// Destroys (moves out from) the element
53+
virtual IListValueBuilder& Add(TUnboxedValue&& element) = 0;
54+
55+
// Destroys (moves out from) the elements
56+
virtual IListValueBuilder& AddMany(const NUdf::TUnboxedValue* elements, size_t count) = 0;
57+
58+
virtual TUnboxedValue Build() = 0;
59+
};
60+
61+
UDF_ASSERT_TYPE_SIZE(IListValueBuilder, 8);
62+
4563
///////////////////////////////////////////////////////////////////////////////
4664
// IDateBuilder
4765
///////////////////////////////////////////////////////////////////////////////
@@ -208,6 +226,7 @@ class IValueBuilder1
208226

209227
virtual IDictValueBuilder::TPtr NewDict(const TType* dictType, ui32 flags) const = 0;
210228

229+
// Destroys (moves out from) items
211230
virtual TUnboxedValue NewList(TUnboxedValue* items, ui64 count) const = 0;
212231

213232
virtual TUnboxedValue ReverseList(const TUnboxedValuePod& list) const = 0;
@@ -288,7 +307,19 @@ class IValueBuilder7: public IValueBuilder6 {
288307
};
289308
#endif
290309

291-
#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 27)
310+
#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 39)
311+
class IValueBuilder8: public IValueBuilder7 {
312+
public:
313+
virtual IListValueBuilder::TPtr NewListBuilder() const = 0;
314+
};
315+
#endif
316+
317+
#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 39)
318+
class IValueBuilder: public IValueBuilder8 {
319+
protected:
320+
IValueBuilder();
321+
};
322+
#elif UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 27)
292323
class IValueBuilder: public IValueBuilder7 {
293324
protected:
294325
IValueBuilder();

ydb/library/yql/public/udf/udf_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace NYql {
77
namespace NUdf {
88

99
#define CURRENT_UDF_ABI_VERSION_MAJOR 2
10-
#define CURRENT_UDF_ABI_VERSION_MINOR 38
10+
#define CURRENT_UDF_ABI_VERSION_MINOR 39
1111
#define CURRENT_UDF_ABI_VERSION_PATCH 0
1212

1313
#ifdef USE_CURRENT_UDF_ABI_VERSION

0 commit comments

Comments
 (0)