Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test execute queries #99

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions hooli_data_eng/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

marketing_assets = load_assets_from_package_module(marketing, group_name="MARKETING")


# ---------------------------------------------------
# Definitions

Expand Down
30 changes: 28 additions & 2 deletions hooli_snowflake_insights/definitions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import os

from dagster import Definitions, EnvVar, ResourceDefinition
from dagster import Definitions, EnvVar, ResourceDefinition,asset, AssetExecutionContext
from dagster_cloud.dagster_insights import (
create_snowflake_insights_asset_and_schedule,
)
from dagster_snowflake import SnowflakeResource
from contextlib import closing

# Used to derive environment (LOCAL, BRANCH, PROD)
def get_env():
Expand Down Expand Up @@ -35,6 +36,31 @@ def get_env():
},
}


def execute_snowflake_queries(context, snowflake: SnowflakeResource, queries: list):
with snowflake.get_connection() as conn:
with closing(conn.cursor()) as cursor:
for query in queries:
cursor.execute(query)
context.log.info("Executing query: " + query)


@asset
def test_execute_queries_with_get_connection(context: AssetExecutionContext, snowflake_insights: SnowflakeResource):
queries = [
"select 1",
"select 2"
]
execute_snowflake_queries(context, snowflake_insights, queries)

@asset
def test_execute_queries(snowflake_insights: SnowflakeResource):
queries = [
"select 1",
"select 2"
]
snowflake_insights.execute_queries(sql_queries=queries, fetch_results=False)

# Creates an asset (poll_snowflake_query_history_hour) and sets its schedule
snowflake_insights_definitions = create_snowflake_insights_asset_and_schedule(
"2023-10-29-00:00",
Expand All @@ -43,7 +69,7 @@ def get_env():
)

defs = Definitions(
assets=[*snowflake_insights_definitions.assets,],
assets=[*snowflake_insights_definitions.assets,test_execute_queries, test_execute_queries_with_get_connection],
schedules=[snowflake_insights_definitions.schedule,],
resources=resource_def[get_env()],
)
Loading