private void populateInsertUpdateMap(Map<PartitionInfo, ColumnStatistics> statsPartInfoMap,
                                       Map<PartColNameInfo, MPartitionColumnStatistics> updateMap,
                                       Map<PartColNameInfo, MPartitionColumnStatistics>insertMap,
                                       Connection dbConn, Table tbl) throws SQLException, MetaException, NoSuchObjectException {
    StringBuilder prefix = new StringBuilder();
    StringBuilder suffix = new StringBuilder();
    List<String> queries = new ArrayList<>();
    Set<PartColNameInfo> selectedParts = new HashSet<>();

    List<Long> partIdList = statsPartInfoMap.keySet().stream().map(
            e -> e.partitionId).collect(Collectors.toList()
    );

    prefix.append("select \"PART_ID\", \"COLUMN_NAME\", \"ENGINE\" from \"PART_COL_STATS\" WHERE ");
    TxnUtils.buildQueryWithINClause(conf, queries, prefix, suffix,
            partIdList, "\"PART_ID\"", true, false);

    try (Statement statement = dbConn.createStatement()) {
      for (String query : queries) {
        LOG.debug("Execute query: " + query);
        try (ResultSet rs = statement.executeQuery(query)) {
          while (rs.next()) {
            selectedParts.add(new PartColNameInfo(rs.getLong(1), rs.getString(2), rs.getString(3)));
          }
        }
      }
    }

    for (Map.Entry entry : statsPartInfoMap.entrySet()) {
      PartitionInfo partitionInfo = (PartitionInfo) entry.getKey();
      ColumnStatistics colStats = (ColumnStatistics) entry.getValue();
      long partId = partitionInfo.partitionId;
      ColumnStatisticsDesc statsDesc = colStats.getStatsDesc();
      if (!statsDesc.isSetCatName()) {
        statsDesc.setCatName(tbl.getCatName());
      }
      for (ColumnStatisticsObj statisticsObj : colStats.getStatsObj()) {
        PartColNameInfo temp = new PartColNameInfo(partId, statisticsObj.getColName(),
            colStats.getEngine());
        if (selectedParts.contains(temp)) {
          updateMap.put(temp, StatObjectConverter.
                  convertToMPartitionColumnStatistics(null, statsDesc, statisticsObj, colStats.getEngine()));
        } else {
          insertMap.put(temp, StatObjectConverter.
                  convertToMPartitionColumnStatistics(null, statsDesc, statisticsObj, colStats.getEngine()));
        }
      }
    }
  }
This class contains the optimizations for MetaStore that rely on direct SQL access to
the underlying database. It should use ANSI SQL and be compatible with common databases
such as MySQL (note that MySQL doesn't use full ANSI mode by default), Postgres, etc.

This class separates out the update part from MetaStoreDirectSql class.
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/DirectSqlUpdatePart.java