Skip to content

Commit

Permalink
Mark some functions of RowContainer as const (facebookincubator#11510)
Browse files Browse the repository at this point in the history
Summary:
Some functions of RowContainer should be const, and then prefix sort RowContainer can be const also, change both in this PR.

Pull Request resolved: facebookincubator#11510

Reviewed By: gggrace14

Differential Revision: D65803417

Pulled By: xiaoxmeng

fbshipit-source-id: 8e28c29528cd0c603e75bb94040f57bded5f413d
  • Loading branch information
jinchengchenghh authored and facebook-github-bot committed Nov 12, 2024
1 parent f3fdec3 commit fcce674
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 64 deletions.
6 changes: 3 additions & 3 deletions velox/exec/PrefixSort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ int PrefixSort::comparePartNormalizedKeys(char* left, char* right) {
}

PrefixSort::PrefixSort(
RowContainer* rowContainer,
const RowContainer* rowContainer,
const PrefixSortLayout& sortLayout,
memory::MemoryPool* pool)
: rowContainer_(rowContainer), sortLayout_(sortLayout), pool_(pool) {}
Expand Down Expand Up @@ -229,7 +229,7 @@ void PrefixSort::extractRowAndEncodePrefixKeys(char* row, char* prefixBuffer) {

// static.
uint32_t PrefixSort::maxRequiredBytes(
RowContainer* rowContainer,
const RowContainer* rowContainer,
const std::vector<CompareFlags>& compareFlags,
const velox::common::PrefixSortConfig& config,
memory::MemoryPool* pool) {
Expand All @@ -250,7 +250,7 @@ uint32_t PrefixSort::maxRequiredBytes(
// static
void PrefixSort::stdSort(
std::vector<char*, memory::StlAllocator<char*>>& rows,
RowContainer* rowContainer,
const RowContainer* rowContainer,
const std::vector<CompareFlags>& compareFlags) {
std::sort(
rows.begin(), rows.end(), [&](const char* leftRow, const char* rightRow) {
Expand Down
10 changes: 5 additions & 5 deletions velox/exec/PrefixSort.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct PrefixSortLayout {
class PrefixSort {
public:
PrefixSort(
RowContainer* rowContainer,
const RowContainer* rowContainer,
const PrefixSortLayout& sortLayout,
memory::MemoryPool* pool);

Expand Down Expand Up @@ -100,7 +100,7 @@ class PrefixSort {
/// @param rows The result of RowContainer::listRows(), assuming that the
/// caller (SortBuffer etc.) has already got the result.
FOLLY_ALWAYS_INLINE static void sort(
RowContainer* rowContainer,
const RowContainer* rowContainer,
const std::vector<CompareFlags>& compareFlags,
const velox::common::PrefixSortConfig& config,
memory::MemoryPool* pool,
Expand Down Expand Up @@ -128,7 +128,7 @@ class PrefixSort {
/// such as prefix data. The logic is similar to the above function
/// PrefixSort::sort but returns the maximum buffer the sort may need.
static uint32_t maxRequiredBytes(
RowContainer* rowContainer,
const RowContainer* rowContainer,
const std::vector<CompareFlags>& compareFlags,
const velox::common::PrefixSortConfig& config,
memory::MemoryPool* pool);
Expand All @@ -139,7 +139,7 @@ class PrefixSort {
/// user experienced data.
static void stdSort(
std::vector<char*, memory::StlAllocator<char*>>& rows,
RowContainer* rowContainer,
const RowContainer* rowContainer,
const std::vector<CompareFlags>& compareFlags);

// Estimates the memory required for prefix sort such as prefix buffer and
Expand All @@ -161,7 +161,7 @@ class PrefixSort {
prefixBuffer + sortLayout_.normalizedBufferSize);
}

RowContainer* const rowContainer_;
const RowContainer* const rowContainer_;
const PrefixSortLayout sortLayout_;
memory::MemoryPool* const pool_;
};
Expand Down
29 changes: 15 additions & 14 deletions velox/exec/RowContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ void RowContainer::eraseRows(folly::Range<char**> rows) {
numFreeRows_ += rows.size();
}

int32_t RowContainer::findRows(folly::Range<char**> rows, char** result) {
int32_t RowContainer::findRows(folly::Range<char**> rows, char** result) const {
raw_vector<folly::Range<char*>> ranges;
ranges.resize(rows_.numRanges());
for (auto i = 0; i < rows_.numRanges(); ++i) {
Expand Down Expand Up @@ -424,7 +424,7 @@ void RowContainer::freeVariableWidthFields(folly::Range<char**> rows) {
}
}

void RowContainer::checkConsistency() {
void RowContainer::checkConsistency() const {
constexpr int32_t kBatch = 1000;
std::vector<char*> rows(kBatch);

Expand Down Expand Up @@ -563,7 +563,8 @@ std::unique_ptr<ByteInputStream> RowContainer::prepareRead(
HashStringAllocator::headerOf(view->data()));
}

int32_t RowContainer::variableSizeAt(const char* row, column_index_t column) {
int32_t RowContainer::variableSizeAt(const char* row, column_index_t column)
const {
const auto rowColumn = rowColumns_[column];

if (isNullAt(row, rowColumn)) {
Expand All @@ -580,14 +581,14 @@ int32_t RowContainer::variableSizeAt(const char* row, column_index_t column) {
}
}

int32_t RowContainer::fixedSizeAt(column_index_t column) {
int32_t RowContainer::fixedSizeAt(column_index_t column) const {
return typeKindSize(typeKinds_[column]);
}

int32_t RowContainer::extractVariableSizeAt(
const char* row,
column_index_t column,
char* output) {
char* output) const {
const auto rowColumn = rowColumns_[column];

// 4 bytes for size + N bytes for data.
Expand Down Expand Up @@ -660,7 +661,7 @@ int32_t RowContainer::storeVariableSizeAt(

void RowContainer::extractSerializedRows(
folly::Range<char**> rows,
const VectorPtr& result) {
const VectorPtr& result) const {
// The format of the extracted row is: null bytes followed by keys and
// dependent columns. Fixed-width columns are serialized into fixed number of
// bytes (see typeKindSize). Variable-width columns are serialized as 4 bytes
Expand Down Expand Up @@ -815,7 +816,7 @@ int RowContainer::compareComplexType(
int32_t offset,
const DecodedVector& decoded,
vector_size_t index,
CompareFlags flags) {
CompareFlags flags) const {
VELOX_DCHECK(flags.nullAsValue(), "not supported null handling mode");

auto stream = prepareRead(row, offset);
Expand All @@ -835,7 +836,7 @@ int32_t RowContainer::compareComplexType(
const Type* type,
int32_t leftOffset,
int32_t rightOffset,
CompareFlags flags) {
CompareFlags flags) const {
VELOX_DCHECK(flags.nullAsValue(), "not supported null handling mode");

auto leftStream = prepareRead(left, leftOffset);
Expand All @@ -848,7 +849,7 @@ int32_t RowContainer::compareComplexType(
const char* right,
const Type* type,
int32_t offset,
CompareFlags flags) {
CompareFlags flags) const {
return compareComplexType(left, right, type, offset, offset, flags);
}

Expand All @@ -859,7 +860,7 @@ void RowContainer::hashTyped(
bool nullable,
folly::Range<char**> rows,
bool mix,
uint64_t* result) {
uint64_t* result) const {
using T = typename KindToFlatVector<Kind>::HashRowType;

auto offset = column.offset();
Expand Down Expand Up @@ -899,7 +900,7 @@ void RowContainer::hash(
int32_t column,
folly::Range<char**> rows,
bool mix,
uint64_t* result) {
uint64_t* result) const {
if (typeKinds_[column] == TypeKind::UNKNOWN) {
for (auto i = 0; i < rows.size(); ++i) {
result[i] = mix ? bits::hashMix(result[i], BaseVector::kNullHash)
Expand Down Expand Up @@ -973,7 +974,7 @@ void RowContainer::extractProbedFlags(
int32_t numRows,
bool setNullForNullKeysRow,
bool setNullForNonProbedRow,
const VectorPtr& result) {
const VectorPtr& result) const {
result->resize(numRows);
result->clearAllNulls();
auto flatResult = result->as<FlatVector<bool>>();
Expand Down Expand Up @@ -1029,7 +1030,7 @@ int64_t RowContainer::sizeIncrement(
bits::roundUp(needBytes, kAllocUnit);
}

void RowContainer::skip(RowContainerIterator& iter, int32_t numRows) {
void RowContainer::skip(RowContainerIterator& iter, int32_t numRows) const {
VELOX_DCHECK(accumulators_.empty(), "Used in join only");
VELOX_DCHECK_LE(0, numRows);
if (!iter.endOfRun) {
Expand Down Expand Up @@ -1087,7 +1088,7 @@ int32_t RowContainer::listPartitionRows(
uint8_t partition,
int32_t maxRows,
const RowPartitions& rowPartitions,
char** result) {
char** result) const {
VELOX_CHECK(
!mutable_, "Can't list partition rows from a mutable row container");
VELOX_CHECK_EQ(
Expand Down
Loading

0 comments on commit fcce674

Please sign in to comment.