Snowflake
This example demonstrates how to use the Snowflake
connector in ydata-sdk
.
Don't forget to set up your license key
Example Code
"""Example of a snowflake connector interface."""
# If running locally this example please set your environment variables first: 'RUNNING_ENV'=='LOCAL'
# set env variables as shown in examples.local setting_dask_env file
from ydata.connectors import SnowflakeConnector
if __name__ == "__main__":
USERNAME = "username"
PASSWORD = "password"
ACCOUNT_IDENTIFIER = "account"
PORT = 443
DATABASE_NAME = "DATABASE"
SCHEMA = "SCHEMA"
WAREHOUSE = "WAREHOUSE"
conn_str = {
"hostname": ACCOUNT_IDENTIFIER,
"username": USERNAME,
"password": PASSWORD,
"port": PORT,
"database": DATABASE_NAME,
"warehouse": WAREHOUSE
}
conn = SnowflakeConnector(conn_string=conn_str)
schemas_available = conn.list_schemas()
# use a schema
conn.set_schema('schema')
# Get a the details of a selected database schema (tables, columns, etc)
conn.get_database_schema("schema")
# Query
conn.query("SELECT * FROM TABLE")
# Query sample
sample = conn.query_sample("SELECT * FROM TABLE", sample_size=1000)
# Read a table
table = conn.get_table("table",
schema_name='schema', index_col='id')
# Read table sample
tables = conn.get_tables(['table', 'TABLE'],
schema_name='schema')
# write data to a new table
conn.write_table(data=sample,
name='new_table',
schema_name='schema',
if_exists='replace')