This commit is contained in:
Nikita Mikhaylov 2020-09-08 23:12:55 +03:00
parent c4f0465a7c
commit 614e01b0e4
2 changed files with 12 additions and 14 deletions

View File

@ -334,8 +334,6 @@ void ColumnNullable::updatePermutation(bool reverse, size_t limit, int null_dire
if (equal_ranges.empty())
return;
std::cout << "limit " << limit << std::endl;
/// We will sort nested columns into `new_ranges` and call updatePermutation in next columns with `null_ranges`.
EqualRanges new_ranges, null_ranges;
@ -347,7 +345,7 @@ void ColumnNullable::updatePermutation(bool reverse, size_t limit, int null_dire
for (const auto & [first, last] : equal_ranges)
{
/// Current interval is righter than limit.
if (first > limit)
if (limit && first > limit)
break;
/// Consider a half interval [first, last)
@ -404,7 +402,7 @@ void ColumnNullable::updatePermutation(bool reverse, size_t limit, int null_dire
for (const auto & [first, last] : equal_ranges)
{
/// Current interval is righter than limit.
if (first > limit)
if (limit && first > limit)
break;
ssize_t read_idx = last - 1;
@ -439,15 +437,7 @@ void ColumnNullable::updatePermutation(bool reverse, size_t limit, int null_dire
}
}
std::cout << "New Ranges " << std::endl;
for (auto [first, last] : new_ranges )
std::cout << "first " << first << " last " << last << std::endl;
std::cout << "Null Ranges " << std::endl;
for (auto [first, last] : null_ranges)
std::cout << "first " << first << " last " << last << std::endl;
getNestedColumn().updatePermutation(reverse, 0, null_direction_hint, res, new_ranges);
getNestedColumn().updatePermutation(reverse, limit, null_direction_hint, res, new_ranges);
equal_ranges = std::move(new_ranges);
std::move(null_ranges.begin(), null_ranges.end(), std::back_inserter(equal_ranges));

View File

@ -18,6 +18,8 @@
#include <pdqsort.h>
#include <numeric>
#include <ext/scope_guard.h>
#if !defined(ARCADIA_BUILD)
# include <Common/config.h>
# if USE_OPENCL
@ -250,6 +252,7 @@ void ColumnVector<T>::updatePermutation(bool reverse, size_t limit, int nan_dire
limit = 0;
EqualRanges new_ranges;
SCOPE_EXIT({equal_range = std::move(new_ranges);});
for (size_t i = 0; i < equal_range.size() - bool(limit); ++i)
{
@ -278,6 +281,12 @@ void ColumnVector<T>::updatePermutation(bool reverse, size_t limit, int nan_dire
if (limit)
{
const auto & [first, last] = equal_range.back();
if (limit < first || limit >= last)
return;
/// Since then, we are working inside the interval.
if (reverse)
std::partial_sort(res.begin() + first, res.begin() + limit, res.begin() + last, greater(*this, nan_direction_hint));
else
@ -310,7 +319,6 @@ void ColumnVector<T>::updatePermutation(bool reverse, size_t limit, int nan_dire
new_ranges.emplace_back(new_first, new_last);
}
}
equal_range = std::move(new_ranges);
}
template <typename T>