Skip to content

Commit

Permalink
Merge pull request #6225 from xudong963/tpch_test
Browse files Browse the repository at this point in the history
feat(test): add tpch stateless-test
  • Loading branch information
BohuTANG authored Jun 25, 2022
2 parents e7bb1a2 + 57185ef commit 3f6c0bb
Show file tree
Hide file tree
Showing 47 changed files with 9,470 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/compat/test-compat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ run_test() {
)
suite_path="old_suite/tests/suites"
fi
./tests/databend-test --suites "$suite_path" --mode 'standalone' --run-dir 0_stateless -- 05_
./tests/databend-test --suites "$suite_path" --mode 'standalone' --run-dir 0_stateless -- '^05_*'
}

# -- main --
Expand Down
8 changes: 8 additions & 0 deletions tests/suites/0_stateless/13_tpch/13_0000_prepare.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
customer
lineitem
nation
orders
partsupp
part
region
supplier
106 changes: 106 additions & 0 deletions tests/suites/0_stateless/13_tpch/13_0000_prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/usr/bin/env bash

CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
. "$CURDIR"/../../../shell_env.sh


# create tpch tables
echo "CREATE TABLE IF NOT EXISTS nation
(
n_nationkey INTEGER not null,
n_name STRING not null,
n_regionkey INTEGER not null,
n_comment STRING
)" | $MYSQL_CLIENT_CONNECT

echo "CREATE TABLE IF NOT EXISTS region
(
r_regionkey INTEGER not null,
r_name STRING not null,
r_comment STRING
)" | $MYSQL_CLIENT_CONNECT

echo "CREATE TABLE IF NOT EXISTS part
(
p_partkey BIGINT not null,
p_name STRING not null,
p_mfgr STRING not null,
p_brand STRING not null,
p_type STRING not null,
p_size INTEGER not null,
p_container STRING not null,
p_retailprice DOUBLE not null,
p_comment STRING not null
)" | $MYSQL_CLIENT_CONNECT

echo "CREATE TABLE IF NOT EXISTS supplier
(
s_suppkey BIGINT not null,
s_name STRING not null,
s_address STRING not null,
s_nationkey INTEGER not null,
s_phone STRING not null,
s_acctbal DOUBLE not null,
s_comment STRING not null
)" | $MYSQL_CLIENT_CONNECT

echo "CREATE TABLE IF NOT EXISTS partsupp
(
ps_partkey BIGINT not null,
ps_suppkey BIGINT not null,
ps_availqty BIGINT not null,
ps_supplycost DOUBLE not null,
ps_comment STRING not null
)" | $MYSQL_CLIENT_CONNECT

echo "CREATE TABLE IF NOT EXISTS customer
(
c_custkey BIGINT not null,
c_name STRING not null,
c_address STRING not null,
c_nationkey INTEGER not null,
c_phone STRING not null,
c_acctbal DOUBLE not null,
c_mktsegment STRING not null,
c_comment STRING not null
)" | $MYSQL_CLIENT_CONNECT

echo "CREATE TABLE IF NOT EXISTS orders
(
o_orderkey BIGINT not null,
o_custkey BIGINT not null,
o_orderstatus STRING not null,
o_totalprice DOUBLE not null,
o_orderdate DATE not null,
o_orderpriority STRING not null,
o_clerk STRING not null,
o_shippriority INTEGER not null,
o_comment STRING not null
)" | $MYSQL_CLIENT_CONNECT

echo "CREATE TABLE IF NOT EXISTS lineitem
(
l_orderkey BIGINT not null,
l_partkey BIGINT not null,
l_suppkey BIGINT not null,
l_linenumber BIGINT not null,
l_quantity DOUBLE not null,
l_extendedprice DOUBLE not null,
l_discount DOUBLE not null,
l_tax DOUBLE not null,
l_returnflag STRING not null,
l_linestatus STRING not null,
l_shipdate DATE not null,
l_commitdate DATE not null,
l_receiptdate DATE not null,
l_shipinstruct STRING not null,
l_shipmode STRING not null,
l_comment STRING not null
)" | $MYSQL_CLIENT_CONNECT

