in tools/query_verification/src/main/java/com/google/bigquery/QueryVerifier.java [100:137]
public static List<ResultDifferences> compareResults(List<QueryJobResults> migratedResults, List<QueryJobResults> originalResults) throws IllegalArgumentException {
// Check if same amount of queries were run
if (migratedResults.size() == originalResults.size()) {
List<ResultDifferences> differences = new ArrayList<ResultDifferences>();
for (int i = 0; i < migratedResults.size(); i++) {
Set<List<Object>> migratedJobResults = migratedResults.get(i).results();
Set<List<Object>> originalJobResults = originalResults.get(i).results();
if (migratedJobResults == null) {
migratedJobResults = new HashSet<List<Object>>();
}
if (originalJobResults == null) {
originalJobResults = new HashSet<List<Object>>();
}
// Rows present in migrated query results, but not original query results
List<List<String>> extraResults = new ArrayList<List<String>>();
for (List<Object> migratedQueryResults : migratedJobResults) {
// Rows that exist in both results are removed from missing results set
if (!originalJobResults.remove(migratedQueryResults)) {
// Rows in the migrated results that don't exist in original results are classified as extra in migrated results
extraResults.add(toStringTypes(migratedQueryResults));
}
}
// Any leftover rows in the original results without a match are classified as missing in migrated results
List<List<String>> missingResults = originalJobResults.stream().map(QueryVerifier::toStringTypes).collect(Collectors.toList());
differences.add(ResultDifferences.create(extraResults, missingResults));
}
return differences;
} else {
throw new IllegalArgumentException("Number of statements in migrated query file should be equal to the number of statements in the original query file.");
}
}