-
Notifications
You must be signed in to change notification settings - Fork 28
Issue #39 | ClickhouseTable: integration tests #43
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
Open
IceKhan13
wants to merge
19
commits into
neuralinkcorp:main
Choose a base branch
from
IceKhan13:chore/ci-integration-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
05860a9
Issue #39 | ClickhouseTable: integration tests
IceKhan13 96764c6
Docker and remove polars build
IceKhan13 ed2cf3e
Fix client
IceKhan13 5fd121d
Add connectorx dep
IceKhan13 a4ef395
Fix connectorx errors
IceKhan13 7f331d9
Start containers
IceKhan13 614ae34
Remove testcontainers
IceKhan13 fd2e814
db configs
IceKhan13 9e479fc
Fix table names
IceKhan13 982d241
Fix table names
IceKhan13 23b458c
Add protocol
IceKhan13 31ca8fb
Add protocol
IceKhan13 b340353
Add protocol
IceKhan13 e53fb27
test protocol
IceKhan13 bfb4257
revert
IceKhan13 d1a2e2b
Issue #39 | ClickhouseTable: integration tests
IceKhan13 c828b78
Deps
IceKhan13 e1155b9
GH actions: add dep on tests
IceKhan13 a63b56e
Remove docker dependency
IceKhan13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| version: '3.9' | ||
|
|
||
IceKhan13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| services: | ||
| clickhouse: | ||
| image: clickhouse/clickhouse-server:latest | ||
| ports: | ||
| - "8123:8123" | ||
| - "9000:9000" | ||
| - "9004:9004" | ||
| environment: | ||
| CLICKHOUSE_USER: chuser | ||
| CLICKHOUSE_PASSWORD: chpass | ||
| CLICKHOUSE_DB: testdb | ||
| healthcheck: | ||
| test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8123/ping"] | ||
| interval: 3s | ||
| timeout: 5s | ||
| retries: 5 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| import os | ||
| import pytest | ||
| import pyarrow as pa | ||
|
|
||
| import clickhouse_driver | ||
| from datarepo.core.tables.clickhouse_table import ClickHouseTable, ClickHouseTableConfig | ||
| from datarepo.core.tables.filters import Filter | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def clickhouse_config() -> ClickHouseTableConfig: | ||
| """Create a ClickHouseTableConfig for the container.""" | ||
| # Get connection details from environment or use defaults | ||
| client = clickhouse_driver.Client.from_url(f"clickhouse://chuser:chpass@localhost:9000/testdb") | ||
IceKhan13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| client.execute(""" | ||
| CREATE TABLE IF NOT EXISTS testdb.test_table ( | ||
| implant_id Int64, | ||
| date String, | ||
| value Int64, | ||
| str_value String | ||
| ) ENGINE = MergeTree() | ||
| ORDER BY (implant_id, date) | ||
| """) | ||
|
|
||
| # Insert test data | ||
| client.execute(""" | ||
| INSERT INTO testdb.test_table | ||
| (implant_id, date, value, str_value) | ||
| VALUES | ||
| (1, '2023-01-01', 100, 'alpha'), | ||
| (1, '2023-01-02', 110, 'beta'), | ||
| (2, '2023-01-01', 200, 'gamma'), | ||
| (2, '2023-01-02', 210, 'delta'), | ||
| (3, '2023-01-03', 300, 'epsilon') | ||
| """) | ||
|
|
||
| return ClickHouseTableConfig( | ||
| host="localhost", | ||
| port="8123", | ||
| username="chuser", | ||
| password="chpass", | ||
| database="testdb", | ||
IceKhan13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def clickhouse_table(clickhouse_config: ClickHouseTableConfig) -> ClickHouseTable: | ||
| """Create a ClickHouseTable for testing.""" | ||
| return ClickHouseTable( | ||
| name="test_table", | ||
| schema=pa.schema([ | ||
| ("implant_id", pa.int64()), | ||
| ("date", pa.string()), | ||
| ("value", pa.int64()), | ||
| ("str_value", pa.string()), | ||
| ]), | ||
| config=clickhouse_config, | ||
| description="Test ClickHouse table", | ||
| ) | ||
|
|
||
|
|
||
| class TestClickHouseTableIntegration: | ||
| def test_query_all_data(self, clickhouse_table: ClickHouseTable): | ||
| """Test querying all data from the table.""" | ||
| df = clickhouse_table().collect() | ||
|
|
||
| assert df.height == 5 | ||
| assert df.width == 4 | ||
|
|
||
| assert set(df.columns) == {"implant_id", "date", "value", "str_value"} | ||
|
|
||
| assert df["implant_id"].to_list() == [1, 1, 2, 2, 3] | ||
|
|
||
| def test_filter_by_equality(self, clickhouse_table: ClickHouseTable): | ||
| """Test filtering by equality.""" | ||
| df = clickhouse_table(filters=[Filter("implant_id", "=", 1)]).collect() | ||
|
|
||
| assert df.height == 2 | ||
| assert all(id == 1 for id in df["implant_id"]) | ||
|
|
||
| def test_filter_by_comparison(self, clickhouse_table: ClickHouseTable): | ||
| """Test filtering by comparison.""" | ||
| df = clickhouse_table(filters=[Filter("value", ">", 200)]).collect() | ||
|
|
||
| assert df.height == 2 | ||
| assert all(val > 200 for val in df["value"]) | ||
|
|
||
| def test_filter_by_in(self, clickhouse_table: ClickHouseTable): | ||
| """Test filtering using IN operator.""" | ||
| df = clickhouse_table(filters=[Filter("implant_id", "in", [1, 3])]).collect() | ||
|
|
||
| assert df.height == 3 | ||
| assert set(df["implant_id"].unique().to_list()) == {1, 3} | ||
|
|
||
| def test_select_columns(self, clickhouse_table: ClickHouseTable): | ||
| """Test selecting specific columns.""" | ||
| df = clickhouse_table(columns=["implant_id", "value"]).collect() | ||
|
|
||
| assert df.width == 2 | ||
| assert set(df.columns) == {"implant_id", "value"} | ||
|
|
||
| def test_combined_filters(self, clickhouse_table: ClickHouseTable): | ||
| """Test combining multiple filters.""" | ||
| df = clickhouse_table(filters=[[Filter("implant_id", "=", 1)], | ||
| [Filter("date", "=", "2023-01-03")]]).collect() | ||
|
|
||
| assert df.height == 3 | ||
|
|
||
| df = clickhouse_table(filters=[[Filter("implant_id", "=", 1), | ||
| Filter("date", "=", "2023-01-01")]]).collect() | ||
|
|
||
| assert df.height == 1 | ||
| assert df["implant_id"][0] == 1 | ||
| assert df["date"][0] == "2023-01-01" | ||
|
|
||
| def test_string_like_filter(self, clickhouse_table: ClickHouseTable): | ||
| """Test LIKE filter for string matching.""" | ||
| df = clickhouse_table(filters=[Filter("str_value", "contains", "%lta%")]).collect() | ||
IceKhan13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| assert df.height == 1 | ||
| assert df["str_value"][0] == "delta" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.