[UT] Add integration test for runtime profile (#29065)

Fixes #issue

## What type of PR is this:
- [ ] BugFix
- [ ] Feature
- [ ] Enhancement
- [ ] Refactor
- [x] UT
- [ ] Doc
- [ ] Tool

## Checklist:
- [ ] I have added test cases for my bug fix or my new feature
- [ ] This pr will affect users' behaviors
- [ ] This pr needs user documentation (for new or modified features or
behaviors)
  - [ ] I have added documentation for my new feature or new function

## Bugfix cherry-pick branch check:
- [x] I have checked the version labels which the pr will be
auto-backported to the target branch
  - [ ] 3.1
  - [ ] 3.0
  - [ ] 2.5
  - [ ] 2.4

Signed-off-by: liuyehcf <1559500551@qq.com>
This commit is contained in:
liuyehcf 2023-08-14 18:58:14 +08:00 committed by GitHub
parent 13bca233ae
commit 76eaf65839
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
44 changed files with 202 additions and 1 deletions

1
.gitignore vendored
View File

@ -41,6 +41,7 @@ dependency-reduced-pom.xml
test/conf/
test/conf/sr.conf
test/nosetests.xml
test/common/data
tags
.tags
.cache

View File

@ -7,6 +7,7 @@ http_port =
[replace]
url = http://${mysql-client:host}:${mysql-client:http_port}
mysql_cmd = mysql -h${mysql-client:host} -P${mysql-client:port} -u${mysql-client:user}
[env]
oss_bucket =
@ -22,4 +23,4 @@ hive_metastore_uris =
hudi_hive_metastore_uris =
iceberg_catalog_hive_metastore_uris =
iceberg_catalog_hive_metastore_uris =

View File

@ -1093,6 +1093,8 @@ class StarrocksSQLApiLib(object):
# load data
data_files = self.get_common_data_files(data_name)
for data in data_files:
if ".gitkeep" in data:
continue
label = "%s_load_label_%s" % (data_name, uuid.uuid1().hex)
file_name = data.split("/")[-1]
table_name = file_name.split(".")[0]

View File

@ -0,0 +1,88 @@
-- name: test_runtime_profile
CREATE TABLE `t_runtime_profile` (
`c1` int(11) NOT NULL COMMENT "",
`c2` int(11) NULL COMMENT ""
) ENGINE=OLAP
DUPLICATE KEY(`c1`)
DISTRIBUTED BY HASH(`c1`) BUCKETS 200
PROPERTIES (
"replication_num" = "1",
"in_memory" = "false",
"enable_persistent_index" = "false",
"replicated_storage" = "true",
"compression" = "LZ4"
);
-- result:
-- !result
INSERT INTO `t_runtime_profile` (c1, c2) VALUES
(1,1),(2,2),(3,3),(4,4),
(5,5),(6,6),(7,7),(8,8),
(9,9),(10,10),(11,11),(12,12),
(13,13),(14,14),(15,15),(16,16);
-- result:
-- !result
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
-- result:
-- !result
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
-- result:
-- !result
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
-- result:
-- !result
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
-- result:
-- !result
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
-- result:
-- !result
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
-- result:
-- !result
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
-- result:
-- !result
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
-- result:
-- !result
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
-- result:
-- !result
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
-- result:
-- !result
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
-- result:
-- !result
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
-- result:
-- !result
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
-- result:
-- !result
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
-- result:
-- !result
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
-- result:
-- !result
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
-- result:
-- !result
shell: env mysql_cmd="${mysql_cmd} -D${db[0]}" bash ${root_path}/sql/test_profile/T/test_runtime_profile.sh
-- result:
0
Analyze runtime profile succeeded
-- !result
-- name: test_explain_analyze
function: prepare_data("tpcds", "${db[0]}")
-- result:
None
-- !result
shell: env mysql_cmd="${mysql_cmd} -D${db[0]}" bash ${root_path}/sql/test_profile/T/test_profile_analysis.sh
-- result:
0
Analyze profile succeeded
Analyze profile succeeded
Analyze profile succeeded
-- !result

View File

@ -0,0 +1,42 @@
-- name: test_runtime_profile
CREATE TABLE `t_runtime_profile` (
`c1` int(11) NOT NULL COMMENT "",
`c2` int(11) NULL COMMENT ""
) ENGINE=OLAP
DUPLICATE KEY(`c1`)
DISTRIBUTED BY HASH(`c1`) BUCKETS 200
PROPERTIES (
"replication_num" = "1",
"in_memory" = "false",
"enable_persistent_index" = "false",
"replicated_storage" = "true",
"compression" = "LZ4"
);
INSERT INTO `t_runtime_profile` (c1, c2) VALUES
(1,1),(2,2),(3,3),(4,4),
(5,5),(6,6),(7,7),(8,8),
(9,9),(10,10),(11,11),(12,12),
(13,13),(14,14),(15,15),(16,16);
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
INSERT INTO `t_runtime_profile` SELECT * FROM `t_runtime_profile`;
shell: env mysql_cmd="${mysql_cmd} -D${db[0]}" bash ${root_path}/sql/test_profile/T/test_runtime_profile.sh
-- name: test_explain_analyze
function: prepare_data("tpcds", "${db[0]}")
shell: env mysql_cmd="${mysql_cmd} -D${db[0]}" bash ${root_path}/sql/test_profile/T/test_profile_analysis.sh

View File

@ -0,0 +1,43 @@
#!/bin/bash
function test_explain_analyze() {
sql=$1
analyze_output=$(${mysql_cmd} -e "${sql}")
if grep -q "Summary" <<< "${analyze_output}"; then
echo "Analyze profile succeeded"
else
echo "Analyze profile failed"
exit 1
fi
}
sql=$(cat << EOF
explain analyze
with customer_total_return as
(select sr_customer_sk as ctr_customer_sk
,sr_store_sk as ctr_store_sk
,sum(SR_RETURN_AMT) as ctr_total_return
from store_returns
,date_dim
where sr_returned_date_sk = d_date_sk
and d_year =2000
group by sr_customer_sk
,sr_store_sk)
select c_customer_id
from customer_total_return ctr1
,store
,customer
where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2
from customer_total_return ctr2
where ctr1.ctr_store_sk = ctr2.ctr_store_sk)
and s_store_sk = ctr1.ctr_store_sk
and s_state = 'TN'
and ctr1.ctr_customer_sk = c_customer_sk
order by c_customer_id
limit 100;
EOF
)
test_explain_analyze "${sql}"
test_explain_analyze "set enable_runtime_adaptive_dop = true; ${sql}"
test_explain_analyze "set enable_spill = true; set spill_mode = 'force'; ${sql}"

View File

@ -0,0 +1,24 @@
#!/bin/bash
${mysql_cmd} -e '
set enable_profile=true;
set runtime_profile_report_interval=2;
SELECT SUM(wv), AVG(wv) FROM (
SELECT max(c1) OVER (ORDER BY c2 ROWS BETWEEN UNBOUNDED PRECEDING AND 2 PRECEDING) AS wv FROM t_runtime_profile
) t
' &
query_pid=$!
trap "kill -9 ${query_pid};" SIGINT SIGTERM EXIT
sleep 10
query_id=$(${mysql_cmd} -e 'show profilelist limit 5' | grep 'Running' | awk '{print $1}' | head -n 1)
analyze_output=$(${mysql_cmd} -e "analyze profile from '${query_id}'")
if grep -q 'Summary' <<< "${analyze_output}"; then
echo "Analyze runtime profile succeeded"
else
echo "Analyze runtime profile failed"
exit 1
fi