public List<String> getPartitionNamesViaSql(SqlFilterForPushdown filter, List<FieldSchema> partitionKeys,
      String defaultPartName, String order, Integer max) throws MetaException {
    boolean doTrace = LOG.isDebugEnabled();
    List<Object[]> orderSpecs = MetaStoreUtils.makeOrderSpecs(order);
    String catName = filter.catName.toLowerCase(), dbName = filter.dbName.toLowerCase(),
        tblName = filter.tableName.toLowerCase(), sqlFilter = filter.filter;
    List<Object> paramsForFilter = filter.params;
    List<String> joins =  filter.joins;
    if (joins.isEmpty()) {
      for (int i = 0; i < partitionKeys.size(); i++) {
        joins.add(null);
      }
    }

    StringBuilder orderColumns = new StringBuilder(), orderClause = new StringBuilder();
    int i = 0;
    List<Object> paramsForOrder = new ArrayList<Object>();
    boolean dbHasJoinCastBug = dbType.hasJoinOperationOrderBug();
    for (Object[] orderSpec: orderSpecs) {
      int partColIndex = (int)orderSpec[0];
      String orderAlias = "ODR" + (i++);
      String tableValue, tableAlias;
      if (joins.get(partColIndex) == null) {
        tableAlias = "ORDER"  + partColIndex;
        joins.set(partColIndex, "inner join " + PARTITION_KEY_VALS + " \"" + tableAlias
            + "\" on \""  + tableAlias + "\".\"PART_ID\" = " + PARTITIONS + ".\"PART_ID\""
            + " and \"" + tableAlias + "\".\"INTEGER_IDX\" = " + partColIndex);
        tableValue = " \"" + tableAlias + "\".\"PART_KEY_VAL\" ";
      } else {
        tableAlias = "FILTER" + partColIndex;
        tableValue = " \"" + tableAlias + "\".\"PART_KEY_VAL\" ";
      }

      String tableColumn = tableValue;
      String colType = partitionKeys.get(partColIndex).getType();
      PartitionFilterGenerator.FilterType type =
          PartitionFilterGenerator.FilterType.fromType(colType);
      if (type == PartitionFilterGenerator.FilterType.Date) {
      	tableValue = dbType.toDate(tableValue);
      } else if (type == PartitionFilterGenerator.FilterType.Timestamp) {
        tableValue = dbType.toTimestamp(tableValue);
      } else if (type == PartitionFilterGenerator.FilterType.Integral) {
        tableValue = "CAST(" + tableColumn + " AS decimal(21,0))";
      }
      String tableValue0 = tableValue;
      tableValue = " (case when " + tableColumn + " <> ?";
      paramsForOrder.add(defaultPartName);
      if (dbHasJoinCastBug) {
        tableValue += (" and " + TBLS + ".\"TBL_NAME\" = ? and " + DBS + ".\"NAME\" = ? and "
            + DBS + ".\"CTLG_NAME\" = ? and "
            + "\"" + tableAlias + "\".\"PART_ID\" = " + PARTITIONS + ".\"PART_ID\" and "
            + "\"" + tableAlias + "\".\"INTEGER_IDX\" = " + partColIndex);
        paramsForOrder.add(tblName);
        paramsForOrder.add(dbName);
        paramsForOrder.add(catName);
      }
      tableValue += " then " + tableValue0 + " else null end) AS \"" + orderAlias + "\" ";
      orderColumns.append(tableValue).append(",");
      orderClause.append(" \"").append(orderAlias).append("\" ")
          .append((String)orderSpec[1]).append(",");
    }

    for (int j = 0; j < joins.size(); j++) {
      if (joins.get(j) == null) {
        joins.remove(j--);
      }
    }
    if (orderClause.length() > 0) {
      orderClause.setLength(orderClause.length() - 1);
      orderColumns.setLength(orderColumns.length() - 1);
    }

    String orderCls = " order by " +
        (orderClause.length() > 0 ? orderClause.toString() : "\"PART_NAME\" asc");
    String columns = orderColumns.length() > 0 ? (", " + orderColumns.toString()) : "";
    String queryText =
        "select " + PARTITIONS + ".\"PART_NAME\"" + 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(joins, ' ')
            + " where " + DBS + ".\"CTLG_NAME\" = ? "
            + (StringUtils.isBlank(sqlFilter) ? "" : (" and " + sqlFilter)) + orderCls;

    Object[] params = new Object[paramsForFilter.size() + paramsForOrder.size() + 3];
    i = 0;
    for (; i < paramsForOrder.size(); i++) {
      params[i] = paramsForOrder.get(i);
    }
    params[i] = tblName;
    params[i+1] = dbName;
    params[i+2] = catName;
    for (int j = 0; j < paramsForFilter.size(); j++) {
      params[i + j + 3] = paramsForFilter.get(j);
    }

    List<String> partNames = new LinkedList<String>();
    int limit = (max == null ? -1 : max);
    try (QueryWrapper query = new QueryWrapper(pm.newQuery("javax.jdo.query.SQL", queryText))) {
      long start = doTrace ? System.nanoTime() : 0;
      List<Object> sqlResult = executeWithArray(query.getInnerQuery(), params, queryText, limit);
      long queryTime = doTrace ? System.nanoTime() : 0;
      MetastoreDirectSqlUtils.timingTrace(doTrace, queryText, start, queryTime);
      for (Object result : sqlResult) {
        Object obj = !columns.isEmpty() ? ((Object[]) result)[0] : result;
        partNames.add((String)obj);
      }
    }
    return partNames;
  }
Get partition names by using direct SQL queries.
@param filter filter to use with direct sql
@param partitionKeys partition columns
@param defaultPartName default partition name
@param order the specification for ordering partition names
@param max maximum number of partition names to return
@return list of partition names
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java