[ https://issues.apache.org/jira/browse/HIVE-26443?focusedWorklogId=802479&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-802479 ]
ASF GitHub Bot logged work on HIVE-26443: ----------------------------------------- Author: ASF GitHub Bot Created on: 22/Aug/22 13:37 Start Date: 22/Aug/22 13:37 Worklog Time Spent: 10m Work Description: veghlaci05 commented on code in PR #3513: URL: https://github.com/apache/hive/pull/3513#discussion_r951451013 ########## 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: Due to your comment I realized that I forgot to enhance the `SHOW COMPACTIONS `command with the `POOL 'poolname'` part :). It will be in my next commit along with the fixes of your points. Regarding the prepared statement, the reason behind it is the same like for the ALTER TABLE COMPACT command: The pool is coming from the user and could be a subject of SQL injection. Issue Time Tracking ------------------- Worklog Id: (was: 802479) Time Spent: 6h (was: 5h 50m) > 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: 6h > Remaining Estimate: 0h > > The details can be found in the attached design doc. -- This message was sent by Atlassian Jira (v8.20.10#820010)