pkumarsinha commented on a change in pull request #2396:
URL: https://github.com/apache/hive/pull/2396#discussion_r663019158
##########
File path:
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java
##########
@@ -1122,12 +1154,79 @@ public void abortTxns(AbortTxnsRequest rqst) throws
MetaException {
}
}
+ private long getDatabaseId(Connection dbConn, String database, String
catalog) throws SQLException {
+ ResultSet rs = null;
+ PreparedStatement pst = null;
+ try {
+ String query = "select \"DB_ID\" from \"DBS\" where \"NAME\" = ? and
\"CTLG_NAME\" = ?";
+ pst = sqlGenerator.prepareStmtWithParameters(dbConn, query,
Arrays.asList(database, catalog));
+ LOG.debug("Going to execute query <" + query.replaceAll("\\?", "{}") +
">",
+ quoteString(database), quoteString(catalog));
+ rs = pst.executeQuery();
+ if (!rs.next()) {
+ LOG.error("Database: " + database + " does not exist in catalog " +
catalog);
+ return -1;
+ }
+ return rs.getLong(1);
+ } finally {
+ close(rs);
+ closeStmt(pst);
+ }
+ }
+
+ private void updateDatabaseProp(Connection dbConn, long dbId, String prop,
String propValue) throws SQLException {
+ ResultSet rs = null;
+ PreparedStatement pst = null;
+ try {
+ String query = "SELECT \"PARAM_VALUE\" FROM \"DATABASE_PARAMS\" WHERE
\"PARAM_KEY\" = " +
+ "'" + prop + "' AND \"DB_ID\" = " + dbId;
+ pst = sqlGenerator.prepareStmtWithParameters(dbConn, query, null);
+ rs = pst.executeQuery();
+ query = null;
+ if (!rs.next()) {
+ query = "INSERT INTO \"DATABASE_PARAMS\" VALUES ( " + dbId + " , '" +
prop + "' , ? )";
+ } else if (!rs.getString(1).equals(propValue)) {
+ query = "UPDATE \"DATABASE_PARAMS\" SET \"PARAM_VALUE\" = ? WHERE
\"DB_ID\" = " + dbId +
+ " AND \"PARAM_KEY\" = '" + prop + "'";
+ }
+ closeStmt(pst);
+ if (query != null) {
+ pst = sqlGenerator.prepareStmtWithParameters(dbConn, query,
Arrays.asList(propValue));
+ LOG.debug("Updating " + prop + " for db <" + query.replaceAll("\\?",
"{}") + ">", propValue);
Review comment:
Db name would be helpful.
##########
File path:
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java
##########
@@ -1122,12 +1154,79 @@ public void abortTxns(AbortTxnsRequest rqst) throws
MetaException {
}
}
+ private long getDatabaseId(Connection dbConn, String database, String
catalog) throws SQLException {
+ ResultSet rs = null;
+ PreparedStatement pst = null;
+ try {
+ String query = "select \"DB_ID\" from \"DBS\" where \"NAME\" = ? and
\"CTLG_NAME\" = ?";
+ pst = sqlGenerator.prepareStmtWithParameters(dbConn, query,
Arrays.asList(database, catalog));
+ LOG.debug("Going to execute query <" + query.replaceAll("\\?", "{}") +
">",
+ quoteString(database), quoteString(catalog));
+ rs = pst.executeQuery();
+ if (!rs.next()) {
+ LOG.error("Database: " + database + " does not exist in catalog " +
catalog);
+ return -1;
+ }
+ return rs.getLong(1);
+ } finally {
+ close(rs);
+ closeStmt(pst);
+ }
+ }
+
+ private void updateDatabaseProp(Connection dbConn, long dbId, String prop,
String propValue) throws SQLException {
+ ResultSet rs = null;
+ PreparedStatement pst = null;
+ try {
+ String query = "SELECT \"PARAM_VALUE\" FROM \"DATABASE_PARAMS\" WHERE
\"PARAM_KEY\" = " +
+ "'" + prop + "' AND \"DB_ID\" = " + dbId;
+ pst = sqlGenerator.prepareStmtWithParameters(dbConn, query, null);
+ rs = pst.executeQuery();
+ query = null;
+ if (!rs.next()) {
+ query = "INSERT INTO \"DATABASE_PARAMS\" VALUES ( " + dbId + " , '" +
prop + "' , ? )";
+ } else if (!rs.getString(1).equals(propValue)) {
+ query = "UPDATE \"DATABASE_PARAMS\" SET \"PARAM_VALUE\" = ? WHERE
\"DB_ID\" = " + dbId +
+ " AND \"PARAM_KEY\" = '" + prop + "'";
+ }
+ closeStmt(pst);
+ if (query != null) {
Review comment:
if query == null, having a log message should be useful.
##########
File path:
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java
##########
@@ -1143,37 +1242,13 @@ private void updateReplId(Connection dbConn,
ReplLastIdInfo replLastIdInfo) thro
stmt.execute(s);
}
- String query = "select \"DB_ID\" from \"DBS\" where \"NAME\" = ? and
\"CTLG_NAME\" = ?";
- List<String> params = Arrays.asList(db, catalog);
- pst = sqlGenerator.prepareStmtWithParameters(dbConn, query, params);
- LOG.debug("Going to execute query <" + query.replaceAll("\\?", "{}") +
">",
- quoteString(db), quoteString(catalog));
- rs = pst.executeQuery();
- if (!rs.next()) {
- throw new MetaException("DB with name " + db + " does not exist in
catalog " + catalog);
+ long dbId = getDatabaseId(dbConn, db, catalog);
+ if (dbId == -1) {
Review comment:
Why is this not an error?
--
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]