Skip to content

Commit 96a9a16

Browse files
authored
Merge branch 'main' into feature/DRM/indirect-non-breaking-always-uses-prod-ledger
2 parents 0ca3162 + ce229ae commit 96a9a16

7 files changed

Lines changed: 97 additions & 30 deletions

File tree

‎.github/scripts/update-pypirc.sh‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎.github/workflows/release.yaml‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,6 @@ jobs:
5555
env:
5656
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
5757
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
58-
- name: Update pypirc for private repository
59-
run: ./.github/scripts/update-pypirc.sh
60-
env:
61-
TOBIKO_PRIVATE_PYPI_URL: ${{ secrets.TOBIKO_PRIVATE_PYPI_URL }}
62-
TOBIKO_PRIVATE_PYPI_KEY: ${{ secrets.TOBIKO_PRIVATE_PYPI_KEY }}
63-
- name: Publish Python Tests package
64-
run: unset TWINE_USERNAME TWINE_PASSWORD && make publish-tests
6558

6659
gh-release:
6760
runs-on: ubuntu-24.04

‎Makefile‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,6 @@ publish: package
9696
package-tests:
9797
$(PIP) install build && cp pyproject.toml tests/sqlmesh_pyproject.toml && python3 -m build tests/
9898

99-
publish-tests: package-tests
100-
$(PIP) install twine && python3 -m twine upload -r tobiko-private tests/dist/*
101-
10299
docs-serve:
103100
mkdocs serve
104101

‎sqlmesh/core/engine_adapter/clickhouse.py‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -861,17 +861,19 @@ def _exchange_tables(
861861
try:
862862
self.execute(f"EXCHANGE TABLES {old_table_sql} AND {new_table_sql}{on_cluster_sql}")
863863
except DatabaseError as e:
864-
if "NOT_IMPLEMENTED" in str(e):
865-
# If someone is using an old Clickhouse version, an OS that doesn't support atomic exchanges,
866-
# or a database engine that doesn't support atomic exchanges, we do a non-atomic rename instead.
867-
#
868-
# Executing multiple renames in one call like `RENAME TABLE a to b, c to a` is supported
869-
# but not an atomic operation. Because it is not atomic, doing it in two calls is equivalent
870-
# and does not require defining an additional method.
871-
throwaway_table_name = self._get_temp_table(old_table_name)
872-
self._rename_table(old_table_name, throwaway_table_name)
873-
self._rename_table(new_table_name, old_table_name)
874-
self.drop_table(throwaway_table_name)
864+
if "NOT_IMPLEMENTED" not in str(e):
865+
raise
866+
867+
# If someone is using an old Clickhouse version, an OS that doesn't support atomic exchanges,
868+
# or a database engine that doesn't support atomic exchanges, we do a non-atomic rename instead.
869+
#
870+
# Executing multiple renames in one call like `RENAME TABLE a to b, c to a` is supported
871+
# but not an atomic operation. Because it is not atomic, doing it in two calls is equivalent
872+
# and does not require defining an additional method.
873+
throwaway_table_name = self._get_temp_table(old_table_name)
874+
self._rename_table(old_table_name, throwaway_table_name)
875+
self._rename_table(new_table_name, old_table_name)
876+
self.drop_table(throwaway_table_name)
875877

876878
def _rename_table(
877879
self,

‎sqlmesh/core/snapshot/definition.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,7 @@ def depends_on_past(self) -> bool:
14731473
An example of this can be an INCREMENTAL_BY_TIME_RANGE model that references previous records from itself.
14741474
2. Models that can only be restated from the beginning of history *and* their interval batches must be processed sequentially.
14751475
"""
1476-
return self.depends_on_self or self.full_history_restatement_only
1476+
return self.full_history_restatement_only or self.depends_on_self
14771477

14781478
@property
14791479
def depends_on_self(self) -> bool:

‎tests/core/engine_adapter/test_clickhouse.py‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,64 @@ def test_exchange_tables(
14521452
]
14531453

14541454

1455+
def _executed_sql(execute_mock: t.Any) -> t.List[str]:
1456+
return [
1457+
quote_identifiers(call.args[0]).sql("clickhouse")
1458+
if isinstance(call.args[0], exp.Expr)
1459+
else call.args[0]
1460+
for call in execute_mock.call_args_list
1461+
]
1462+
1463+
1464+
def test_insert_overwrite_by_condition_replace_exchange_error_propagates(
1465+
make_mocked_engine_adapter: t.Callable, mocker: MockerFixture, make_temp_table_name: t.Callable
1466+
):
1467+
from clickhouse_connect.driver.exceptions import DatabaseError # type: ignore
1468+
1469+
adapter = make_mocked_engine_adapter(ClickhouseEngineAdapter)
1470+
1471+
temp_table_mock = mocker.patch("sqlmesh.core.engine_adapter.EngineAdapter._get_temp_table")
1472+
temp_table_mock.return_value = make_temp_table_name("target", "abcd")
1473+
1474+
fetchone_mock = mocker.patch("sqlmesh.core.engine_adapter.ClickhouseEngineAdapter.fetchone")
1475+
fetchone_mock.return_value = None
1476+
1477+
insert_table_name = make_temp_table_name("new_records", "abcd")
1478+
existing_table_name = make_temp_table_name("existing_records", "abcd")
1479+
1480+
source_queries, columns_to_types = adapter._get_source_queries_and_columns_to_types(
1481+
parse_one(f"SELECT * FROM {insert_table_name}"),
1482+
{
1483+
"id": exp.DataType.build("Int8", dialect="clickhouse"),
1484+
"ds": exp.DataType.build("Date", dialect="clickhouse"),
1485+
},
1486+
existing_table_name,
1487+
)
1488+
1489+
def execute_side_effect(sql: t.Any, *args: t.Any, **kwargs: t.Any) -> None:
1490+
if str(sql).startswith("EXCHANGE TABLES"):
1491+
raise DatabaseError("DB::Exception: Not enough privileges. (ACCESS_DENIED)")
1492+
1493+
execute_mock = mocker.patch("sqlmesh.core.engine_adapter.ClickhouseEngineAdapter.execute")
1494+
execute_mock.side_effect = execute_side_effect
1495+
1496+
with pytest.raises(DatabaseError, match="ACCESS_DENIED"):
1497+
adapter._insert_overwrite_by_condition(
1498+
existing_table_name.sql(),
1499+
source_queries,
1500+
columns_to_types,
1501+
)
1502+
1503+
executed = _executed_sql(execute_mock)
1504+
assert executed[-2:] == [
1505+
'EXCHANGE TABLES "__temp_existing_records_abcd" AND "__temp_target_abcd"',
1506+
'DROP TABLE IF EXISTS "__temp_target_abcd"',
1507+
]
1508+
assert not any(sql.startswith("RENAME") for sql in executed)
1509+
dropped = [sql for sql in executed if sql.startswith("DROP")]
1510+
assert dropped == ['DROP TABLE IF EXISTS "__temp_target_abcd"']
1511+
1512+
14551513
def test_virtual_catalog_ddl_stripping(make_mocked_engine_adapter: t.Callable):
14561514
"""After inject_virtual_catalog(), create_schema() with the virtual catalog prefix must strip
14571515
the catalog and execute without raising, and with a wrong catalog must raise SQLMeshError."""

‎tests/core/test_snapshot.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,31 @@ def test_get_removal_intervals_full_history_restatement_model(make_snapshot):
962962
assert interval == (to_timestamp("2023-01-01"), execution_time)
963963

964964

965+
def test_get_removal_interval_full_history_does_not_render_model(
966+
make_snapshot: t.Callable[..., Snapshot], mocker: MockerFixture
967+
):
968+
# Full history restatement models are already known to depend on past intervals, so computing
969+
# the removal interval must not render the model query (which may fail to hydrate user code).
970+
model = SqlModel(
971+
name="name",
972+
kind=IncrementalUnmanagedKind(),
973+
query=parse_one("SELECT 1"),
974+
)
975+
snapshot = make_snapshot(model)
976+
snapshot.add_interval("2020-01-01", "2024-01-01")
977+
# Drop the cached dependencies, as for a snapshot loaded from the state sync.
978+
snapshot.model._full_depends_on = None
979+
980+
render_query = mocker.patch.object(SqlModel, "render_query", side_effect=ModuleNotFoundError)
981+
982+
execution_time = to_timestamp("2024-01-02")
983+
interval = snapshot.get_removal_interval(
984+
"2023-01-01", "2023-01-01", execution_time=execution_time
985+
)
986+
assert interval == (to_timestamp("2020-01-01"), execution_time)
987+
render_query.assert_not_called()
988+
989+
965990
def test_get_removal_intervals_warns_when_requested_range_automatically_widened(
966991
make_snapshot: t.Callable[..., Snapshot], mocker: MockerFixture
967992
):

0 commit comments

Comments
 (0)