Skip to content

Commit 89517af

Browse files
Merge ddc79c0 into 665c03b
2 parents 665c03b + ddc79c0 commit 89517af

2 files changed

Lines changed: 23 additions & 10 deletions

File tree

ydb/core/formats/arrow/replace_key.h

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ class TReplaceKeyTemplate {
5757
, Position(position)
5858
{
5959
Y_ABORT_UNLESS(Size() > 0 && Position < (ui64)Column(0).length());
60+
for (auto&& i : *Columns) {
61+
Types.emplace_back(i->type_id());
62+
}
6063
}
6164

6265
template<typename T = TArrayVecPtr> requires IsOwning
@@ -65,13 +68,16 @@ class TReplaceKeyTemplate {
6568
, Position(position)
6669
{
6770
Y_ABORT_UNLESS(Size() > 0 && Position < (ui64)Column(0).length());
71+
for (auto&& i : *Columns) {
72+
Types.emplace_back(i->type_id());
73+
}
6874
}
6975

7076
template<typename T>
7177
bool operator == (const TReplaceKeyTemplate<T>& key) const {
7278
Y_ABORT_UNLESS(Size() == key.Size());
7379

74-
for (int i = 0; i < Size(); ++i) {
80+
for (ui32 i = 0; i < Size(); ++i) {
7581
auto cmp = CompareColumnValue(i, key, i);
7682
if (std::is_neq(cmp)) {
7783
return false;
@@ -84,7 +90,7 @@ class TReplaceKeyTemplate {
8490
std::partial_ordering operator <=> (const TReplaceKeyTemplate<T>& key) const {
8591
Y_ABORT_UNLESS(Size() == key.Size());
8692

87-
for (int i = 0; i < Size(); ++i) {
93+
for (ui32 i = 0; i < Size(); ++i) {
8894
auto cmp = CompareColumnValue(i, key, i);
8995
if (std::is_neq(cmp)) {
9096
return cmp;
@@ -97,7 +103,7 @@ class TReplaceKeyTemplate {
97103
std::partial_ordering CompareNotNull(const TReplaceKeyTemplate<T>& key) const {
98104
Y_ABORT_UNLESS(Size() == key.Size());
99105

100-
for (int i = 0; i < Size(); ++i) {
106+
for (ui32 i = 0; i < Size(); ++i) {
101107
auto cmp = CompareColumnValueNotNull(i, key, i);
102108
if (std::is_neq(cmp)) {
103109
return cmp;
@@ -107,11 +113,11 @@ class TReplaceKeyTemplate {
107113
}
108114

109115
template<typename T>
110-
std::partial_ordering ComparePartNotNull(const TReplaceKeyTemplate<T>& key, int size) const {
116+
std::partial_ordering ComparePartNotNull(const TReplaceKeyTemplate<T>& key, const ui32 size) const {
111117
Y_ABORT_UNLESS(size <= key.Size());
112118
Y_ABORT_UNLESS(size <= Size());
113119

114-
for (int i = 0; i < size; ++i) {
120+
for (ui32 i = 0; i < size; ++i) {
115121
auto cmp = CompareColumnValueNotNull(i, key, i);
116122
if (std::is_neq(cmp)) {
117123
return cmp;
@@ -130,11 +136,13 @@ class TReplaceKeyTemplate {
130136
template<typename T>
131137
std::partial_ordering CompareColumnValue(int column, const TReplaceKeyTemplate<T>& key, int keyColumn) const {
132138
Y_DEBUG_ABORT_UNLESS(Column(column).type_id() == key.Column(keyColumn).type_id());
139+
Y_DEBUG_ABORT_UNLESS(Types[column] == Column(column).type_id());
140+
Y_DEBUG_ABORT_UNLESS(Types.size() == Size());
133141

134-
return TComparator::TypedCompare<false>(Column(column), Position, key.Column(keyColumn), key.Position);
142+
return TComparator::ConcreteTypedCompare<false>(Types[column], Column(column), Position, key.Column(keyColumn), key.Position);
135143
}
136144

137-
int Size() const {
145+
ui64 Size() const {
138146
Y_DEBUG_ABORT_UNLESS(Columns);
139147
return Columns->size();
140148
}
@@ -166,7 +174,7 @@ class TReplaceKeyTemplate {
166174

167175
template<typename T = TArrayVecPtr> requires IsOwning
168176
std::shared_ptr<arrow::RecordBatch> RestoreBatch(const std::shared_ptr<arrow::Schema>& schema) const {
169-
AFL_VERIFY(Size() && Size() == schema->num_fields())("columns", DebugString())("schema", JoinSeq(",", schema->field_names()));
177+
AFL_VERIFY(Size() && Size() == (ui32)schema->num_fields())("columns", DebugString())("schema", JoinSeq(",", schema->field_names()));
170178
const auto& columns = *Columns;
171179
return arrow::RecordBatch::Make(schema, columns[0]->length(), columns);
172180
}
@@ -220,6 +228,7 @@ class TReplaceKeyTemplate {
220228

221229
private:
222230
TArrayVecPtr Columns = nullptr;
231+
std::vector<arrow::Type::type> Types;
223232
ui64 Position = 0;
224233

225234
};

ydb/core/formats/arrow/switch/compare.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ namespace NKikimr::NArrow {
77
class TComparator {
88
public:
99
template <bool notNull>
10-
static std::partial_ordering TypedCompare(const arrow::Array& lhs, const int lpos, const arrow::Array& rhs, const int rpos) {
11-
arrow::Type::type typeId = lhs.type_id();
10+
static std::partial_ordering ConcreteTypedCompare(const arrow::Type::type typeId, const arrow::Array& lhs, const int lpos, const arrow::Array& rhs, const int rpos) {
1211
switch (typeId) {
1312
case arrow::Type::NA:
1413
case arrow::Type::BOOL:
@@ -73,6 +72,11 @@ class TComparator {
7372
return std::partial_ordering::equivalent;
7473
}
7574

75+
template <bool notNull>
76+
static std::partial_ordering TypedCompare(const arrow::Array& lhs, const int lpos, const arrow::Array& rhs, const int rpos) {
77+
return ConcreteTypedCompare<notNull>(lhs.type_id(), lhs, lpos, rhs, rpos);
78+
}
79+
7680
template <typename T, bool notNull>
7781
static std::partial_ordering CompareView(const arrow::Array& lhs, int lpos, const arrow::Array& rhs, int rpos) {
7882
auto& left = static_cast<const T&>(lhs);

0 commit comments

Comments
 (0)