forked from dbt-labs/jaffle-shop-classic
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
227 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,227 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"RendererRegistry.enable('jupyterlab')" | ||
] | ||
}, | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"import altair as alt\n", | ||
"import duckdb\n", | ||
"\n", | ||
"alt.renderers.enable(\"jupyterlab\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"c = duckdb.connect(\"dbt.duckdb\", read_only=True)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"application/vnd.vegalite.v5+json": { | ||
"$schema": "https://vega.github.io/schema/vega-lite/v5.20.1.json", | ||
"config": { | ||
"view": { | ||
"continuousHeight": 300, | ||
"continuousWidth": 300 | ||
} | ||
}, | ||
"data": { | ||
"name": "data-e9ffe44f4a940c91c142d6703ef79b9b" | ||
}, | ||
"datasets": { | ||
"data-e9ffe44f4a940c91c142d6703ef79b9b": [ | ||
{ | ||
"first_order_month": "2018-01-01T00:00:00", | ||
"num_new_customers": 24 | ||
}, | ||
{ | ||
"first_order_month": "2018-02-01T00:00:00", | ||
"num_new_customers": 18 | ||
}, | ||
{ | ||
"first_order_month": "2018-03-01T00:00:00", | ||
"num_new_customers": 18 | ||
}, | ||
{ | ||
"first_order_month": "2018-04-01T00:00:00", | ||
"num_new_customers": 2 | ||
} | ||
] | ||
}, | ||
"encoding": { | ||
"x": { | ||
"field": "first_order_month", | ||
"timeUnit": "yearmonth", | ||
"type": "temporal" | ||
}, | ||
"y": { | ||
"field": "num_new_customers", | ||
"type": "quantitative" | ||
} | ||
}, | ||
"mark": { | ||
"type": "bar" | ||
} | ||
}, | ||
"text/plain": [ | ||
"<VegaLite 5 object>\n", | ||
"\n", | ||
"If you see this message, it means the renderer has not been properly enabled\n", | ||
"for the frontend that you are using. For more information, see\n", | ||
"https://altair-viz.github.io/user_guide/display_frontends.html#troubleshooting\n" | ||
] | ||
}, | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"t = c.sql(\n", | ||
" \"\"\"\n", | ||
" SELECT *\n", | ||
" FROM fnl_sales_newcustomers\n", | ||
" ORDER BY first_order_month\n", | ||
" \"\"\"\n", | ||
")\n", | ||
"\n", | ||
"(\n", | ||
" alt.Chart(t)\n", | ||
" .mark_bar()\n", | ||
" .encode(\n", | ||
" x=alt.X(\"yearmonth(first_order_month):T\"),\n", | ||
" y=alt.Y(\"num_new_customers:Q\"),\n", | ||
" )\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"application/vnd.vegalite.v5+json": { | ||
"$schema": "https://vega.github.io/schema/vega-lite/v5.20.1.json", | ||
"config": { | ||
"view": { | ||
"continuousHeight": 300, | ||
"continuousWidth": 300 | ||
} | ||
}, | ||
"data": { | ||
"name": "data-f6fa15d27bf142925fe0f5eb72fd0105" | ||
}, | ||
"datasets": { | ||
"data-f6fa15d27bf142925fe0f5eb72fd0105": [ | ||
{ | ||
"customer_id": 1, | ||
"total_returned_amount_aud": 10 | ||
}, | ||
{ | ||
"customer_id": 2, | ||
"total_returned_amount_aud": 23 | ||
}, | ||
{ | ||
"customer_id": 40, | ||
"total_returned_amount_aud": 3 | ||
}, | ||
{ | ||
"customer_id": 64, | ||
"total_returned_amount_aud": 13 | ||
} | ||
] | ||
}, | ||
"encoding": { | ||
"x": { | ||
"field": "total_returned_amount_aud", | ||
"type": "quantitative" | ||
}, | ||
"y": { | ||
"field": "customer_id", | ||
"sort": "-x", | ||
"type": "ordinal" | ||
} | ||
}, | ||
"mark": { | ||
"type": "bar" | ||
} | ||
}, | ||
"text/plain": [ | ||
"<VegaLite 5 object>\n", | ||
"\n", | ||
"If you see this message, it means the renderer has not been properly enabled\n", | ||
"for the frontend that you are using. For more information, see\n", | ||
"https://altair-viz.github.io/user_guide/display_frontends.html#troubleshooting\n" | ||
] | ||
}, | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"t = c.sql(\n", | ||
" \"\"\"\n", | ||
" SELECT *\n", | ||
" FROM fnl_finance_returnsamout\n", | ||
" WHERE total_returned_amount_aud > 0\n", | ||
" \"\"\"\n", | ||
")\n", | ||
"\n", | ||
"(\n", | ||
" alt.Chart(t)\n", | ||
" .mark_bar()\n", | ||
" .encode(\n", | ||
" x=alt.X(\"total_returned_amount_aud:Q\"),\n", | ||
" y=alt.Y(\"customer_id:O\", sort=alt.Sort(\"-x\")),\n", | ||
" )\n", | ||
")" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": ".venv", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.14" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |