https://dagster.io/ logo
#integration-snowflake
Title
# integration-snowflake
c

clay

03/22/2023, 5:00 PM
If I put the SQL into the asset definition as text, it works fine, with this type of approach:
Copy code
def get_sql_from_file(filename) -> str:
    """
    Reads the query in from a SQL file and returns the string
    """
    query = ""

    __location__ = os.path.realpath(
        os.path.join(os.getcwd(), os.path.dirname(filename))
    )

    with open(os.path.join(__location__, filename), "r") as sqlfile:
        query = sqlfile.read()

    return query


@asset(
    required_resource_keys={"snowflake"},
    compute_kind="Snowflake",
)
def ED_CRM_DASH_CRM_JIRA_CUSTOM_FIELD(context: OpExecutionContext) -> None:
    """
    Pull CRM Jira Custom field data.
    """
    <http://context.log.info|context.log.info>(glob.glob("*.sql"))
    glob.glob("*.sql")

    with context.resources.snowflake.get_connection() as conn:
        with closing(conn.cursor()) as cursor:

            # This works just fine
            q0 = "SELECT * FROM MYTABLE"
            cursor.execute(q0)

            # This does not work
            q1 = get_sql_from_file("01_ED_CRM_DASH_CRM_JIRA_CUSTOM_FIELD.sql")
            cursor.execute(q1)

    return None
2 Views