public <T> List<T> getPartitionFieldsViaSqlFilter(
      String catName, String dbName, String tblName, List<String> partColumns, String sqlFilter,
      List<? extends Object> paramsForFilter, List<String> joinsForFilter, Integer max)
      throws MetaException {
    boolean doTrace = LOG.isDebugEnabled();
    final String dbNameLcase = dbName.toLowerCase();
    final String tblNameLcase = tblName.toLowerCase();
    final String catNameLcase = normalizeSpace(catName).toLowerCase();

    // We have to be mindful of order during filtering if we are not returning all partitions.
    String orderForFilter = (max != null) ? " order by " + MetastoreConf.getVar(conf, ConfVars.PARTITION_ORDER_EXPR) : "";
    String columns = partColumns.stream().map(col -> PARTITIONS + "." + col).collect(Collectors.joining(","));

    String queryText =
        "select " + columns + " from " + PARTITIONS + ""
            + "  inner join " + TBLS + " on " + PARTITIONS + ".\"TBL_ID\" = " + TBLS + ".\"TBL_ID\" "
            + "    and " + TBLS + ".\"TBL_NAME\" = ? "
            + "  inner join " + DBS + " on " + TBLS + ".\"DB_ID\" = " + DBS + ".\"DB_ID\" "
            + "     and " + DBS + ".\"NAME\" = ? "
            + join(joinsForFilter, ' ')
            + " where " + DBS + ".\"CTLG_NAME\" = ? "
            + (StringUtils.isBlank(sqlFilter) ? "" : (" and " + sqlFilter)) + orderForFilter;
    Object[] params = new Object[paramsForFilter.size() + 3];
    params[0] = tblNameLcase;
    params[1] = dbNameLcase;
    params[2] = catNameLcase;
    for (int i = 0; i < paramsForFilter.size(); ++i) {
      params[i + 3] = paramsForFilter.get(i);
    }

    long start = doTrace ? System.nanoTime() : 0;
    try (QueryWrapper query = new QueryWrapper(pm.newQuery("javax.jdo.query.SQL", queryText))) {
      List<T> sqlResult = executeWithArray(query.getInnerQuery(), params, queryText,
          ((max == null) ? -1 : max.intValue()));
      long queryTime = doTrace ? System.nanoTime() : 0;
      MetastoreDirectSqlUtils.timingTrace(doTrace, queryText, start, queryTime);
      List<T> result = new ArrayList<>(sqlResult);
      return result;
    }
  }
Get partition fields for the query using direct SQL queries, to avoid bazillion
queries created by DN retrieving stuff for each object individually.
@param catName MetaStore catalog name
@param dbName MetaStore db name
@param tblName MetaStore table name
@param partColumns part fields want to get
@param sqlFilter SQL filter to use. Better be SQL92-compliant.
@param paramsForFilter params for ?-s in SQL filter text. Params must be in order.
@param joinsForFilter if the filter needs additional join statement, they must be in
                      this list. Better be SQL92-compliant.
@param max The maximum number of partitions to return.
@return List of partition objects.
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java