maheshk114 commented on a change in pull request #2266:
URL: https://github.com/apache/hive/pull/2266#discussion_r642269504



##########
File path: 
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java
##########
@@ -5394,6 +5410,476 @@ public void countOpenTxns() throws MetaException {
     }
   }
 
+  private void cleanOldStatsFromPartColStatTable(Map<PartitionInfo, 
ColumnStatistics> statsPartInfoMap,
+                                                 Connection dbConn) throws 
SQLException {
+    PreparedStatement preparedStatement = null;
+    int numRows = 0;
+    int maxNumRows = MetastoreConf.getIntVar(conf, 
ConfVars.DIRECT_SQL_MAX_ELEMENTS_VALUES_CLAUSE);
+
+    // Index is present on DB_NAME,TABLE_NAME,COLUMN_NAME,PARTITION_NAME. use 
that.
+    // TODO : Need to add catalog name to the index
+    String delete = "DELETE FROM \"PART_COL_STATS\" where \"DB_NAME\" = ? AND "
+            + "\"TABLE_NAME\" = ? AND \"COLUMN_NAME\" = ? AND 
\"PARTITION_NAME\" = ? "
+            + "AND \"PART_ID\" = ?";
+
+    try {
+      preparedStatement = sqlGenerator.prepareStmtWithParameters(dbConn, 
delete, null);
+      for (Map.Entry entry : statsPartInfoMap.entrySet()) {
+        ColumnStatistics colStats = (ColumnStatistics) entry.getValue();
+        PartitionInfo partitionInfo = (PartitionInfo) entry.getKey();
+        for (ColumnStatisticsObj statisticsObj : colStats.getStatsObj()) {
+          preparedStatement.setString(1, colStats.getStatsDesc().getDbName());
+          preparedStatement.setString(2, 
colStats.getStatsDesc().getTableName());
+          preparedStatement.setString(3, statisticsObj.getColName());
+          preparedStatement.setString(4, 
colStats.getStatsDesc().getPartName());
+          preparedStatement.setLong(5, partitionInfo.partitionId);
+          numRows++;
+          preparedStatement.addBatch();
+          if (numRows == maxNumRows) {
+            preparedStatement.executeBatch();
+            numRows = 0;
+            LOG.debug("Executed delete " + delete + " for numRows " + numRows);
+          }
+        }
+      }
+
+      if (numRows != 0) {
+        preparedStatement.executeBatch();
+        LOG.debug("Executed delete " + delete + " for numRows " + numRows);
+      }
+    } finally {
+      closeStmt(preparedStatement);
+    }
+  }
+
+  private void insertIntoPartColStatTable(Map<PartitionInfo, ColumnStatistics> 
partitionInfoMap,
+                                          long maxCsId,
+                                          Connection dbConn) throws 
SQLException, MetaException, NoSuchObjectException {
+    PreparedStatement preparedStatement = null;
+    int numRows = 0;
+    int maxNumRows = MetastoreConf.getIntVar(conf, 
ConfVars.DIRECT_SQL_MAX_ELEMENTS_VALUES_CLAUSE);
+    String insert = "INSERT INTO \"PART_COL_STATS\" (\"CS_ID\", \"CAT_NAME\", 
\"DB_NAME\","
+            + "\"TABLE_NAME\", \"PARTITION_NAME\", \"COLUMN_NAME\", 
\"COLUMN_TYPE\", \"PART_ID\","
+            + " \"LONG_LOW_VALUE\", \"LONG_HIGH_VALUE\", 
\"DOUBLE_HIGH_VALUE\", \"DOUBLE_LOW_VALUE\","
+            + " \"BIG_DECIMAL_LOW_VALUE\", \"BIG_DECIMAL_HIGH_VALUE\", 
\"NUM_NULLS\", \"NUM_DISTINCTS\", \"BIT_VECTOR\" ,"
+            + " \"AVG_COL_LEN\", \"MAX_COL_LEN\", \"NUM_TRUES\", 
\"NUM_FALSES\", \"LAST_ANALYZED\", \"ENGINE\") values "
+            + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 
?, ?)";
+
+    try {
+      preparedStatement = sqlGenerator.prepareStmtWithParameters(dbConn, 
insert, null);
+      for (Map.Entry entry : partitionInfoMap.entrySet()) {
+        ColumnStatistics colStats = (ColumnStatistics) entry.getValue();
+        PartitionInfo partitionInfo = (PartitionInfo)entry.getKey();
+        ColumnStatisticsDesc statsDesc = colStats.getStatsDesc();
+        long partId = partitionInfo.partitionId;
+
+        for (ColumnStatisticsObj statisticsObj : colStats.getStatsObj()) {
+          MPartitionColumnStatistics mPartitionColumnStatistics = 
StatObjectConverter.
+                  convertToMPartitionColumnStatistics(null, statsDesc, 
statisticsObj, colStats.getEngine());
+
+          preparedStatement.setLong(1, maxCsId);
+          preparedStatement.setString(2, 
mPartitionColumnStatistics.getCatName());
+          preparedStatement.setString(3, 
mPartitionColumnStatistics.getDbName());
+          preparedStatement.setString(4, 
mPartitionColumnStatistics.getTableName());
+          preparedStatement.setString(5, 
mPartitionColumnStatistics.getPartitionName());
+          preparedStatement.setString(6, 
mPartitionColumnStatistics.getColName());
+          preparedStatement.setString(7, 
mPartitionColumnStatistics.getColType());
+          preparedStatement.setLong(8, partId);
+          preparedStatement.setObject(9, 
mPartitionColumnStatistics.getLongLowValue());
+          preparedStatement.setObject(10, 
mPartitionColumnStatistics.getLongHighValue());
+          preparedStatement.setObject(11, 
mPartitionColumnStatistics.getDoubleHighValue());
+          preparedStatement.setObject(12, 
mPartitionColumnStatistics.getDoubleLowValue());
+          preparedStatement.setString(13, 
mPartitionColumnStatistics.getDecimalLowValue());
+          preparedStatement.setString(14, 
mPartitionColumnStatistics.getDecimalHighValue());
+          preparedStatement.setObject(15, 
mPartitionColumnStatistics.getNumNulls());
+          preparedStatement.setObject(16, 
mPartitionColumnStatistics.getNumDVs());
+          preparedStatement.setObject(17, 
mPartitionColumnStatistics.getBitVector());
+          preparedStatement.setObject(18, 
mPartitionColumnStatistics.getAvgColLen());
+          preparedStatement.setObject(19, 
mPartitionColumnStatistics.getMaxColLen());
+          preparedStatement.setObject(20, 
mPartitionColumnStatistics.getNumTrues());
+          preparedStatement.setObject(21, 
mPartitionColumnStatistics.getNumFalses());
+          preparedStatement.setLong(22, 
mPartitionColumnStatistics.getLastAnalyzed());
+          preparedStatement.setString(23, 
mPartitionColumnStatistics.getEngine());
+
+          maxCsId++;
+          numRows++;
+          preparedStatement.addBatch();
+          if (numRows == maxNumRows) {
+            preparedStatement.executeBatch();
+            numRows = 0;
+          }
+        }
+      }
+
+      if (numRows != 0) {

Review comment:
       in this case it does not matter i think.




-- 
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:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to