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.
@@ -1,9 +1,19 @@
1
- from dagster.core.utils import check_dagster_package_version
1
+ from dagster_shared.libraries import DagsterLibraryRegistry
2
2
 
3
- from .resources import SnowflakeConnection, snowflake_resource
4
- from .solids import snowflake_solid_for_query
5
- from .version import __version__
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
- check_dagster_package_version("dagster-snowflake", __version__)
8
-
9
- __all__ = ["snowflake_solid_for_query", "snowflake_resource", "SnowflakeConnection"]
19
+ DagsterLibraryRegistry.register("dagster-snowflake", __version__)
@@ -0,0 +1,5 @@
1
+ from dagster_snowflake.components.sql_component.component import SnowflakeConnectionComponent
2
+
3
+ __all__ = [
4
+ "SnowflakeConnectionComponent",
5
+ ]
@@ -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 InputDefinition, Nothing, check, op, solid
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
- input_defs=[InputDefinition("start", Nothing)],
16
+ ins={"start": In(Nothing)},
11
17
  required_resource_keys={"snowflake"},
12
- tags={"kind": "sql", "sql": sql},
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 pipeline construction time. If you'd like to execute queries dynamically during
25
- pipeline execution, you should manually execute those queries in your custom solid using the
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(solid, "solid", sql, parameters)
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 pipeline construction time. If you'd like to execute queries dynamically during
43
- pipeline execution, you should manually execute those queries in your custom op using the
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