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
250 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,250 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import altair as alt\n", | ||
"import duckdb" | ||
] | ||
}, | ||
{ | ||
"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": { | ||
"text/html": [ | ||
"\n", | ||
"<style>\n", | ||
" #altair-viz-a072d4b80d6348bfba9549f394250756.vega-embed {\n", | ||
" width: 100%;\n", | ||
" display: flex;\n", | ||
" }\n", | ||
"\n", | ||
" #altair-viz-a072d4b80d6348bfba9549f394250756.vega-embed details,\n", | ||
" #altair-viz-a072d4b80d6348bfba9549f394250756.vega-embed details summary {\n", | ||
" position: relative;\n", | ||
" }\n", | ||
"</style>\n", | ||
"<div id=\"altair-viz-a072d4b80d6348bfba9549f394250756\"></div>\n", | ||
"<script type=\"text/javascript\">\n", | ||
" var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n", | ||
" (function(spec, embedOpt){\n", | ||
" let outputDiv = document.currentScript.previousElementSibling;\n", | ||
" if (outputDiv.id !== \"altair-viz-a072d4b80d6348bfba9549f394250756\") {\n", | ||
" outputDiv = document.getElementById(\"altair-viz-a072d4b80d6348bfba9549f394250756\");\n", | ||
" }\n", | ||
" const paths = {\n", | ||
" \"vega\": \"https://cdn.jsdelivr.net/npm/vega@5?noext\",\n", | ||
" \"vega-lib\": \"https://cdn.jsdelivr.net/npm/vega-lib?noext\",\n", | ||
" \"vega-lite\": \"https://cdn.jsdelivr.net/npm/[email protected]?noext\",\n", | ||
" \"vega-embed\": \"https://cdn.jsdelivr.net/npm/vega-embed@6?noext\",\n", | ||
" };\n", | ||
"\n", | ||
" function maybeLoadScript(lib, version) {\n", | ||
" var key = `${lib.replace(\"-\", \"\")}_version`;\n", | ||
" return (VEGA_DEBUG[key] == version) ?\n", | ||
" Promise.resolve(paths[lib]) :\n", | ||
" new Promise(function(resolve, reject) {\n", | ||
" var s = document.createElement('script');\n", | ||
" document.getElementsByTagName(\"head\")[0].appendChild(s);\n", | ||
" s.async = true;\n", | ||
" s.onload = () => {\n", | ||
" VEGA_DEBUG[key] = version;\n", | ||
" return resolve(paths[lib]);\n", | ||
" };\n", | ||
" s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n", | ||
" s.src = paths[lib];\n", | ||
" });\n", | ||
" }\n", | ||
"\n", | ||
" function showError(err) {\n", | ||
" outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n", | ||
" throw err;\n", | ||
" }\n", | ||
"\n", | ||
" function displayChart(vegaEmbed) {\n", | ||
" vegaEmbed(outputDiv, spec, embedOpt)\n", | ||
" .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n", | ||
" }\n", | ||
"\n", | ||
" if(typeof define === \"function\" && define.amd) {\n", | ||
" requirejs.config({paths});\n", | ||
" require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n", | ||
" } else {\n", | ||
" maybeLoadScript(\"vega\", \"5\")\n", | ||
" .then(() => maybeLoadScript(\"vega-lite\", \"5.20.1\"))\n", | ||
" .then(() => maybeLoadScript(\"vega-embed\", \"6\"))\n", | ||
" .catch(showError)\n", | ||
" .then(() => displayChart(vegaEmbed));\n", | ||
" }\n", | ||
" })({\"config\": {\"view\": {\"continuousWidth\": 300, \"continuousHeight\": 300}}, \"data\": {\"name\": \"data-e9ffe44f4a940c91c142d6703ef79b9b\"}, \"mark\": {\"type\": \"bar\"}, \"encoding\": {\"x\": {\"field\": \"first_order_month\", \"timeUnit\": \"yearmonth\", \"type\": \"temporal\"}, \"y\": {\"field\": \"num_new_customers\", \"type\": \"quantitative\"}}, \"$schema\": \"https://vega.github.io/schema/vega-lite/v5.20.1.json\", \"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}]}}, {\"mode\": \"vega-lite\"});\n", | ||
"</script>" | ||
], | ||
"text/plain": [ | ||
"alt.Chart(...)" | ||
] | ||
}, | ||
"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": { | ||
"text/html": [ | ||
"\n", | ||
"<style>\n", | ||
" #altair-viz-c30e8330bd9c403e9938ea537abc14a1.vega-embed {\n", | ||
" width: 100%;\n", | ||
" display: flex;\n", | ||
" }\n", | ||
"\n", | ||
" #altair-viz-c30e8330bd9c403e9938ea537abc14a1.vega-embed details,\n", | ||
" #altair-viz-c30e8330bd9c403e9938ea537abc14a1.vega-embed details summary {\n", | ||
" position: relative;\n", | ||
" }\n", | ||
"</style>\n", | ||
"<div id=\"altair-viz-c30e8330bd9c403e9938ea537abc14a1\"></div>\n", | ||
"<script type=\"text/javascript\">\n", | ||
" var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n", | ||
" (function(spec, embedOpt){\n", | ||
" let outputDiv = document.currentScript.previousElementSibling;\n", | ||
" if (outputDiv.id !== \"altair-viz-c30e8330bd9c403e9938ea537abc14a1\") {\n", | ||
" outputDiv = document.getElementById(\"altair-viz-c30e8330bd9c403e9938ea537abc14a1\");\n", | ||
" }\n", | ||
" const paths = {\n", | ||
" \"vega\": \"https://cdn.jsdelivr.net/npm/vega@5?noext\",\n", | ||
" \"vega-lib\": \"https://cdn.jsdelivr.net/npm/vega-lib?noext\",\n", | ||
" \"vega-lite\": \"https://cdn.jsdelivr.net/npm/[email protected]?noext\",\n", | ||
" \"vega-embed\": \"https://cdn.jsdelivr.net/npm/vega-embed@6?noext\",\n", | ||
" };\n", | ||
"\n", | ||
" function maybeLoadScript(lib, version) {\n", | ||
" var key = `${lib.replace(\"-\", \"\")}_version`;\n", | ||
" return (VEGA_DEBUG[key] == version) ?\n", | ||
" Promise.resolve(paths[lib]) :\n", | ||
" new Promise(function(resolve, reject) {\n", | ||
" var s = document.createElement('script');\n", | ||
" document.getElementsByTagName(\"head\")[0].appendChild(s);\n", | ||
" s.async = true;\n", | ||
" s.onload = () => {\n", | ||
" VEGA_DEBUG[key] = version;\n", | ||
" return resolve(paths[lib]);\n", | ||
" };\n", | ||
" s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n", | ||
" s.src = paths[lib];\n", | ||
" });\n", | ||
" }\n", | ||
"\n", | ||
" function showError(err) {\n", | ||
" outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n", | ||
" throw err;\n", | ||
" }\n", | ||
"\n", | ||
" function displayChart(vegaEmbed) {\n", | ||
" vegaEmbed(outputDiv, spec, embedOpt)\n", | ||
" .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n", | ||
" }\n", | ||
"\n", | ||
" if(typeof define === \"function\" && define.amd) {\n", | ||
" requirejs.config({paths});\n", | ||
" require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n", | ||
" } else {\n", | ||
" maybeLoadScript(\"vega\", \"5\")\n", | ||
" .then(() => maybeLoadScript(\"vega-lite\", \"5.20.1\"))\n", | ||
" .then(() => maybeLoadScript(\"vega-embed\", \"6\"))\n", | ||
" .catch(showError)\n", | ||
" .then(() => displayChart(vegaEmbed));\n", | ||
" }\n", | ||
" })({\"config\": {\"view\": {\"continuousWidth\": 300, \"continuousHeight\": 300}}, \"data\": {\"name\": \"data-f6fa15d27bf142925fe0f5eb72fd0105\"}, \"mark\": {\"type\": \"bar\"}, \"encoding\": {\"x\": {\"field\": \"total_returned_amount_aud\", \"type\": \"quantitative\"}, \"y\": {\"field\": \"customer_id\", \"sort\": \"-x\", \"type\": \"ordinal\"}}, \"$schema\": \"https://vega.github.io/schema/vega-lite/v5.20.1.json\", \"datasets\": {\"data-f6fa15d27bf142925fe0f5eb72fd0105\": [{\"customer_id\": 1, \"total_returned_amount_aud\": 10.0}, {\"customer_id\": 2, \"total_returned_amount_aud\": 23.0}, {\"customer_id\": 40, \"total_returned_amount_aud\": 3.0}, {\"customer_id\": 64, \"total_returned_amount_aud\": 13.0}]}}, {\"mode\": \"vega-lite\"});\n", | ||
"</script>" | ||
], | ||
"text/plain": [ | ||
"alt.Chart(...)" | ||
] | ||
}, | ||
"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 | ||
} |