RasgoQL
Search…
πŸ‹
Quick Start

Install RasgoQL

From your CLI or jupyter notebook, install the package from pypi:
Snowflake
BigQuery
Redshift
Postgres
MySQL
1
pip install "rasgoql[snowflake]"
2
pip install rasgotransforms --upgrade
Copied!
1
pip install "rasgoql[bigquery]"
2
pip install rasgotransforms --upgrade
Copied!
1
pip install "rasgoql[redshift]"
2
pip install rasgotransforms --upgrade
Copied!
1
pip install "rasgoql[postgres]"
2
pip install rasgotransforms --upgrade
Copied!
1
pip install "rasgoql[mysql]"
2
pip install rasgotransforms --upgrade
Copied!

Connect to Your Data Warehouse

Use this code to import rasgoql and connect to your data warehouse:
Snowflake
BigQuery
Redshift
Postgres
MySQL
1
import rasgoql
2
​
3
# Fill in your own data warehouse credentials
4
creds = rasgoql.SnowflakeCredentials(
5
account="...",
6
user="...",
7
password="...",
8
role="...",
9
warehouse="...",
10
database="...",
11
schema="..."
12
)
13
​
14
# Connect to your Data Warehouse
15
rql = rasgoql.connect(creds)
Copied!
1
import rasgoql
2
​
3
# Fill in your own data warehouse credentials
4
creds = rasgoql.BigQueryCredentials(
5
secret_type="service",
6
secret_filepath="<path to your file>.json",
7
project="...",
8
dataset="..."
9
)
10
​
11
# Connect to your Data Warehouse
12
rql = rasgoql.connect(creds)
Copied!
1
import rasgoql
2
​
3
# Fill in your own data warehouse credentials
4
creds = rasgoql.RedshiftCredentials(
5
username="...",
6
password="...",
7
host="...",
8
port="...",
9
database="...",
10
schema="..."
11
)
12
​
13
# Connect to your Data Warehouse
14
rql = rasgoql.connect(creds)
Copied!
1
import rasgoql
2
​
3
# Fill in your own data warehouse credentials
4
creds = rasgoql.PostgresCredentials(
5
username="...",
6
password="...",
7
host="...",
8
port="...",
9
database="...",
10
schema="..."
11
)
12
​
13
# Connect to your Data Warehouse
14
rql = rasgoql.connect(creds)
Copied!
1
import rasgoql
2
​
3
# Fill in your own data warehouse credentials
4
creds = rasgoql.MySQLCredentials(
5
username="...",
6
password="...",
7
host="...",
8
database="..."
9
)
10
​
11
# Connect to your Data Warehouse
12
rql = rasgoql.connect(creds)
Copied!
Sweet! Let's start generating SQL with RasgoQL

Show All Tables & Views in Your DW

1
rql.list_tables()
Copied!

Start a SQL Chain

1
# Pick a table or view as your starting dataset
2
ds = rql.dataset(fqtn='RASGO.PUBLIC.ABCD123')
3
​
4
# Preview the Dataset (creates a pandas dataframe of the first 10 rows)
5
ds.preview()
6
​
7
# Applying a RQL Transform to start building a SQL "chain"
8
ds1 = ds.aggregate(
9
aggregations={
10
'SALES_AMOUNT':['SUM', 'AVG']
11
},
12
group_by=['CUSTOMER_ID']
13
)
14
​
15
# Print the SQL generated by the above step
16
ds1.sql()
17
​
18
# Preview the results of the SQL in pandas
19
ds1.preview()
Copied!
For a full list of available transforms, check out the Column, Row, and Table Transform sections of the docs.

Extend Your SQL Chain

1
ds2 = ds1.apply(sql="""
2
SELECT * FROM {{ source_table }}
3
WHERE CUSTOMER_ID IN (SELECT CUSTOMER_ID FROM BEST_CUSTOMERS)
4
""")
5
​
6
ds2.preview()
Copied!
The .apply() transform supports adding arbitrary SQL statements in your chain. Just make sure you use {{ source_table }} so that RasgoQL can handle assigning the intermediate table/view names in your chain.

Save Your New SQL Chain to the DW

1
new_view = ds2.save(table_name='MY_RQL_TEST', table_type='view')
Copied!