dagster-snowflake 0.13.3rc0__py3-none-any.whl → 0.28.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dagster_snowflake/__init__.py +17 -7
- dagster_snowflake/components/__init__.py +5 -0
- dagster_snowflake/components/sql_component/component.py +61 -0
- dagster_snowflake/constants.py +7 -0
- dagster_snowflake/{solids.py → ops.py} +14 -8
- dagster_snowflake/py.typed +1 -0
- dagster_snowflake/resources.py +806 -115
- dagster_snowflake/snowflake_io_manager.py +436 -0
- dagster_snowflake/version.py +1 -1
- dagster_snowflake-0.28.1.dist-info/METADATA +36 -0
- dagster_snowflake-0.28.1.dist-info/RECORD +16 -0
- {dagster_snowflake-0.13.3rc0.dist-info → dagster_snowflake-0.28.1.dist-info}/WHEEL +1 -1
- dagster_snowflake-0.28.1.dist-info/entry_points.txt +2 -0
- {dagster_snowflake-0.13.3rc0.dist-info → dagster_snowflake-0.28.1.dist-info/licenses}/LICENSE +1 -1
- dagster_snowflake-0.28.1.dist-info/top_level.txt +1 -0
- dagster_snowflake/configs.py +0 -156
- dagster_snowflake-0.13.3rc0.dist-info/METADATA +0 -23
- dagster_snowflake-0.13.3rc0.dist-info/RECORD +0 -15
- dagster_snowflake-0.13.3rc0.dist-info/top_level.txt +0 -2
- dagster_snowflake_tests/test_resources.py +0 -90
- dagster_snowflake_tests/test_solids.py +0 -39
- dagster_snowflake_tests/test_version.py +0 -5
- dagster_snowflake_tests/utils.py +0 -15
- {dagster_snowflake_tests → dagster_snowflake/components/sql_component}/__init__.py +0 -0
dagster_snowflake/__init__.py
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
from
|
|
1
|
+
from dagster_shared.libraries import DagsterLibraryRegistry
|
|
2
2
|
|
|
3
|
-
from .
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
from dagster_snowflake.components import (
|
|
4
|
+
SnowflakeConnectionComponent as SnowflakeConnectionComponent,
|
|
5
|
+
)
|
|
6
|
+
from dagster_snowflake.ops import snowflake_op_for_query as snowflake_op_for_query
|
|
7
|
+
from dagster_snowflake.resources import (
|
|
8
|
+
SnowflakeConnection as SnowflakeConnection,
|
|
9
|
+
SnowflakeResource as SnowflakeResource,
|
|
10
|
+
fetch_last_updated_timestamps as fetch_last_updated_timestamps,
|
|
11
|
+
snowflake_resource as snowflake_resource,
|
|
12
|
+
)
|
|
13
|
+
from dagster_snowflake.snowflake_io_manager import (
|
|
14
|
+
SnowflakeIOManager as SnowflakeIOManager,
|
|
15
|
+
build_snowflake_io_manager as build_snowflake_io_manager,
|
|
16
|
+
)
|
|
17
|
+
from dagster_snowflake.version import __version__
|
|
6
18
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
__all__ = ["snowflake_solid_for_query", "snowflake_resource", "SnowflakeConnection"]
|
|
19
|
+
DagsterLibraryRegistry.register("dagster-snowflake", __version__)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
from functools import cached_property
|
|
2
|
+
from typing import Any, cast
|
|
3
|
+
|
|
4
|
+
import dagster as dg
|
|
5
|
+
from dagster._annotations import preview, public
|
|
6
|
+
from dagster._core.definitions.definitions_class import Definitions
|
|
7
|
+
from dagster.components.core.context import ComponentLoadContext
|
|
8
|
+
from dagster.components.lib.sql_component.sql_client import SQLClient
|
|
9
|
+
from pydantic import BaseModel, create_model
|
|
10
|
+
|
|
11
|
+
from dagster_snowflake.resources import SnowflakeResource
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@public
|
|
15
|
+
@preview
|
|
16
|
+
class SnowflakeConnectionComponentBase(dg.Component, dg.Resolvable, dg.Model, SQLClient):
|
|
17
|
+
"""A component that represents a Snowflake connection. Use this component if you are
|
|
18
|
+
also using the TemplatedSqlComponent to execute SQL queries, and need to connect to Snowflake.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
@cached_property
|
|
22
|
+
def _snowflake_resource(self) -> SnowflakeResource:
|
|
23
|
+
return SnowflakeResource(
|
|
24
|
+
**{
|
|
25
|
+
(field.alias or field_name): getattr(self, field_name)
|
|
26
|
+
for field_name, field in self.__class__.model_fields.items()
|
|
27
|
+
}
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
def connect_and_execute(self, sql: str) -> None:
|
|
31
|
+
"""Connect to the SQL database and execute the SQL query."""
|
|
32
|
+
return self._snowflake_resource.connect_and_execute(sql)
|
|
33
|
+
|
|
34
|
+
def build_defs(self, context: ComponentLoadContext) -> Definitions:
|
|
35
|
+
return Definitions()
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _copy_fields_to_model(
|
|
39
|
+
copy_from: type[BaseModel], copy_to: type[BaseModel], new_model_cls_name: str
|
|
40
|
+
) -> None:
|
|
41
|
+
"""Given two models, creates a copy of the second model with the fields of the first model."""
|
|
42
|
+
field_definitions: dict[str, tuple[type, Any]] = {
|
|
43
|
+
field_name: (cast("type", field.annotation), field)
|
|
44
|
+
for field_name, field in copy_from.model_fields.items()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return create_model(
|
|
48
|
+
new_model_cls_name,
|
|
49
|
+
__base__=copy_to,
|
|
50
|
+
__doc__=copy_to.__doc__,
|
|
51
|
+
**field_definitions, # type: ignore
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
SnowflakeConnectionComponent = public(preview)(
|
|
56
|
+
_copy_fields_to_model(
|
|
57
|
+
copy_from=SnowflakeResource,
|
|
58
|
+
copy_to=SnowflakeConnectionComponentBase,
|
|
59
|
+
new_model_cls_name="SnowflakeConnectionComponent",
|
|
60
|
+
)
|
|
61
|
+
)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Description: This file contains the Snowflake connection identifiers for the Snowflake partner account.
|
|
2
|
+
# The connection identifiers are used to identify the partner account when connecting to Snowflake.
|
|
3
|
+
|
|
4
|
+
# We use different connection identifiers for different connection code paths to ensure that each is
|
|
5
|
+
# working as expected.
|
|
6
|
+
SNOWFLAKE_PARTNER_CONNECTION_IDENTIFIER = "DagsterLabs_Dagster"
|
|
7
|
+
SNOWFLAKE_PARTNER_CONNECTION_IDENTIFIER_SQLALCHEMY = "DagsterLabs_Dagster_SqlAlchemy"
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
from dagster import
|
|
1
|
+
from dagster import (
|
|
2
|
+
Nothing,
|
|
3
|
+
_check as check,
|
|
4
|
+
op,
|
|
5
|
+
)
|
|
6
|
+
from dagster._core.definitions.input import In
|
|
7
|
+
from dagster._core.storage.tags import COMPUTE_KIND_TAG
|
|
2
8
|
|
|
3
9
|
|
|
4
10
|
def _core_create_snowflake_command(dagster_decorator, decorator_name, sql, parameters=None):
|
|
@@ -7,9 +13,9 @@ def _core_create_snowflake_command(dagster_decorator, decorator_name, sql, param
|
|
|
7
13
|
|
|
8
14
|
@dagster_decorator(
|
|
9
15
|
name=f"snowflake_{decorator_name}",
|
|
10
|
-
|
|
16
|
+
ins={"start": In(Nothing)},
|
|
11
17
|
required_resource_keys={"snowflake"},
|
|
12
|
-
tags={
|
|
18
|
+
tags={COMPUTE_KIND_TAG: "sql", "sql": sql},
|
|
13
19
|
)
|
|
14
20
|
def snowflake_fn(context):
|
|
15
21
|
context.resources.snowflake.execute_query(sql=sql, parameters=parameters)
|
|
@@ -21,8 +27,8 @@ def snowflake_solid_for_query(sql, parameters=None):
|
|
|
21
27
|
"""This function is a solid factory that constructs solids to execute a snowflake query.
|
|
22
28
|
|
|
23
29
|
Note that you can only use `snowflake_solid_for_query` if you know the query you'd like to
|
|
24
|
-
execute at
|
|
25
|
-
|
|
30
|
+
execute at job construction time. If you'd like to execute queries dynamically during
|
|
31
|
+
job execution, you should manually execute those queries in your custom solid using the
|
|
26
32
|
snowflake resource.
|
|
27
33
|
|
|
28
34
|
Args:
|
|
@@ -32,15 +38,15 @@ def snowflake_solid_for_query(sql, parameters=None):
|
|
|
32
38
|
Returns:
|
|
33
39
|
SolidDefinition: Returns the constructed solid definition.
|
|
34
40
|
"""
|
|
35
|
-
return _core_create_snowflake_command(
|
|
41
|
+
return _core_create_snowflake_command(op, "solid", sql, parameters)
|
|
36
42
|
|
|
37
43
|
|
|
38
44
|
def snowflake_op_for_query(sql, parameters=None):
|
|
39
45
|
"""This function is an op factory that constructs an op to execute a snowflake query.
|
|
40
46
|
|
|
41
47
|
Note that you can only use `snowflake_op_for_query` if you know the query you'd like to
|
|
42
|
-
execute at
|
|
43
|
-
|
|
48
|
+
execute at graph construction time. If you'd like to execute queries dynamically during
|
|
49
|
+
job execution, you should manually execute those queries in your custom op using the
|
|
44
50
|
snowflake resource.
|
|
45
51
|
|
|
46
52
|
Args:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
partial
|