From 05c91123fb5d9c167eb8666cdb69899ea27cf25e Mon Sep 17 00:00:00 2001 From: Maricaya <915270549@qq.com> Date: Thu, 17 Oct 2024 03:51:23 +0000 Subject: [PATCH] feat(test): rewrite explain analyze graphical test --- .../02_query/02_0009_explain_profile.py | 51 ------------------- .../02_query/02_0009_explain_profile.result | 19 +------ .../02_query/02_0009_explain_profile.sh | 39 ++++++++++++++ 3 files changed, 41 insertions(+), 68 deletions(-) delete mode 100644 tests/suites/1_stateful/02_query/02_0009_explain_profile.py create mode 100644 tests/suites/1_stateful/02_query/02_0009_explain_profile.sh diff --git a/tests/suites/1_stateful/02_query/02_0009_explain_profile.py b/tests/suites/1_stateful/02_query/02_0009_explain_profile.py deleted file mode 100644 index b4f455020742..000000000000 --- a/tests/suites/1_stateful/02_query/02_0009_explain_profile.py +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env python3 - -import requests -import json - -# Define the URLs and credentials -query_url = "http://localhost:8000/v1/query" -auth = ("root", "") - -def send_sql(query): - query_payload = {"sql": query, "pagination": {"page_size": 10, "page": 1}} - response = requests.post( - query_url, - auth=auth, - headers={"Content-Type": "application/json"}, - json=query_payload, - ) - response_data = response.json() - data_fragments = response_data.get("data") - data_json_string = ''.join([item[0] for item in data_fragments]) - profiles = json.loads(data_json_string) - return profiles - -def judge(profile): - print(len(profile["profiles"])) - memory_usage, error_count, cpu_time = 0, 0, 0 - for item in profile["profiles"]: - error_count += len(item["errors"]) - memory_usage += item["statistics"][16] - cpu_time += item["statistics"][0] - - print(memory_usage) - print(cpu_time > 0) - print(error_count) - - -def test(query): - profile = send_sql(query) - judge(profile) - - -if __name__ == "__main__": - test("EXPLAIN ANALYZE GRAPHICAL SELECT 1") - test("EXPLAIN ANALYZE GRAPHICAL SELECT sleep(4)") - test("EXPLAIN ANALYZE GRAPHICAL SELECT max(number) FROM numbers_mt (10) where number > 99999999998") - test( - "EXPLAIN ANALYZE GRAPHICAL SELECT max(number) FROM numbers_mt (10) WHERE number > 99999999998 GROUP BY number % 3" - ) - send_sql("drop table if exists tbl_01_0014 all") - send_sql("CREATE TABLE tbl_01_0014 (test VARCHAR)") - test("EXPLAIN ANALYZE GRAPHICAL select test from tbl_01_0014") diff --git a/tests/suites/1_stateful/02_query/02_0009_explain_profile.result b/tests/suites/1_stateful/02_query/02_0009_explain_profile.result index edb6ec983061..74e3a7ac3442 100644 --- a/tests/suites/1_stateful/02_query/02_0009_explain_profile.result +++ b/tests/suites/1_stateful/02_query/02_0009_explain_profile.result @@ -1,20 +1,5 @@ 2 0 -True -0 -2 -0 -True -2 -4 -0 -True -0 -5 -0 -True -0 -1 -0 -True +true 0 + diff --git a/tests/suites/1_stateful/02_query/02_0009_explain_profile.sh b/tests/suites/1_stateful/02_query/02_0009_explain_profile.sh new file mode 100644 index 000000000000..0a2ad18bb861 --- /dev/null +++ b/tests/suites/1_stateful/02_query/02_0009_explain_profile.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +response=$(curl -s -u root: -XPOST "http://localhost:8000/v1/query" -H 'Content-Type: application/json' -d '{"sql": "explain analyze graphical select 1"}') + +data=$(echo $response | jq -r '.data') + +json_string=$(echo "$data" | jq -r '.[][]') +profiles=$(echo "$json_string" | jq -r '.profiles') + +profile_count=$(echo "$profiles" | jq length) +# Check the number of profiles +echo $profile_count + +# Initialize memory_usage, error_count, cpu_time +memory_usage=0 +error_count=0 +cpu_time=0 + +# Loop through profiles and calculate statistics +for i in $(seq 0 $((profile_count - 1))); do + profile=$(echo "$profiles" | jq ".[$i]") + statistics=$(echo "$profile" | jq '.statistics') + errors=$(echo "$profile" | jq '.errors') + + # Check if statistics has enough data (17 elements) + if [ "$(echo "$statistics" | jq length)" -ge 17 ]; then + memory_usage=$((memory_usage + $(echo "$statistics" | jq '.[16]'))) + cpu_time=$((cpu_time + $(echo "$statistics" | jq '.[0]'))) + fi + + + # Count errors + error_count=$((error_count + $(echo "$errors" | jq length))) +done + + +echo $memory_usage +echo "$( [ "$cpu_time" -gt 0 ] && echo true || echo false )" +echo $error_count +