-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Allow CustomKind subclasses for custom materializations (#3863)
- Loading branch information
Showing
13 changed files
with
392 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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 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
35 changes: 35 additions & 0 deletions
35
examples/custom_materializations/custom_materializations/custom_kind.py
This file contains 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,35 @@ | ||
from __future__ import annotations | ||
|
||
import typing as t | ||
|
||
from sqlmesh import CustomMaterialization, CustomKind, Model | ||
from sqlmesh.utils.pydantic import validate_string | ||
from pydantic import field_validator | ||
|
||
if t.TYPE_CHECKING: | ||
from sqlmesh import QueryOrDF | ||
|
||
|
||
class ExtendedCustomKind(CustomKind): | ||
custom_property: t.Optional[str] = None | ||
|
||
@field_validator("custom_property", mode="before") | ||
@classmethod | ||
def _validate_custom_property(cls, v: t.Any) -> str: | ||
return validate_string(v) | ||
|
||
|
||
class CustomFullWithCustomKindMaterialization(CustomMaterialization[ExtendedCustomKind]): | ||
NAME = "custom_full_with_custom_kind" | ||
|
||
def insert( | ||
self, | ||
table_name: str, | ||
query_or_df: QueryOrDF, | ||
model: Model, | ||
is_first_insert: bool, | ||
**kwargs: t.Any, | ||
) -> None: | ||
assert type(model.kind).__name__ == "ExtendedCustomKind" | ||
|
||
self._replace_query_for_model(model, table_name, query_or_df) |
This file contains 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 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,13 @@ | ||
MODEL ( | ||
name sushi.latest_order, | ||
kind CUSTOM ( | ||
materialization 'custom_full_with_custom_kind', | ||
custom_property 'sushi!!!' | ||
), | ||
cron '@daily' | ||
); | ||
|
||
SELECT id, customer_id, start_ts, end_ts, event_date | ||
FROM sushi.orders | ||
ORDER BY event_date DESC LIMIT 1 | ||
|
This file contains 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 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 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 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 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
Oops, something went wrong.