Skip to content

Commit 3c73193

Browse files
mbasmanovafacebook-github-bot
authored andcommitted
refactor(vector): Improve usage of VELOX_CHECK macros in ComplexVector.cpp (#11828)
Summary: Pull Request resolved: #11828 - Use VELOX_CHECK(condition) instead of if (condition) + VELOX_CHECK(false). - VELOX_DCHECK_GE(a, b) instead of VELOX_DCHECK(a >= b) - Use VELOX_FAIL(message) instead of VELOX_CHECK(false, message) Reviewed By: Yuhta Differential Revision: D67095792 fbshipit-source-id: f4b1b61c05219790455e13bbef285f314f99dfcb
1 parent 7a02321 commit 3c73193

File tree

1 file changed

+25
-29
lines changed

1 file changed

+25
-29
lines changed

velox/vector/ComplexVector.cpp

+25-29
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,11 @@ std::optional<int32_t> RowVector::compare(
8888
vector_size_t otherIndex,
8989
CompareFlags flags) const {
9090
auto otherRow = other->wrappedVector()->as<RowVector>();
91-
if (otherRow->encoding() != VectorEncoding::Simple::ROW) {
92-
VELOX_CHECK(
93-
false,
94-
"Compare of ROW and non-ROW {} and {}",
95-
BaseVector::toString(),
96-
otherRow->BaseVector::toString());
97-
}
91+
VELOX_CHECK(
92+
otherRow->encoding() == VectorEncoding::Simple::ROW,
93+
"Compare of ROW and non-ROW {} and {}",
94+
BaseVector::toString(),
95+
otherRow->BaseVector::toString());
9896

9997
bool isNull = isNullAt(index);
10098
bool otherNull = other->isNullAt(otherIndex);
@@ -118,13 +116,14 @@ std::optional<int32_t> RowVector::compare(
118116
if (!child || !otherChild) {
119117
return child ? 1 : -1; // Absent child counts as less.
120118
}
121-
if (child->typeKind() != otherChild->typeKind()) {
122-
VELOX_CHECK(
123-
false,
124-
"Compare of different child types: {} and {}",
125-
BaseVector::toString(),
126-
other->BaseVector::toString());
127-
}
119+
120+
VELOX_CHECK_EQ(
121+
child->typeKind(),
122+
otherChild->typeKind(),
123+
"Compare of different child types: {} and {}",
124+
BaseVector::toString(),
125+
other->BaseVector::toString());
126+
128127
auto wrappedOtherIndex = other->wrappedIndex(otherIndex);
129128
auto result = child->compare(
130129
otherChild->loadedVector(), index, wrappedOtherIndex, flags);
@@ -582,7 +581,7 @@ void ArrayVectorBase::copyRangesImpl(
582581
applyToEachRange(
583582
ranges, [&](auto targetIndex, auto sourceIndex, auto count) {
584583
if (count > 0) {
585-
VELOX_DCHECK(BaseVector::length_ >= targetIndex + count);
584+
VELOX_DCHECK_GE(BaseVector::length_, targetIndex + count);
586585
totalCount += count;
587586
}
588587
});
@@ -665,9 +664,7 @@ void RowVector::resize(vector_size_t newSize, bool setNotNull) {
665664
// Resize all the children.
666665
for (auto& child : children_) {
667666
if (child != nullptr) {
668-
if (child->isLazy()) {
669-
VELOX_FAIL("Resize on a lazy vector is not allowed");
670-
}
667+
VELOX_CHECK(!child->isLazy(), "Resize on a lazy vector is not allowed");
671668

672669
// If we are just reducing the size of the vector, its safe
673670
// to skip uniqueness check since effectively we are just changing
@@ -1028,13 +1025,13 @@ std::optional<int32_t> ArrayVector::compare(
10281025

10291026
auto otherArray = otherValue->asUnchecked<ArrayVector>();
10301027
auto otherElements = otherArray->elements_.get();
1031-
if (elements_->typeKind() != otherElements->typeKind()) {
1032-
VELOX_CHECK(
1033-
false,
1034-
"Compare of arrays of different element type: {} and {}",
1035-
BaseVector::toString(),
1036-
otherArray->BaseVector::toString());
1037-
}
1028+
1029+
VELOX_CHECK_EQ(
1030+
elements_->typeKind(),
1031+
otherElements->typeKind(),
1032+
"Compare of arrays of different element type: {} and {}",
1033+
BaseVector::toString(),
1034+
otherArray->BaseVector::toString());
10381035

10391036
if (flags.equalsOnly &&
10401037
rawSizes_[index] != otherArray->rawSizes_[wrappedOtherIndex]) {
@@ -1250,8 +1247,7 @@ std::optional<int32_t> MapVector::compare(
12501247

12511248
if (keys_->typeKind() != otherMap->keys_->typeKind() ||
12521249
values_->typeKind() != otherMap->values_->typeKind()) {
1253-
VELOX_CHECK(
1254-
false,
1250+
VELOX_FAIL(
12551251
"Compare of maps of different key/value types: {} and {}",
12561252
BaseVector::toString(),
12571253
otherMap->BaseVector::toString());
@@ -1328,7 +1324,7 @@ void MapVector::canonicalize(
13281324
// threads. The keys and values do not have to be uniquely owned
13291325
// since they are not mutated but rather transposed, which is
13301326
// non-destructive.
1331-
VELOX_CHECK(map.use_count() == 1);
1327+
VELOX_CHECK_EQ(map.use_count(), 1);
13321328
BufferPtr indices;
13331329
vector_size_t* indicesRange;
13341330
for (auto i = 0; i < map->BaseVector::length_; ++i) {
@@ -1697,7 +1693,7 @@ MapVectorPtr MapVector::updateImpl(
16971693

16981694
MapVectorPtr MapVector::update(const std::vector<MapVectorPtr>& others) const {
16991695
VELOX_CHECK(!others.empty());
1700-
VELOX_CHECK(others.size() < std::numeric_limits<int8_t>::max());
1696+
VELOX_CHECK_LT(others.size(), std::numeric_limits<int8_t>::max());
17011697
for (auto& other : others) {
17021698
VELOX_CHECK_EQ(size(), other->size());
17031699
}

0 commit comments

Comments
 (0)