private void dropDanglingColumnDescriptors(List<Long> columnDescriptorIdList)
      throws MetaException {
    if (columnDescriptorIdList.isEmpty()) {
      return;
    }
    String queryText;
    String colIds = getIdListForIn(columnDescriptorIdList);

    // Drop column descriptor, if no relation left
    queryText =
        "SELECT " + SDS + ".\"CD_ID\" "
            + "from " + SDS + " "
            + "WHERE " + SDS + ".\"CD_ID\" in (" + colIds + ") "
            + "GROUP BY " + SDS + ".\"CD_ID\"";
    Set<Long> danglingColumnDescriptorIdSet = new HashSet<>(columnDescriptorIdList);
    try (QueryWrapper query = new QueryWrapper(pm.newQuery("javax.jdo.query.SQL", queryText))) {
      List<Object> sqlResult = executeWithArray(query.getInnerQuery(), null, queryText);

      if (!sqlResult.isEmpty()) {
        for (Object cdId : sqlResult) {
          // the returned CD is not dangling, so remove it from the list
          danglingColumnDescriptorIdSet.remove(MetastoreDirectSqlUtils.extractSqlLong(cdId));
        }
      }
    }
    if (!danglingColumnDescriptorIdSet.isEmpty()) {
      try {
        String danglingCDIds = getIdListForIn(danglingColumnDescriptorIdSet);

        // Drop the columns_v2
        queryText = "delete from " + COLUMNS_V2 + " where \"CD_ID\" in (" + danglingCDIds + ")";
        executeNoResult(queryText);
        Deadline.checkTimeout();

        // Drop the cols
        queryText = "delete from " + CDS + " where \"CD_ID\" in (" + danglingCDIds + ")";
        executeNoResult(queryText);
      } catch (SQLException sqlException) {
        LOG.warn("SQL error executing query while dropping dangling col descriptions", sqlException);
        throw new MetaException("Encountered error while dropping col descriptions");
      }
    }
  }
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