-
Notifications
You must be signed in to change notification settings - Fork 7.2k
[Data] Add TPCH queries 3, 10, and 18 for benchmarking #60667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
daiping8
wants to merge
5
commits into
ray-project:master
Choose a base branch
from
daiping8:tpchq3
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+307
−3
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f8b74a0
[release test] Add TPCH queries Q3, Q10, and Q18 to release data tests
daiping8 dc19806
Merge branch 'master' into tpchq3
daiping8 116c997
[tpch] Add customer, orders, and nation table definitions to common.py
daiping8 82f3d7a
[tpch] Update column keys in common.py for customer, orders, and nati…
daiping8 9f4cbd5
[Refactor] Remove lazy import of pandas in data batch conversion func…
daiping8 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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,93 @@ | ||
| import ray | ||
| from ray.data.aggregate import Sum | ||
| from ray.data.expressions import col | ||
| from common import parse_tpch_args, load_table, to_f64, run_tpch_benchmark | ||
|
|
||
|
|
||
| def main(args): | ||
| def benchmark_fn(): | ||
| from datetime import datetime | ||
|
|
||
| # Load all required tables | ||
| customer = load_table("customer", args.sf) | ||
| orders = load_table("orders", args.sf) | ||
| lineitem = load_table("lineitem", args.sf) | ||
| nation = load_table("nation", args.sf) | ||
|
|
||
| # Q10 parameters | ||
| date = datetime(1993, 10, 1) | ||
| # Calculate end date (3 months later) | ||
| if date.month <= 9: | ||
| end_date = datetime(date.year, date.month + 3, date.day) | ||
| else: | ||
| end_date = datetime(date.year + 1, date.month + 3 - 12, date.day) | ||
|
|
||
| # Filter orders by date (3 months range) | ||
| orders_filtered = orders.filter( | ||
| expr=((col("o_orderdate") >= date) & (col("o_orderdate") < end_date)) | ||
| ) | ||
|
|
||
| # Filter lineitem by return flag | ||
| lineitem_filtered = lineitem.filter(expr=col("l_returnflag") == "R") | ||
|
|
||
| # Join lineitem with orders | ||
| lineitem_orders = lineitem_filtered.join( | ||
| orders_filtered, | ||
| join_type="inner", | ||
| num_partitions=100, | ||
| on=("l_orderkey",), | ||
| right_on=("o_orderkey",), | ||
| ) | ||
|
|
||
| # Join with customer | ||
| ds = lineitem_orders.join( | ||
| customer, | ||
| join_type="inner", | ||
daiping8 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| num_partitions=100, | ||
| on=("o_custkey",), | ||
| right_on=("c_custkey",), | ||
| ) | ||
|
|
||
| # Join with nation | ||
| ds = ds.join( | ||
| nation, | ||
| join_type="inner", | ||
daiping8 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| num_partitions=100, | ||
| on=("c_nationkey",), | ||
| right_on=("n_nationkey",), | ||
| ) | ||
|
|
||
| # Calculate revenue | ||
| ds = ds.with_column( | ||
| "revenue", | ||
| to_f64(col("l_extendedprice")) * (1 - to_f64(col("l_discount"))), | ||
daiping8 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
| # Aggregate by customer key, customer name, address, phone, account balance, nation, and region | ||
| _ = ( | ||
| ds.groupby( | ||
| [ | ||
| "c_custkey", | ||
| "c_name", | ||
| "c_acctbal", | ||
| "n_name", | ||
| "c_address", | ||
| "c_phone", | ||
| "c_comment", | ||
| ] | ||
| ) | ||
| .aggregate(Sum(on="revenue", alias_name="revenue")) | ||
| .sort(key="revenue", descending=True) | ||
| .materialize() | ||
| ) | ||
|
|
||
| # Report arguments for the benchmark. | ||
| return vars(args) | ||
|
|
||
| run_tpch_benchmark("tpch_q10", benchmark_fn) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| ray.init() | ||
| args = parse_tpch_args() | ||
| main(args) | ||
This file contains hidden or 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,71 @@ | ||
| import ray | ||
| from ray.data.aggregate import Sum | ||
| from ray.data.expressions import col | ||
| from common import parse_tpch_args, load_table, run_tpch_benchmark | ||
|
|
||
|
|
||
| def main(args): | ||
| def benchmark_fn(): | ||
|
|
||
| # Load all required tables | ||
| customer = load_table("customer", args.sf) | ||
| orders = load_table("orders", args.sf) | ||
| lineitem = load_table("lineitem", args.sf) | ||
|
|
||
| # Q18 parameters | ||
| quantity = 300 | ||
daiping8 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Calculate total quantity per order | ||
| lineitem_quantity = lineitem.groupby("l_orderkey").aggregate( | ||
| Sum(on="l_quantity", alias_name="total_quantity") | ||
| ) | ||
|
|
||
| # Filter orders with total quantity > threshold | ||
| large_orders = lineitem_quantity.filter(expr=col("total_quantity") > quantity) | ||
|
|
||
| # Join lineitem with large orders | ||
| lineitem_large = lineitem.join( | ||
| large_orders, | ||
| join_type="inner", | ||
| num_partitions=100, | ||
| on="l_orderkey", | ||
daiping8 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
| # Join with orders | ||
| lineitem_orders = lineitem_large.join( | ||
| orders, | ||
| join_type="inner", | ||
| num_partitions=100, | ||
| on=("l_orderkey",), | ||
| right_on=("o_orderkey",), | ||
| ) | ||
|
|
||
| # Join with customer | ||
| ds = lineitem_orders.join( | ||
| customer, | ||
daiping8 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| join_type="inner", | ||
| num_partitions=100, | ||
| on=("o_custkey",), | ||
| right_on=("c_custkey",), | ||
| ) | ||
|
|
||
| # Aggregate by customer name, customer key, order key, and order date | ||
| _ = ( | ||
| ds.groupby( | ||
daiping8 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ["c_name", "c_custkey", "o_orderkey", "o_orderdate", "o_totalprice"] | ||
| ) | ||
| .aggregate(Sum(on="l_quantity", alias_name="sum_quantity")) | ||
| .sort(key=["o_totalprice", "o_orderdate"], descending=[True, False]) | ||
| .materialize() | ||
| ) | ||
|
|
||
| # Report arguments for the benchmark. | ||
| return vars(args) | ||
|
|
||
| run_tpch_benchmark("tpch_q18", benchmark_fn) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| ray.init() | ||
| args = parse_tpch_args() | ||
| main(args) | ||
This file contains hidden or 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,68 @@ | ||
| import ray | ||
| from ray.data.aggregate import Sum | ||
| from ray.data.expressions import col | ||
| from common import parse_tpch_args, load_table, to_f64, run_tpch_benchmark | ||
|
|
||
|
|
||
| def main(args): | ||
| def benchmark_fn(): | ||
| from datetime import datetime | ||
|
|
||
| # Load all required tables | ||
| customer = load_table("customer", args.sf) | ||
| orders = load_table("orders", args.sf) | ||
| lineitem = load_table("lineitem", args.sf) | ||
|
|
||
| # Q3 parameters | ||
| date = datetime(1995, 3, 15) | ||
| segment = "BUILDING" | ||
|
|
||
| # Filter customer by segment | ||
| customer_filtered = customer.filter(expr=col("c_mktsegment") == segment) | ||
|
|
||
| # Filter orders by date | ||
| orders_filtered = orders.filter(expr=col("o_orderdate") < date) | ||
daiping8 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Join orders with customer | ||
| orders_customer = orders_filtered.join( | ||
| customer_filtered, | ||
| join_type="inner", | ||
| num_partitions=100, | ||
| on=("o_custkey",), | ||
| right_on=("c_custkey",), | ||
| ) | ||
|
|
||
| # Join with lineitem and filter by ship date | ||
daiping8 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| lineitem_filtered = lineitem.filter(expr=col("l_shipdate") > date) | ||
| ds = lineitem_filtered.join( | ||
| orders_customer, | ||
| join_type="inner", | ||
| num_partitions=100, | ||
| on=("l_orderkey",), | ||
| right_on=("o_orderkey",), | ||
| ) | ||
|
|
||
| # Calculate revenue | ||
| ds = ds.with_column( | ||
| "revenue", | ||
daiping8 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| to_f64(col("l_extendedprice")) * (1 - to_f64(col("l_discount"))), | ||
| ) | ||
|
|
||
| # Aggregate by order key, order date, and ship priority | ||
| _ = ( | ||
| ds.groupby(["l_orderkey", "o_orderdate", "o_shippriority"]) | ||
| .aggregate(Sum(on="revenue", alias_name="revenue")) | ||
| .sort(key=["revenue", "o_orderdate"], descending=[True, False]) | ||
| .materialize() | ||
| ) | ||
|
|
||
| # Report arguments for the benchmark. | ||
| return vars(args) | ||
|
|
||
| run_tpch_benchmark("tpch_q3", benchmark_fn) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| ray.init() | ||
| args = parse_tpch_args() | ||
| main(args) | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.