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


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/DirectSqlUpdatePart.java:
##########
@@ -615,42 +541,39 @@ public long getNextCSIdForMPartitionColumnStatistics(long 
numStats) throws MetaE
                 + "WHERE \"SEQUENCE_NAME\"= "
                 + 
quoteString("org.apache.hadoop.hive.metastore.model.MPartitionColumnStatistics"));
         LOG.debug("Going to execute query " + query);
-        statement = dbConn.createStatement();
-        rs = statement.executeQuery(query);
-        if (rs.next()) {
-          maxCsId = rs.getLong(1);
-        } else if (insertDone) {
-          throw new MetaException("Invalid state of SEQUENCE_TABLE for 
MPartitionColumnStatistics");
-        } else {
-          insertDone = true;
-          closeStmt(statement);
-          statement = dbConn.createStatement();
-          query = "INSERT INTO \"SEQUENCE_TABLE\" (\"SEQUENCE_NAME\", 
\"NEXT_VAL\")  VALUES ( "
-                  + 
quoteString("org.apache.hadoop.hive.metastore.model.MPartitionColumnStatistics")
 + "," + 1
-                  + ")";
-          try {
-            statement.executeUpdate(query);
-          } catch (SQLException e) {
-            // If the record is already inserted by some other thread continue 
to select.
-            if (dbType.isDuplicateKeyError(e)) {
-              continue;
+        try (Statement statement = dbConn.createStatement();
+             ResultSet rs = statement.executeQuery(query)) {
+          if (rs.next()) {
+            maxCsId = rs.getLong(1);
+          } else if (insertDone) {
+            throw new MetaException("Invalid state of SEQUENCE_TABLE for 
MPartitionColumnStatistics");
+          } else {
+            insertDone = true;
+            query = "INSERT INTO \"SEQUENCE_TABLE\" (\"SEQUENCE_NAME\", 
\"NEXT_VAL\")  VALUES ( "
+                    + 
quoteString("org.apache.hadoop.hive.metastore.model.MPartitionColumnStatistics")
 + "," + 1
+                    + ")";
+            try (Statement stmt = dbConn.createStatement()) {

Review Comment:
   can't we reuse the existing statement?



-- 
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: gitbox-unsubscr...@hive.apache.org

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