Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/docs/source/src/python/user-guide/concepts/streaming.py
7890 views
1
import base64
2
3
# --8<-- [start:import]
4
import polars as pl
5
# --8<-- [end:import]
6
7
# --8<-- [start:streaming]
8
q1 = (
9
pl.scan_csv("docs/assets/data/iris.csv")
10
.filter(pl.col("sepal_length") > 5)
11
.group_by("species")
12
.agg(pl.col("sepal_width").mean())
13
)
14
df = q1.collect(engine="streaming")
15
# --8<-- [end:streaming]
16
17
"""
18
# --8<-- [start:createplan_query]
19
q1 = (
20
pl.scan_csv("docs/assets/data/iris.csv")
21
.filter(pl.col("sepal_length") > 5)
22
.group_by("species")
23
.agg(
24
mean_width=pl.col("sepal_width").mean(),
25
mean_width2=pl.col("sepal_width").sum() / pl.col("sepal_length").count(),
26
)
27
.show_graph(plan_stage="physical", engine="streaming")
28
)
29
# --8<-- [end:createplan_query]
30
"""
31
32
# --8<-- [start:createplan]
33
import base64
34
import polars as pl
35
36
q1 = (
37
pl.scan_csv("docs/assets/data/iris.csv")
38
.filter(pl.col("sepal_length") > 5)
39
.group_by("species")
40
.agg(
41
mean_width=pl.col("sepal_width").mean(),
42
mean_width2=pl.col("sepal_width").sum() / pl.col("sepal_length").count(),
43
)
44
)
45
46
q1.show_graph(
47
plan_stage="physical",
48
engine="streaming",
49
show=False,
50
output_path="docs/assets/images/query_plan.png",
51
)
52
with open("docs/assets/images/query_plan.png", "rb") as f:
53
png = base64.b64encode(f.read()).decode()
54
print(f'<img src="data:image/png;base64, {png}"/>')
55
# --8<-- [end:createplan]
56
57