-
Notifications
You must be signed in to change notification settings - Fork 7
CI: ADBC coverage #76
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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,155 @@ | ||
| """Best-effort ADBC integration smoke tests for CI. | ||
|
|
||
| These tests are intended to run in CI against whatever ADBC drivers are available. | ||
| If an ADBC driver (or a usable endpoint) is not available for a given DB, the | ||
| tests will skip rather than fail. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import importlib | ||
| import os | ||
|
|
||
| import pytest | ||
|
|
||
| from sidemantic import Metric, Model, SemanticLayer | ||
|
|
||
| pytestmark = [ | ||
| pytest.mark.integration, | ||
| pytest.mark.skipif(os.getenv("ADBC_TEST") != "1", reason="Set ADBC_TEST=1 to run ADBC CI smoke tests"), | ||
| ] | ||
|
|
||
|
|
||
| def _adbc_db() -> str: | ||
| db = os.getenv("ADBC_DB") | ||
| if not db: | ||
| pytest.skip("ADBC_DB is not set") | ||
| return db.lower() | ||
|
|
||
|
|
||
| def _expected_dialect(db: str) -> str: | ||
| expected = { | ||
| "postgres": "postgres", | ||
| "bigquery": "bigquery", | ||
| "snowflake": "snowflake", | ||
| "clickhouse": "clickhouse", | ||
| }.get(db) | ||
| if not expected: | ||
| pytest.skip(f"Unsupported ADBC_DB={db!r}") | ||
| return expected | ||
|
|
||
|
|
||
| def _target_uri(db: str) -> str: | ||
| if db == "postgres": | ||
| uri = os.getenv("POSTGRES_URL") | ||
| if not uri: | ||
| pytest.skip("POSTGRES_URL is not set") | ||
| return uri | ||
|
|
||
| if db == "bigquery": | ||
| emulator_host = os.getenv("BIGQUERY_EMULATOR_HOST") | ||
| if emulator_host: | ||
| os.environ["BIGQUERY_EMULATOR_HOST"] = emulator_host | ||
| project = os.getenv("BIGQUERY_PROJECT", "test-project") | ||
| dataset = os.getenv("BIGQUERY_DATASET", "test_dataset") | ||
| return f"bigquery://{project}/{dataset}" | ||
|
|
||
| if db == "snowflake": | ||
| return "snowflake://test:test@test/testdb/public?warehouse=test_warehouse" | ||
|
|
||
| if db == "clickhouse": | ||
| host = os.getenv("CLICKHOUSE_HOST", "localhost") | ||
| port = os.getenv("CLICKHOUSE_PORT", "8123") | ||
| password = os.getenv("CLICKHOUSE_PASSWORD", "clickhouse") | ||
| return f"clickhouse://default:{password}@{host}:{port}/default" | ||
|
|
||
| pytest.skip(f"Unsupported ADBC_DB={db!r}") | ||
|
|
||
|
|
||
| def _driver_suffix(db: str) -> str: | ||
| if db == "postgres": | ||
| return "postgresql" | ||
| return db | ||
|
|
||
|
|
||
| def _candidate_adbc_drivers(db: str) -> list[str]: | ||
| suffix = _driver_suffix(db) | ||
| candidates: list[str] = [] | ||
|
|
||
| pkg_name = f"adbc_driver_{suffix}" | ||
| try: | ||
| importlib.import_module(pkg_name) | ||
| except Exception: | ||
| pass | ||
| else: | ||
| candidates.append(pkg_name) | ||
|
|
||
| candidates.append(suffix) | ||
| return candidates | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def adbc_layer() -> SemanticLayer: | ||
| db = _adbc_db() | ||
| uri = _target_uri(db) | ||
| candidates = _candidate_adbc_drivers(db) | ||
|
|
||
| from sidemantic.db.adbc import ADBCAdapter | ||
|
|
||
| last_exc: Exception | None = None | ||
| for driver in candidates: | ||
| try: | ||
| adapter = ADBCAdapter(driver=driver, uri=uri) | ||
| except Exception as exc: | ||
| last_exc = exc | ||
| continue | ||
| layer = SemanticLayer(connection=adapter) | ||
| try: | ||
| probe = layer.adapter.execute("SELECT 1 as x") | ||
| row = probe.fetchone() | ||
| if row != (1,): | ||
| raise RuntimeError(f"Unexpected probe result: {row!r}") | ||
| except Exception as exc: | ||
| last_exc = exc | ||
| try: | ||
| adapter.close() | ||
| except Exception: | ||
| pass | ||
| continue | ||
|
|
||
| yield layer | ||
| try: | ||
| adapter.close() | ||
| except Exception: | ||
| pass | ||
| return | ||
|
|
||
| details = f"Tried drivers={candidates!r}. URI={uri!r}." | ||
| if last_exc is not None: | ||
| details += f" Last error={last_exc!r}" | ||
| pytest.skip(f"No working ADBC driver for {db!r}. {details}") | ||
|
|
||
|
|
||
| def test_adbc_smoke_basic_execute(adbc_layer: SemanticLayer) -> None: | ||
| result = adbc_layer.adapter.execute("SELECT 1 as x, 2 as y") | ||
| assert result.fetchone() == (1, 2) | ||
|
|
||
|
|
||
| def test_adbc_smoke_semantic_layer_query_sum(adbc_layer: SemanticLayer) -> None: | ||
| orders = Model( | ||
| name="orders", | ||
| table="(SELECT 1 as id, 10 as amount UNION ALL SELECT 2, 20)", | ||
| primary_key="id", | ||
| metrics=[Metric(name="total_amount", agg="sum", sql="amount")], | ||
| ) | ||
| adbc_layer.add_model(orders) | ||
|
|
||
| result = adbc_layer.query(metrics=["orders.total_amount"]) | ||
| row = result.fetchone() | ||
| assert row is not None | ||
| assert float(row[0]) == 30.0 | ||
|
|
||
|
|
||
| def test_adbc_smoke_dialect(adbc_layer: SemanticLayer) -> None: | ||
| expected = _expected_dialect(_adbc_db()) | ||
| assert adbc_layer.dialect == expected | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CI matrix includes a Snowflake run but there’s no Snowflake service configured;
_target_uri()hardcodes a dummy Snowflake URL, and the fixture only skips whenADBCAdapterinitialization fails. Many ADBC drivers connect lazily, soexecute("SELECT 1 as x, 2 as y")can be the first point of failure, which will raise and fail the test instead of skipping. This makes the “best‑effort” smoke job flaky or consistently failing wheneveradbc_driver_snowflakeinstalls successfully. Consider probing the connection in the fixture (andpytest.skipon failure) to keep the job best‑effort as intended.Useful? React with 👍 / 👎.