Skip to content

Commit d8d6441

Browse files
committed
update tpch examples for latest function uses
1 parent 885502b commit d8d6441

File tree

5 files changed

+14
-13
lines changed

5 files changed

+14
-13
lines changed

examples/tpch/q02_minimum_cost_supplier.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import datafusion
3333
from datafusion import SessionContext, col, lit
3434
from datafusion import functions as F
35+
from datafusion.expr import Window
3536
from util import get_data_path
3637

3738
# This is the part we're looking for. Values selected here differ from the spec in order to run
@@ -106,11 +107,8 @@
106107
window_frame = datafusion.WindowFrame("rows", None, None)
107108
df = df.with_column(
108109
"min_cost",
109-
F.window(
110-
"min",
111-
[col("ps_supplycost")],
112-
partition_by=[col("ps_partkey")],
113-
window_frame=window_frame,
110+
F.min(col("ps_supplycost")).over(
111+
Window(partition_by=[col("ps_partkey")], window_frame=window_frame)
114112
),
115113
)
116114

examples/tpch/q11_important_stock_identification.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
from datafusion import SessionContext, WindowFrame, col, lit
3131
from datafusion import functions as F
32+
from datafusion.expr import Window
3233
from util import get_data_path
3334

3435
NATION = "GERMANY"
@@ -71,7 +72,7 @@
7172
window_frame = WindowFrame("rows", None, None)
7273

7374
df = df.with_column(
74-
"total_value", F.window("sum", [col("value")], window_frame=window_frame)
75+
"total_value", F.sum(col("value")).over(Window(window_frame=window_frame))
7576
)
7677

7778
# Limit to the parts for which there is a significant value based on the fraction of the total

examples/tpch/q15_top_supplier.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import pyarrow as pa
3232
from datafusion import SessionContext, WindowFrame, col, lit
3333
from datafusion import functions as F
34+
from datafusion.expr import Window
3435
from util import get_data_path
3536

3637
DATE = "1996-01-01"
@@ -70,7 +71,8 @@
7071
# Use a window function to find the maximum revenue across the entire dataframe
7172
window_frame = WindowFrame("rows", None, None)
7273
df = df.with_column(
73-
"max_revenue", F.window("max", [col("total_revenue")], window_frame=window_frame)
74+
"max_revenue",
75+
F.max(col("total_revenue")).over(Window(window_frame=window_frame)),
7476
)
7577

7678
# Find all suppliers whose total revenue is the same as the maximum

examples/tpch/q17_small_quantity_order.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
from datafusion import SessionContext, WindowFrame, col, lit
3232
from datafusion import functions as F
33+
from datafusion.expr import Window
3334
from util import get_data_path
3435

3536
BRAND = "Brand#23"
@@ -58,11 +59,8 @@
5859
window_frame = WindowFrame("rows", None, None)
5960
df = df.with_column(
6061
"avg_quantity",
61-
F.window(
62-
"avg",
63-
[col("l_quantity")],
64-
window_frame=window_frame,
65-
partition_by=[col("l_partkey")],
62+
F.avg(col("l_quantity")).over(
63+
Window(partition_by=[col("l_partkey")], window_frame=window_frame)
6664
),
6765
)
6866

examples/tpch/q22_global_sales_opportunity.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
from datafusion import SessionContext, WindowFrame, col, lit
3030
from datafusion import functions as F
31+
from datafusion.expr import Window
3132
from util import get_data_path
3233

3334
NATION_CODES = [13, 31, 23, 29, 30, 18, 17]
@@ -55,7 +56,8 @@
5556
# current row. We want our frame to cover the entire data frame.
5657
window_frame = WindowFrame("rows", None, None)
5758
df = df.with_column(
58-
"avg_balance", F.window("avg", [col("c_acctbal")], window_frame=window_frame)
59+
"avg_balance",
60+
F.avg(col("c_acctbal")).over(Window(window_frame=window_frame)),
5961
)
6062

6163
df.show()

0 commit comments

Comments
 (0)