# insert data to tables
for t in customer lineitem nation orders partsupp part region supplier
do
echo "$t"
curl -s -u root: -XPUT "http://localhost:${QUERY_HTTP_HANDLER_PORT}/v1/streaming_load" -H 'insert_sql: insert into '$t' format CSV' -H 'skip_header: 0' -H 'field_delimiter:|' -H 'record_delimiter: \n' -F 'upload=@"'${CURDIR}'/data/'$t'.tbl"' > /dev/null 2>&1
done
4 changes: 4 additions & 0 deletions tests/suites/0_stateless/13_tpch/13_0001_q1.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
A F 37474.0 37569624.63999998 35676192.096999995 37101416.22242404 25.354533152909337 25419.231826792948 0.050866035182679493 1478
N F 1041.0 1041301.07 999060.8979999998 1036450.80228 27.394736842105264 27402.659736842103 0.042894736842105284 38
N O 77372.0 77592631.4299997 73758104.09310009 76702028.45039181 25.518469656992085 25591.237279023644 0.04971635883905023 3032
R F 36511.0 36570841.24 34738472.87580004 36169060.11219294 25.059025394646532 25100.09693891558 0.050027453671928686 1457
22 changes: 22 additions & 0 deletions tests/suites/0_stateless/13_tpch/13_0001_q1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
set enable_planner_v2 = 1;
select
l_returnflag,
l_linestatus,
sum(l_quantity) as sum_qty,
sum(l_extendedprice) as sum_base_price,
sum(l_extendedprice * (1 - l_discount)) as sum_disc_price,
sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge,
avg(l_quantity) as avg_qty,
avg(l_extendedprice) as avg_price,
avg(l_discount) as avg_disc,
count(*) as count_order
from
lineitem
where
l_shipdate <= addDays(to_date('1998-12-01'), 90)
group by
l_returnflag,
l_linestatus
order by
l_returnflag,
l_linestatus;
Empty file.
44 changes: 44 additions & 0 deletions tests/suites/0_stateless/13_tpch/13_0002_q2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
set enable_planner_v2 = 1;
select
s_acctbal,
s_name,
n_name,
p_partkey,
p_mfgr,
s_address,
s_phone,
s_comment
from
part,
supplier,
partsupp,
nation,
region
where
p_partkey = ps_partkey
and s_suppkey = ps_suppkey
and p_size = 15
and p_type like '%BRASS'
and s_nationkey = n_nationkey
and n_regionkey = r_regionkey
and r_name = 'EUROPE'
and ps_supplycost = (
select
min(ps_supplycost)
from
partsupp,
supplier,
nation,
region
where
p_partkey = ps_partkey
and s_suppkey = ps_suppkey
and s_nationkey = n_nationkey
and n_regionkey = r_regionkey
and r_name = 'EUROPE'
)
order by
s_acctbal desc,
n_name,
s_name,
p_partkey;
5 changes: 5 additions & 0 deletions tests/suites/0_stateless/13_tpch/13_0003_q3.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1637 164224.9253 1995-02-08 0
5191 49378.309400000006 1994-12-11 0
742 43728.048 1994-12-23 0
3492 43716.072400000005 1994-11-24 0
2883 36666.9612 1995-01-23 0
24 changes: 24 additions & 0 deletions tests/suites/0_stateless/13_tpch/13_0003_q3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
set enable_planner_v2 = 1;
select
l_orderkey,
sum(l_extendedprice * (1 - l_discount)) as revenue,
o_orderdate,
o_shippriority
from
customer,
orders,
lineitem
where
c_mktsegment = 'BUILDING'
and c_custkey = o_custkey
and l_orderkey = o_orderkey
and o_orderdate < to_date('1995-03-15')
and l_shipdate > to_date('1995-03-15')
group by
l_orderkey,
o_orderdate,
o_shippriority
order by
revenue desc,
o_orderdate
limit 5;
5 changes: 5 additions & 0 deletions tests/suites/0_stateless/13_tpch/13_0004_q4.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1-URGENT 9
2-HIGH 7
3-MEDIUM 9
4-NOT SPECIFIED 8
5-LOW 12
22 changes: 22 additions & 0 deletions tests/suites/0_stateless/13_tpch/13_0004_q4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
set enable_planner_v2 = 1;
select
o_orderpriority,
count(*) as order_count
from
orders
where
o_orderdate >= to_date('1993-07-01')
and o_orderdate < addMonths(to_date('1993-07-01'), 3)
and exists (
select
*
from
lineitem
where
l_orderkey = o_orderkey
and l_commitdate < l_receiptdate
)
group by
o_orderpriority
order by
o_orderpriority;
Empty file.
25 changes: 25 additions & 0 deletions tests/suites/0_stateless/13_tpch/13_0005_q5.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
set enable_planner_v2 = 1;
select
n_name,
sum(l_extendedprice * (1 - l_discount)) as revenue
from
customer,
orders,
lineitem,
supplier,
nation,
region
where
c_custkey = o_custkey
and l_orderkey = o_orderkey
and l_suppkey = s_suppkey
and c_nationkey = s_nationkey
and s_nationkey = n_nationkey
and n_regionkey = r_regionkey
and r_name = 'ASIA'
and o_orderdate >= to_date('1994-01-01')
and o_orderdate < addYears(to_date('1994-01-01'), 1)
group by
n_name
order by
revenue desc;
Empty file.
40 changes: 40 additions & 0 deletions tests/suites/0_stateless/13_tpch/13_0007_q7.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
set enable_planner_v2 = 1;
select
supp_nation,
cust_nation,
l_year,
sum(volume) as revenue
from
(
select
n1.n_name as supp_nation,
n2.n_name as cust_nation,
extract(year from l_shipdate) as l_year,
l_extendedprice * (1 - l_discount) as volume
from
supplier,
lineitem,
orders,
customer,
nation n1,
nation n2
where
s_suppkey = l_suppkey
and o_orderkey = l_orderkey
and c_custkey = o_custkey
and s_nationkey = n1.n_nationkey
and c_nationkey = n2.n_nationkey
and (
(n1.n_name = 'FRANCE' and n2.n_name = 'GERMANY')
or (n1.n_name = 'GERMANY' and n2.n_name = 'FRANCE')
)
and l_shipdate between to_date('1995-01-01') and to_date('1996-12-31')
) as shipping
group by
supp_nation,
cust_nation,
l_year
order by
supp_nation,
cust_nation,
l_year;
2 changes: 2 additions & 0 deletions tests/suites/0_stateless/13_tpch/13_0008_q8.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1995 0.0
1996 0.0
38 changes: 38 additions & 0 deletions tests/suites/0_stateless/13_tpch/13_0008_q8.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
set enable_planner_v2 = 1;
select
o_year,
sum(case
when nation = 'BRAZIL' then volume
else 0
end) / sum(volume) as mkt_share
from
(
select
extract(year from o_orderdate) as o_year,
l_extendedprice * (1 - l_discount) as volume,
n2.n_name as nation
from
part,
supplier,
lineitem,
orders,
customer,
nation n1,
nation n2,
region
where
p_partkey = l_partkey
and s_suppkey = l_suppkey
and l_orderkey = o_orderkey
and o_custkey = c_custkey
and c_nationkey = n1.n_nationkey
and n1.n_regionkey = r_regionkey
and r_name = 'AMERICA'
and s_nationkey = n2.n_nationkey
and o_orderdate between to_date('1995-01-01') and to_date('1996-12-31')
and p_type = 'ECONOMY ANODIZED STEEL'
) as all_nations
group by
o_year
order by
o_year;
5 changes: 5 additions & 0 deletions tests/suites/0_stateless/13_tpch/13_0009_q9.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ARGENTINA 1998 17779.069700000007
ARGENTINA 1997 13943.953800000003
ARGENTINA 1996 7641.422700000003
ARGENTINA 1995 20892.7525
ARGENTINA 1994 15088.352599999998
Loading

0 comments on commit 3f6c0bb

Please sign in to comment.