public Map<String, List<String>> getColAndPartNamesWithStats(
      String catName, String dbName, String tableName) throws MetaException {
    // Could we also join with ACID tables to only get tables with outdated stats?
    String queryText = "SELECT DISTINCT " + PARTITIONS + ".\"PART_NAME\", " + PART_COL_STATS
        + ".\"COLUMN_NAME\" FROM " + TBLS + " INNER JOIN " + DBS + " ON " + TBLS + ".\"DB_ID\" = "
        + DBS + ".\"DB_ID\" INNER JOIN " + PARTITIONS + " ON " + TBLS + ".\"TBL_ID\" = "
        + PARTITIONS + ".\"TBL_ID\"  INNER JOIN " + PART_COL_STATS + " ON " + PARTITIONS
        + ".\"PART_ID\" = " + PART_COL_STATS + ".\"PART_ID\" WHERE " + DBS + ".\"NAME\" = ? AND "
        + DBS + ".\"CTLG_NAME\" = ? AND " + TBLS + ".\"TBL_NAME\" = ? ORDER BY "
        + PARTITIONS + ".\"PART_NAME\"";

    LOG.debug("Running {}", queryText);
    try (QueryWrapper query = new QueryWrapper(pm.newQuery("javax.jdo.query.SQL", queryText))) {
      List<Object[]> sqlResult = MetastoreDirectSqlUtils.ensureList(executeWithArray(
          query.getInnerQuery(), new Object[] { dbName, catName, tableName }, queryText));
      Map<String, List<String>> result = new HashMap<>();
      String lastPartName = null;
      List<String> cols = null;
      for (Object[] line : sqlResult) {
        String col = MetastoreDirectSqlUtils.extractSqlString(line[1]);
        String part = MetastoreDirectSqlUtils.extractSqlString(line[0]);
        if (!part.equals(lastPartName)) {
          if (lastPartName != null) {
            result.put(lastPartName, cols);
          }
          cols = cols == null ? new ArrayList<>() : new ArrayList<>(cols.size());
          lastPartName = part;
        }
        cols.add(col);
      }
      if (lastPartName != null) {
        result.put(lastPartName, cols);
      }
      return result;
    }
  }
Checks if the column descriptors still has references for other SD-s. If not, then removes
them. Should be called with the list short enough to not trip up Oracle/etc.
@param columnDescriptorIdList The column identifiers
@throws MetaException If there is an SQL exception during the execution it converted to
MetaException
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java