deniskuzZ commented on code in PR #3513:
URL: https://github.com/apache/hive/pull/3513#discussion_r955051510


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java:
##########
@@ -3844,34 +3847,51 @@ protected static String compactorStateToResponse(char 
s) {
   public ShowCompactResponse showCompact(ShowCompactRequest rqst) throws 
MetaException {
     ShowCompactResponse response = new ShowCompactResponse(new ArrayList<>());
     Connection dbConn = null;
-    Statement stmt = null;
+    PreparedStatement stmt = null;
     try {
       try {
-        dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED);
-        stmt = dbConn.createStatement();
-        String s = "" +
-            //-1 because 'null' literal doesn't work for all DBs...
+        StringBuilder sb =new StringBuilder(2048);
+        sb.append(
             "SELECT " +
             "  \"CQ_DATABASE\", \"CQ_TABLE\", \"CQ_PARTITION\", \"CQ_STATE\", 
\"CQ_TYPE\", \"CQ_WORKER_ID\", " +
             "  \"CQ_START\", -1 \"CC_END\", \"CQ_RUN_AS\", 
\"CQ_HADOOP_JOB_ID\", \"CQ_ID\", \"CQ_ERROR_MESSAGE\", " +
             "  \"CQ_ENQUEUE_TIME\", \"CQ_WORKER_VERSION\", 
\"CQ_INITIATOR_ID\", \"CQ_INITIATOR_VERSION\", " +
-            "  \"CQ_CLEANER_START\"" +
+            "  \"CQ_CLEANER_START\", \"CQ_POOL_NAME\"" +
             "FROM " +
-            "  \"COMPACTION_QUEUE\" " +
+                "  \"COMPACTION_QUEUE\" "
+        );
+        if 
(org.apache.commons.lang3.StringUtils.isNotBlank(rqst.getPoolName())) {
+          sb.append("WHERE \"CQ_POOL_NAME\" = ? ");
+        }
+        sb.append(
             "UNION ALL " +
             "SELECT " +
             "  \"CC_DATABASE\", \"CC_TABLE\", \"CC_PARTITION\", \"CC_STATE\", 
\"CC_TYPE\", \"CC_WORKER_ID\", " +
             "  \"CC_START\", \"CC_END\", \"CC_RUN_AS\", \"CC_HADOOP_JOB_ID\", 
\"CC_ID\", \"CC_ERROR_MESSAGE\", " +
             "  \"CC_ENQUEUE_TIME\", \"CC_WORKER_VERSION\", 
\"CC_INITIATOR_ID\", \"CC_INITIATOR_VERSION\", " +
-            "  -1 " +
+            "  -1 , \"CC_POOL_NAME\"" +
             "FROM " +
-            "  \"COMPLETED_COMPACTIONS\""; //todo: sort by cq_id?
+            "  \"COMPLETED_COMPACTIONS\" "
+        );
+        if 
(org.apache.commons.lang3.StringUtils.isNotBlank(rqst.getPoolName())) {
+          sb.append("WHERE \"CC_POOL_NAME\" = ?");
+        }
+        //todo: sort by cq_id?
         //what I want is order by cc_end desc, cc_start asc (but derby has a 
bug https://issues.apache.org/jira/browse/DERBY-6013)
         //to sort so that currently running jobs are at the end of the list 
(bottom of screen)
         //and currently running ones are in sorted by start time
         //w/o order by likely currently running compactions will be first (LHS 
of Union)
-        LOG.debug("Going to execute query <" + s + ">");
-        ResultSet rs = stmt.executeQuery(s);
+
+        String query = sb.toString();
+        dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED);
+        stmt = dbConn.prepareStatement(query);
+        if 
(org.apache.commons.lang3.StringUtils.isNotBlank(rqst.getPoolName())) {

Review Comment:
   +1



-- 
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