Skip to content

Commit

Permalink
[Improvement](profile) add catalog info in profile (#38302)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yulei-Yang authored Jul 25, 2024
1 parent d19b3a5 commit c23228e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class SummaryProfile {
public static final String TOTAL_TIME = "Total";
public static final String TASK_STATE = "Task State";
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 Down Expand Up @@ -100,7 +101,7 @@ public class SummaryProfile {
// a column, so that should not
// add many columns here. Add to ExecutionSummary list.
public static final ImmutableList<String> SUMMARY_KEYS = ImmutableList.of(PROFILE_ID, TASK_TYPE,
START_TIME, END_TIME, TOTAL_TIME, TASK_STATE, USER, DEFAULT_DB, SQL_STATEMENT);
START_TIME, END_TIME, TOTAL_TIME, TASK_STATE, USER, DEFAULT_CATALOG, DEFAULT_DB, SQL_STATEMENT);

// The display order of execution summary items.
public static final ImmutableList<String> EXECUTION_SUMMARY_KEYS = ImmutableList.of(
Expand Down Expand Up @@ -536,6 +537,11 @@ public SummaryBuilder user(String val) {
return this;
}

public SummaryBuilder defaultCatalog(String val) {
map.put(DEFAULT_CATALOG, val);
return this;
}

public SummaryBuilder defaultDb(String val) {
map.put(DEFAULT_DB, val);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.apache.doris.common.util.MetaLockUtils;
import org.apache.doris.common.util.ProfileManager.ProfileType;
import org.apache.doris.common.util.TimeUtils;
import org.apache.doris.datasource.InternalCatalog;
import org.apache.doris.datasource.property.constants.S3Properties;
import org.apache.doris.load.BrokerFileGroup;
import org.apache.doris.load.BrokerFileGroupAggInfo.FileGroupAggKey;
Expand Down Expand Up @@ -352,6 +353,7 @@ private Map<String, String> getSummaryInfo(boolean isFinished) {
}
builder.taskState("FINISHED");
builder.user(getUserInfo() != null ? getUserInfo().getQualifiedUser() : "N/A");
builder.defaultCatalog(InternalCatalog.INTERNAL_CATALOG_NAME);
builder.defaultDb(getDefaultDb());
builder.sqlStatement(getOriginStmt().originStmt);
return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ private Map<String, String> getSummaryInfo(boolean isFinished) {
builder.taskState(!isFinished && context.getState().getStateType().equals(MysqlStateType.OK) ? "RUNNING"
: context.getState().toString());
builder.user(context.getQualifiedUser());
builder.defaultCatalog(context.getCurrentCatalog().getName());
builder.defaultDb(context.getDatabase());
builder.workloadGroup(context.getWorkloadGroupName());
builder.sqlStatement(originStmt.originStmt);
Expand Down
20 changes: 1 addition & 19 deletions regression-test/suites/query_profile/test_profile.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -104,24 +104,6 @@ suite('test_profile') {
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[9]
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")
Expand All @@ -138,7 +120,7 @@ suite('test_profile') {

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())
}
Expand Down

0 comments on commit c23228e

Please sign in to comment.