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

Function compareOrderedPartitions

bolt/exec/tests/utils/QueryAssertions.cpp:1258–1294  ·  view source on GitHub ↗

Special function to compare ordered partitions in a way that we compare all floating point values inside using 'epsilon' constant. Returns true if equal.

Source from the content-addressed store, hash-verified

1256// To handle the case when the sorting keys are not unique and the order
1257// within the same key is not deterministic, we partition the results with
1258// sorting keys and verify the partitions are equal using set-diff.
1259using OrderedPartition = std::pair<MaterializedRow, MaterializedRowMultiset>;
1260
1261// Special function to compare ordered partitions in a way that
1262// we compare all floating point values inside using 'epsilon' constant.
1263// Returns true if equal.
1264static bool compareOrderedPartitions(
1265 const OrderedPartition& expected,
1266 const OrderedPartition& actual) {
1267 if (expected.first.size() != actual.first.size() or
1268 expected.second.size() != actual.second.size()) {
1269 return false;
1270 }
1271
1272 for (size_t i = 0; i < expected.first.size(); ++i) {
1273 if (not expected.first[i].equalsWithEpsilon(actual.first[i])) {
1274 return false;
1275 }
1276 }
1277
1278 if (expected.second.empty()) {
1279 return true;
1280 }
1281
1282 if (!equalTypeKinds(*expected.second.begin(), *actual.second.begin())) {
1283 ADD_FAILURE() << "Types of expected and actual results do not match";
1284 return false;
1285 }
1286
1287 auto [numFloatingPointColumns, columns] =
1288 findFloatingPointColumns(*expected.second.begin());
1289 if (numFloatingPointColumns) {
1290 MaterializedRowEpsilonComparator comparator{
1291 numFloatingPointColumns, columns};
1292 if (auto result = comparator.areEqual(expected.second, actual.second)) {
1293 return result.value();
1294 }
1295 }
1296 // Compare the results directly without epsilon. This may cause false alarm
1297 // if there are floating-point columns that are computed during the

Callers 2

assertResultsOrderedFunction · 0.85

Calls 9

equalTypeKindsFunction · 0.85
findFloatingPointColumnsFunction · 0.85
compareMaterializedRowsFunction · 0.85
equalsWithEpsilonMethod · 0.80
areEqualMethod · 0.80
sizeMethod · 0.45
emptyMethod · 0.45
beginMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected