/** * Get a list of {@link Partition}s for the <code>table</code> that matches an optional <code>filter</code> * * @param client an {@link IMetaStoreClient} for the correct metastore. * @param table the {@link Table} for which we should get partitions. * @param filter an optional filter for partitions as would be used in Hive. Can only filter on String columns. * (e.g. "part = \"part1\"" or "date > \"2015\"". * @return a list of {@link Partition}s */ public static List<Partition> getPartitions(IMetaStoreClient client, Table table, Optional<String> filter, Optional<? extends HivePartitionExtendedFilter> hivePartitionExtendedFilterOptional) throws IOException { try { List<Partition> partitions = Lists.newArrayList(); List<org.apache.hadoop.hive.metastore.api.Partition> partitionsList = filter.isPresent() ? client.listPartitionsByFilter(table.getDbName(), table.getTableName(), filter.get(), (short) -1) : client.listPartitions(table.getDbName(), table.getTableName(), (short) -1); for (org.apache.hadoop.hive.metastore.api.Partition p : partitionsList) { if (!hivePartitionExtendedFilterOptional.isPresent() || hivePartitionExtendedFilterOptional.get().accept(p)) { Partition partition = new Partition(table, p); partitions.add(partition); } } return partitions; } catch (TException | HiveException te) { throw new IOException("Hive Error", te); } }
/** * Get a list of {@link Partition}s for the <code>table</code> that matches an optional <code>filter</code> * * @param client an {@link IMetaStoreClient} for the correct metastore. * @param table the {@link Table} for which we should get partitions. * @param filter an optional filter for partitions as would be used in Hive. Can only filter on String columns. * (e.g. "part = \"part1\"" or "date > \"2015\"". * @return a list of {@link Partition}s */ public static List<Partition> getPartitions(IMetaStoreClient client, Table table, Optional<String> filter, Optional<? extends HivePartitionExtendedFilter> hivePartitionExtendedFilterOptional) throws IOException { try { List<Partition> partitions = Lists.newArrayList(); List<org.apache.hadoop.hive.metastore.api.Partition> partitionsList = filter.isPresent() ? client.listPartitionsByFilter(table.getDbName(), table.getTableName(), filter.get(), (short) -1) : client.listPartitions(table.getDbName(), table.getTableName(), (short) -1); for (org.apache.hadoop.hive.metastore.api.Partition p : partitionsList) { if (!hivePartitionExtendedFilterOptional.isPresent() || hivePartitionExtendedFilterOptional.get().accept(p)) { Partition partition = new Partition(table, p); partitions.add(partition); } } return partitions; } catch (TException | HiveException te) { throw new IOException("Hive Error", te); } }