Skip to content

TPC-DS-OBT Q14b

TPC-DS-OBT benchmark · all TPC-DS-OBT queries

Representative SQL

Rendered for DataFusion with default parameters.

WITH cross_items AS (
SELECT
item_i_item_sk
FROM (
SELECT DISTINCT
item_i_item_sk,
item_i_brand_id,
item_i_class_id,
item_i_category_id
FROM tpcds_sales_returns_obt
WHERE
NOT item_i_item_sk IS NULL
) AS i
JOIN (
SELECT
item_i_brand_id,
item_i_class_id,
item_i_category_id
FROM tpcds_sales_returns_obt
WHERE
channel = 'store' AND sold_date_d_year BETWEEN 1998 AND 1998 + 2
INTERSECT
SELECT
item_i_brand_id,
item_i_class_id,
item_i_category_id
FROM tpcds_sales_returns_obt
WHERE
channel = 'catalog' AND sold_date_d_year BETWEEN 1998 AND 1998 + 2
INTERSECT
SELECT
item_i_brand_id,
item_i_class_id,
item_i_category_id
FROM tpcds_sales_returns_obt
WHERE
channel = 'web' AND sold_date_d_year BETWEEN 1998 AND 1998 + 2
) AS x
ON i.item_i_brand_id = x.item_i_brand_id
AND i.item_i_class_id = x.item_i_class_id
AND i.item_i_category_id = x.item_i_category_id
), avg_sales AS (
SELECT
AVG(quantity * list_price) AS average_sales
FROM tpcds_sales_returns_obt
WHERE
sold_date_d_year BETWEEN 1998 AND 1998 + 2
), weekly AS (
SELECT
sold_date_d_week_seq AS week_seq,
item_i_brand_id AS i_brand_id,
item_i_class_id AS i_class_id,
item_i_category_id AS i_category_id,
SUM(quantity * list_price) AS sales,
COUNT(*) AS number_sales
FROM tpcds_sales_returns_obt
WHERE
channel = 'store'
AND item_sk IN (
SELECT
item_i_item_sk
FROM cross_items
)
AND sold_date_d_week_seq IN (
SELECT DISTINCT
sold_date_d_week_seq
FROM tpcds_sales_returns_obt
WHERE
sold_date_d_year IN (1998, 1998 + 1)
AND sold_date_d_moy = 12
AND sold_date_d_dom = 16
)
GROUP BY
sold_date_d_week_seq,
item_i_brand_id,
item_i_class_id,
item_i_category_id
HAVING
SUM(quantity * list_price) > (
SELECT
average_sales
FROM avg_sales
)
)
SELECT
this_year.channel AS ty_channel,
this_year.i_brand_id AS ty_brand,
this_year.i_class_id AS ty_class,
this_year.i_category_id AS ty_category,
this_year.sales AS ty_sales,
this_year.number_sales AS ty_number_sales,
last_year.channel AS ly_channel,
last_year.i_brand_id AS ly_brand,
last_year.i_class_id AS ly_class,
last_year.i_category_id AS ly_category,
last_year.sales AS ly_sales,
last_year.number_sales AS ly_number_sales
FROM (
SELECT
'store' AS channel,
w.*
FROM weekly AS w
WHERE
week_seq = (
SELECT DISTINCT
sold_date_d_week_seq
FROM tpcds_sales_returns_obt
WHERE
sold_date_d_year = 1998 + 1 AND sold_date_d_moy = 12 AND sold_date_d_dom = 16
)
) AS this_year, (
SELECT
'store' AS channel,
w.*
FROM weekly AS w
WHERE
week_seq = (
SELECT DISTINCT
sold_date_d_week_seq
FROM tpcds_sales_returns_obt
WHERE
sold_date_d_year = 1998 AND sold_date_d_moy = 12 AND sold_date_d_dom = 16
)
) AS last_year
WHERE
this_year.i_brand_id = last_year.i_brand_id
AND this_year.i_class_id = last_year.i_class_id
AND this_year.i_category_id = last_year.i_category_id
ORDER BY
this_year.channel,
this_year.i_brand_id,
this_year.i_class_id,
this_year.i_category_id
LIMIT 100

Representative DataFrame

No DataFrame implementation is registered for this query.

Get the exact query for your run

The blocks above are representative. To get the precise statement a specific platform runs at a specific scale, substitute your own values:

from benchbox import TPCDSOBT
bench = TPCDSOBT(scale_factor=1.0) # your scale factor
queries = bench.get_queries(dialect="datafusion") # your platform's dialect; drop dialect= for native SQL
print(queries['14b'])

Source

Query text: benchbox/core/tpcds_obt/queries.py