[ 
https://issues.apache.org/jira/browse/HIVE-26443?focusedWorklogId=802062&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-802062
 ]

ASF GitHub Bot logged work on HIVE-26443:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 19/Aug/22 15:45
            Start Date: 19/Aug/22 15:45
    Worklog Time Spent: 10m 
      Work Description: deniskuzZ commented on code in PR #3513:
URL: https://github.com/apache/hive/pull/3513#discussion_r950333258


##########
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:
   i think, regular statement would be more elegant here



##########
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:
   i think, simple statement would be more elegant here





Issue Time Tracking
-------------------

    Worklog Id:     (was: 802062)
    Time Spent: 4h 50m  (was: 4h 40m)

> Add priority queueing to compaction
> -----------------------------------
>
>                 Key: HIVE-26443
>                 URL: https://issues.apache.org/jira/browse/HIVE-26443
>             Project: Hive
>          Issue Type: New Feature
>            Reporter: László Végh
>            Assignee: László Végh
>            Priority: Major
>              Labels: pull-request-available
>         Attachments: Pool based compaction queues.docx
>
>          Time Spent: 4h 50m
>  Remaining Estimate: 0h
>
> The details can be found in the attached design doc.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to