MCPcopy Create free account
hub / github.com/bytedance/bolt / compare

Method compare

bolt/vector/ComplexVector.cpp:99–161  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

97}
98
99std::optional<int32_t> RowVector::compare(
100 const BaseVector* other,
101 vector_size_t index,
102 vector_size_t otherIndex,
103 CompareFlags flags) const {
104 auto otherRow = other->wrappedVector()->as<RowVector>();
105 if (otherRow->encoding() != VectorEncoding::Simple::ROW) {
106 BOLT_CHECK(
107 false,
108 "Compare of ROW and non-ROW {} and {}",
109 BaseVector::toString(),
110 otherRow->BaseVector::toString());
111 }
112
113 bool isNull = isNullAt(index);
114 bool otherNull = other->isNullAt(otherIndex);
115
116 if (isNull || otherNull) {
117 return BaseVector::compareNulls(isNull, otherNull, flags);
118 }
119
120 if (flags.equalsOnly && children_.size() != otherRow->children_.size()) {
121 return 1;
122 }
123
124 auto compareSize = std::min(children_.size(), otherRow->children_.size());
125 bool resultIsindeterminate = false;
126 for (int32_t i = 0; i < compareSize; ++i) {
127 BaseVector* child = children_[i].get();
128 BaseVector* otherChild = otherRow->childAt(i).get();
129 if (!child && !otherChild) {
130 continue;
131 }
132 if (!child || !otherChild) {
133 return child ? 1 : -1; // Absent child counts as less.
134 }
135 if (child->typeKind() != otherChild->typeKind()) {
136 BOLT_CHECK(
137 false,
138 "Compare of different child types: {} and {}",
139 BaseVector::toString(),
140 other->BaseVector::toString());
141 }
142 BaseVector* otherChildLoadedVec = otherChild->loadedVector();
143 auto wrappedOtherIndex = other->wrappedIndex(otherIndex);
144 auto result =
145 child->compare(otherChildLoadedVec, index, wrappedOtherIndex, flags);
146 if (result == kIndeterminate) {
147 BOLT_DCHECK(
148 flags.equalsOnly,
149 "Compare should have thrown when null is encountered in child.");
150 resultIsindeterminate = true;
151 } else if (result.value() != 0) {
152 // If values are not equal no need to continue looping.
153 return result;
154 }
155 }
156

Callers 3

compareArraysFunction · 0.45
isSortedMethod · 0.45
canonicalizeMethod · 0.45

Calls 15

childAtMethod · 0.80
nullAsValueMethod · 0.80
sortedKeyIndicesMethod · 0.80
has_valueMethod · 0.80
toStringFunction · 0.70
isNullAtFunction · 0.70
compareArraysFunction · 0.70
minFunction · 0.50
wrappedVectorMethod · 0.45
encodingMethod · 0.45
isNullAtMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected