From 8d31745415abfeaf07cd5b397c5b7c63f3138481 Mon Sep 17 00:00:00 2001 From: Kikyou1997 <33112463+Kikyou1997@users.noreply.github.com> Date: Fri, 29 Jul 2022 10:45:36 +0800 Subject: [PATCH] [Regression](planner) Add tpch plan check (#11181) Add plan check for tpch so that we can sense any changes to the final plan opportunely. --- .licenserc.yaml | 1 + regression-test/script/README | 16 ++ .../script/plan_checker_generator.py | 188 ++++++++++++++++++ .../suites/tpch_sf1/explain/test_q1.groovy | 66 ++++++ .../suites/tpch_sf1/explain/test_q10.groovy | 98 +++++++++ .../suites/tpch_sf1/explain/test_q11.groovy | 110 ++++++++++ .../suites/tpch_sf1/explain/test_q12.groovy | 81 ++++++++ .../suites/tpch_sf1/explain/test_q13.groovy | 78 ++++++++ .../suites/tpch_sf1/explain/test_q14.groovy | 62 ++++++ .../suites/tpch_sf1/explain/test_q15.groovy | 91 +++++++++ .../suites/tpch_sf1/explain/test_q16.groovy | 90 +++++++++ .../suites/tpch_sf1/explain/test_q17.groovy | 80 ++++++++ .../suites/tpch_sf1/explain/test_q18.groovy | 109 ++++++++++ .../suites/tpch_sf1/explain/test_q19.groovy | 87 ++++++++ .../suites/tpch_sf1/explain/test_q2.groovy | 141 +++++++++++++ .../suites/tpch_sf1/explain/test_q20.groovy | 110 ++++++++++ .../suites/tpch_sf1/explain/test_q21.groovy | 122 ++++++++++++ .../suites/tpch_sf1/explain/test_q22.groovy | 95 +++++++++ .../suites/tpch_sf1/explain/test_q3.groovy | 84 ++++++++ .../suites/tpch_sf1/explain/test_q4.groovy | 72 +++++++ .../suites/tpch_sf1/explain/test_q5.groovy | 103 ++++++++++ .../suites/tpch_sf1/explain/test_q6.groovy | 52 +++++ .../suites/tpch_sf1/explain/test_q7.groovy | 119 +++++++++++ .../suites/tpch_sf1/explain/test_q8.groovy | 128 ++++++++++++ .../suites/tpch_sf1/explain/test_q9.groovy | 109 ++++++++++ regression-test/suites/tpch_sf1/load.groovy | 3 + 26 files changed, 2295 insertions(+) create mode 100644 regression-test/script/README create mode 100644 regression-test/script/plan_checker_generator.py create mode 100644 regression-test/suites/tpch_sf1/explain/test_q1.groovy create mode 100644 regression-test/suites/tpch_sf1/explain/test_q10.groovy create mode 100644 regression-test/suites/tpch_sf1/explain/test_q11.groovy create mode 100644 regression-test/suites/tpch_sf1/explain/test_q12.groovy create mode 100644 regression-test/suites/tpch_sf1/explain/test_q13.groovy create mode 100644 regression-test/suites/tpch_sf1/explain/test_q14.groovy create mode 100644 regression-test/suites/tpch_sf1/explain/test_q15.groovy create mode 100644 regression-test/suites/tpch_sf1/explain/test_q16.groovy create mode 100644 regression-test/suites/tpch_sf1/explain/test_q17.groovy create mode 100644 regression-test/suites/tpch_sf1/explain/test_q18.groovy create mode 100644 regression-test/suites/tpch_sf1/explain/test_q19.groovy create mode 100644 regression-test/suites/tpch_sf1/explain/test_q2.groovy create mode 100644 regression-test/suites/tpch_sf1/explain/test_q20.groovy create mode 100644 regression-test/suites/tpch_sf1/explain/test_q21.groovy create mode 100644 regression-test/suites/tpch_sf1/explain/test_q22.groovy create mode 100644 regression-test/suites/tpch_sf1/explain/test_q3.groovy create mode 100644 regression-test/suites/tpch_sf1/explain/test_q4.groovy create mode 100644 regression-test/suites/tpch_sf1/explain/test_q5.groovy create mode 100644 regression-test/suites/tpch_sf1/explain/test_q6.groovy create mode 100644 regression-test/suites/tpch_sf1/explain/test_q7.groovy create mode 100644 regression-test/suites/tpch_sf1/explain/test_q8.groovy create mode 100644 regression-test/suites/tpch_sf1/explain/test_q9.groovy diff --git a/.licenserc.yaml b/.licenserc.yaml index 9a8bf99264..595deb665f 100644 --- a/.licenserc.yaml +++ b/.licenserc.yaml @@ -61,5 +61,6 @@ header: - "docs/.vuepress/public/js/jquery.min.js" - "docs/.vuepress/public/js/wow.min.js" - "docs/package-lock.json" + - "regression-test/script/README" comment: on-failure diff --git a/regression-test/script/README b/regression-test/script/README new file mode 100644 index 0000000000..fdf1cdee1e --- /dev/null +++ b/regression-test/script/README @@ -0,0 +1,16 @@ +# Manual + +This script is used to generate any SQL plan checker groovy in batch. + +You need to pass two parameter to this script: + +* The path of the directory which contains the SQL files. +* The path of the directory where you expect to save the generated groovy test file,if there doesn't exists such directory, script would try to create it. + +Note that you must pass the parameters as above showed order. + +Below is a example: + +``` +python3 plan_checker_generator.py {YOUR_DORIS_HOME}/regression-test/suites/tpch_sf1/sql {YOUR_DORIS_HOME}/regression-test/suites/tpch_sf1/explain +``` diff --git a/regression-test/script/plan_checker_generator.py b/regression-test/script/plan_checker_generator.py new file mode 100644 index 0000000000..c3d38425af --- /dev/null +++ b/regression-test/script/plan_checker_generator.py @@ -0,0 +1,188 @@ +# 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. + +from curses.ascii import isalpha +import sys +import re +import os + +# line format is "sql_name, groovy_name" + +suite = """// 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. + +suite("test_explain_tpch_sf_1_q{}", "tpch_sf1") {{ + String realDb = context.config.getDbNameByFile(context.file) + // get parent directory's group + realDb = realDb.substring(0, realDb.lastIndexOf("_")) + + sql "use ${{realDb}}" +""" + +params = sys.argv + +sql_dir = params[1] + +output_dir = params[2] + +if not os.path.exists(output_dir): + os.mkdir(output_dir) + +sql_files = [f for f in os.listdir(sql_dir) if os.path.isfile(os.path.join(sql_dir, f))] + +sql_numbers = [re.findall(r'\d+', f)[0] for f in sql_files] + +output_files = [os.path.join(output_dir, 'test_'+x[1] + '.groovy') for x in zip(sql_files, sql_numbers)] + +sql_files_path = [os.path.join(sql_dir, p) for p in sql_files] + +tasks = zip(sql_files_path, output_files, sql_numbers) + +patterns = [ + 'order by.*$', + 'runtime filters.*$', + 'VTOP-N', + 'join op.*$', + 'equal join.*$', + 'TABLE.*$', + 'PREDICATES.*$', + 'output.*$', + 'other join predicates.*$', + 'other predicates.*$', + 'group by.*$', + 'VAGGREGATE.*$', + 'STREAMING', + 'cross join.*$', + 'predicates.*$', +] + +for task in tasks: + + print(task) + f1, f2, num = task + + f = open(f1, 'r') + oldsql = f.read() + f.close() + + f = open(f1, 'w') + f.write('explain\n' + oldsql + ';') + f.close() + + conn = 'mysql -h 127.0.0.1 -P 9030 -uroot regression_test_tpch_sf1 <' + + print(conn + f1) + + lines = os.popen(conn + f1).readlines() + + f = open(f1, 'w') + f.write(oldsql) + f.close() + + # print(oldsql) + + sqls = open(f1).readlines() + + print(len(lines)) + + res_pattern = [] + + res_g = [] + + for id, line in enumerate(lines): + lines[id] = line.rstrip('\n') + + res = [] + + cur = [] + for id, line in enumerate(lines): + # print(g) + line = line.replace('$','\$') + for p in patterns: + if len(re.findall(p, line)) > 0: #and line.find('null') == -1: + cur.append((line, id)) + + # print(cur) + res_g = [[cur[0][0]]] + for i in range(1, len(cur)): + if cur[i][1] == cur[i - 1][1] + 1: + res_g[-1].append(cur[i][0]) + else: + res_g.append([cur[i][0]]) + + for g in res_g: + s = g[0] + while not isalpha(s[0]): + s = s[1:] + g[0] = s + + explain_pattern = ''' + explainStr -> + explainStr.contains(''' + + explain_pattern1 = ''') && + explainStr.contains(''' + + chkstr = '' + for g in res_g: + chkstr = chkstr + '\t\t' + 'explainStr.contains("' + g[0] + if len(g) == 1: + chkstr = chkstr + '") && \n' + continue + else: + chkstr = chkstr + '\\n" + \n' + for s in g[1:-1]: + chkstr = chkstr + '\t\t\t\t"' + s + '\\n" + \n' + chkstr = chkstr + '\t\t\t\t"' + g[-1] + '") && \n' + + chkstr = chkstr[:-4] + pattern = ''' + explain { + sql """ +''' + pattern1 = ''' + """ + check { + explainStr -> +''' + + pattern2 = ''' + + } + } +}''' + + sql = '' + for line in sqls[1:]: + sql = sql + '\t\t' + line + + # print(suite.format(num) + pattern + sql + pattern1 + chkstr + pattern2) + open(f2, 'w').write(suite.format(num) + pattern + sql + pattern1 + chkstr + pattern2) \ No newline at end of file diff --git a/regression-test/suites/tpch_sf1/explain/test_q1.groovy b/regression-test/suites/tpch_sf1/explain/test_q1.groovy new file mode 100644 index 0000000000..65c7ac8b03 --- /dev/null +++ b/regression-test/suites/tpch_sf1/explain/test_q1.groovy @@ -0,0 +1,66 @@ +// 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. + +suite("test_explain_tpch_sf_1_q1", "tpch_sf1") { + String realDb = context.config.getDbNameByFile(context.file) + // get parent directory's group + realDb = realDb.substring(0, realDb.lastIndexOf("_")) + + sql "use ${realDb}" + + explain { + sql """ + 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 <= DATE '1998-12-01' - INTERVAL '90' DAY + GROUP BY + l_returnflag, + l_linestatus + ORDER BY + l_returnflag, + l_linestatus + + """ + check { + explainStr -> + explainStr.contains("VTOP-N\n" + + " | order by: `l_returnflag` ASC, `l_linestatus` ASC") && + explainStr.contains("VAGGREGATE (merge finalize)\n" + + " | output: sum( sum(`l_quantity`)), sum( sum(`l_extendedprice`)), sum( sum(`l_extendedprice` * (1 - `l_discount`))), sum( sum(`l_extendedprice` * (1 - `l_discount`) * (1 + `l_tax`))), avg( avg(`l_quantity`)), avg( avg(`l_extendedprice`)), avg( avg(`l_discount`)), count( count(*))\n" + + " | group by: `l_returnflag`, `l_linestatus`") && + explainStr.contains("VAGGREGATE (update serialize)\n" + + " | STREAMING\n" + + " | output: sum(`l_quantity`), sum(`l_extendedprice`), sum(`l_extendedprice` * (1 - `l_discount`)), sum(`l_extendedprice` * (1 - `l_discount`) * (1 + `l_tax`)), avg(`l_quantity`), avg(`l_extendedprice`), avg(`l_discount`), count(*)\n" + + " | group by: `l_returnflag`, `l_linestatus`") && + explainStr.contains("TABLE: lineitem(lineitem), PREAGGREGATION: ON\n" + + " PREDICATES: `l_shipdate` <= '1998-09-02 00:00:00'") + + } + } +} \ No newline at end of file diff --git a/regression-test/suites/tpch_sf1/explain/test_q10.groovy b/regression-test/suites/tpch_sf1/explain/test_q10.groovy new file mode 100644 index 0000000000..ae1267f94d --- /dev/null +++ b/regression-test/suites/tpch_sf1/explain/test_q10.groovy @@ -0,0 +1,98 @@ +// 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. + +suite("test_explain_tpch_sf_1_q10", "tpch_sf1") { + String realDb = context.config.getDbNameByFile(context.file) + // get parent directory's group + realDb = realDb.substring(0, realDb.lastIndexOf("_")) + + sql "use ${realDb}" + + explain { + sql """ + SELECT + c_custkey, + c_name, + sum(l_extendedprice * (1 - l_discount)) AS revenue, + c_acctbal, + n_name, + c_address, + c_phone, + c_comment + FROM + customer, + orders, + lineitem, + nation + WHERE + c_custkey = o_custkey + AND l_orderkey = o_orderkey + AND o_orderdate >= DATE '1993-10-01' + AND o_orderdate < DATE '1993-10-01' + INTERVAL '3' MONTH + AND l_returnflag = 'R' + AND c_nationkey = n_nationkey + GROUP BY + c_custkey, + c_name, + c_acctbal, + c_phone, + n_name, + c_address, + c_comment + ORDER BY + revenue DESC + LIMIT 20 + + """ + check { + explainStr -> + explainStr.contains("VTOP-N\n" + + " | order by: sum(`l_extendedprice` * (1 - `l_discount`)) DESC") && + explainStr.contains("VAGGREGATE (merge finalize)\n" + + " | output: sum( sum(`l_extendedprice` * (1 - `l_discount`)))\n" + + " | group by: `c_custkey`, `c_name`, `c_acctbal`, `c_phone`, `n_name`, `c_address`, `c_comment`") && + explainStr.contains("VAGGREGATE (update serialize)\n" + + " | STREAMING\n" + + " | output: sum( * (1 - ))\n" + + " | group by: , , , , , , ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `n_nationkey`") && + explainStr.contains("vec output tuple id: 8") && + explainStr.contains("output slot ids: 53 54 60 61 62 63 64 65 67 \n" + + " | hash output slot ids: 48 49 50 51 5 39 40 46 47 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `c_custkey`") && + explainStr.contains("vec output tuple id: 7") && + explainStr.contains("output slot ids: 39 40 46 47 48 49 50 51 52 \n" + + " | hash output slot ids: 32 0 33 1 4 6 7 8 14 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[Tables are not in the same group]\n" + + " | equal join conjunct: `l_orderkey` = `o_orderkey`\n" + + " | runtime filters: RF000[in_or_bloom] <- `o_orderkey`") && + explainStr.contains("vec output tuple id: 6") && + explainStr.contains("output slot ids: 32 33 36 \n" + + " | hash output slot ids: 2 3 9 ") && + explainStr.contains("TABLE: lineitem(lineitem), PREAGGREGATION: ON\n" + + " PREDICATES: `l_returnflag` = 'R'\n" + + " runtime filters: RF000[in_or_bloom] -> `l_orderkey`") && + explainStr.contains("TABLE: nation(nation), PREAGGREGATION: ON") && + explainStr.contains("TABLE: customer(customer), PREAGGREGATION: ON") && + explainStr.contains("TABLE: orders(orders), PREAGGREGATION: ON\n" + + " PREDICATES: `o_orderdate` >= '1993-10-01 00:00:00', `o_orderdate` < '1994-01-01 00:00:00'") + + } + } +} \ No newline at end of file diff --git a/regression-test/suites/tpch_sf1/explain/test_q11.groovy b/regression-test/suites/tpch_sf1/explain/test_q11.groovy new file mode 100644 index 0000000000..258c0fa230 --- /dev/null +++ b/regression-test/suites/tpch_sf1/explain/test_q11.groovy @@ -0,0 +1,110 @@ +// 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. + +suite("test_explain_tpch_sf_1_q11", "tpch_sf1") { + String realDb = context.config.getDbNameByFile(context.file) + // get parent directory's group + realDb = realDb.substring(0, realDb.lastIndexOf("_")) + + sql "use ${realDb}" + + explain { + sql """ + SELECT + ps_partkey, + sum(ps_supplycost * ps_availqty) AS value + FROM + partsupp, + supplier, + nation + WHERE + ps_suppkey = s_suppkey + AND s_nationkey = n_nationkey + AND n_name = 'GERMANY' + GROUP BY + ps_partkey + HAVING + sum(ps_supplycost * ps_availqty) > ( + SELECT sum(ps_supplycost * ps_availqty) * 0.0001 + FROM + partsupp, + supplier, + nation + WHERE + ps_suppkey = s_suppkey + AND s_nationkey = n_nationkey + AND n_name = 'GERMANY' + ) + ORDER BY + value DESC + + """ + check { + explainStr -> + explainStr.contains("VTOP-N\n" + + " | order by: `\$a\$1`.`\$c\$2` DESC") && + explainStr.contains("cross join:\n" + + " | predicates: sum(`ps_supplycost` * `ps_availqty`) > sum(`ps_supplycost` * `ps_availqty`) * 0.0001") && + explainStr.contains("VAGGREGATE (merge finalize)\n" + + " | output: sum( sum(`ps_supplycost` * `ps_availqty`))\n" + + " | group by: `ps_partkey`") && + explainStr.contains("VAGGREGATE (merge finalize)\n" + + " | output: sum( sum(`ps_supplycost` * `ps_availqty`))\n" + + " | group by: ") && + explainStr.contains("VAGGREGATE (update serialize)\n" + + " | output: sum( * )\n" + + " | group by: ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `n_nationkey`") && + explainStr.contains("vec output tuple id: 15") && + explainStr.contains("output slot ids: 43 44 \n" + + " | hash output slot ids: 38 39 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[Tables are not in the same group]\n" + + " | equal join conjunct: `ps_suppkey` = `s_suppkey`\n" + + " | runtime filters: RF001[in_or_bloom] <- `s_suppkey`") && + explainStr.contains("vec output tuple id: 14") && + explainStr.contains("output slot ids: 38 39 42 \n" + + " | hash output slot ids: 16 12 13 ") && + explainStr.contains("TABLE: partsupp(partsupp), PREAGGREGATION: ON\n" + + " runtime filters: RF001[in_or_bloom] -> `ps_suppkey`") && + explainStr.contains("TABLE: nation(nation), PREAGGREGATION: ON\n" + + " PREDICATES: `n_name` = 'GERMANY'") && + explainStr.contains("TABLE: supplier(supplier), PREAGGREGATION: ON") && + explainStr.contains("VAGGREGATE (update serialize)\n" + + " | STREAMING\n" + + " | output: sum( * )\n" + + " | group by: ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `n_nationkey`") && + explainStr.contains("vec output tuple id: 13") && + explainStr.contains("output slot ids: 30 31 32 \n" + + " | hash output slot ids: 24 25 26 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[Tables are not in the same group]\n" + + " | equal join conjunct: `ps_suppkey` = `s_suppkey`\n" + + " | runtime filters: RF000[in_or_bloom] <- `s_suppkey`") && + explainStr.contains("vec output tuple id: 12") && + explainStr.contains("output slot ids: 24 25 26 29 \n" + + " | hash output slot ids: 0 1 2 5 ") && + explainStr.contains("TABLE: partsupp(partsupp), PREAGGREGATION: ON\n" + + " runtime filters: RF000[in_or_bloom] -> `ps_suppkey`") && + explainStr.contains("TABLE: nation(nation), PREAGGREGATION: ON\n" + + " PREDICATES: `n_name` = 'GERMANY'") && + explainStr.contains("TABLE: supplier(supplier), PREAGGREGATION: ON") + + } + } +} \ No newline at end of file diff --git a/regression-test/suites/tpch_sf1/explain/test_q12.groovy b/regression-test/suites/tpch_sf1/explain/test_q12.groovy new file mode 100644 index 0000000000..4e9d900e69 --- /dev/null +++ b/regression-test/suites/tpch_sf1/explain/test_q12.groovy @@ -0,0 +1,81 @@ +// 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. + +suite("test_explain_tpch_sf_1_q12", "tpch_sf1") { + String realDb = context.config.getDbNameByFile(context.file) + // get parent directory's group + realDb = realDb.substring(0, realDb.lastIndexOf("_")) + + sql "use ${realDb}" + + explain { + sql """ + SELECT + l_shipmode, + sum(CASE + WHEN o_orderpriority = '1-URGENT' + OR o_orderpriority = '2-HIGH' + THEN 1 + ELSE 0 + END) AS high_line_count, + sum(CASE + WHEN o_orderpriority <> '1-URGENT' + AND o_orderpriority <> '2-HIGH' + THEN 1 + ELSE 0 + END) AS low_line_count + FROM + orders, + lineitem + WHERE + o_orderkey = l_orderkey + AND l_shipmode IN ('MAIL', 'SHIP') + AND l_commitdate < l_receiptdate + AND l_shipdate < l_commitdate + AND l_receiptdate >= DATE '1994-01-01' + AND l_receiptdate < DATE '1994-01-01' + INTERVAL '1' YEAR + GROUP BY + l_shipmode + ORDER BY + l_shipmode + + """ + check { + explainStr -> + explainStr.contains("VTOP-N\n" + + " | order by: `l_shipmode` ASC") && + explainStr.contains("VAGGREGATE (merge finalize)\n" + + " | output: sum( sum(CASE WHEN ((`o_orderpriority` = '1-URGENT' OR `o_orderpriority` = '2-HIGH') AND (`o_orderpriority` = '1-URGENT' OR `o_orderpriority` = '2-HIGH')) THEN 1 ELSE 0 END)), sum( sum(CASE WHEN `o_orderpriority` != '1-URGENT' AND `o_orderpriority` != '2-HIGH' THEN 1 ELSE 0 END))\n" + + " | group by: `l_shipmode`") && + explainStr.contains("VAGGREGATE (update serialize)\n" + + " | STREAMING\n" + + " | output: sum(CASE WHEN (( = '1-URGENT' OR = '2-HIGH') AND ( = '1-URGENT' OR = '2-HIGH')) THEN 1 ELSE 0 END), sum(CASE WHEN != '1-URGENT' AND != '2-HIGH' THEN 1 ELSE 0 END)\n" + + " | group by: ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[Tables are not in the same group]\n" + + " | equal join conjunct: `l_orderkey` = `o_orderkey`\n" + + " | runtime filters: RF000[in_or_bloom] <- `o_orderkey`") && + explainStr.contains("vec output tuple id: 4") && + explainStr.contains("output slot ids: 13 18 \n" + + " | hash output slot ids: 0 1 ") && + explainStr.contains("TABLE: lineitem(lineitem), PREAGGREGATION: ON\n" + + " PREDICATES: `l_shipmode` IN ('MAIL', 'SHIP'), `l_commitdate` < `l_receiptdate`, `l_shipdate` < `l_commitdate`, `l_receiptdate` >= '1994-01-01 00:00:00', `l_receiptdate` < '1995-01-01 00:00:00'\n" + + " runtime filters: RF000[in_or_bloom] -> `l_orderkey`") && + explainStr.contains("TABLE: orders(orders), PREAGGREGATION: ON") + + } + } +} \ No newline at end of file diff --git a/regression-test/suites/tpch_sf1/explain/test_q13.groovy b/regression-test/suites/tpch_sf1/explain/test_q13.groovy new file mode 100644 index 0000000000..cf3c98f2eb --- /dev/null +++ b/regression-test/suites/tpch_sf1/explain/test_q13.groovy @@ -0,0 +1,78 @@ +// 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. + +suite("test_explain_tpch_sf_1_q13", "tpch_sf1") { + String realDb = context.config.getDbNameByFile(context.file) + // get parent directory's group + realDb = realDb.substring(0, realDb.lastIndexOf("_")) + + sql "use ${realDb}" + + explain { + sql """ + SELECT + c_count, + count(*) AS custdist + FROM ( + SELECT + c_custkey, + count(o_orderkey) AS c_count + FROM + customer + LEFT OUTER JOIN orders ON + c_custkey = o_custkey + AND o_comment NOT LIKE '%special%requests%' + GROUP BY + c_custkey + ) AS c_orders + GROUP BY + c_count + ORDER BY + custdist DESC, + c_count DESC + + """ + check { + explainStr -> + explainStr.contains("VTOP-N\n" + + " | order by: count(*) DESC, `c_count` DESC") && + explainStr.contains("VAGGREGATE (merge finalize)\n" + + " | output: count( count(*))\n" + + " | group by: `c_count`") && + explainStr.contains("VAGGREGATE (update serialize)\n" + + " | STREAMING\n" + + " | output: count(*)\n" + + " | group by: count(`o_orderkey`)") && + explainStr.contains("VAGGREGATE (merge finalize)\n" + + " | output: count( count(`o_orderkey`))\n" + + " | group by: `c_custkey`") && + explainStr.contains("VAGGREGATE (update serialize)\n" + + " | STREAMING\n" + + " | output: count()\n" + + " | group by: ") && + explainStr.contains("join op: LEFT OUTER JOIN(BROADCAST)[Tables are not in the same group]\n" + + " | equal join conjunct: `c_custkey` = `o_custkey`") && + explainStr.contains("vec output tuple id: 6") && + explainStr.contains("output slot ids: 12 15 \n" + + " | hash output slot ids: 0 3 ") && + explainStr.contains("TABLE: customer(customer), PREAGGREGATION: ON") && + explainStr.contains("TABLE: orders(orders), PREAGGREGATION: ON\n" + + " PREDICATES: NOT `o_comment` LIKE '%special%requests%'") + + } + } +} \ No newline at end of file diff --git a/regression-test/suites/tpch_sf1/explain/test_q14.groovy b/regression-test/suites/tpch_sf1/explain/test_q14.groovy new file mode 100644 index 0000000000..c8edaa3241 --- /dev/null +++ b/regression-test/suites/tpch_sf1/explain/test_q14.groovy @@ -0,0 +1,62 @@ +// 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. + +suite("test_explain_tpch_sf_1_q14", "tpch_sf1") { + String realDb = context.config.getDbNameByFile(context.file) + // get parent directory's group + realDb = realDb.substring(0, realDb.lastIndexOf("_")) + + sql "use ${realDb}" + + explain { + sql """ + SELECT 100.00 * sum(CASE + WHEN p_type LIKE 'PROMO%' + THEN l_extendedprice * (1 - l_discount) + ELSE 0 + END) / sum(l_extendedprice * (1 - l_discount)) AS promo_revenue + FROM + lineitem, + part + WHERE + l_partkey = p_partkey + AND l_shipdate >= DATE '1995-09-01' + AND l_shipdate < DATE '1995-09-01' + INTERVAL '1' MONTH + + """ + check { + explainStr -> + explainStr.contains("VAGGREGATE (merge finalize)\n" + + " | output: sum( sum(CASE WHEN `p_type` LIKE 'PROMO%' THEN `l_extendedprice` * (1 - `l_discount`) ELSE 0 END)), sum( sum(`l_extendedprice` * (1 - `l_discount`)))\n" + + " | group by: ") && + explainStr.contains("VAGGREGATE (update serialize)\n" + + " | output: sum(CASE WHEN LIKE 'PROMO%' THEN * (1 - ) ELSE 0 END), sum( * (1 - ))\n" + + " | group by: ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[Tables are not in the same group]\n" + + " | equal join conjunct: `l_partkey` = `p_partkey`\n" + + " | runtime filters: RF000[in_or_bloom] <- `p_partkey`") && + explainStr.contains("vec output tuple id: 4") && + explainStr.contains("output slot ids: 10 11 14 \n" + + " | hash output slot ids: 0 1 2 ") && + explainStr.contains("TABLE: lineitem(lineitem), PREAGGREGATION: ON\n" + + " PREDICATES: `l_shipdate` >= '1995-09-01 00:00:00', `l_shipdate` < '1995-10-01 00:00:00'\n" + + " runtime filters: RF000[in_or_bloom] -> `l_partkey`") && + explainStr.contains("TABLE: part(part), PREAGGREGATION: ON") + + } + } +} \ No newline at end of file diff --git a/regression-test/suites/tpch_sf1/explain/test_q15.groovy b/regression-test/suites/tpch_sf1/explain/test_q15.groovy new file mode 100644 index 0000000000..b01a160216 --- /dev/null +++ b/regression-test/suites/tpch_sf1/explain/test_q15.groovy @@ -0,0 +1,91 @@ +// 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. + +suite("test_explain_tpch_sf_1_q15", "tpch_sf1") { + String realDb = context.config.getDbNameByFile(context.file) + // get parent directory's group + realDb = realDb.substring(0, realDb.lastIndexOf("_")) + + sql "use ${realDb}" + + explain { + sql """ + SELECT + s_suppkey, + s_name, + s_address, + s_phone, + total_revenue + FROM + supplier, + revenue1 + WHERE + s_suppkey = supplier_no + AND total_revenue = ( + SELECT max(total_revenue) + FROM + revenue1 + ) + ORDER BY + s_suppkey; + + """ + check { + explainStr -> + explainStr.contains("VTOP-N\n" + + " | order by: `s_suppkey` ASC") && + explainStr.contains("join op: LEFT SEMI JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = max(`total_revenue`)") && + explainStr.contains("vec output tuple id: 12") && + explainStr.contains("output slot ids: 34 35 36 37 39 \n" + + " | hash output slot ids: 33 28 29 30 31 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: `s_suppkey` = `l_suppkey`\n" + + " | runtime filters: RF000[in_or_bloom] <- `l_suppkey`") && + explainStr.contains("vec output tuple id: 11") && + explainStr.contains("output slot ids: 28 29 30 31 33 \n" + + " | hash output slot ids: 19 20 21 5 22 ") && + explainStr.contains("TABLE: supplier(supplier), PREAGGREGATION: ON\n" + + " runtime filters: RF000[in_or_bloom] -> `s_suppkey`") && + explainStr.contains("VAGGREGATE (merge finalize)\n" + + " | output: max( max(`total_revenue`))\n" + + " | group by: ") && + explainStr.contains("VAGGREGATE (update serialize)\n" + + " | output: max( sum(`l_extendedprice` * (1 - `l_discount`)))\n" + + " | group by: ") && + explainStr.contains("VAGGREGATE (merge finalize)\n" + + " | output: sum( sum(`l_extendedprice` * (1 - `l_discount`)))\n" + + " | group by: `l_suppkey`") && + explainStr.contains("VAGGREGATE (update serialize)\n" + + " | STREAMING\n" + + " | output: sum(`l_extendedprice` * (1 - `l_discount`))\n" + + " | group by: `l_suppkey`") && + explainStr.contains("TABLE: lineitem(lineitem), PREAGGREGATION: ON\n" + + " PREDICATES: `l_shipdate` >= '1996-01-01 00:00:00', `l_shipdate` < '1996-04-01 00:00:00'") && + explainStr.contains("VAGGREGATE (merge finalize)\n" + + " | output: sum( sum(`l_extendedprice` * (1 - `l_discount`)))\n" + + " | group by: `l_suppkey`") && + explainStr.contains("VAGGREGATE (update serialize)\n" + + " | STREAMING\n" + + " | output: sum(`l_extendedprice` * (1 - `l_discount`))\n" + + " | group by: `l_suppkey`") && + explainStr.contains("TABLE: lineitem(lineitem), PREAGGREGATION: ON\n" + + " PREDICATES: `l_shipdate` >= '1996-01-01 00:00:00', `l_shipdate` < '1996-04-01 00:00:00'") + + } + } +} \ No newline at end of file diff --git a/regression-test/suites/tpch_sf1/explain/test_q16.groovy b/regression-test/suites/tpch_sf1/explain/test_q16.groovy new file mode 100644 index 0000000000..aa434b6177 --- /dev/null +++ b/regression-test/suites/tpch_sf1/explain/test_q16.groovy @@ -0,0 +1,90 @@ +// 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. + +suite("test_explain_tpch_sf_1_q16", "tpch_sf1") { + String realDb = context.config.getDbNameByFile(context.file) + // get parent directory's group + realDb = realDb.substring(0, realDb.lastIndexOf("_")) + + sql "use ${realDb}" + + explain { + sql """ + SELECT + p_brand, + p_type, + p_size, + count(DISTINCT ps_suppkey) AS supplier_cnt + FROM + partsupp, + part + WHERE + p_partkey = ps_partkey + AND p_brand <> 'Brand#45' + AND p_type NOT LIKE 'MEDIUM POLISHED%' + AND p_size IN (49, 14, 23, 45, 19, 3, 36, 9) + AND ps_suppkey NOT IN ( + SELECT s_suppkey + FROM + supplier + WHERE + s_comment LIKE '%Customer%Complaints%' + ) + GROUP BY + p_brand, + p_type, + p_size + ORDER BY + supplier_cnt DESC, + p_brand, + p_type, + p_size + + """ + check { + explainStr -> + explainStr.contains("VTOP-N\n" + + " | order by: count( `ps_suppkey`) DESC, `p_brand` ASC, `p_type` ASC, `p_size` ASC") && + explainStr.contains("VAGGREGATE (update finalize)\n" + + " | output: count( `ps_suppkey`)\n" + + " | group by: `p_brand`, `p_type`, `p_size`") && + explainStr.contains("VAGGREGATE (merge serialize)\n" + + " | group by: `p_brand`, `p_type`, `p_size`, `ps_suppkey`") && + explainStr.contains("VAGGREGATE (update serialize)\n" + + " | STREAMING\n" + + " | group by: , , , ") && + explainStr.contains("join op: LEFT ANTI JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `s_suppkey`") && + explainStr.contains("vec output tuple id: 8") && + explainStr.contains("output slot ids: 27 29 30 31 \n" + + " | hash output slot ids: 21 23 24 25 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[Tables are not in the same group]\n" + + " | equal join conjunct: `ps_partkey` = `p_partkey`\n" + + " | runtime filters: RF000[in_or_bloom] <- `p_partkey`") && + explainStr.contains("vec output tuple id: 7") && + explainStr.contains("output slot ids: 21 23 24 25 \n" + + " | hash output slot ids: 3 4 5 6 ") && + explainStr.contains("TABLE: partsupp(partsupp), PREAGGREGATION: ON\n" + + " runtime filters: RF000[in_or_bloom] -> `ps_partkey`") && + explainStr.contains("TABLE: supplier(supplier), PREAGGREGATION: ON\n" + + " PREDICATES: `s_comment` LIKE '%Customer%Complaints%'") && + explainStr.contains("TABLE: part(part), PREAGGREGATION: ON\n" + + " PREDICATES: `p_brand` != 'Brand#45', NOT `p_type` LIKE 'MEDIUM POLISHED%', `p_size` IN (49, 14, 23, 45, 19, 3, 36, 9)") + + } + } +} \ No newline at end of file diff --git a/regression-test/suites/tpch_sf1/explain/test_q17.groovy b/regression-test/suites/tpch_sf1/explain/test_q17.groovy new file mode 100644 index 0000000000..52c184b301 --- /dev/null +++ b/regression-test/suites/tpch_sf1/explain/test_q17.groovy @@ -0,0 +1,80 @@ +// 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. + +suite("test_explain_tpch_sf_1_q17", "tpch_sf1") { + String realDb = context.config.getDbNameByFile(context.file) + // get parent directory's group + realDb = realDb.substring(0, realDb.lastIndexOf("_")) + + sql "use ${realDb}" + + explain { + sql """ + SELECT sum(l_extendedprice) / 7.0 AS avg_yearly + FROM + lineitem, + part + WHERE + p_partkey = l_partkey + AND p_brand = 'Brand#23' + AND p_container = 'MED BOX' + AND l_quantity < ( + SELECT 0.2 * avg(l_quantity) + FROM + lineitem + WHERE + l_partkey = p_partkey + ) + + """ + check { + explainStr -> + explainStr.contains("VAGGREGATE (merge finalize)\n" + + " | output: sum( sum(`l_extendedprice`))\n" + + " | group by: ") && + explainStr.contains("VAGGREGATE (update serialize)\n" + + " | output: sum()\n" + + " | group by: ") && + explainStr.contains("join op: LEFT SEMI JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `l_partkey`\n" + + " | other join predicates: < 0.2 * ") && + explainStr.contains("other join predicates: < 0.2 * ") && + explainStr.contains("vec output tuple id: 8") && + explainStr.contains("output slot ids: 21 \n" + + " | hash output slot ids: 3 14 15 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[Tables are not in the same group]\n" + + " | equal join conjunct: `l_partkey` = `p_partkey`\n" + + " | runtime filters: RF000[in_or_bloom] <- `p_partkey`") && + explainStr.contains("vec output tuple id: 7") && + explainStr.contains("output slot ids: 14 15 17 \n" + + " | hash output slot ids: 6 7 8 ") && + explainStr.contains("TABLE: lineitem(lineitem), PREAGGREGATION: ON\n" + + " runtime filters: RF000[in_or_bloom] -> `l_partkey`") && + explainStr.contains("VAGGREGATE (merge finalize)\n" + + " | output: avg( avg(`l_quantity`))\n" + + " | group by: `l_partkey`") && + explainStr.contains("VAGGREGATE (update serialize)\n" + + " | STREAMING\n" + + " | output: avg(`l_quantity`)\n" + + " | group by: `l_partkey`") && + explainStr.contains("TABLE: lineitem(lineitem), PREAGGREGATION: ON") && + explainStr.contains("TABLE: part(part), PREAGGREGATION: ON\n" + + " PREDICATES: `p_brand` = 'Brand#23', `p_container` = 'MED BOX'") + + } + } +} \ No newline at end of file diff --git a/regression-test/suites/tpch_sf1/explain/test_q18.groovy b/regression-test/suites/tpch_sf1/explain/test_q18.groovy new file mode 100644 index 0000000000..50cf426a99 --- /dev/null +++ b/regression-test/suites/tpch_sf1/explain/test_q18.groovy @@ -0,0 +1,109 @@ +// 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. + +suite("test_explain_tpch_sf_1_q18", "tpch_sf1") { + String realDb = context.config.getDbNameByFile(context.file) + // get parent directory's group + realDb = realDb.substring(0, realDb.lastIndexOf("_")) + + sql "use ${realDb}" + + explain { + sql """ + SELECT + c_name, + c_custkey, + o_orderkey, + o_orderdate, + o_totalprice, + sum(l_quantity) + FROM + customer, + orders, + lineitem + WHERE + o_orderkey IN ( + SELECT l_orderkey + FROM + lineitem + GROUP BY + l_orderkey + HAVING + sum(l_quantity) > 300 + ) + AND c_custkey = o_custkey + AND o_orderkey = l_orderkey + GROUP BY + c_name, + c_custkey, + o_orderkey, + o_orderdate, + o_totalprice + ORDER BY + o_totalprice DESC, + o_orderdate + LIMIT 100 + + """ + check { + explainStr -> + explainStr.contains("VTOP-N\n" + + " | order by: `o_totalprice` DESC, `o_orderdate` ASC") && + explainStr.contains("VAGGREGATE (merge finalize)\n" + + " | output: sum( sum(`l_quantity`))\n" + + " | group by: `c_name`, `c_custkey`, `o_orderkey`, `o_orderdate`, `o_totalprice`") && + explainStr.contains("VAGGREGATE (update serialize)\n" + + " | STREAMING\n" + + " | output: sum()\n" + + " | group by: , , , , ") && + explainStr.contains("join op: LEFT SEMI JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `l_orderkey`") && + explainStr.contains("vec output tuple id: 14") && + explainStr.contains("output slot ids: 53 54 55 56 58 59 \n" + + " | hash output slot ids: 48 50 51 45 46 47 ") && + explainStr.contains("join op: LEFT SEMI JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `l_orderkey`") && + explainStr.contains("vec output tuple id: 13") && + explainStr.contains("output slot ids: 44 45 46 47 48 50 51 \n" + + " | hash output slot ids: 36 37 38 39 40 42 43 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `c_custkey`") && + explainStr.contains("vec output tuple id: 12") && + explainStr.contains("output slot ids: 36 37 38 39 40 42 43 \n" + + " | hash output slot ids: 32 33 34 12 13 30 31 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[Tables are not in the same group]\n" + + " | equal join conjunct: `l_orderkey` = `o_orderkey`\n" + + " | runtime filters: RF000[in_or_bloom] <- `o_orderkey`") && + explainStr.contains("vec output tuple id: 11") && + explainStr.contains("output slot ids: 30 31 32 33 34 35 \n" + + " | hash output slot ids: 16 17 5 11 14 15 ") && + explainStr.contains("TABLE: lineitem(lineitem), PREAGGREGATION: ON\n" + + " runtime filters: RF000[in_or_bloom] -> `l_orderkey`") && + explainStr.contains("VAGGREGATE (update finalize)\n" + + " | output: sum(`l_quantity`)\n" + + " | group by: `l_orderkey`") && + explainStr.contains("TABLE: lineitem(lineitem), PREAGGREGATION: ON") && + explainStr.contains("VAGGREGATE (update finalize)\n" + + " | output: sum(`l_quantity`)\n" + + " | group by: `l_orderkey`") && + explainStr.contains("TABLE: lineitem(lineitem), PREAGGREGATION: ON") && + explainStr.contains("TABLE: customer(customer), PREAGGREGATION: ON") && + explainStr.contains("TABLE: orders(orders), PREAGGREGATION: ON") + + } + } +} \ No newline at end of file diff --git a/regression-test/suites/tpch_sf1/explain/test_q19.groovy b/regression-test/suites/tpch_sf1/explain/test_q19.groovy new file mode 100644 index 0000000000..692656d75e --- /dev/null +++ b/regression-test/suites/tpch_sf1/explain/test_q19.groovy @@ -0,0 +1,87 @@ +// 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. + +suite("test_explain_tpch_sf_1_q19", "tpch_sf1") { + String realDb = context.config.getDbNameByFile(context.file) + // get parent directory's group + realDb = realDb.substring(0, realDb.lastIndexOf("_")) + + sql "use ${realDb}" + + explain { + sql """ + SELECT sum(l_extendedprice * (1 - l_discount)) AS revenue + FROM + lineitem, + part + WHERE + ( + p_partkey = l_partkey + AND p_brand = 'Brand#12' + AND p_container IN ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG') + AND l_quantity >= 1 AND l_quantity <= 1 + 10 + AND p_size BETWEEN 1 AND 5 + AND l_shipmode IN ('AIR', 'AIR REG') + AND l_shipinstruct = 'DELIVER IN PERSON' + ) + OR + ( + p_partkey = l_partkey + AND p_brand = 'Brand#23' + AND p_container IN ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK') + AND l_quantity >= 10 AND l_quantity <= 10 + 10 + AND p_size BETWEEN 1 AND 10 + AND l_shipmode IN ('AIR', 'AIR REG') + AND l_shipinstruct = 'DELIVER IN PERSON' + ) + OR + ( + p_partkey = l_partkey + AND p_brand = 'Brand#34' + AND p_container IN ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG') + AND l_quantity >= 20 AND l_quantity <= 20 + 10 + AND p_size BETWEEN 1 AND 15 + AND l_shipmode IN ('AIR', 'AIR REG') + AND l_shipinstruct = 'DELIVER IN PERSON' + ) + + """ + check { + explainStr -> + explainStr.contains("VAGGREGATE (merge finalize)\n" + + " | output: sum( sum(`l_extendedprice` * (1 - `l_discount`)))\n" + + " | group by: ") && + explainStr.contains("VAGGREGATE (update serialize)\n" + + " | output: sum( * (1 - ))\n" + + " | group by: ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[Tables are not in the same group]\n" + + " | equal join conjunct: `l_partkey` = `p_partkey`\n" + + " | other predicates: (( = 'Brand#12' AND IN ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG') AND >= 1 AND <= 11 AND <= 5) OR ( = 'Brand#23' AND IN ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK') AND >= 10 AND <= 20 AND <= 10) OR ( = 'Brand#34' AND IN ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG') AND >= 20 AND <= 30 AND <= 15))") && + explainStr.contains("other predicates: (( = 'Brand#12' AND IN ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG') AND >= 1 AND <= 11 AND <= 5) OR ( = 'Brand#23' AND IN ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK') AND >= 10 AND <= 20 AND <= 10) OR ( = 'Brand#34' AND IN ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG') AND >= 20 AND <= 30 AND <= 15))\n" + + " | runtime filters: RF000[in_or_bloom] <- `p_partkey`") && + explainStr.contains("vec output tuple id: 4") && + explainStr.contains("output slot ids: 12 13 \n" + + " | hash output slot ids: 0 1 4 7 8 9 ") && + explainStr.contains("TABLE: lineitem(lineitem), PREAGGREGATION: ON\n" + + " PREDICATES: `l_shipmode` IN ('AIR', 'AIR REG'), `l_shipinstruct` = 'DELIVER IN PERSON', `l_quantity` >= 1, `l_quantity` <= 30\n" + + " runtime filters: RF000[in_or_bloom] -> `l_partkey`") && + explainStr.contains("TABLE: part(part), PREAGGREGATION: ON\n" + + " PREDICATES: `p_size` >= 1, (`p_brand` = 'Brand#12' OR `p_brand` = 'Brand#23' OR `p_brand` = 'Brand#34'), `p_size` <= 15, `p_container` IN ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG', 'MED BAG', 'MED BOX', 'MED PKG', 'MED PACK', 'LG CASE', 'LG BOX', 'LG PACK', 'LG PKG')") + + } + } +} \ No newline at end of file diff --git a/regression-test/suites/tpch_sf1/explain/test_q2.groovy b/regression-test/suites/tpch_sf1/explain/test_q2.groovy new file mode 100644 index 0000000000..3639219f88 --- /dev/null +++ b/regression-test/suites/tpch_sf1/explain/test_q2.groovy @@ -0,0 +1,141 @@ +// 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. + +suite("test_explain_tpch_sf_1_q2", "tpch_sf1") { + String realDb = context.config.getDbNameByFile(context.file) + // get parent directory's group + realDb = realDb.substring(0, realDb.lastIndexOf("_")) + + sql "use ${realDb}" + + explain { + sql """ + 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 + LIMIT 100 + + """ + check { + explainStr -> + explainStr.contains("VTOP-N\n" + + " | order by: `s_acctbal` DESC, `n_name` ASC, `s_name` ASC, `p_partkey` ASC") && + explainStr.contains("join op: LEFT SEMI JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = min(`ps_supplycost`)\n" + + " | equal join conjunct: = `ps_partkey`") && + explainStr.contains("vec output tuple id: 19") && + explainStr.contains("output slot ids: 121 122 125 126 127 128 129 132 \n" + + " | hash output slot ids: 81 82 85 86 87 88 89 92 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `r_regionkey`") && + explainStr.contains("vec output tuple id: 15") && + explainStr.contains("output slot ids: 78 81 82 85 86 87 88 89 92 \n" + + " | hash output slot ids: 64 65 68 69 70 71 72 75 61 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `n_nationkey`") && + explainStr.contains("vec output tuple id: 14") && + explainStr.contains("output slot ids: 61 64 65 68 69 70 71 72 75 77 \n" + + " | hash output slot ids: 17 50 51 54 55 56 57 58 29 47 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `s_suppkey`") && + explainStr.contains("vec output tuple id: 13") && + explainStr.contains("output slot ids: 47 50 51 54 55 56 57 58 60 \n" + + " | hash output slot ids: 16 19 20 21 40 43 27 44 15 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[Tables are not in the same group]\n" + + " | equal join conjunct: `ps_partkey` = `p_partkey`\n" + + " | runtime filters: RF000[in_or_bloom] <- `p_partkey`") && + explainStr.contains("vec output tuple id: 12") && + explainStr.contains("output slot ids: 40 42 43 44 \n" + + " | hash output slot ids: 18 24 13 14 ") && + explainStr.contains("TABLE: partsupp(partsupp), PREAGGREGATION: ON\n" + + " runtime filters: RF000[in_or_bloom] -> `ps_partkey`") && + explainStr.contains("VAGGREGATE (merge finalize)\n" + + " | output: min( min(`ps_supplycost`))\n" + + " | group by: `ps_partkey`") && + explainStr.contains("VAGGREGATE (update serialize)\n" + + " | STREAMING\n" + + " | output: min()\n" + + " | group by: ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `r_regionkey`") && + explainStr.contains("vec output tuple id: 18") && + explainStr.contains("output slot ids: 109 110 \n" + + " | hash output slot ids: 102 103 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `n_nationkey`") && + explainStr.contains("vec output tuple id: 17") && + explainStr.contains("output slot ids: 102 103 108 \n" + + " | hash output slot ids: 97 98 6 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[Tables are not in the same group]\n" + + " | equal join conjunct: `ps_suppkey` = `s_suppkey`\n" + + " | runtime filters: RF001[in_or_bloom] <- `s_suppkey`") && + explainStr.contains("vec output tuple id: 16") && + explainStr.contains("output slot ids: 97 98 101 \n" + + " | hash output slot ids: 0 1 4 ") && + explainStr.contains("TABLE: partsupp(partsupp), PREAGGREGATION: ON\n" + + " runtime filters: RF001[in_or_bloom] -> `ps_suppkey`") && + explainStr.contains("TABLE: region(region), PREAGGREGATION: ON\n" + + " PREDICATES: `r_name` = 'EUROPE'") && + explainStr.contains("TABLE: nation(nation), PREAGGREGATION: ON") && + explainStr.contains("TABLE: supplier(supplier), PREAGGREGATION: ON") && + explainStr.contains("TABLE: region(region), PREAGGREGATION: ON\n" + + " PREDICATES: `r_name` = 'EUROPE'") && + explainStr.contains("TABLE: nation(nation), PREAGGREGATION: ON") && + explainStr.contains("TABLE: supplier(supplier), PREAGGREGATION: ON") && + explainStr.contains("TABLE: part(part), PREAGGREGATION: ON\n" + + " PREDICATES: `p_size` = 15, `p_type` LIKE '%BRASS'") + + } + } +} \ No newline at end of file diff --git a/regression-test/suites/tpch_sf1/explain/test_q20.groovy b/regression-test/suites/tpch_sf1/explain/test_q20.groovy new file mode 100644 index 0000000000..1f4a0e05ea --- /dev/null +++ b/regression-test/suites/tpch_sf1/explain/test_q20.groovy @@ -0,0 +1,110 @@ +// 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. + +suite("test_explain_tpch_sf_1_q20", "tpch_sf1") { + String realDb = context.config.getDbNameByFile(context.file) + // get parent directory's group + realDb = realDb.substring(0, realDb.lastIndexOf("_")) + + sql "use ${realDb}" + + explain { + sql """ + SELECT + s_name, + s_address + FROM + supplier, nation + WHERE + s_suppkey IN ( + SELECT ps_suppkey + FROM + partsupp + WHERE + ps_partkey IN ( + SELECT p_partkey + FROM + part + WHERE + p_name LIKE 'forest%' + ) + AND ps_availqty > ( + SELECT 0.5 * sum(l_quantity) + FROM + lineitem + WHERE + l_partkey = ps_partkey + AND l_suppkey = ps_suppkey + AND l_shipdate >= date('1994-01-01') + AND l_shipdate < date('1994-01-01') + interval '1' YEAR + ) + ) + AND s_nationkey = n_nationkey + AND n_name = 'CANADA' + ORDER BY s_name + + """ + check { + explainStr -> + explainStr.contains("VTOP-N\n" + + " | order by: `s_name` ASC") && + explainStr.contains("join op: LEFT SEMI JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = ") && + explainStr.contains("vec output tuple id: 13") && + explainStr.contains("output slot ids: 38 39 \n" + + " | hash output slot ids: 26 27 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[Tables are not in the same group]\n" + + " | equal join conjunct: `s_nationkey` = `n_nationkey`\n" + + " | runtime filters: RF000[in_or_bloom] <- `n_nationkey`") && + explainStr.contains("vec output tuple id: 10") && + explainStr.contains("output slot ids: 25 26 27 \n" + + " | hash output slot ids: 17 18 19 ") && + explainStr.contains("TABLE: supplier(supplier), PREAGGREGATION: ON\n" + + " runtime filters: RF000[in_or_bloom] -> `s_nationkey`") && + explainStr.contains("join op: LEFT SEMI JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `l_suppkey`\n" + + " | equal join conjunct: = `l_partkey`\n" + + " | other join predicates: > 0.5 * ") && + explainStr.contains("other join predicates: > 0.5 * ") && + explainStr.contains("vec output tuple id: 12") && + explainStr.contains("output slot ids: 36 \n" + + " | hash output slot ids: 32 33 10 ") && + explainStr.contains("join op: LEFT SEMI JOIN(BROADCAST)[Tables are not in the same group]\n" + + " | equal join conjunct: `ps_partkey` = `p_partkey`\n" + + " | runtime filters: RF001[in_or_bloom] <- `p_partkey`") && + explainStr.contains("vec output tuple id: 11") && + explainStr.contains("output slot ids: 31 32 33 \n" + + " | hash output slot ids: 3 14 15 ") && + explainStr.contains("TABLE: partsupp(partsupp), PREAGGREGATION: ON\n" + + " runtime filters: RF001[in_or_bloom] -> `ps_partkey`") && + explainStr.contains("VAGGREGATE (merge finalize)\n" + + " | output: sum( sum(`l_quantity`))\n" + + " | group by: `l_partkey`, `l_suppkey`") && + explainStr.contains("VAGGREGATE (update serialize)\n" + + " | STREAMING\n" + + " | output: sum(`l_quantity`)\n" + + " | group by: `l_partkey`, `l_suppkey`") && + explainStr.contains("TABLE: lineitem(lineitem), PREAGGREGATION: ON\n" + + " PREDICATES: `l_shipdate` >= date('1994-01-01 00:00:00'), `l_shipdate` < date('1994-01-01 00:00:00') + INTERVAL 1 YEAR") && + explainStr.contains("TABLE: part(part), PREAGGREGATION: ON\n" + + " PREDICATES: `p_name` LIKE 'forest%'") && + explainStr.contains("TABLE: nation(nation), PREAGGREGATION: ON\n" + + " PREDICATES: `n_name` = 'CANADA'") + + } + } +} \ No newline at end of file diff --git a/regression-test/suites/tpch_sf1/explain/test_q21.groovy b/regression-test/suites/tpch_sf1/explain/test_q21.groovy new file mode 100644 index 0000000000..e684b09619 --- /dev/null +++ b/regression-test/suites/tpch_sf1/explain/test_q21.groovy @@ -0,0 +1,122 @@ +// 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. + +suite("test_explain_tpch_sf_1_q21", "tpch_sf1") { + String realDb = context.config.getDbNameByFile(context.file) + // get parent directory's group + realDb = realDb.substring(0, realDb.lastIndexOf("_")) + + sql "use ${realDb}" + + explain { + sql """ + SELECT + s_name, + count(*) AS numwait + FROM + supplier, + lineitem l1, + orders, + nation + WHERE + s_suppkey = l1.l_suppkey + AND o_orderkey = l1.l_orderkey + AND o_orderstatus = 'F' + AND l1.l_receiptdate > l1.l_commitdate + AND exists( + SELECT * + FROM + lineitem l2 + WHERE + l2.l_orderkey = l1.l_orderkey + AND l2.l_suppkey <> l1.l_suppkey + ) + AND NOT exists( + SELECT * + FROM + lineitem l3 + WHERE + l3.l_orderkey = l1.l_orderkey + AND l3.l_suppkey <> l1.l_suppkey + AND l3.l_receiptdate > l3.l_commitdate + ) + AND s_nationkey = n_nationkey + AND n_name = 'SAUDI ARABIA' + GROUP BY + s_name + ORDER BY + numwait DESC, + s_name + LIMIT 100 + + """ + check { + explainStr -> + explainStr.contains("VTOP-N\n" + + " | order by: count(*) DESC, `s_name` ASC") && + explainStr.contains("VAGGREGATE (merge finalize)\n" + + " | output: count( count(*))\n" + + " | group by: `s_name`") && + explainStr.contains("VAGGREGATE (update serialize)\n" + + " | STREAMING\n" + + " | output: count(*)\n" + + " | group by: ") && + explainStr.contains("join op: LEFT ANTI JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `l3`.`l_orderkey`\n" + + " | other join predicates: != ") && + explainStr.contains("other join predicates: != ") && + explainStr.contains("vec output tuple id: 14") && + explainStr.contains("output slot ids: 125 \n" + + " | hash output slot ids: 114 37 110 ") && + explainStr.contains("join op: LEFT SEMI JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `l2`.`l_orderkey`\n" + + " | other join predicates: != ") && + explainStr.contains("other join predicates: != ") && + explainStr.contains("vec output tuple id: 13") && + explainStr.contains("output slot ids: 110 111 114 \n" + + " | hash output slot ids: 1 99 100 103 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `n_nationkey`") && + explainStr.contains("vec output tuple id: 12") && + explainStr.contains("output slot ids: 99 100 103 \n" + + " | hash output slot ids: 90 91 94 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `o_orderkey`") && + explainStr.contains("vec output tuple id: 11") && + explainStr.contains("output slot ids: 90 91 94 96 \n" + + " | hash output slot ids: 83 84 87 89 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[Tables are not in the same group]\n" + + " | equal join conjunct: `l1`.`l_suppkey` = `s_suppkey`\n" + + " | runtime filters: RF000[in_or_bloom] <- `s_suppkey`") && + explainStr.contains("vec output tuple id: 10") && + explainStr.contains("output slot ids: 83 84 87 89 \n" + + " | hash output slot ids: 34 35 70 76 ") && + explainStr.contains("TABLE: lineitem(lineitem), PREAGGREGATION: ON\n" + + " PREDICATES: `l1`.`l_receiptdate` > `l1`.`l_commitdate`\n" + + " runtime filters: RF000[in_or_bloom] -> `l1`.`l_suppkey`") && + explainStr.contains("TABLE: lineitem(lineitem), PREAGGREGATION: ON\n" + + " PREDICATES: `l3`.`l_receiptdate` > `l3`.`l_commitdate`") && + explainStr.contains("TABLE: lineitem(lineitem), PREAGGREGATION: ON") && + explainStr.contains("TABLE: nation(nation), PREAGGREGATION: ON\n" + + " PREDICATES: `n_name` = 'SAUDI ARABIA'") && + explainStr.contains("TABLE: orders(orders), PREAGGREGATION: ON\n" + + " PREDICATES: `o_orderstatus` = 'F'") && + explainStr.contains("TABLE: supplier(supplier), PREAGGREGATION: ON") + + } + } +} \ No newline at end of file diff --git a/regression-test/suites/tpch_sf1/explain/test_q22.groovy b/regression-test/suites/tpch_sf1/explain/test_q22.groovy new file mode 100644 index 0000000000..abed3e1168 --- /dev/null +++ b/regression-test/suites/tpch_sf1/explain/test_q22.groovy @@ -0,0 +1,95 @@ +// 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. + +suite("test_explain_tpch_sf_1_q22", "tpch_sf1") { + String realDb = context.config.getDbNameByFile(context.file) + // get parent directory's group + realDb = realDb.substring(0, realDb.lastIndexOf("_")) + + sql "use ${realDb}" + + explain { + sql """ + SELECT + cntrycode, + count(*) AS numcust, + sum(c_acctbal) AS totacctbal + FROM ( + SELECT + substr(c_phone, 1, 2) AS cntrycode, + c_acctbal + FROM + customer + WHERE + substr(c_phone, 1, 2) IN + ('13', '31', '23', '29', '30', '18', '17') + AND c_acctbal > ( + SELECT avg(c_acctbal) + FROM + customer + WHERE + c_acctbal > 0.00 + AND substr(c_phone, 1, 2) IN + ('13', '31', '23', '29', '30', '18', '17') + ) + AND NOT exists( + SELECT * + FROM + orders + WHERE + o_custkey = c_custkey + ) + ) AS custsale + GROUP BY + cntrycode + ORDER BY + cntrycode + + """ + check { + explainStr -> + explainStr.contains("VTOP-N\n" + + " | order by: `cntrycode` ASC") && + explainStr.contains("VAGGREGATE (merge finalize)\n" + + " | output: count( count(*)), sum( sum(`c_acctbal`))\n" + + " | group by: `cntrycode`") && + explainStr.contains("VAGGREGATE (update serialize)\n" + + " | STREAMING\n" + + " | output: count(*), sum()\n" + + " | group by: substr(, 1, 2)") && + explainStr.contains("join op: LEFT ANTI JOIN(BROADCAST)[Tables are not in the same group]\n" + + " | equal join conjunct: `c_custkey` = `o_custkey`") && + explainStr.contains("vec output tuple id: 10") && + explainStr.contains("output slot ids: 36 37 \n" + + " | hash output slot ids: 25 26 ") && + explainStr.contains("cross join:\n" + + " | predicates: `c_acctbal` > avg(`c_acctbal`)") && + explainStr.contains("TABLE: customer(customer), PREAGGREGATION: ON\n" + + " PREDICATES: substr(`c_phone`, 1, 2) IN ('13', '31', '23', '29', '30', '18', '17')") && + explainStr.contains("TABLE: orders(orders), PREAGGREGATION: ON") && + explainStr.contains("VAGGREGATE (merge finalize)\n" + + " | output: avg( avg(`c_acctbal`))\n" + + " | group by: ") && + explainStr.contains("VAGGREGATE (update serialize)\n" + + " | output: avg(`c_acctbal`)\n" + + " | group by: ") && + explainStr.contains("TABLE: customer(customer), PREAGGREGATION: ON\n" + + " PREDICATES: `c_acctbal` > 0.00, substr(`c_phone`, 1, 2) IN ('13', '31', '23', '29', '30', '18', '17')") + + } + } +} \ No newline at end of file diff --git a/regression-test/suites/tpch_sf1/explain/test_q3.groovy b/regression-test/suites/tpch_sf1/explain/test_q3.groovy new file mode 100644 index 0000000000..61f5c329e6 --- /dev/null +++ b/regression-test/suites/tpch_sf1/explain/test_q3.groovy @@ -0,0 +1,84 @@ +// 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. + +suite("test_explain_tpch_sf_1_q3", "tpch_sf1") { + String realDb = context.config.getDbNameByFile(context.file) + // get parent directory's group + realDb = realDb.substring(0, realDb.lastIndexOf("_")) + + sql "use ${realDb}" + + explain { + sql """ + 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 < DATE '1995-03-15' + AND l_shipdate > DATE '1995-03-15' + GROUP BY + l_orderkey, + o_orderdate, + o_shippriority + ORDER BY + revenue DESC, + o_orderdate + LIMIT 10 + + """ + check { + explainStr -> + explainStr.contains("VTOP-N\n" + + " | order by: sum(`l_extendedprice` * (1 - `l_discount`)) DESC, `o_orderdate` ASC") && + explainStr.contains("VAGGREGATE (merge finalize)\n" + + " | output: sum( sum(`l_extendedprice` * (1 - `l_discount`)))\n" + + " | group by: `l_orderkey`, `o_orderdate`, `o_shippriority`") && + explainStr.contains("VAGGREGATE (update serialize)\n" + + " | STREAMING\n" + + " | output: sum( * (1 - ))\n" + + " | group by: , , ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `c_custkey`") && + explainStr.contains("vec output tuple id: 6") && + explainStr.contains("output slot ids: 26 27 28 30 31 \n" + + " | hash output slot ids: 18 19 20 22 23 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[Tables are not in the same group]\n" + + " | equal join conjunct: `l_orderkey` = `o_orderkey`\n" + + " | runtime filters: RF000[in_or_bloom] <- `o_orderkey`") && + explainStr.contains("vec output tuple id: 5") && + explainStr.contains("output slot ids: 18 19 20 22 23 24 \n" + + " | hash output slot ids: 0 1 2 3 4 7 ") && + explainStr.contains("TABLE: lineitem(lineitem), PREAGGREGATION: ON\n" + + " PREDICATES: `l_shipdate` > '1995-03-15 00:00:00'\n" + + " runtime filters: RF000[in_or_bloom] -> `l_orderkey`") && + explainStr.contains("TABLE: customer(customer), PREAGGREGATION: ON\n" + + " PREDICATES: `c_mktsegment` = 'BUILDING'") && + explainStr.contains("TABLE: orders(orders), PREAGGREGATION: ON\n" + + " PREDICATES: `o_orderdate` < '1995-03-15 00:00:00'") + + } + } +} \ No newline at end of file diff --git a/regression-test/suites/tpch_sf1/explain/test_q4.groovy b/regression-test/suites/tpch_sf1/explain/test_q4.groovy new file mode 100644 index 0000000000..45d26dbf74 --- /dev/null +++ b/regression-test/suites/tpch_sf1/explain/test_q4.groovy @@ -0,0 +1,72 @@ +// 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. + +suite("test_explain_tpch_sf_1_q4", "tpch_sf1") { + String realDb = context.config.getDbNameByFile(context.file) + // get parent directory's group + realDb = realDb.substring(0, realDb.lastIndexOf("_")) + + sql "use ${realDb}" + + explain { + sql """ + SELECT + o_orderpriority, + count(*) AS order_count + FROM orders + WHERE + o_orderdate >= DATE '1993-07-01' + AND o_orderdate < DATE '1993-07-01' + INTERVAL '3' MONTH + AND EXISTS ( + SELECT * + FROM lineitem + WHERE + l_orderkey = o_orderkey + AND l_commitdate < l_receiptdate + ) + GROUP BY + o_orderpriority + ORDER BY + o_orderpriority + + """ + check { + explainStr -> + explainStr.contains("VTOP-N\n" + + " | order by: `o_orderpriority` ASC") && + explainStr.contains("VAGGREGATE (merge finalize)\n" + + " | output: count( count(*))\n" + + " | group by: `o_orderpriority`") && + explainStr.contains("VAGGREGATE (update serialize)\n" + + " | STREAMING\n" + + " | output: count(*)\n" + + " | group by: ") && + explainStr.contains("join op: LEFT SEMI JOIN(BROADCAST)[Tables are not in the same group]\n" + + " | equal join conjunct: `o_orderkey` = `l_orderkey`\n" + + " | runtime filters: RF000[in_or_bloom] <- `l_orderkey`") && + explainStr.contains("vec output tuple id: 5") && + explainStr.contains("output slot ids: 41 \n" + + " | hash output slot ids: 34 ") && + explainStr.contains("TABLE: orders(orders), PREAGGREGATION: ON\n" + + " PREDICATES: `o_orderdate` >= '1993-07-01 00:00:00', `o_orderdate` < '1993-10-01 00:00:00'\n" + + " runtime filters: RF000[in_or_bloom] -> `o_orderkey`") && + explainStr.contains("TABLE: lineitem(lineitem), PREAGGREGATION: ON\n" + + " PREDICATES: `l_commitdate` < `l_receiptdate`") + + } + } +} \ No newline at end of file diff --git a/regression-test/suites/tpch_sf1/explain/test_q5.groovy b/regression-test/suites/tpch_sf1/explain/test_q5.groovy new file mode 100644 index 0000000000..946122bb1e --- /dev/null +++ b/regression-test/suites/tpch_sf1/explain/test_q5.groovy @@ -0,0 +1,103 @@ +// 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. + +suite("test_explain_tpch_sf_1_q5", "tpch_sf1") { + String realDb = context.config.getDbNameByFile(context.file) + // get parent directory's group + realDb = realDb.substring(0, realDb.lastIndexOf("_")) + + sql "use ${realDb}" + + explain { + sql """ + 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 >= DATE '1994-01-01' + AND o_orderdate < DATE '1994-01-01' + INTERVAL '1' YEAR + GROUP BY + n_name + ORDER BY + revenue DESC + + """ + check { + explainStr -> + explainStr.contains("VTOP-N\n" + + " | order by: sum(`l_extendedprice` * (1 - `l_discount`)) DESC") && + explainStr.contains("VAGGREGATE (merge finalize)\n" + + " | output: sum( sum(`l_extendedprice` * (1 - `l_discount`)))\n" + + " | group by: `n_name`") && + explainStr.contains("VAGGREGATE (update serialize)\n" + + " | STREAMING\n" + + " | output: sum( * (1 - ))\n" + + " | group by: ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `r_regionkey`") && + explainStr.contains("vec output tuple id: 12") && + explainStr.contains("output slot ids: 61 62 72 \n" + + " | hash output slot ids: 48 58 47 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `n_nationkey`") && + explainStr.contains("vec output tuple id: 11") && + explainStr.contains("output slot ids: 47 48 58 60 \n" + + " | hash output slot ids: 0 36 37 12 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `c_custkey`\n" + + " | equal join conjunct: = `c_nationkey`") && + explainStr.contains("vec output tuple id: 10") && + explainStr.contains("output slot ids: 36 37 44 \n" + + " | hash output slot ids: 35 27 28 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `s_suppkey`") && + explainStr.contains("vec output tuple id: 9") && + explainStr.contains("output slot ids: 27 28 31 35 \n" + + " | hash output slot ids: 20 21 24 10 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[Tables are not in the same group]\n" + + " | equal join conjunct: `l_orderkey` = `o_orderkey`\n" + + " | runtime filters: RF000[in_or_bloom] <- `o_orderkey`") && + explainStr.contains("vec output tuple id: 8") && + explainStr.contains("output slot ids: 20 21 23 24 \n" + + " | hash output slot ids: 1 2 4 7 ") && + explainStr.contains("TABLE: lineitem(lineitem), PREAGGREGATION: ON\n" + + " runtime filters: RF000[in_or_bloom] -> `l_orderkey`") && + explainStr.contains("TABLE: region(region), PREAGGREGATION: ON\n" + + " PREDICATES: `r_name` = 'ASIA'") && + explainStr.contains("TABLE: nation(nation), PREAGGREGATION: ON") && + explainStr.contains("TABLE: customer(customer), PREAGGREGATION: ON") && + explainStr.contains("TABLE: supplier(supplier), PREAGGREGATION: ON") && + explainStr.contains("TABLE: orders(orders), PREAGGREGATION: ON\n" + + " PREDICATES: `o_orderdate` >= '1994-01-01 00:00:00', `o_orderdate` < '1995-01-01 00:00:00'") + + } + } +} \ No newline at end of file diff --git a/regression-test/suites/tpch_sf1/explain/test_q6.groovy b/regression-test/suites/tpch_sf1/explain/test_q6.groovy new file mode 100644 index 0000000000..b12b36a01c --- /dev/null +++ b/regression-test/suites/tpch_sf1/explain/test_q6.groovy @@ -0,0 +1,52 @@ +// 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. + +suite("test_explain_tpch_sf_1_q6", "tpch_sf1") { + String realDb = context.config.getDbNameByFile(context.file) + // get parent directory's group + realDb = realDb.substring(0, realDb.lastIndexOf("_")) + + sql "use ${realDb}" + + explain { + sql """ + + SELECT sum(l_extendedprice * l_discount) AS revenue + FROM + lineitem + WHERE + l_shipdate >= DATE '1994-01-01' + AND l_shipdate < DATE '1994-01-01' + INTERVAL '1' YEAR + AND l_discount BETWEEN 0.06 - 0.01 AND .06 + 0.01 + AND l_quantity < 24 + + + """ + check { + explainStr -> + explainStr.contains("VAGGREGATE (merge finalize)\n" + + " | output: sum( sum(`l_extendedprice` * `l_discount`))\n" + + " | group by: ") && + explainStr.contains("VAGGREGATE (update serialize)\n" + + " | output: sum(`l_extendedprice` * `l_discount`)\n" + + " | group by: ") && + explainStr.contains("TABLE: lineitem(lineitem), PREAGGREGATION: ON\n" + + " PREDICATES: `l_shipdate` >= '1994-01-01 00:00:00', `l_shipdate` < '1995-01-01 00:00:00', `l_discount` >= 0.05, `l_discount` <= 0.07, `l_quantity` < 24") + + } + } +} \ No newline at end of file diff --git a/regression-test/suites/tpch_sf1/explain/test_q7.groovy b/regression-test/suites/tpch_sf1/explain/test_q7.groovy new file mode 100644 index 0000000000..92495f3410 --- /dev/null +++ b/regression-test/suites/tpch_sf1/explain/test_q7.groovy @@ -0,0 +1,119 @@ +// 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. + +suite("test_explain_tpch_sf_1_q7", "tpch_sf1") { + String realDb = context.config.getDbNameByFile(context.file) + // get parent directory's group + realDb = realDb.substring(0, realDb.lastIndexOf("_")) + + sql "use ${realDb}" + + explain { + sql """ + 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 DATE '1995-01-01' AND DATE '1996-12-31' + ) AS shipping + GROUP BY + supp_nation, + cust_nation, + l_year + ORDER BY + supp_nation, + cust_nation, + l_year + + """ + check { + explainStr -> + explainStr.contains("VTOP-N\n" + + " | order by: `supp_nation` ASC, `cust_nation` ASC, `l_year` ASC") && + explainStr.contains("VAGGREGATE (merge finalize)\n" + + " | output: sum( sum(`volume`))\n" + + " | group by: `supp_nation`, `cust_nation`, `l_year`") && + explainStr.contains("VAGGREGATE (update serialize)\n" + + " | STREAMING\n" + + " | output: sum( * (1 - ))\n" + + " | group by: , , year()") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `n2`.`n_nationkey`\n" + + " | other predicates: (( = 'FRANCE' AND = 'GERMANY') OR ( = 'GERMANY' AND = 'FRANCE'))") && + explainStr.contains("other predicates: (( = 'FRANCE' AND = 'GERMANY') OR ( = 'GERMANY' AND = 'FRANCE'))") && + explainStr.contains("vec output tuple id: 13") && + explainStr.contains("output slot ids: 67 68 69 76 80 \n" + + " | hash output slot ids: 1 54 55 56 63 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `c_custkey`") && + explainStr.contains("vec output tuple id: 12") && + explainStr.contains("output slot ids: 54 55 56 63 66 \n" + + " | hash output slot ids: 52 43 44 45 13 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `n1`.`n_nationkey`") && + explainStr.contains("vec output tuple id: 11") && + explainStr.contains("output slot ids: 43 44 45 51 52 \n" + + " | hash output slot ids: 0 34 35 36 42 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `o_orderkey`") && + explainStr.contains("vec output tuple id: 10") && + explainStr.contains("output slot ids: 34 35 36 40 42 \n" + + " | hash output slot ids: 33 10 27 28 29 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[Tables are not in the same group]\n" + + " | equal join conjunct: `l_suppkey` = `s_suppkey`\n" + + " | runtime filters: RF000[in_or_bloom] <- `s_suppkey`") && + explainStr.contains("vec output tuple id: 9") && + explainStr.contains("output slot ids: 27 28 29 31 33 \n" + + " | hash output slot ids: 2 3 4 8 11 ") && + explainStr.contains("TABLE: lineitem(lineitem), PREAGGREGATION: ON\n" + + " PREDICATES: `l_shipdate` >= '1995-01-01 00:00:00', `l_shipdate` <= '1996-12-31 00:00:00'\n" + + " runtime filters: RF000[in_or_bloom] -> `l_suppkey`") && + explainStr.contains("TABLE: nation(nation), PREAGGREGATION: ON\n" + + " PREDICATES: (`n2`.`n_name` = 'FRANCE' OR `n2`.`n_name` = 'GERMANY')") && + explainStr.contains("TABLE: customer(customer), PREAGGREGATION: ON") && + explainStr.contains("TABLE: nation(nation), PREAGGREGATION: ON\n" + + " PREDICATES: (`n1`.`n_name` = 'FRANCE' OR `n1`.`n_name` = 'GERMANY')") && + explainStr.contains("TABLE: orders(orders), PREAGGREGATION: ON") && + explainStr.contains("TABLE: supplier(supplier), PREAGGREGATION: ON") + + } + } +} \ No newline at end of file diff --git a/regression-test/suites/tpch_sf1/explain/test_q8.groovy b/regression-test/suites/tpch_sf1/explain/test_q8.groovy new file mode 100644 index 0000000000..5b714a5a2e --- /dev/null +++ b/regression-test/suites/tpch_sf1/explain/test_q8.groovy @@ -0,0 +1,128 @@ +// 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. + +suite("test_explain_tpch_sf_1_q8", "tpch_sf1") { + String realDb = context.config.getDbNameByFile(context.file) + // get parent directory's group + realDb = realDb.substring(0, realDb.lastIndexOf("_")) + + sql "use ${realDb}" + + explain { + sql """ + 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 DATE '1995-01-01' AND DATE '1996-12-31' + AND p_type = 'ECONOMY ANODIZED STEEL' + ) AS all_nations + GROUP BY + o_year + ORDER BY + o_year + + """ + check { + explainStr -> + explainStr.contains("VTOP-N\n" + + " | order by: `o_year` ASC") && + explainStr.contains("VAGGREGATE (merge finalize)\n" + + " | output: sum( sum(CASE WHEN `nation` = 'BRAZIL' THEN `volume` ELSE 0 END)), sum( sum(`volume`))\n" + + " | group by: `o_year`") && + explainStr.contains("VAGGREGATE (update serialize)\n" + + " | STREAMING\n" + + " | output: sum(CASE WHEN = 'BRAZIL' THEN * (1 - ) ELSE 0 END), sum( * (1 - ))\n" + + " | group by: year()") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `r_regionkey`") && + explainStr.contains("vec output tuple id: 17") && + explainStr.contains("output slot ids: 105 106 114 117 \n" + + " | hash output slot ids: 96 99 87 88 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `n1`.`n_nationkey`") && + explainStr.contains("vec output tuple id: 16") && + explainStr.contains("output slot ids: 87 88 96 99 104 \n" + + " | hash output slot ids: 80 83 71 72 14 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `c_custkey`") && + explainStr.contains("vec output tuple id: 15") && + explainStr.contains("output slot ids: 71 72 80 83 86 \n" + + " | hash output slot ids: 66 69 57 58 12 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `n2`.`n_nationkey`") && + explainStr.contains("vec output tuple id: 14") && + explainStr.contains("output slot ids: 57 58 66 68 69 \n" + + " | hash output slot ids: 3 54 56 45 46 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `o_orderkey`") && + explainStr.contains("vec output tuple id: 13") && + explainStr.contains("output slot ids: 45 46 53 54 56 \n" + + " | hash output slot ids: 0 36 37 10 44 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `s_suppkey`") && + explainStr.contains("vec output tuple id: 12") && + explainStr.contains("output slot ids: 36 37 40 44 \n" + + " | hash output slot ids: 33 17 29 30 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[Tables are not in the same group]\n" + + " | equal join conjunct: `l_partkey` = `p_partkey`\n" + + " | runtime filters: RF000[in_or_bloom] <- `p_partkey`") && + explainStr.contains("vec output tuple id: 11") && + explainStr.contains("output slot ids: 29 30 32 33 \n" + + " | hash output slot ids: 1 2 7 8 ") && + explainStr.contains("TABLE: lineitem(lineitem), PREAGGREGATION: ON\n" + + " runtime filters: RF000[in_or_bloom] -> `l_partkey`") && + explainStr.contains("TABLE: region(region), PREAGGREGATION: ON\n" + + " PREDICATES: `r_name` = 'AMERICA'") && + explainStr.contains("TABLE: nation(nation), PREAGGREGATION: ON") && + explainStr.contains("TABLE: customer(customer), PREAGGREGATION: ON") && + explainStr.contains("TABLE: nation(nation), PREAGGREGATION: ON") && + explainStr.contains("TABLE: orders(orders), PREAGGREGATION: ON\n" + + " PREDICATES: `o_orderdate` >= '1995-01-01 00:00:00', `o_orderdate` <= '1996-12-31 00:00:00'") && + explainStr.contains("TABLE: supplier(supplier), PREAGGREGATION: ON") && + explainStr.contains("TABLE: part(part), PREAGGREGATION: ON\n" + + " PREDICATES: `p_type` = 'ECONOMY ANODIZED STEEL'") + + } + } +} \ No newline at end of file diff --git a/regression-test/suites/tpch_sf1/explain/test_q9.groovy b/regression-test/suites/tpch_sf1/explain/test_q9.groovy new file mode 100644 index 0000000000..23faee3d98 --- /dev/null +++ b/regression-test/suites/tpch_sf1/explain/test_q9.groovy @@ -0,0 +1,109 @@ +// 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. + +suite("test_explain_tpch_sf_1_q9", "tpch_sf1") { + String realDb = context.config.getDbNameByFile(context.file) + // get parent directory's group + realDb = realDb.substring(0, realDb.lastIndexOf("_")) + + sql "use ${realDb}" + + explain { + sql """ + SELECT + nation, + o_year, + sum(amount) AS sum_profit + FROM ( + SELECT + n_name AS nation, + extract(YEAR FROM o_orderdate) AS o_year, + l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity AS amount + FROM + part, + supplier, + lineitem, + partsupp, + orders, + nation + WHERE + s_suppkey = l_suppkey + AND ps_suppkey = l_suppkey + AND ps_partkey = l_partkey + AND p_partkey = l_partkey + AND o_orderkey = l_orderkey + AND s_nationkey = n_nationkey + AND p_name LIKE '%green%' + ) AS profit + GROUP BY + nation, + o_year + ORDER BY + nation, + o_year DESC + + """ + check { + explainStr -> + explainStr.contains("VTOP-N\n" + + " | order by: `nation` ASC, `o_year` DESC") && + explainStr.contains("VAGGREGATE (merge finalize)\n" + + " | output: sum( sum(`amount`))\n" + + " | group by: `nation`, `o_year`") && + explainStr.contains("VAGGREGATE (update serialize)\n" + + " | STREAMING\n" + + " | output: sum( * (1 - ) - * )\n" + + " | group by: , year()") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `n_nationkey`") && + explainStr.contains("vec output tuple id: 13") && + explainStr.contains("output slot ids: 73 74 75 81 86 88 \n" + + " | hash output slot ids: 0 66 71 58 59 60 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `o_orderkey`") && + explainStr.contains("vec output tuple id: 12") && + explainStr.contains("output slot ids: 58 59 60 65 66 71 \n" + + " | hash output slot ids: 1 52 53 45 46 47 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `p_partkey`") && + explainStr.contains("vec output tuple id: 11") && + explainStr.contains("output slot ids: 45 46 47 50 52 53 \n" + + " | hash output slot ids: 34 35 36 39 41 42 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[The src data has been redistributed]\n" + + " | equal join conjunct: = `ps_suppkey`\n" + + " | equal join conjunct: = `ps_partkey`") && + explainStr.contains("vec output tuple id: 10") && + explainStr.contains("output slot ids: 34 35 36 38 39 41 42 \n" + + " | hash output slot ids: 33 4 26 27 28 30 31 ") && + explainStr.contains("join op: INNER JOIN(BROADCAST)[Tables are not in the same group]\n" + + " | equal join conjunct: `l_suppkey` = `s_suppkey`\n" + + " | runtime filters: RF000[in_or_bloom] <- `s_suppkey`") && + explainStr.contains("vec output tuple id: 9") && + explainStr.contains("output slot ids: 26 27 28 29 30 31 33 \n" + + " | hash output slot ids: 2 3 5 7 10 13 14 ") && + explainStr.contains("TABLE: lineitem(lineitem), PREAGGREGATION: ON\n" + + " runtime filters: RF000[in_or_bloom] -> `l_suppkey`") && + explainStr.contains("TABLE: nation(nation), PREAGGREGATION: ON") && + explainStr.contains("TABLE: orders(orders), PREAGGREGATION: ON") && + explainStr.contains("TABLE: part(part), PREAGGREGATION: ON\n" + + " PREDICATES: `p_name` LIKE '%green%'") && + explainStr.contains("TABLE: partsupp(partsupp), PREAGGREGATION: ON") && + explainStr.contains("TABLE: supplier(supplier), PREAGGREGATION: ON") + + } + } +} \ No newline at end of file diff --git a/regression-test/suites/tpch_sf1/load.groovy b/regression-test/suites/tpch_sf1/load.groovy index 797b3a5913..3e5fcd0f59 100644 --- a/regression-test/suites/tpch_sf1/load.groovy +++ b/regression-test/suites/tpch_sf1/load.groovy @@ -77,4 +77,7 @@ suite("load") { def table = "revenue1" sql new File("""${context.file.parent}/ddl/${table}_delete.sql""").text sql new File("""${context.file.parent}/ddl/${table}.sql""").text + // We need wait to make sure BE could pass the stats info to FE so that + // avoid unnessary inconsistent generated plan which would cause the regression test fail + sleep(60000) }