Snowflake Query#

This example shows how to use a Flyte SnowflakeTask to execute a query.

from flytekit import kwtypes, task, workflow
from flytekit.types.schema import FlyteSchema
from flytekitplugins.snowflake import SnowflakeConfig, SnowflakeTask

This is the world’s simplest query. Note that in order for registration to work properly, you’ll need to give your Snowflake task a name that’s unique across your project/domain for your Flyte installation.

snowflake_task_no_io = SnowflakeTask(
    query_template="SELECT 1",
    task_config=SnowflakeConfig(account="", database="SNOWFLAKE_SAMPLE_DATA",
                                schema="TPCH_SF1000", warehouse="COMPUTE_WH"),

def no_io_wf():
    return snowflake_task_no_io()

Of course, in real world applications we are usually more interested in using Snowflake to query a dataset. In this case we use SNOWFLAKE_SAMPLE_DATA which is default dataset in snowflake service. here The data is formatted according to this schema:


C_NAME (string)

C_ADDRESS (string)


C_PHONE (string)

C_ACCTBAL (float)


C_COMMENT (string)

Let’s look out how we can parameterize our query to filter results for a specific country, provided as a user input specifying a nation key.

snowflake_task_templatized_query = SnowflakeTask(
    # Define inputs as well as their types that can be used to customize the query.
    task_config=SnowflakeConfig(account="", database="SNOWFLAKE_SAMPLE_DATA",
                                schema="TPCH_SF1000", warehouse="COMPUTE_WH"),
    query_template="SELECT * from CUSTOMER where C_NATIONKEY =  {{ .inputs.nation_key }} limit 100",

def full_snowflake_wf(nation_key: int):
    return snowflake_task_templatized_query(nation_key=nation_key)

Check query result on snowflake console: https://<account>

For example,

Total running time of the script: ( 0 minutes 0.000 seconds)

Gallery generated by Sphinx-Gallery