FAQ
Author: khorgath
Date: Wed Apr 8 17:27:05 2015
New Revision: 1672126

URL: http://svn.apache.org/r1672126
Log:
HIVE-9633 : Add HCatClient.dropPartitions() overload to skip deletion of partition-directories. (Mithun Radhakrishnan via Sushanth Sowmyan)

Modified:
     hive/trunk/hcatalog/webhcat/java-client/src/main/java/org/apache/hive/hcatalog/api/HCatClient.java
     hive/trunk/hcatalog/webhcat/java-client/src/main/java/org/apache/hive/hcatalog/api/HCatClientHMSImpl.java

Modified: hive/trunk/hcatalog/webhcat/java-client/src/main/java/org/apache/hive/hcatalog/api/HCatClient.java
URL: http://svn.apache.org/viewvc/hive/trunk/hcatalog/webhcat/java-client/src/main/java/org/apache/hive/hcatalog/api/HCatClient.java?rev=1672126&r1=1672125&r2=1672126&view=diff
==============================================================================
--- hive/trunk/hcatalog/webhcat/java-client/src/main/java/org/apache/hive/hcatalog/api/HCatClient.java (original)
+++ hive/trunk/hcatalog/webhcat/java-client/src/main/java/org/apache/hive/hcatalog/api/HCatClient.java Wed Apr 8 17:27:05 2015
@@ -381,6 +381,24 @@ public abstract class HCatClient {
      throws HCatException;

    /**
+ * Drops partition(s) that match the specified (and possibly partial) partition specification.
+ * A partial partition-specification is one where not all partition-keys have associated values. For example,
+ * for a table ('myDb.myTable') with 2 partition keys (dt string, region string),
+ * if for each dt ('20120101', '20120102', etc.) there can exist 3 regions ('us', 'uk', 'in'), then,
+ * 1. Complete partition spec: dropPartitions('myDb', 'myTable', {dt='20120101', region='us'}) would drop 1 partition.
+ * 2. Partial partition spec: dropPartitions('myDb', 'myTable', {dt='20120101'}) would drop all 3 partitions,
+ * with dt='20120101' (i.e. region = 'us', 'uk' and 'in').
+ * @param dbName The database name.
+ * @param tableName The table name.
+ * @param partitionSpec The partition specification, {[col_name,value],[col_name2,value2]}.
+ * @param ifExists Hive returns an error if the partition specified does not exist, unless ifExists is set to true.
+ * @param deleteData Whether to delete the underlying data.
+ * @throws HCatException,ConnectionFailureException
+ */
+ public abstract void dropPartitions(String dbName, String tableName,
+ Map<String, String> partitionSpec, boolean ifExists, boolean deleteData)
+ throws HCatException;
+ /**
     * List partitions by filter.
     *
     * @param dbName The database name.

Modified: hive/trunk/hcatalog/webhcat/java-client/src/main/java/org/apache/hive/hcatalog/api/HCatClientHMSImpl.java
URL: http://svn.apache.org/viewvc/hive/trunk/hcatalog/webhcat/java-client/src/main/java/org/apache/hive/hcatalog/api/HCatClientHMSImpl.java?rev=1672126&r1=1672125&r2=1672126&view=diff
==============================================================================
--- hive/trunk/hcatalog/webhcat/java-client/src/main/java/org/apache/hive/hcatalog/api/HCatClientHMSImpl.java (original)
+++ hive/trunk/hcatalog/webhcat/java-client/src/main/java/org/apache/hive/hcatalog/api/HCatClientHMSImpl.java Wed Apr 8 17:27:05 2015
@@ -573,33 +573,35 @@ public class HCatClientHMSImpl extends H
          && "TRUE".equalsIgnoreCase(table.getParameters().get("EXTERNAL"));
    }

- private void dropPartitionsUsingExpressions(Table table, Map<String, String> partitionSpec, boolean ifExists)
- throws SemanticException, TException {
+ private void dropPartitionsUsingExpressions(Table table, Map<String, String> partitionSpec,
+ boolean ifExists, boolean deleteData)
+ throws SemanticException, TException {
      LOG.info("HCatClient: Dropping partitions using partition-predicate Expressions.");
      ExprNodeGenericFuncDesc partitionExpression = new ExpressionBuilder(table, partitionSpec).build();
      ObjectPair<Integer, byte[]> serializedPartitionExpression =
          new ObjectPair<Integer, byte[]>(partitionSpec.size(),
              Utilities.serializeExpressionToKryo(partitionExpression));
      hmsClient.dropPartitions(table.getDbName(), table.getTableName(), Arrays.asList(serializedPartitionExpression),
- !isExternal(table), // Delete data?
- false, // Ignore Protection?
- ifExists, // Fail if table doesn't exist?
- false); // Need results back?
+ deleteData && !isExternal(table), // Delete data?
+ false, // Ignore Protection?
+ ifExists, // Fail if table doesn't exist?
+ false); // Need results back?
    }

    private void dropPartitionsIteratively(String dbName, String tableName,
- Map<String, String> partitionSpec, boolean ifExists) throws HCatException, TException {
+ Map<String, String> partitionSpec, boolean ifExists, boolean deleteData)
+ throws HCatException, TException {
      LOG.info("HCatClient: Dropping partitions iteratively.");
      List<Partition> partitions = hmsClient.listPartitionsByFilter(dbName, tableName,
          getFilterString(partitionSpec), (short) -1);
      for (Partition partition : partitions) {
- dropPartition(partition, ifExists);
+ dropPartition(partition, ifExists, deleteData);
      }
    }

    @Override
    public void dropPartitions(String dbName, String tableName,
- Map<String, String> partitionSpec, boolean ifExists)
+ Map<String, String> partitionSpec, boolean ifExists, boolean deleteData)
      throws HCatException {
      LOG.info("HCatClient dropPartitions(db=" + dbName + ",table=" + tableName + ", partitionSpec: ["+ partitionSpec + "]).");
      try {
@@ -608,17 +610,17 @@ public class HCatClientHMSImpl extends H

        if (hiveConfig.getBoolVar(HiveConf.ConfVars.METASTORE_CLIENT_DROP_PARTITIONS_WITH_EXPRESSIONS)) {
          try {
- dropPartitionsUsingExpressions(table, partitionSpec, ifExists);
+ dropPartitionsUsingExpressions(table, partitionSpec, ifExists, deleteData);
          }
          catch (SemanticException parseFailure) {
            LOG.warn("Could not push down partition-specification to back-end, for dropPartitions(). Resorting to iteration.",
                parseFailure);
- dropPartitionsIteratively(dbName, tableName, partitionSpec, ifExists);
+ dropPartitionsIteratively(dbName, tableName, partitionSpec, ifExists, deleteData);
          }
        }
        else {
          // Not using expressions.
- dropPartitionsIteratively(dbName, tableName, partitionSpec, ifExists);
+ dropPartitionsIteratively(dbName, tableName, partitionSpec, ifExists, deleteData);
        }
      } catch (NoSuchObjectException e) {
        throw new ObjectNotFoundException(
@@ -633,10 +635,16 @@ public class HCatClientHMSImpl extends H
      }
    }

- private void dropPartition(Partition partition, boolean ifExists)
+ @Override
+ public void dropPartitions(String dbName, String tableName,
+ Map<String, String> partitionSpec, boolean ifExists) throws HCatException {
+ dropPartitions(dbName, tableName, partitionSpec, ifExists, true);
+ }
+
+ private void dropPartition(Partition partition, boolean ifExists, boolean deleteData)
      throws HCatException, MetaException, TException {
      try {
- hmsClient.dropPartition(partition.getDbName(), partition.getTableName(), partition.getValues());
+ hmsClient.dropPartition(partition.getDbName(), partition.getTableName(), partition.getValues(), deleteData);
      } catch (NoSuchObjectException e) {
        if (!ifExists) {
          throw new ObjectNotFoundException(

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcommits @
categorieshive, hadoop
postedApr 8, '15 at 5:33p
activeApr 8, '15 at 5:33p
posts1
users1
websitehive.apache.org

1 user in discussion

Khorgath: 1 post

People

Translate

site design / logo © 2022 Grokbase