This is an automated email from the ASF dual-hosted git repository.
dataroaring pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new ad5022dd38 [regression-test](profile) add regression tests for query
profile and insert profile (#16998)
ad5022dd38 is described below
commit ad5022dd38c229fe6d20163c089108456ebd0f37
Author: Yusheng Xu <[email protected]>
AuthorDate: Thu Feb 23 15:35:20 2023 +0800
[regression-test](profile) add regression tests for query profile and
insert profile (#16998)
---
.../suites/query_profile/test_profile.groovy | 149 +++++++++++++++++++++
1 file changed, 149 insertions(+)
diff --git a/regression-test/suites/query_profile/test_profile.groovy
b/regression-test/suites/query_profile/test_profile.groovy
new file mode 100644
index 0000000000..783c60b3b4
--- /dev/null
+++ b/regression-test/suites/query_profile/test_profile.groovy
@@ -0,0 +1,149 @@
+// 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.
+
+import groovy.json.JsonOutput
+import groovy.json.JsonSlurper
+
+/**
+* @Params url is "/xxx"
+* @Return response body
+*/
+def http_get(url) {
+ def dst = 'http://' + context.config.feHttpAddress
+ def conn = new URL(dst + url).openConnection()
+ conn.setRequestMethod("GET")
+ //token for root
+ conn.setRequestProperty("Authorization","Basic cm9vdDo=")
+ return conn.getInputStream().getText()
+}
+
+def SUCCESS_MSG = 'success'
+def SUCCESS_CODE = 0
+def QUERY_NUM = 5
+
+random = new Random()
+
+def getRandomNumber(int num){
+ return random.nextInt(num)
+}
+
+suite('test_profile') {
+ def table = 'test_profile_table'
+ def id_data = [1,2,3,4,5,6,7]
+ def value_data = [1,2,3,4,5,6,7]
+ def len = id_data.size
+
+ assertEquals(id_data.size, value_data.size)
+
+ sql """ DROP TABLE IF EXISTS ${table} """
+
+ sql """
+ CREATE TABLE IF NOT EXISTS ${table}(
+ `id` INT,
+ `cost` INT
+ )
+ DISTRIBUTED BY HASH(id) BUCKETS 1
+ PROPERTIES (
+ "replication_num" = "1"
+ )
+ """
+
+ sql """ SET enable_profile = true """
+
+ //———————— test for insert stmt ——————————
+ for(int i = 0; i < len; i++){
+ sql """ INSERT INTO ${table} values (${id_data[i]},
"${value_data[i]}") """
+ }
+
+ //———————— test for insert stmt (SQL) ——————————
+ log.info("test HTTP API interface for insert profile")
+ def url = '/rest/v1/query_profile/'
+ def query_list_result = http_get(url)
+
+ def obj = new JsonSlurper().parseText(query_list_result)
+ assertEquals(obj.msg, SUCCESS_MSG)
+ assertEquals(obj.code, SUCCESS_CODE)
+
+ for(int i = 0 ; i < len ; i++){
+ def insert_order = len - i - 1
+ def stmt_query_info = obj.data.rows[i]
+
+ assertNotNull(stmt_query_info["Query ID"])
+ assertNotEquals(stmt_query_info["Query ID"], "N/A")
+ assertNotNull(stmt_query_info["Detail"])
+ assertNotEquals(stmt_query_info["Detail"], "N/A")
+
+ assertEquals(stmt_query_info['Sql Statement'].toString(),
+ """ INSERT INTO ${table} values (${id_data[insert_order]},
"${value_data[insert_order]}") """.toString())
+ }
+
+ //———————— test for select stmt ———————————
+ def op_data = ["<", ">", "=", "<=", ">="]
+
+ def ops = []
+ def nums = []
+
+ for(int i = 0 ; i < QUERY_NUM ; i++){
+ ops.add(op_data[getRandomNumber(5)])
+ nums.add(getRandomNumber(len + 1))
+ sql """ SELECT * FROM ${table} WHERE cost ${ops[i]} ${nums[i]} """
+ }
+
+
+ /* test for `show query profile` stmt
+ query profile header
+
JobID|QueryId|User|DefaultDb|SQL|QueryType|StartTime|EndTime|TotalTime|QueryState
*/
+ //———————— test for select stmt (SQL) ———————————
+ log.info("test for show query profile stmt")
+ List<List<Object>> show_query_profile_obj = sql """ show query profile "/"
"""
+ log.info("found ${show_query_profile_obj.size} profile data".toString())
+ assertTrue(show_query_profile_obj.size >= QUERY_NUM)
+
+ for(int i = 0 ; i < QUERY_NUM ; i++){
+ def insert_order = QUERY_NUM - i - 1
+ def current_obj = show_query_profile_obj[i]
+ def stmt_query_info = current_obj[4]
+ assertNotEquals(current_obj[1].toString(), "N/A".toString())
+ assertEquals(stmt_query_info.toString(), """ SELECT * FROM ${table}
WHERE cost ${ops[insert_order]} ${nums[insert_order]} """.toString())
+ }
+
+ //———————— test for select stmt (HTTP)————————
+ log.info("test HTTP API interface for query profile")
+ url = '/rest/v1/query_profile/'
+ query_list_result = http_get(url)
+
+ obj = new JsonSlurper().parseText(query_list_result)
+ assertEquals(obj.msg, SUCCESS_MSG)
+ assertEquals(obj.code, SUCCESS_CODE)
+
+ for(int i = 0 ; i < QUERY_NUM ; i++){
+ def insert_order = QUERY_NUM - i - 1
+ def stmt_query_info = obj.data.rows[i]
+
+ assertNotNull(stmt_query_info["Query ID"])
+ assertNotEquals(stmt_query_info["Query ID"].toString(),
"N/A".toString())
+ assertNotNull(stmt_query_info["Detail"])
+ assertNotEquals(stmt_query_info["Detail"], "N/A")
+
+ assertEquals(stmt_query_info['Sql Statement'].toString(),
+ """ SELECT * FROM ${table} WHERE cost ${ops[insert_order]}
${nums[insert_order]} """.toString())
+ }
+
+ //———————— clean table and disable profile ————————
+ sql """ SET enable_profile = false """
+ sql """ DROP TABLE IF EXISTS ${table} """
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]