static void setPartitionParametersWithFilter(String PARTITION_PARAMS,
      boolean convertMapNullsToEmptyStrings, PersistenceManager pm, String partIds,
      TreeMap<Long, Partition> partitions, String includeParamKeyPattern, String excludeParamKeyPattern)
      throws MetaException {
    StringBuilder queryTextBuilder = new StringBuilder("select \"PART_ID\", \"PARAM_KEY\", \"PARAM_VALUE\" from ")
        .append(PARTITION_PARAMS)
        .append(" where \"PART_ID\" in (")
        .append(partIds)
        .append(") and \"PARAM_KEY\" is not null");
    List<Object> queryParams = new ArrayList<>(2);;
    if (includeParamKeyPattern != null && !includeParamKeyPattern.isEmpty()) {
      queryTextBuilder.append(" and \"PARAM_KEY\" LIKE (?)");
      queryParams.add(includeParamKeyPattern);
    }
    if (excludeParamKeyPattern != null && !excludeParamKeyPattern.isEmpty()) {
      queryTextBuilder.append(" and \"PARAM_KEY\" NOT LIKE (?)");
      queryParams.add(excludeParamKeyPattern);
    }

    queryTextBuilder.append(" order by \"PART_ID\" asc");
    String queryText = queryTextBuilder.toString();
    loopJoinOrderedResult(pm, partitions, queryText, queryParams.toArray(), 0, new ApplyFunc<Partition>() {
      @Override
      public void apply(Partition t, Object[] fields) {
        t.putToParameters((String) fields[1], extractSqlClob(fields[2]));
      }
    });
    // Perform conversion of null map values
    for (Partition t : partitions.values()) {
      t.setParameters(MetaStoreServerUtils.trimMapNulls(t.getParameters(), convertMapNullsToEmptyStrings));
    }
  }
Merges applies the result of a PM SQL query into a tree of object.
Essentially it's an object join. DN could do this for us, but it issues queries
separately for every object, which is suboptimal.
@param pm
@param tree The object tree, by ID.
@param queryText The query text.
@param keyIndex Index of the Long column corresponding to the map ID in query result rows.
@param func The function that is called on each (object,row) pair with the same id.
@return the count of results returned from the query.
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/MetastoreDirectSqlUtils.java