1515
1616namespace NKikimr ::NArrow {
1717
18- std::shared_ptr<arrow::UInt64Array> MakeSortPermutation (const std::shared_ptr<arrow::RecordBatch>& batch, const std::shared_ptr<arrow::Schema>& sortingKey, const bool andUnique) {
19- auto keyBatch = TColumnOperator ().VerifyIfAbsent ().Adapt (batch, sortingKey).DetachResult ();
20- auto keyColumns = std::make_shared<TArrayVec>(keyBatch->columns ());
18+ std::shared_ptr<arrow::UInt64Array> MakeSortPermutation (const std::vector<std::shared_ptr<arrow::Array>>& keyColumns, const bool andUnique) {
19+ std::optional<i64 > count;
20+ for (auto && i : keyColumns) {
21+ AFL_VERIFY (i);
22+ if (!count) {
23+ count = i->length ();
24+ } else {
25+ AFL_VERIFY (*count == i->length ());
26+ }
27+ }
28+ AFL_VERIFY (count);
2129 std::vector<TRawReplaceKey> points;
22- points.reserve (keyBatch->num_rows ());
23-
24- for (int i = 0 ; i < keyBatch->num_rows (); ++i) {
25- points.push_back (TRawReplaceKey (keyColumns.get (), i));
30+ points.reserve (*count);
31+ for (int i = 0 ; i < *count; ++i) {
32+ points.push_back (TRawReplaceKey (&keyColumns, i));
2633 }
2734
2835 bool haveNulls = false ;
29- for (auto & column : * keyColumns) {
36+ for (auto & column : keyColumns) {
3037 if (HasNulls (column)) {
3138 haveNulls = true ;
3239 break ;
@@ -36,11 +43,9 @@ std::shared_ptr<arrow::UInt64Array> MakeSortPermutation(const std::shared_ptr<ar
3643 if (haveNulls) {
3744 std::sort (points.begin (), points.end ());
3845 } else {
39- std::sort (points.begin (), points.end (),
40- [](const TRawReplaceKey& a, const TRawReplaceKey& b) {
41- return a.CompareNotNull (b) == std::partial_ordering::less;
42- }
43- );
46+ std::sort (points.begin (), points.end (), [](const TRawReplaceKey& a, const TRawReplaceKey& b) {
47+ return a.CompareNotNull (b) == std::partial_ordering::less;
48+ });
4449 }
4550
4651 arrow::UInt64Builder builder;
@@ -78,6 +83,12 @@ std::shared_ptr<arrow::UInt64Array> MakeSortPermutation(const std::shared_ptr<ar
7883 return out;
7984}
8085
86+ std::shared_ptr<arrow::UInt64Array> MakeSortPermutation (const std::shared_ptr<arrow::RecordBatch>& batch,
87+ const std::shared_ptr<arrow::Schema>& sortingKey, const bool andUnique) {
88+ auto keyBatch = TColumnOperator ().VerifyIfAbsent ().Adapt (batch, sortingKey).DetachResult ();
89+ return MakeSortPermutation (keyBatch->columns (), andUnique);
90+ }
91+
8192namespace {
8293
8394template <class TDataContainer >
0 commit comments