This is an automated email from the ASF dual-hosted git repository.

agrove pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-comet.git


The following commit(s) were added to refs/heads/main by this push:
     new 896096aa chore: Add microbenchmarks (#671)
896096aa is described below

commit 896096aa4de04e8707769f877346790bbb443f00
Author: Andy Grove <[email protected]>
AuthorDate: Wed Jul 17 18:44:12 2024 -0600

    chore: Add microbenchmarks (#671)
---
 .../tpcds-micro-benchmarks/add_many_decimals.sql   | 34 +++++++++
 .../tpcds-micro-benchmarks/add_many_integers.sql   | 33 +++++++++
 .../agg_high_cardinality.sql                       | 18 +++++
 .../tpcds-micro-benchmarks/agg_low_cardinality.sql | 18 +++++
 .../agg_sum_decimals_no_grouping.sql               | 31 +++++++++
 .../agg_sum_integers_no_grouping.sql               | 30 ++++++++
 .../case_when_column_or_null.sql                   | 26 +++++++
 .../tpcds-micro-benchmarks/case_when_scalar.sql    | 22 ++++++
 .../filter_highly_selective.sql                    | 18 +++++
 .../filter_less_selective.sql                      | 18 +++++
 .../tpcds-micro-benchmarks/if_column_or_null.sql   | 27 ++++++++
 .../resources/tpcds-micro-benchmarks/join_anti.sql | 29 ++++++++
 .../tpcds-micro-benchmarks/join_condition.sql      | 23 ++++++
 .../join_exploding_output.sql                      | 22 ++++++
 .../tpcds-micro-benchmarks/join_inner.sql          | 20 ++++++
 .../tpcds-micro-benchmarks/join_left_outer.sql     | 20 ++++++
 .../resources/tpcds-micro-benchmarks/join_semi.sql | 30 ++++++++
 .../org/apache/spark/sql/CometTPCQueryBase.scala   | 20 +++++-
 ...rkBase.scala => CometTPCDSMicroBenchmark.scala} | 81 ++++++++++++++++++----
 .../sql/benchmark/CometTPCQueryBenchmarkBase.scala |  3 -
 20 files changed, 502 insertions(+), 21 deletions(-)

diff --git 
a/spark/src/test/resources/tpcds-micro-benchmarks/add_many_decimals.sql 
b/spark/src/test/resources/tpcds-micro-benchmarks/add_many_decimals.sql
new file mode 100644
index 00000000..597bdf8e
--- /dev/null
+++ b/spark/src/test/resources/tpcds-micro-benchmarks/add_many_decimals.sql
@@ -0,0 +1,34 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied.  See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+
+-- This is testing the cost of a complex expression that will create many 
intermediate arrays in Comet
+
+select sum(
+    ss_wholesale_cost+
+    ss_list_price+
+    ss_sales_price+
+    ss_ext_discount_amt+
+    ss_ext_sales_price+
+    ss_ext_wholesale_cost+
+    ss_ext_list_price+
+    ss_ext_tax+
+    ss_coupon_amt+
+    ss_net_paid+
+    ss_net_paid_inc_tax+
+    ss_net_profit
+)
+from store_sales;
diff --git 
a/spark/src/test/resources/tpcds-micro-benchmarks/add_many_integers.sql 
b/spark/src/test/resources/tpcds-micro-benchmarks/add_many_integers.sql
new file mode 100644
index 00000000..40406987
--- /dev/null
+++ b/spark/src/test/resources/tpcds-micro-benchmarks/add_many_integers.sql
@@ -0,0 +1,33 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied.  See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+
+-- This is testing the cost of a complex expression that will create many 
intermediate arrays in Comet
+
+select sum(
+    ss_sold_date_sk+
+    ss_sold_time_sk+
+    ss_item_sk+
+    ss_customer_sk+
+    ss_cdemo_sk+
+    ss_hdemo_sk+
+    ss_addr_sk+
+    ss_store_sk+
+    ss_promo_sk+
+    ss_ticket_number+
+    ss_quantity
+)
+from store_sales;
diff --git 
a/spark/src/test/resources/tpcds-micro-benchmarks/agg_high_cardinality.sql 
b/spark/src/test/resources/tpcds-micro-benchmarks/agg_high_cardinality.sql
new file mode 100644
index 00000000..68c2d910
--- /dev/null
+++ b/spark/src/test/resources/tpcds-micro-benchmarks/agg_high_cardinality.sql
@@ -0,0 +1,18 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied.  See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+                  
+select ws_item_sk, sum(ws_wholesale_cost) from web_sales group by ws_item_sk;
\ No newline at end of file
diff --git 
a/spark/src/test/resources/tpcds-micro-benchmarks/agg_low_cardinality.sql 
b/spark/src/test/resources/tpcds-micro-benchmarks/agg_low_cardinality.sql
new file mode 100644
index 00000000..7b69548d
--- /dev/null
+++ b/spark/src/test/resources/tpcds-micro-benchmarks/agg_low_cardinality.sql
@@ -0,0 +1,18 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied.  See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+                  
+select ws_warehouse_sk, sum(ws_wholesale_cost) from web_sales group by 
ws_warehouse_sk;
\ No newline at end of file
diff --git 
a/spark/src/test/resources/tpcds-micro-benchmarks/agg_sum_decimals_no_grouping.sql
 
b/spark/src/test/resources/tpcds-micro-benchmarks/agg_sum_decimals_no_grouping.sql
new file mode 100644
index 00000000..d0c10c75
--- /dev/null
+++ 
b/spark/src/test/resources/tpcds-micro-benchmarks/agg_sum_decimals_no_grouping.sql
@@ -0,0 +1,31 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied.  See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+
+select
+    sum(ss_wholesale_cost),
+    sum(ss_list_price),
+    sum(ss_sales_price),
+    sum(ss_ext_discount_amt),
+    sum(ss_ext_sales_price),
+    sum(ss_ext_wholesale_cost),
+    sum(ss_ext_list_price),
+    sum(ss_ext_tax),
+    sum(ss_coupon_amt),
+    sum(ss_net_paid),
+    sum(ss_net_paid_inc_tax),
+    sum(ss_net_profit)
+from store_sales;
\ No newline at end of file
diff --git 
a/spark/src/test/resources/tpcds-micro-benchmarks/agg_sum_integers_no_grouping.sql
 
b/spark/src/test/resources/tpcds-micro-benchmarks/agg_sum_integers_no_grouping.sql
new file mode 100644
index 00000000..a1892845
--- /dev/null
+++ 
b/spark/src/test/resources/tpcds-micro-benchmarks/agg_sum_integers_no_grouping.sql
@@ -0,0 +1,30 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied.  See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+
+select
+    sum(ss_sold_date_sk),
+    sum(ss_sold_time_sk),
+    sum(ss_item_sk),
+    sum(ss_customer_sk),
+    sum(ss_cdemo_sk),
+    sum(ss_hdemo_sk),
+    sum(ss_addr_sk),
+    sum(ss_store_sk),
+    sum(ss_promo_sk),
+    sum(ss_ticket_number),
+    sum(ss_quantity)
+from store_sales;
\ No newline at end of file
diff --git 
a/spark/src/test/resources/tpcds-micro-benchmarks/case_when_column_or_null.sql 
b/spark/src/test/resources/tpcds-micro-benchmarks/case_when_column_or_null.sql
new file mode 100644
index 00000000..23fdca59
--- /dev/null
+++ 
b/spark/src/test/resources/tpcds-micro-benchmarks/case_when_column_or_null.sql
@@ -0,0 +1,26 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied.  See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+
+select
+    sum(case when (ss_quantity=1) then ss_sales_price else null end) sun_sales,
+    sum(case when (ss_quantity=2) then ss_sales_price else null end) mon_sales,
+    sum(case when (ss_quantity=3) then ss_sales_price else null end) tue_sales,
+    sum(case when (ss_quantity=4) then ss_sales_price else null end) wed_sales,
+    sum(case when (ss_quantity=5) then ss_sales_price else null end) thu_sales,
+    sum(case when (ss_quantity=6) then ss_sales_price else null end) fri_sales,
+    sum(case when (ss_quantity=7) then ss_sales_price else null end) sat_sales
+from store_sales;
diff --git 
a/spark/src/test/resources/tpcds-micro-benchmarks/case_when_scalar.sql 
b/spark/src/test/resources/tpcds-micro-benchmarks/case_when_scalar.sql
new file mode 100644
index 00000000..1d2e4675
--- /dev/null
+++ b/spark/src/test/resources/tpcds-micro-benchmarks/case_when_scalar.sql
@@ -0,0 +1,22 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied.  See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+                  
+select
+    sum(case when ws_wholesale_cost > 10 then 1 else 0 end) as a,
+    sum(case when ws_wholesale_cost > 20 then 1 else 0 end) as b,
+    sum(case when ws_wholesale_cost > 30 then 1 else 0 end) as c
+from web_sales;
\ No newline at end of file
diff --git 
a/spark/src/test/resources/tpcds-micro-benchmarks/filter_highly_selective.sql 
b/spark/src/test/resources/tpcds-micro-benchmarks/filter_highly_selective.sql
new file mode 100644
index 00000000..26786ba1
--- /dev/null
+++ 
b/spark/src/test/resources/tpcds-micro-benchmarks/filter_highly_selective.sql
@@ -0,0 +1,18 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied.  See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+
+select count(*) from web_sales where ws_wholesale_cost = 100;
\ No newline at end of file
diff --git 
a/spark/src/test/resources/tpcds-micro-benchmarks/filter_less_selective.sql 
b/spark/src/test/resources/tpcds-micro-benchmarks/filter_less_selective.sql
new file mode 100644
index 00000000..6dffc8b5
--- /dev/null
+++ b/spark/src/test/resources/tpcds-micro-benchmarks/filter_less_selective.sql
@@ -0,0 +1,18 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied.  See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+                  
+select count(*) from web_sales where ws_wholesale_cost > 10;
\ No newline at end of file
diff --git 
a/spark/src/test/resources/tpcds-micro-benchmarks/if_column_or_null.sql 
b/spark/src/test/resources/tpcds-micro-benchmarks/if_column_or_null.sql
new file mode 100644
index 00000000..da7a0b75
--- /dev/null
+++ b/spark/src/test/resources/tpcds-micro-benchmarks/if_column_or_null.sql
@@ -0,0 +1,27 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied.  See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+
+select
+    sum(if(d_day_name='Sunday', ss_sales_price, null)) sun_sales,
+    sum(if(d_day_name='Monday', ss_sales_price, null)) mon_sales,
+    sum(if(d_day_name='Tuesday', ss_sales_price, null)) tue_sales,
+    sum(if(d_day_name='Wednesday', ss_sales_price, null)) wed_sales,
+    sum(if(d_day_name='Thursday', ss_sales_price, null)) thu_sales,
+    sum(if(d_day_name='Friday', ss_sales_price, null)) fri_sales,
+    sum(if(d_day_name='Saturday', ss_sales_price, null)) sat_sales
+from date_dim join store_sales on d_date_sk = ss_sold_date_sk
+where d_year = 2000;
diff --git a/spark/src/test/resources/tpcds-micro-benchmarks/join_anti.sql 
b/spark/src/test/resources/tpcds-micro-benchmarks/join_anti.sql
new file mode 100644
index 00000000..3c16e017
--- /dev/null
+++ b/spark/src/test/resources/tpcds-micro-benchmarks/join_anti.sql
@@ -0,0 +1,29 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied.  See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+
+-- Based on q94
+
+select
+    count(distinct ws_order_number) as `order count`
+from
+    web_sales ws1
+where not exists(select *
+                 from web_returns wr1
+                 where ws1.ws_order_number = wr1.wr_order_number)
+order by count(distinct ws_order_number)
+    LIMIT 100;
+
diff --git a/spark/src/test/resources/tpcds-micro-benchmarks/join_condition.sql 
b/spark/src/test/resources/tpcds-micro-benchmarks/join_condition.sql
new file mode 100644
index 00000000..4e732a6f
--- /dev/null
+++ b/spark/src/test/resources/tpcds-micro-benchmarks/join_condition.sql
@@ -0,0 +1,23 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied.  See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+
+-- This is based on the first join in q72 when there is no join reordering
+
+select count(*)
+from catalog_sales join inventory on cs_item_sk = inv_item_sk
+where cs_warehouse_sk = 1 and inv_quantity_on_hand = 666
+and inv_quantity_on_hand < cs_quantity;
\ No newline at end of file
diff --git 
a/spark/src/test/resources/tpcds-micro-benchmarks/join_exploding_output.sql 
b/spark/src/test/resources/tpcds-micro-benchmarks/join_exploding_output.sql
new file mode 100644
index 00000000..b8ee8916
--- /dev/null
+++ b/spark/src/test/resources/tpcds-micro-benchmarks/join_exploding_output.sql
@@ -0,0 +1,22 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied.  See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+
+-- This is based on the first join in q72 when there is no join reordering
+
+select count(*)
+from catalog_sales join inventory on cs_item_sk = inv_item_sk
+where cs_warehouse_sk = 1 and inv_quantity_on_hand = 666;
\ No newline at end of file
diff --git a/spark/src/test/resources/tpcds-micro-benchmarks/join_inner.sql 
b/spark/src/test/resources/tpcds-micro-benchmarks/join_inner.sql
new file mode 100644
index 00000000..8e7c2412
--- /dev/null
+++ b/spark/src/test/resources/tpcds-micro-benchmarks/join_inner.sql
@@ -0,0 +1,20 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied.  See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+
+select count(*)
+from date_dim join store_sales on d_date_sk = ss_sold_date_sk
+where d_year = 2000;
diff --git 
a/spark/src/test/resources/tpcds-micro-benchmarks/join_left_outer.sql 
b/spark/src/test/resources/tpcds-micro-benchmarks/join_left_outer.sql
new file mode 100644
index 00000000..2bf6db57
--- /dev/null
+++ b/spark/src/test/resources/tpcds-micro-benchmarks/join_left_outer.sql
@@ -0,0 +1,20 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied.  See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+
+select count(*)
+from store_sales left outer join store_returns on
+ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number
\ No newline at end of file
diff --git a/spark/src/test/resources/tpcds-micro-benchmarks/join_semi.sql 
b/spark/src/test/resources/tpcds-micro-benchmarks/join_semi.sql
new file mode 100644
index 00000000..c86901d5
--- /dev/null
+++ b/spark/src/test/resources/tpcds-micro-benchmarks/join_semi.sql
@@ -0,0 +1,30 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied.  See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+
+-- Based on q94
+
+select
+    count(distinct ws_order_number) as `order count`
+from
+    web_sales ws1
+where exists (select *
+              from web_sales ws2
+              where ws1.ws_order_number = ws2.ws_order_number
+                and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk)
+order by count(distinct ws_order_number)
+    LIMIT 100;
+
diff --git a/spark/src/test/scala/org/apache/spark/sql/CometTPCQueryBase.scala 
b/spark/src/test/scala/org/apache/spark/sql/CometTPCQueryBase.scala
index ad989f58..99f5f3f4 100644
--- a/spark/src/test/scala/org/apache/spark/sql/CometTPCQueryBase.scala
+++ b/spark/src/test/scala/org/apache/spark/sql/CometTPCQueryBase.scala
@@ -19,6 +19,8 @@
 
 package org.apache.spark.sql
 
+import java.io.{File, FileNotFoundException}
+
 import scala.util.Try
 
 import org.apache.spark.SparkConf
@@ -70,15 +72,27 @@ trait CometTPCQueryBase extends Logging {
       tables: Seq[String],
       tableColumns: Map[String, StructType] = Map.empty): Map[String, Long] = {
     tables.map { tableName =>
+      // some tools will generate TPC-* Parquet files with a `.parquet` 
extension
+      // and others will not, so let's support both cases
+      val tableFilePathDefault = s"$dataLocation/$tableName"
+      val tableFilePathAlt = s"$dataLocation/$tableName.parquet"
+      val tableFilePath = if (new File(tableFilePathDefault).exists()) {
+        tableFilePathDefault
+      } else if (new File(tableFilePathAlt).exists()) {
+        tableFilePathAlt
+      } else {
+        throw new FileNotFoundException(
+          s"Table does not exist at $tableFilePathDefault or 
$tableFilePathAlt")
+      }
       if (createTempView) {
-        
cometSpark.read.parquet(s"$dataLocation/$tableName").createOrReplaceTempView(tableName)
+        
cometSpark.read.parquet(tableFilePath).createOrReplaceTempView(tableName)
       } else {
         cometSpark.sql(s"DROP TABLE IF EXISTS $tableName")
         if (tableColumns.isEmpty) {
-          cometSpark.catalog.createTable(tableName, 
s"$dataLocation/$tableName", "parquet")
+          cometSpark.catalog.createTable(tableName, tableFilePath, "parquet")
         } else {
           // SPARK-39584: Fix TPCDSQueryBenchmark Measuring Performance of 
Wrong Query Results
-          val options = Map("path" -> s"$dataLocation/$tableName")
+          val options = Map("path" -> tableFilePath)
           cometSpark.catalog.createTable(tableName, "parquet", 
tableColumns(tableName), options)
         }
         // Recover partitions but don't fail if a table is not partitioned.
diff --git 
a/spark/src/test/scala/org/apache/spark/sql/benchmark/CometTPCQueryBenchmarkBase.scala
 
b/spark/src/test/scala/org/apache/spark/sql/benchmark/CometTPCDSMicroBenchmark.scala
similarity index 53%
copy from 
spark/src/test/scala/org/apache/spark/sql/benchmark/CometTPCQueryBenchmarkBase.scala
copy to 
spark/src/test/scala/org/apache/spark/sql/benchmark/CometTPCDSMicroBenchmark.scala
index d23d76fe..22d84670 100644
--- 
a/spark/src/test/scala/org/apache/spark/sql/benchmark/CometTPCQueryBenchmarkBase.scala
+++ 
b/spark/src/test/scala/org/apache/spark/sql/benchmark/CometTPCDSMicroBenchmark.scala
@@ -19,34 +19,71 @@
 
 package org.apache.spark.sql.benchmark
 
+import scala.io.Source
+
 import org.apache.spark.benchmark.Benchmark
-import org.apache.spark.internal.Logging
-import org.apache.spark.sql.{CometTPCQueryBase, SparkSession}
 import org.apache.spark.sql.catalyst.catalog.HiveTableRelation
 import org.apache.spark.sql.catalyst.plans.logical.SubqueryAlias
-import org.apache.spark.sql.catalyst.util.resourceToString
-import org.apache.spark.sql.execution.benchmark.SqlBasedBenchmark
+import org.apache.spark.sql.execution.benchmark.TPCDSQueryBenchmark.tables
+import org.apache.spark.sql.execution.benchmark.TPCDSQueryBenchmarkArguments
 import org.apache.spark.sql.execution.datasources.LogicalRelation
 
 import org.apache.comet.CometConf
 
 /**
- * Base class for CometTPCDSQueryBenchmark and CometTPCHQueryBenchmark Mostly 
copied from
- * TPCDSQueryBenchmark. TODO: make TPCDSQueryBenchmark extensible to avoid 
copies
+ * Benchmark to measure Comet query performance with micro benchmarks that use 
the TPCDS data.
+ * These queries represent subsets of the full TPCDS queries.
+ *
+ * To run this benchmark:
+ * {{{
+ * // Build [tpcds-kit](https://github.com/databricks/tpcds-kit)
+ * cd /tmp && git clone https://github.com/databricks/tpcds-kit.git
+ * cd tpcds-kit/tools && make OS=MACOS
+ *
+ * // GenTPCDSData
+ * cd $COMET_HOME && mkdir /tmp/tpcds
+ * make benchmark-org.apache.spark.sql.GenTPCDSData -- --dsdgenDir 
/tmp/tpcds-kit/tools --location /tmp/tpcds --scaleFactor 1
+ *
+ * // CometTPCDSMicroBenchmark
+ * SPARK_GENERATE_BENCHMARK_FILES=1 make 
benchmark-org.apache.spark.sql.benchmark.CometTPCDSMicroBenchmark -- 
--data-location /tmp/tpcds
+ * }}}
+ *
+ * Results will be written to 
"spark/benchmarks/CometTPCDSMicroBenchmark-**results.txt".
  */
-trait CometTPCQueryBenchmarkBase extends SqlBasedBenchmark with 
CometTPCQueryBase with Logging {
-  override def getSparkSession: SparkSession = cometSpark
+object CometTPCDSMicroBenchmark extends CometTPCQueryBenchmarkBase {
+
+  val queries: Seq[String] = Seq(
+    "add_many_decimals",
+    "add_many_integers",
+    "agg_high_cardinality",
+    "agg_low_cardinality",
+    "agg_sum_decimals_no_grouping",
+    "agg_sum_integers_no_grouping",
+    "case_when_column_or_null",
+    "case_when_scalar",
+    "filter_highly_selective",
+    "filter_less_selective",
+    "if_column_or_null",
+    "join_anti",
+    "join_condition",
+    "join_exploding_output",
+    "join_inner",
+    "join_left_outer",
+    "join_semi")
 
-  protected def runQueries(
+  override def runQueries(
       queryLocation: String,
       queries: Seq[String],
       tableSizes: Map[String, Long],
       benchmarkName: String,
       nameSuffix: String = ""): Unit = {
     queries.foreach { name =>
-      val queryString = resourceToString(
-        s"$queryLocation/$name.sql",
-        classLoader = Thread.currentThread().getContextClassLoader)
+      val source = 
Source.fromFile(s"spark/src/test/resources/tpcds-micro-benchmarks/$name.sql")
+      val queryString = source
+        .getLines()
+        .filterNot(_.startsWith("--"))
+        .mkString("\n")
+      source.close()
 
       // This is an indirect hack to estimate the size of each query's input 
by traversing the
       // logical plan and adding up the sizes of all tables that appear in the 
plan.
@@ -65,9 +102,6 @@ trait CometTPCQueryBenchmarkBase extends SqlBasedBenchmark 
with CometTPCQueryBas
       benchmark.addCase(s"$name$nameSuffix") { _ =>
         cometSpark.sql(queryString).noop()
       }
-      benchmark.addCase(s"$name$nameSuffix") { _ =>
-        cometSpark.sql(queryString).noop()
-      }
       benchmark.addCase(s"$name$nameSuffix: Comet (Scan)") { _ =>
         withSQLConf(CometConf.COMET_ENABLED.key -> "true") {
           cometSpark.sql(queryString).noop()
@@ -84,4 +118,21 @@ trait CometTPCQueryBenchmarkBase extends SqlBasedBenchmark 
with CometTPCQueryBas
       benchmark.run()
     }
   }
+
+  override def runBenchmarkSuite(mainArgs: Array[String]): Unit = {
+    val benchmarkArgs = new TPCDSQueryBenchmarkArguments(mainArgs)
+
+    // If `--query-filter` defined, filters the queries that this option 
selects
+    val queriesToRun = filterQueries(queries, benchmarkArgs.queryFilter)
+
+    val tableSizes = setupTables(
+      benchmarkArgs.dataLocation,
+      createTempView = false,
+      tables,
+      TPCDSSchemaHelper.getTableColumns)
+
+    setupCBO(cometSpark, benchmarkArgs.cboEnabled, tables)
+
+    runQueries("tpcdsmicro", queries = queriesToRun, tableSizes, "TPCDS Micro 
Benchmarks")
+  }
 }
diff --git 
a/spark/src/test/scala/org/apache/spark/sql/benchmark/CometTPCQueryBenchmarkBase.scala
 
b/spark/src/test/scala/org/apache/spark/sql/benchmark/CometTPCQueryBenchmarkBase.scala
index d23d76fe..db4e8ca5 100644
--- 
a/spark/src/test/scala/org/apache/spark/sql/benchmark/CometTPCQueryBenchmarkBase.scala
+++ 
b/spark/src/test/scala/org/apache/spark/sql/benchmark/CometTPCQueryBenchmarkBase.scala
@@ -65,9 +65,6 @@ trait CometTPCQueryBenchmarkBase extends SqlBasedBenchmark 
with CometTPCQueryBas
       benchmark.addCase(s"$name$nameSuffix") { _ =>
         cometSpark.sql(queryString).noop()
       }
-      benchmark.addCase(s"$name$nameSuffix") { _ =>
-        cometSpark.sql(queryString).noop()
-      }
       benchmark.addCase(s"$name$nameSuffix: Comet (Scan)") { _ =>
         withSQLConf(CometConf.COMET_ENABLED.key -> "true") {
           cometSpark.sql(queryString).noop()


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to