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


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java:
##########
@@ -3910,47 +3911,15 @@ public ShowCompactResponse 
showCompact(ShowCompactRequest rqst) throws MetaExcep
     PreparedStatement stmt = null;
     try {
       try {
-        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_POOL_NAME\"" +
-            "FROM " +
-                "  \"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 , \"CC_POOL_NAME\"" +
-            "FROM " +
-            "  \"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)
-
-        String query = sb.toString();
+        String query = TxnQueries.SHOW_COMPACTION_QUERY;
+        String whereClause = getFilterClause(rqst);

Review Comment:
   Could we name the getFilterClause with some qualifier, not clear what is 
that filter for. maybe `getShowCompactionFilterClause`. 
   Result could already contain the 'where' keyword, so no extra if is needed 
to construct the final query.
   ````
   query += whereClause + TxnQueries.SHOW_COMPACTION_ORDERBY_CLAUSE;
   ````
   Also consider using `StringBuilder`



##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/utils/TxnQueries.java:
##########
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.metastore.txn;
+
+public class TxnQueries {

Review Comment:
   TxnQueries is duplicated in `metastore-server` and `metastore-common`. Could 
we please keep just 1 instance?



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