-
Notifications
You must be signed in to change notification settings - Fork 507
/
Copy pathduckdb_example.py
54 lines (41 loc) · 988 Bytes
/
duckdb_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "altair==5.5.0",
# "polars[pyarrow]==1.27.1",
# "marimo[sql]",
# "duckdb==1.2.2",
# "sqlglot==26.13.0",
# ]
# ///
import marimo
__generated_with = "0.12.8"
app = marimo.App(width="medium", sql_output="polars")
@app.cell
def _():
import marimo as mo
import altair as alt
return alt, mo
@app.cell
def _(mo):
digits = mo.ui.slider(label="Digits", start=100, stop=10000, step=200)
digits
return (digits,)
@app.cell
def _(digits, mo):
result = mo.sql(
f"""
CREATE TABLE random_data AS
SELECT i AS id, RANDOM() AS random_value,
FROM range({digits.value}) AS t(i);
SELECT * FROM random_data;
"""
)
return random_data, result
@app.cell
def _(alt, result):
# Plot the data using polars and altair
result.plot.bar(x=alt.X("random_value").bin(), y="count()")
return
if __name__ == "__main__":
app.run()