Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions sqlmesh/cli/example_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def init_example_project(
return

_create_folders([audits_path, macros_path, models_path, tests_path])
_create_macros(macros_path)
_create_audits(audits_path)
_create_models(models_path)
_create_tests(tests_path)
Expand All @@ -159,6 +160,10 @@ def _create_config(config_path: Path, template: ProjectTemplate) -> None:
)


def _create_macros(macros_path: Path) -> None:
(macros_path / "__init__.py").touch()


def _create_audits(audits_path: Path) -> None:
_write_file(audits_path / "example_full_model.sql", EXAMPLE_AUDIT)

Expand Down
9 changes: 9 additions & 0 deletions sqlmesh/core/engine_adapter/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ def create_table(
table_name, query_or_columns_to_types, exists, **kwargs
)

def create_snapshots_table(
Copy link
Member

Choose a reason for hiding this comment

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

I don't really like the fact that the state sync logic leaks into something as low lever as engine adapter

self, snapshots_table_name: str, snapshots_columns: t.Dict[str, exp.DataType]
) -> None:
"""Create a table to store snapshots."""
self.create_table(
snapshots_table_name,
snapshots_columns,
)

def _create_table_from_columns(
self,
table_name: TableName,
Expand Down
19 changes: 19 additions & 0 deletions sqlmesh/core/engine_adapter/base_databricks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import typing as t

from sqlglot import exp

from sqlmesh.core.engine_adapter.base_spark import BaseSparkEngineAdapter


class BaseDatabricks(BaseSparkEngineAdapter):
DIALECT = "databricks"

def create_snapshots_table(
self, snapshots_table_name: str, snapshots_columns: t.Dict[str, exp.DataType]
) -> None:
"""Create a table to store snapshots."""
self.create_table(
snapshots_table_name,
snapshots_columns,
partitioned_by=["name", "identifier"],
)
5 changes: 3 additions & 2 deletions sqlmesh/core/engine_adapter/databricks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

from sqlmesh.core.engine_adapter.base_databricks import BaseDatabricks
from sqlmesh.core.engine_adapter.spark import SparkEngineAdapter


class DatabricksSparkSessionEngineAdapter(SparkEngineAdapter):
DIALECT = "databricks"
class DatabricksSparkSessionEngineAdapter(BaseDatabricks, SparkEngineAdapter):
pass
6 changes: 2 additions & 4 deletions sqlmesh/core/engine_adapter/databricks_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

from sqlglot import exp

from sqlmesh.core.engine_adapter.base_spark import BaseSparkEngineAdapter
from sqlmesh.core.engine_adapter.base_databricks import BaseDatabricks

if t.TYPE_CHECKING:
from sqlmesh.core.engine_adapter._typing import DF


class DatabricksAPIEngineAdapter(BaseSparkEngineAdapter):
DIALECT = "databricks"

class DatabricksAPIEngineAdapter(BaseDatabricks):
def _fetch_native_df(self, query: t.Union[exp.Expression, str]) -> DF:
"""
Returns a Pandas DataFrame from a query or expression.
Expand Down
5 changes: 3 additions & 2 deletions sqlmesh/core/plan/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,10 @@ def _ensure_no_paused_forward_only_upstream(
self, model_name: str, upstream_model_names: t.Iterable[str]
) -> None:
for upstream in upstream_model_names:
upstream_snapshot = self.context_diff.snapshots[upstream]
upstream_snapshot = self.context_diff.snapshots.get(upstream)
if (
upstream_snapshot.version
upstream_snapshot
and upstream_snapshot.version
and upstream_snapshot.is_forward_only
and upstream_snapshot.is_paused
):
Expand Down
2 changes: 1 addition & 1 deletion sqlmesh/core/state_sync/engine_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def init_schema(self) -> None:
"""Creates the schema and table to store state."""
self.engine_adapter.create_schema(self.snapshots_table)

self.engine_adapter.create_table(
self.engine_adapter.create_snapshots_table(
Copy link
Member

@izeigerman izeigerman Feb 6, 2023

Choose a reason for hiding this comment

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

Doesn't the same problem apply to the environments table? Shouldn't we partition it as well?

self.snapshots_table, self.snapshot_columns_to_types
)
self.engine_adapter.create_table(
Expand Down