goiri commented on code in PR #4846:
URL: https://github.com/apache/hadoop/pull/4846#discussion_r970127749


##########
hadoop-yarn-project/hadoop-yarn/bin/FederationStateStore/MySQL/FederationStateStoreStoredProcs.sql:
##########
@@ -122,10 +122,21 @@ BEGIN
    WHERE applicationId = applicationID_IN;
 END //
 
-CREATE PROCEDURE sp_getApplicationsHomeSubCluster()
-BEGIN
-   SELECT applicationId, homeSubCluster
-   FROM applicationsHomeSubCluster;
+CREATE PROCEDURE sp_getApplicationsHomeSubCluster(IN limit_IN int, IN 
homeSubCluster_IN varchar(256))
+BEGIN
+   SELECT
+       applicationId,
+       homeSubCluster,
+       createTime
+    FROM
+        (SELECT
+             *,
+             @rownum := 0,
+             IF(homeSubCluster_IN = '', 1, (homeSubCluster = 
homeSubCluster_IN)) AS filter_result
+         FROM applicationshomesubcluster
+         ORDER BY createTime DESC) AS app_home_sc
+    WHERE filter_result = 1

Review Comment:
   Why you cannot do:
   ```
   SELECT
          applicationId,
          homeSubCluster,
          createTime
   FROM applicationshomesubcluster
   WHERE homeSubCluster_IN = '' OR homeSubCluster = homeSubCluster_IN
   ```



##########
hadoop-yarn-project/hadoop-yarn/bin/FederationStateStore/SQLServer/FederationStateStoreStoreProcs.sql:
##########
@@ -111,12 +111,37 @@ IF OBJECT_ID ( '[sp_getApplicationsHomeSubCluster]', 'P' 
) IS NOT NULL
 GO
 
 CREATE PROCEDURE [dbo].[sp_getApplicationsHomeSubCluster]
+    @limit int,
+    @homeSubCluster VARCHAR(256)
 AS BEGIN
     DECLARE @errorMessage nvarchar(4000)
 
     BEGIN TRY
-        SELECT [applicationId], [homeSubCluster], [createTime]
-        FROM [dbo].[applicationsHomeSubCluster]
+        IF @homeSubCluster = ''
+            SELECT
+                [applicationId],
+                [homeSubCluster],
+                [createTime]
+            FROM(SELECT
+                     [applicationId],
+                     [homeSubCluster],
+                     [createTime],
+                     row_number() over(order by [createTime] desc) AS app_rank
+                 FROM [dbo].[applicationsHomeSubCluster]) AS t
+            WHERE app_rank <= @limit;
+        ELSE
+            SELECT
+                [applicationId],
+                [homeSubCluster],
+                [createTime]
+            FROM(SELECT
+                     [applicationId],
+                     [homeSubCluster],
+                     [createTime],
+                     row_number() over(partition by [homeSubCluster] order by 
[createTime] desc) AS app_rank
+                 FROM [dbo].[applicationsHomeSubCluster]
+                 WHERE [homeSubCluster] = @homeSubCluster) AS t

Review Comment:
   Why not 
   ```
   WHERE [homeSubCluster] = @homeSubCluster OR @homeSubCluster = ''
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to