Skip to content

Commit b00a2aa

Browse files
committed
Sort the results before comparison
The SQL statements don't contain an `ORDER BY` clause, so the ordering can't be an intentional check for this exercise. This exercise happens to work most of the time because BigQuery tends to return results in the same order, but sometimes it doesn't. Learn users shouldn't have to deal with this non-determinism in the check. http://b/415948668
1 parent 9188caf commit b00a2aa

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

learntools/sql/ex6.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,17 @@ def check(self, query, results):
186186
assert ('group by' in lower_query), ('Your query should have a **GROUP BY** clause.')
187187
assert ('count' in lower_query), ('Your query should have a **COUNT** in the **SELECT** statement.')
188188
assert ('%bigquery' in lower_query), ('Your **WHERE** clause is not filtering on the "bigquery" tag correctly.')
189+
189190
# check 2: column names
190191
results.columns = [c.lower() for c in results.columns]
191192
assert ('user_id' in results.columns), ('You do not have a `user_id` column in your results.')
192193
assert ('number_of_answers' in results.columns), ('You do not have a `number_of_answers` column in your results.')
194+
193195
# check 3: correct user IDs
194196
correct_ids = bigquery_experts_answer.loc[bigquery_experts_answer.user_id.notna(), "user_id"].unique()
195197
submitted_ids = results.loc[results.user_id.notna(), "user_id"].unique()
196-
assert np.array_equal(correct_ids, submitted_ids), 'You seem to have the wrong values in the `user_id` column.'
198+
assert np.array_equal(np.sort(correct_ids), np.sort(submitted_ids)), 'You seem to have the wrong values in the `user_id` column.'
199+
197200
# check 4: check one value from other column
198201
first_id = list(bigquery_experts_answer["user_id"])[0]
199202
correct_num = int(bigquery_experts_answer[bigquery_experts_answer["user_id"] == first_id]["number_of_answers"])

0 commit comments

Comments
 (0)