GetPartitionsResponse getPartitionsWithSpecs(GetPartitionsRequest getPartitionsRequest) throws MetaException {
    List<Partition> result = new ArrayList<>();
    PartitionListComposingSpec partListComp;

    PartitionSpec partitionSpec = new PartitionSpec();
    partitionSpec.setCatName(getPartitionsRequest.getCatName());
    partitionSpec.setDbName(getPartitionsRequest.getDbName());
    partitionSpec.setTableName(getPartitionsRequest.getTblName());

    List<PartitionSpec> partSpecs;

    GetPartitionsFilterSpec filterSpec = getPartitionsRequest.getFilterSpec();
    if (filterSpec == null) {
      partListComp = new PartitionListComposingSpec(new ArrayList<>(parts.values()));
      partitionSpec.setPartitionList(partListComp);

      partSpecs = Arrays.asList(partitionSpec);
      return new GetPartitionsResponse(partSpecs);
    }

    for (Map.Entry<String, Partition> entry : parts.entrySet()) {
      Partition partition = entry.getValue();
      boolean matches = false;

      PartitionFilterMode filterMode = filterSpec.getFilterMode();
      switch (filterMode) {
        case BY_NAMES:
          matches = filterSpec.getFilters().contains(entry.getKey());
          break;
        case BY_VALUES:
          matches = filterSpec.getFilters().stream().anyMatch(str -> entry.getValue().getValues().contains(str));
          break;
        case BY_EXPR:
          ScriptEngine se = new ScriptEngineManager().getEngineByName("JavaScript");
          if (se == null) {
            LOG.error("JavaScript script engine is not found, therefore partition filtering "
                    + "for temporary tables is disabled.");
            break;
          }

          for (String filter : filterSpec.getFilters()) {
            try {
              se.put("partition", partition);
              matches = (Boolean) se.eval(filter);
            } catch (ScriptException e) {
              throw new MetaException("Error evaluating filter expression: " + e.getMessage());
            }
          }
          break;
        default:
            throw new MetaException("Unknown filter mode: " + filterMode);
      }
      if (matches) {
        result.add(entry.getValue());
      }
    }

    partListComp = new PartitionListComposingSpec(result);
    partitionSpec.setPartitionList(partListComp);

    partSpecs = Arrays.asList(partitionSpec);
    return new GetPartitionsResponse(partSpecs);
  }
Return a list of partitions matching the filter.
@param filter filter string, must be not null.
@return list of partitions, always not-null.
@throws MetaException
ql/src/java/org/apache/hadoop/hive/ql/metadata/PartitionTree.java