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

yiguolei pushed a commit to branch branch-4.2
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-4.2 by this push:
     new 86982af4783 [fix](fe) Fix query profile ownership filtering and SQL 
retrieval (branch-4.2) (#71351)
86982af4783 is described below

commit 86982af478348e7580fbf8f534a6389db498ef2d
Author: yiguolei <[email protected]>
AuthorDate: Fri Dec 4 09:33:43 2026 +0800

    [fix](fe) Fix query profile ownership filtering and SQL retrieval 
(branch-4.2) (#71351)
    
    ### What problem does this PR solve?
    
    Related PR: #71280
    
    Backport the production fix to branch-4.2. Retained query profile APIs
    resolve owner, profile ID, task type, node, and SQL fields by column
    name. Ordinary users can retrieve their own profiles, and authorized SQL
    requests return the SQL instead of the end timestamp. Existing
    root/admin visibility and response formats are preserved.
    
    The upstream test file is omitted: branch-4.2 lacks the current-query
    normalization functionality used by its pre-existing tests, introduced
    in #68032 and updated in #71236. This backport changes only
    QueryProfileAction.java.
    
    ### Release note
    
    Fix FE v2 query profile ownership filtering and SQL retrieval.
    
    ### Check List (For Author)
    
    - Validation: git diff --check passed. Remote FE compilation and
    existing profile-related FE unit tests are being prepared; results are
    pending.
    - Behavior changed: Yes, fixes retained-profile filtering and SQL
    retrieval.
    - Does this need documentation: No.
---
 .../httpv2/rest/manager/QueryProfileAction.java    | 26 +++++++++++++++-------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/QueryProfileAction.java
 
b/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/QueryProfileAction.java
index d0aae7d1a0e..58175f17451 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/QueryProfileAction.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/QueryProfileAction.java
@@ -42,6 +42,7 @@ import org.apache.doris.service.FrontendOptions;
 import org.apache.doris.thrift.TQueryStatistics;
 import org.apache.doris.thrift.TStatusCode;
 
+import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
@@ -187,15 +188,17 @@ public class QueryProfileAction extends 
RestBaseController {
             return ResponseEntityBuilder.ok(new 
NodeAction.NodeInfo(QUERY_TITLE_NAMES, queries));
         }
 
+        int taskTypeIndex = 
PROFILE_TITLE_NAMES.indexOf(SummaryProfile.TASK_TYPE);
         Stream<List<String>> queryStream = ProfileManager.getInstance()
                 .getQueryInfoByColumnNameList(PROFILE_TITLE_NAMES).stream()
-                .filter(profile -> profile.get(5).equalsIgnoreCase("Query"));
-        queryStream = filterQueriesByUserAndQueryId(queryStream, queryId);
+                .filter(profile -> 
profile.get(taskTypeIndex).equalsIgnoreCase("Query"));
+        queryStream = filterQueriesByUserAndQueryId(queryStream, queryId, 
PROFILE_TITLE_NAMES);
         queries = queryStream.collect(Collectors.toList());
 
         // add node information
+        int nodeIndex = PROFILE_TITLE_NAMES.indexOf(NODE);
         for (List<String> query : queries) {
-            query.set(1, 
NetUtils.getHostPortInAccessibleFormat(Env.getCurrentEnv().getSelfNode().getHost(),
+            query.set(nodeIndex, 
NetUtils.getHostPortInAccessibleFormat(Env.getCurrentEnv().getSelfNode().getHost(),
                     HttpURLUtil.getHttpPort()));
         }
 
@@ -241,25 +244,32 @@ public class QueryProfileAction extends 
RestBaseController {
             }
         } else {
             Stream<List<String>> queryStream = 
ProfileManager.getInstance().getAllQueries().stream();
-            queryStream = filterQueriesByUserAndQueryId(queryStream, queryId);
+            queryStream = filterQueriesByUserAndQueryId(queryStream, queryId, 
SummaryProfile.SUMMARY_KEYS);
             List<List<String>> queries = 
queryStream.collect(Collectors.toList());
             if (!queries.isEmpty()) {
-                querySql.put("sql", queries.get(0).get(3));
+                int sqlIndex = 
SummaryProfile.SUMMARY_KEYS.indexOf(SummaryProfile.SQL_STATEMENT);
+                querySql.put("sql", queries.get(0).get(sqlIndex));
             }
         }
         return ResponseEntityBuilder.ok(querySql);
     }
 
-    private Stream<List<String>> 
filterQueriesByUserAndQueryId(Stream<List<String>> queryStream, String queryId) 
{
+    private Stream<List<String>> 
filterQueriesByUserAndQueryId(Stream<List<String>> queryStream, String queryId,
+            List<String> columnNames) {
+        // query_info and sql use different column orders. Resolve ownership 
from the supplied schema.
+        int userIndex = columnNames.indexOf(SummaryProfile.USER);
+        int queryIdIndex = columnNames.indexOf(SummaryProfile.PROFILE_ID);
+        Preconditions.checkArgument(userIndex >= 0 && queryIdIndex >= 0,
+                "Profile columns must contain User and Profile ID");
         // filter by user
         // Only admin or root user can see all profile.
         // Common user can only review the query of their own.
         String user = 
ConnectContext.get().getCurrentUserIdentity().getQualifiedUser();
         if (!user.equalsIgnoreCase(Auth.ADMIN_USER) && 
!user.equalsIgnoreCase(Auth.ROOT_USER)) {
-            queryStream = queryStream.filter(q -> q.get(1).equals(user));
+            queryStream = queryStream.filter(q -> 
user.equals(q.get(userIndex)));
         }
         if (!Strings.isNullOrEmpty(queryId)) {
-            queryStream = queryStream.filter(query -> 
query.get(0).equals(queryId));
+            queryStream = queryStream.filter(query -> 
queryId.equals(query.get(queryIdIndex)));
         }
         return queryStream;
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to