hsnusonic commented on a change in pull request #2073:
URL: https://github.com/apache/hive/pull/2073#discussion_r605159628



##########
File path: 
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java
##########
@@ -3646,6 +3649,86 @@ public ShowCompactResponse 
showCompact(ShowCompactRequest rqst) throws MetaExcep
     }
   }
 
+  /**
+   * We assume this is only called by metadata cache server to know if there 
are new base/delta files should be read.
+   * The query filters compactions by state and only returns SUCCEEDED or 
READY_FOR_CLEANING compactions because
+   * only these two states means there are new files ready to be read.
+   */
+  @RetrySemantics.ReadOnly
+  public GetLatestCompactionInfoResponse 
getLatestCompactionInfo(GetLatestCompactionInfoRequest rqst)
+      throws MetaException {
+    GetLatestCompactionInfoResponse response = new 
GetLatestCompactionInfoResponse(new ArrayList<>());
+    Connection dbConn = null;
+    PreparedStatement pst = null;
+    ResultSet rs = null;
+    try {
+      try {
+        dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED);
+
+        List<String> params = new ArrayList<>();
+        // This query combines the result sets of SUCCEEDED compactions and 
READY_FOR_CLEANING compactions
+        // We also sort the result by CC_ID in descending order so that we can 
keep only the latest record
+        // according to the order in result set
+        StringBuilder sb = new StringBuilder()
+            .append("SELECT * FROM (")

Review comment:
       @klcopp I was trying to think of an alternative way to do this. One 
possible way is to use `WITH compactions AS (SELECT ..... UNION ALL SELECT 
......)` so that I can reuse the combined table in `WHERE CC_ID IN (SELECT 
max(CC_ID) from compactions GROUP BY ...)`. However, WITH clause is not 
supported universally. If we replace it with subquery, then we need to use the 
UNION ALL statement two times which makes the query too complex. Do you have 
any idea?




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org
For additional commands, e-mail: gitbox-h...@hive.apache.org

Reply via email to