Skip to content

fix trivial batch modification detector #896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions ydb/core/formats/arrow/arrow_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,10 @@ std::vector<std::shared_ptr<arrow::RecordBatch>> SliceSortedBatches(const std::v
}

// Check if the permutation doesn't reorder anything
bool IsNoOp(const arrow::UInt64Array& permutation) {
bool IsTrivial(const arrow::UInt64Array& permutation, const ui64 originalLength) {
if ((ui64)permutation.length() != originalLength) {
return false;
}
for (i64 i = 0; i < permutation.length(); ++i) {
if (permutation.Value(i) != (ui64)i) {
return false;
Expand All @@ -376,7 +379,7 @@ std::shared_ptr<arrow::RecordBatch> Reorder(const std::shared_ptr<arrow::RecordB
const std::shared_ptr<arrow::UInt64Array>& permutation, const bool canRemove) {
Y_ABORT_UNLESS(permutation->length() == batch->num_rows() || canRemove);

auto res = IsNoOp(*permutation) ? batch : arrow::compute::Take(batch, permutation);
auto res = IsTrivial(*permutation, batch->num_rows()) ? batch : arrow::compute::Take(batch, permutation);
Y_ABORT_UNLESS(res.ok());
return (*res).record_batch();
}
Expand Down
8 changes: 5 additions & 3 deletions ydb/core/formats/arrow/permutations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ std::shared_ptr<arrow::UInt64Array> MakePermutation(const int size, const bool r
return out;
}

std::shared_ptr<arrow::UInt64Array> MakeSortPermutation(const std::shared_ptr<arrow::RecordBatch>& batch,
const std::shared_ptr<arrow::Schema>& sortingKey, const bool andUnique) {
auto keyBatch = ExtractColumns(batch, sortingKey);
std::shared_ptr<arrow::UInt64Array> MakeSortPermutation(const std::shared_ptr<arrow::RecordBatch>& batch, const std::shared_ptr<arrow::Schema>& sortingKey, const bool andUnique) {
auto keyBatch = ExtractColumns(batch, sortingKey, false);
AFL_VERIFY(batch);
AFL_VERIFY(sortingKey);
AFL_VERIFY(!!keyBatch)("problem", "cannot_find_columns")("schema", batch->schema()->ToString())("columns", sortingKey->ToString());
auto keyColumns = std::make_shared<TArrayVec>(keyBatch->columns());
std::vector<TRawReplaceKey> points;
points.reserve(keyBatch->num_rows());
Expand Down
3 changes: 1 addition & 2 deletions ydb/core/formats/arrow/permutations.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ class TShardingSplitIndex {
std::shared_ptr<arrow::UInt64Array> MakePermutation(const int size, const bool reverse = false);
std::shared_ptr<arrow::UInt64Array> MakeFilterPermutation(const std::vector<ui64>& indexes);
std::shared_ptr<arrow::UInt64Array> MakeFilterPermutation(const std::vector<ui32>& indexes);
std::shared_ptr<arrow::UInt64Array> MakeSortPermutation(const std::shared_ptr<arrow::RecordBatch>& batch,
const std::shared_ptr<arrow::Schema>& sortingKey, const bool andUnique);
std::shared_ptr<arrow::UInt64Array> MakeSortPermutation(const std::shared_ptr<arrow::RecordBatch>& batch, const std::shared_ptr<arrow::Schema>& sortingKey, const bool andUnique);
std::shared_ptr<arrow::RecordBatch> ReverseRecords(const std::shared_ptr<arrow::RecordBatch>& batch);

std::shared_ptr<arrow::Array> CopyRecords(const std::shared_ptr<arrow::Array>& source, const std::vector<ui64>& indexes);
Expand Down