private static void makeFilterForEquals(String keyName, String value, String paramName,
      Map<String, Object> params, int keyPos, int keyCount, boolean isEq, FilterBuilder fltr)
          throws MetaException {
    Map<String, String> partKeyToVal = new HashMap<>();
    partKeyToVal.put(keyName, value);
    // If a partition has multiple partition keys, we make the assumption that
    // makePartName with one key will return a substring of the name made
    // with both all the keys.
    String escapedNameFragment = Warehouse.makePartName(partKeyToVal, false);
    if (keyCount == 1) {
      // Case where this is no other partition columns
      params.put(paramName, escapedNameFragment);
      fltr.append("partitionName ").append(isEq ? "== " : "!= ").append(paramName);
    } else if (keyPos + 1 == keyCount) {
      // Case where the partition column is at the end of the name. There will
      // be a leading '/' but no trailing '/'
      params.put(paramName, "/" + escapedNameFragment);
      fltr.append(isEq ? "" : "!").append("partitionName.endsWith(")
        .append(paramName).append(")");
    } else if (keyPos == 0) {
      // Case where the partition column is at the beginning of the name. There will
      // be a trailing '/' but no leading '/'
      params.put(paramName, escapedNameFragment + "/");
      fltr.append(isEq ? "" : "!").append("partitionName.startsWith(")
        .append(paramName).append(")");
    } else {
      // Case where the partition column is in the middle of the name. There will
      // be a leading '/' and an trailing '/'
      params.put(paramName, "/" + escapedNameFragment + "/");
      fltr.append("partitionName.indexOf(").append(paramName).append(")")
        .append(isEq ? ">= 0" : "< 0");
    }
  }
For equals and not-equals, we can make the JDO query much faster by filtering
based on the partition name. For a condition like ds="2010-10-01", we can see
if there are any partitions with a name that contains the substring "ds=2010-10-01/"
False matches aren't possible since "=" is escaped for partition names
and the trailing '/' ensures that we won't get a match with ds=2010-10-011
Note that filters on integral type equality also work correctly by virtue of
comparing them as part of ds=1234 string.

Two cases to keep in mind: Case with only one partition column (no '/'s)
Case where the partition key column is at the end of the name. (no
tailing '/')

@param keyName name of the partition column e.g. ds.
@param value The value to compare to.
@param paramName name of the parameter to use for JDOQL.
@param params a map from the parameter name to their values.
@param keyPos The index of the requisite partition column in the list of such columns.
@param keyCount Partition column count for the table.
@param isEq whether the operator is equals, or not-equals.
@param fltr Filter builder used to append the filter, or report errors.
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/parser/ExpressionTree.java