Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Improvement](profile) add catalog info in profile #38326

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -84,7 +85,7 @@ public enum ProfileType {
}

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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
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;
Expand Down Expand Up @@ -327,6 +328,7 @@ private void writeProfile() {
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ private Map<String, String> getSummaryInfo() {
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");
Expand Down
149 changes: 149 additions & 0 deletions regression-test/suites/query_profile/test_profile.groovy
Original file line number Diff line number Diff line change
@@ -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} """
}
Loading