veghlaci05 commented on code in PR #4410:
URL: https://github.com/apache/hive/pull/4410#discussion_r1228054836


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/CompactionTxnHandler.java:
##########
@@ -1295,25 +1288,33 @@ private static boolean timedOut(CompactionInfo ci, 
RetentionCounters rc, long pa
             && (rc.hasSucceededMajorCompaction || 
(rc.hasSucceededMinorCompaction && ci.type == CompactionType.MINOR));
   }
 
-  private void removeAbortRetryEntries(Connection dbConn, CompactionInfo info) 
throws MetaException, RetryException {
-    LOG.debug("Going to execute update <{}>", 
DELETE_ABORT_RETRY_ENTRIES_FROM_COMPACTION_QUEUE);
-    try (PreparedStatement pStmt = 
dbConn.prepareStatement(DELETE_ABORT_RETRY_ENTRIES_FROM_COMPACTION_QUEUE)) {
+  private void removeCompactionAndAbortRetryEntries(Connection dbConn, 
CompactionInfo info) throws MetaException, RetryException {
+    String query = 
String.format(DELETE_COMPACTION_AND_ABORT_RETRY_ENTRIES_FROM_COMPACTION_QUEUE,
+            info.partName != null ? " = ? " : " IS NULL ", info.id > 0 ? " OR 
\"CQ_ID\" = ?" : "");
+    LOG.debug("Going to execute update <{}>", query);
+    try (PreparedStatement pStmt = dbConn.prepareStatement(query)) {
       pStmt.setString(1, info.dbname);
       pStmt.setString(2, info.tableName);
       if (info.partName != null) {
         pStmt.setString(3, info.partName);
-      } else {
-        // Since the type of 'CQ_PARTITION' column is varchar.
-        // Hence, setting null for VARCHAR type.
-        pStmt.setNull(3, Types.VARCHAR);
+        if (info.id > 0) {
+          pStmt.setLong(4, info.id);
+        }
+      } else if (info.id > 0) {
+        pStmt.setLong(3, info.id);

Review Comment:
   You may use a variable and increment it, to avoid having this ugly if-else:
   ```
   int index = 0;
   pStmt.setString(index++, info.dbname);
   ...
   ```



##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/CompactionTxnHandler.java:
##########
@@ -1295,25 +1288,33 @@ private static boolean timedOut(CompactionInfo ci, 
RetentionCounters rc, long pa
             && (rc.hasSucceededMajorCompaction || 
(rc.hasSucceededMinorCompaction && ci.type == CompactionType.MINOR));
   }
 
-  private void removeAbortRetryEntries(Connection dbConn, CompactionInfo info) 
throws MetaException, RetryException {
-    LOG.debug("Going to execute update <{}>", 
DELETE_ABORT_RETRY_ENTRIES_FROM_COMPACTION_QUEUE);
-    try (PreparedStatement pStmt = 
dbConn.prepareStatement(DELETE_ABORT_RETRY_ENTRIES_FROM_COMPACTION_QUEUE)) {
+  private void removeCompactionAndAbortRetryEntries(Connection dbConn, 
CompactionInfo info) throws MetaException, RetryException {
+    String query = 
String.format(DELETE_COMPACTION_AND_ABORT_RETRY_ENTRIES_FROM_COMPACTION_QUEUE,
+            info.partName != null ? " = ? " : " IS NULL ", info.id > 0 ? " OR 
\"CQ_ID\" = ?" : "");

Review Comment:
   +1 This construct is extremely hard to understand, should be replaced with 
sth more readable.



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