Skip to content

Commit

Permalink
Merge branch 'voila_app' of https://github.com/ploomber/sql into voil…
Browse files Browse the repository at this point in the history
…a_app
  • Loading branch information
jpjon committed Aug 16, 2023
2 parents d88a199 + 401d6a8 commit 6636b06
Show file tree
Hide file tree
Showing 33 changed files with 592 additions and 143 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,6 @@ products/*
pipeline/products/datadownload.ipynb
pipeline/products/eda-pipeline.ipynb
*.metadata

!docs/intro-to-dashboards-and-apps/data/database/car_data.*
!pipeline/data/database/car_data.*
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

[![Documentation Status](https://readthedocs.org/projects/ploomber-sql/badge/?version=latest)](https://ploomber-sql.readthedocs.io/en/latest/?badge=latest)

## Important links

Visit the Jupyter book: https://ploomber-sql.readthedocs.io/en/latest/index.html

You can explore hands on exercises via Google colab on the `colabs` folder in this repository.

To do so:

1. Open [Google Colab](https://colab.research.google.com/)
2. To open a Jupyter notebook from this repository, change to the GitHub tab, and paste https://github.com/ploomber/sql
3. Press the search icon 🔍
4. Select a notebook

![](sql-ploomber-colab.png)

## Set up for contributors

Expand Down
14 changes: 3 additions & 11 deletions colabs/advanced-querying-techniques/ctes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"metadata": {},
"outputs": [],
"source": [
"%pip install jupysql --upgrade jupysql-plugin --upgrade duckdb-engine --quiet"
"%pip install jupysql --quiet"
]
},
{
Expand All @@ -50,18 +50,10 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"id": "e9f8c2a1",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/bin/bash: wget: command not found\n"
]
}
],
"outputs": [],
"source": [
"# If you are running this from Google Colab\n",
"!wget https://raw.githubusercontent.com/ploomber/sql/main/banking.py # noqa E402"
Expand Down
9 changes: 8 additions & 1 deletion docs/advanced-querying-techniques/advanced-aggregations.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Let's first run the installations and setup before running any queries.
This code installs JupySQL, DuckDB, and Pandas in your environment. We will be using these moving forward.

```{code-cell} ipython3
%pip install jupysql --upgrade duckdb-engine pandas --quiet
%pip install jupysql pandas --quiet
```

## Load the data
Expand Down Expand Up @@ -410,6 +410,13 @@ GROUP BY GROUPING SETS ((date, duration), (status, duration));
</details>
<!-- #endregion -->

Delete table

```{code-cell} ipython3
%%sql
DROP TABLE loan;
```

## Wrapping Up

In this section, we introduced advanced aggregation functions. To summarize:
Expand Down
12 changes: 11 additions & 1 deletion docs/advanced-querying-techniques/advanced-joins.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ kernelspec:
This code installs JupySQL, DuckDB, and Pandas in your environment. We will be using these moving forward.

```{code-cell} ipython3
%pip install jupysql --upgrade duckdb-engine pandas --quiet
%pip install jupysql pandas --quiet
```

## Load the data
Expand Down Expand Up @@ -253,6 +253,16 @@ JOIN s1.loan l ON a.account_id = l.account_id;
</details>
<!-- #endregion -->

Delete tables

```{code-cell} ipython3
%%sql
DROP TABLE s1.account;
DROP TABLE s1.loan;
DROP TABLE s1.district;
DROP SCHEMA s1;
```

## Conclusion

In this tutorial, we have explored advanced join operations in SQL, including nested-loop joins, merge joins, hash joins, internal joins, and the concept of join hints. We learned how to utilize these different join methods in SQL queries and understood the specific scenarios in which each type of join is most efficient.
Expand Down
11 changes: 10 additions & 1 deletion docs/advanced-querying-techniques/ctes.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ In this tutorial, you will learn about Common Table Expressions (CTEs) in SQL an
This code installs JupySQL, and DuckDB in your environment. We will be using these moving forward.

```{code-cell} ipython3
%pip install jupysql --upgrade jupysql-plugin --upgrade duckdb-engine --quiet
%pip install jupysql jupysql-plugin --quiet
```

We continue to work with the Bank and Marketing data set.
Expand Down Expand Up @@ -404,6 +404,15 @@ The importance of checking the data before and after the operations is to verify
</details>
<!-- #endregion -->

Delete tables

```{code-cell} ipython3
%%sql
DROP TABLE IF EXISTS s1.district;
DROP TABLE IF EXISTS bank;
DROP SCHEMA s1;
```

## Summary

In this tutorial we learned:
Expand Down
11 changes: 10 additions & 1 deletion docs/advanced-querying-techniques/subqueries.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Let's demonstrate how powerful subqueries are by continuing with our banking dat
This code installs JupySQL, DuckDB, and Pandas in your environment. We will be using these moving forward.

```{code-cell} ipython3
%pip install jupysql --upgrade duckdb-engine pandas --quiet
%pip install jupysql pandas --quiet
```

## Load the data
Expand Down Expand Up @@ -487,6 +487,15 @@ WHERE amount > (
</details>
<!-- #endregion -->

Delete tables

```{code-cell} ipython3
%%sql
DROP TABLE IF EXISTS s1.loan;
DROP TABLE IF EXISTS s1.account;
DROP TABLE IF EXISTS s1.district;
DROP SCHEMA s1;
```

## Wrapping Up

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The installation of `ipywidgets` was covered previously [here](https://ploomber-
This code installs JupySQL, and DuckDB in your environment. We will be using these moving forward.

```{code-cell} ipython3
%pip install jupysql --upgrade jupysql-plugin --upgrade duckdb-engine --quiet
%pip install jupysql jupysql-plugin --quiet
```

We continue to work with the Bank and Marketing data set.
Expand Down Expand Up @@ -439,6 +439,13 @@ This ends the Interactive Queries and Parameterization module. We hope you use t

<!-- #endregion -->

Delete table

```{code-cell} ipython3
%%sql
DROP TABLE IF EXISTS bank;
```

## References

“Simple Widget Introduction#.” Simple Widget Introduction - Jupyter Widgets 8.0.5 documentation, n.d. https://ipywidgets.readthedocs.io/en/stable/examples/Widget%20Basics.html.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ In the last module, you learned how to use SQL within Jupyter notebooks with Jup
This code installs JupySQL, and DuckDB in your environment. We will be using these moving forward.

```{code-cell} ipython3
%pip install jupysql --upgrade jupysql-plugin --upgrade duckdb-engine --quiet
%pip install jupysql jupysql-plugin --quiet
```

We continue to work with the Bank and Marketing data set.
Expand Down Expand Up @@ -319,6 +319,12 @@ We'll finish off this section by showing you how you can generate multiple table

Your task now is to create separate tables for each job. This can easily be accomplished using a loop and variable expansion:

```{code-cell} ipython3
%%sql
DROP TABLE IF EXISTS services;
DROP TABLE IF EXISTS management;
```

```{code-cell} ipython3
jobs = ["services", "management"]
for job in jobs:
Expand All @@ -331,6 +337,16 @@ Let's check the tables in our schema:
%sqlcmd tables
```

Delete table

```{code-cell} ipython3
%%sql
DROP TABLE bank;
DROP TABLE services;
DROP TABLE management;
```


## Conclusion
In this module, we have explored how to parameterize SQL queries and effectively integrate with Python for a more interactive data analysis workflow within Jupyter notebooks. This method is facilitated using JupySQL and DuckDB. We've also demonstrated how to dynamically create and use variables within SQL queries, further enhancing the flexibility and interactivity of the notebooks.

Expand Down
Loading

0 comments on commit 6636b06

Please sign in to comment.