| 1313 | if (not compareOrderedPartitions(expected[i], actual[i])) { |
| 1314 | return false; |
| 1315 | } |
| 1316 | } |
| 1317 | |
| 1318 | return true; |
| 1319 | } |
| 1320 | |
| 1321 | void assertResultsOrdered( |
| 1322 | const std::vector<RowVectorPtr>& results, |
| 1323 | const RowTypePtr& resultType, |
| 1324 | const std::string& duckDbSql, |
| 1325 | DuckDbQueryRunner& duckDbQueryRunner, |
| 1326 | const std::vector<uint32_t>& sortingKeys) { |
| 1327 | std::vector<OrderedPartition> actualPartitions; |
| 1328 | std::vector<OrderedPartition> expectedPartitions; |
| 1329 | |
| 1330 | for (const auto& vector : results) { |
| 1331 | auto rows = materialize(vector); |
| 1332 | for (const auto& row : rows) { |
| 1333 | auto keys = getColumns(row, sortingKeys); |
| 1334 | if (actualPartitions.empty() || actualPartitions.back().first != keys) { |
| 1335 | actualPartitions.emplace_back(keys, MaterializedRowMultiset()); |
| 1336 | } |
| 1337 | actualPartitions.back().second.insert(row); |
| 1338 | } |
| 1339 | } |
| 1340 | |
| 1341 | auto expectedRows = duckDbQueryRunner.executeOrdered(duckDbSql, resultType); |
| 1342 | for (const auto& row : expectedRows) { |
| 1343 | auto keys = getColumns(row, sortingKeys); |
| 1344 | if (expectedPartitions.empty() || expectedPartitions.back().first != keys) { |
| 1345 | expectedPartitions.emplace_back(keys, MaterializedRowMultiset()); |
| 1346 | } |
| 1347 | expectedPartitions.back().second.insert(row); |
| 1348 | } |
| 1349 | |
| 1350 | if (not compareOrderedPartitionsVectors( |
| 1351 | expectedPartitions, actualPartitions)) { |
| 1352 | auto actualPartIter = actualPartitions.begin(); |
| 1353 | auto expectedPartIter = expectedPartitions.begin(); |
| 1354 | while (expectedPartIter != expectedPartitions.end() && |
| 1355 | actualPartIter != actualPartitions.end()) { |
| 1356 | if (not compareOrderedPartitions(*expectedPartIter, *actualPartIter)) { |
| 1357 | break; |
| 1358 | } |
| 1359 | ++expectedPartIter; |
| 1360 | ++actualPartIter; |
| 1361 | } |
| 1362 | std::ostringstream oss; |
| 1363 | if (expectedPartIter == expectedPartitions.end()) { |
| 1364 | oss << "Got extra rows: keys: " |
| 1365 | << toString(actualPartIter->first, resultType) << std::endl; |
| 1366 | } else if (actualPartIter == actualPartitions.end()) { |
| 1367 | oss << "Missing rows: keys: " |
| 1368 | << toString(expectedPartIter->first, resultType) << std::endl; |
| 1369 | } else { |
| 1370 | if (actualPartIter->first != expectedPartIter->first) { |
| 1371 | oss << "Expected keys: " |
| 1372 | << toString(expectedPartIter->first, resultType) |
no test coverage detected