Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tests): Ensure deterministic SELECT ordering for CSV upload tests #23856

Merged
merged 6 commits into from
Apr 27, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions tests/integration_tests/csv_upload_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import logging
import os
import shutil
import zipfile
from typing import Dict, Optional, Union

from unittest import mock
Expand Down Expand Up @@ -119,7 +120,11 @@ def create_columnar_files():
os.mkdir(ZIP_DIRNAME)
pd.DataFrame({"a": ["john", "paul"], "b": [1, 2]}).to_parquet(PARQUET_FILENAME1)
pd.DataFrame({"a": ["max", "bob"], "b": [3, 4]}).to_parquet(PARQUET_FILENAME2)
shutil.make_archive(ZIP_DIRNAME, "zip", ZIP_DIRNAME)

with zipfile.ZipFile(ZIP_FILENAME, "w") as archive:
archive.write(PARQUET_FILENAME1)
archive.write(PARQUET_FILENAME2)

yield
os.remove(ZIP_FILENAME)
shutil.rmtree(ZIP_DIRNAME)
Expand Down Expand Up @@ -556,4 +561,4 @@ def test_import_parquet(mock_event_logger):

with test_db.get_sqla_engine_with_context() as engine:
data = engine.execute(f"SELECT * from {PARQUET_UPLOAD_TABLE}").fetchall()
assert data == [("max", 3), ("bob", 4), ("john", 1), ("paul", 2)]
assert data == [("john", 1), ("paul", 2), ("max", 3), ("bob", 4)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A SELECT does not guarantee order without an ORDER BY; if we don't want to use sorted() here we need to add an explicit ORDER BY to the query.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@betodealmeida I've re-authored the PR based on your comment.