This is an automated email from the ASF dual-hosted git repository.

liulijia pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-1.2-lts by this push:
     new 61e5874a99f [Improvement](profile) add catalog info in profile (#38326)
61e5874a99f is described below

commit 61e5874a99f88de04387bf42a980660d96dd2ded
Author: Yulei-Yang <yulei.yang0...@gmail.com>
AuthorDate: Fri Jul 26 10:22:02 2024 +0800

    [Improvement](profile) add catalog info in profile (#38326)
    
    bp #38283 add `Default Catalog` column in load/query profile summary
---
 .../doris/analysis/ShowQueryProfileStmt.java       |   1 +
 .../apache/doris/common/util/ProfileManager.java   |   3 +-
 .../apache/doris/load/loadv2/BrokerLoadJob.java    |   2 +
 .../java/org/apache/doris/qe/StmtExecutor.java     |   1 +
 .../suites/query_profile/test_profile.groovy       | 149 +++++++++++++++++++++
 5 files changed, 155 insertions(+), 1 deletion(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowQueryProfileStmt.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowQueryProfileStmt.java
index f5950698257..7c5791c970d 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowQueryProfileStmt.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowQueryProfileStmt.java
@@ -37,6 +37,7 @@ public class ShowQueryProfileStmt extends ShowStmt {
                     .addColumn(new Column("JobId", 
ScalarType.createVarchar(128)))
                     .addColumn(new Column("QueryId", 
ScalarType.createVarchar(128)))
                     .addColumn(new Column("User", 
ScalarType.createVarchar(128)))
+                    .addColumn(new Column("DefaultCatalog", 
ScalarType.createVarchar(128)))
                     .addColumn(new Column("DefaultDb", 
ScalarType.createVarchar(128)))
                     .addColumn(new Column("SQL", 
ScalarType.createVarchar(65535)))
                     .addColumn(new Column("QueryType", 
ScalarType.createVarchar(128)))
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/common/util/ProfileManager.java 
b/fe/fe-core/src/main/java/org/apache/doris/common/util/ProfileManager.java
index bc7a810e5e2..a7ce1efbc43 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/common/util/ProfileManager.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/common/util/ProfileManager.java
@@ -68,6 +68,7 @@ public class ProfileManager {
     public static final String QUERY_STATE = "Query State";
     public static final String DORIS_VERSION = "Doris Version";
     public static final String USER = "User";
+    public static final String DEFAULT_CATALOG = "Default Catalog";
     public static final String DEFAULT_DB = "Default Db";
     public static final String SQL_STATEMENT = "Sql Statement";
     public static final String IS_CACHED = "Is Cached";
@@ -84,7 +85,7 @@ public class ProfileManager {
     }
 
     public static final List<String> PROFILE_HEADERS = 
Collections.unmodifiableList(
-            Arrays.asList(JOB_ID, QUERY_ID, USER, DEFAULT_DB, SQL_STATEMENT, 
QUERY_TYPE,
+            Arrays.asList(JOB_ID, QUERY_ID, USER, DEFAULT_CATALOG, DEFAULT_DB, 
SQL_STATEMENT, QUERY_TYPE,
                     START_TIME, END_TIME, TOTAL_TIME, QUERY_STATE, TRACE_ID));
 
     private class ProfileElement {
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/load/loadv2/BrokerLoadJob.java 
b/fe/fe-core/src/main/java/org/apache/doris/load/loadv2/BrokerLoadJob.java
index 01bbd795f45..dde09f77258 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/load/loadv2/BrokerLoadJob.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/load/loadv2/BrokerLoadJob.java
@@ -38,6 +38,7 @@ import org.apache.doris.common.util.MetaLockUtils;
 import org.apache.doris.common.util.ProfileManager;
 import org.apache.doris.common.util.RuntimeProfile;
 import org.apache.doris.common.util.TimeUtils;
+import org.apache.doris.datasource.InternalCatalog;
 import org.apache.doris.load.BrokerFileGroup;
 import org.apache.doris.load.BrokerFileGroupAggInfo.FileGroupAggKey;
 import org.apache.doris.load.EtlJobType;
@@ -327,6 +328,7 @@ public class BrokerLoadJob extends BulkLoadJob {
         summaryProfile.addInfoString(ProfileManager.QUERY_STATE, "N/A");
         summaryProfile.addInfoString(ProfileManager.USER,
                 getUserInfo() != null ? getUserInfo().getQualifiedUser() : 
"N/A");
+        summaryProfile.addInfoString(ProfileManager.DEFAULT_CATALOG, 
InternalCatalog.INTERNAL_CATALOG_NAME);
         summaryProfile.addInfoString(ProfileManager.DEFAULT_DB, 
getDefaultDb());
         summaryProfile.addInfoString(ProfileManager.SQL_STATEMENT, 
this.getOriginStmt().originStmt);
         summaryProfile.addInfoString(ProfileManager.IS_CACHED, "N/A");
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
index 57d63b688c8..8655019c094 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
@@ -307,6 +307,7 @@ public class StmtExecutor implements ProfileWriter {
         infos.put(ProfileManager.QUERY_TYPE, queryType);
         infos.put(ProfileManager.DORIS_VERSION, Version.DORIS_BUILD_VERSION);
         infos.put(ProfileManager.USER, context.getQualifiedUser());
+        infos.put(ProfileManager.DEFAULT_CATALOG, 
context.getCurrentCatalog().getName());
         infos.put(ProfileManager.DEFAULT_DB, context.getDatabase());
         infos.put(ProfileManager.SQL_STATEMENT, originStmt.originStmt);
         infos.put(ProfileManager.IS_CACHED, isCached ? "Yes" : "No");
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 00000000000..9f26d10fbcf
--- /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.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') {
+
+    // nereids not return same profile with legacy planner, fallback to legacy 
planner.
+    sql """set enable_nereids_planner=false"""
+
+    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["Profile ID"])
+        assertNotEquals(stmt_query_info["Profile ID"], "N/A")
+        assertNotNull(stmt_query_info["Default Catalog"])
+
+        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[8]
+        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["Profile ID"])
+        assertNotEquals(stmt_query_info["Profile ID"].toString(), 
"N/A".toString())
+        assertNotNull(stmt_query_info["Default Catalog"])
+        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} """
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to