diff --git ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java index b900627..f7a5b0e 100644 --- ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java +++ ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java @@ -115,6 +115,8 @@ import com.google.common.collect.Sets; +import javax.jdo.JDODataStoreException; + /** * This class has functions that implement meta data/DDL operations using calls * to the metastore. @@ -1732,31 +1734,18 @@ public Partition getPartition(Table tbl, Map partSpec, if (tpart == null) { LOG.debug("creating partition for table " + tbl.getTableName() + " with partition spec : " + partSpec); - tpart = getMSC().appendPartition(tbl.getDbName(), tbl.getTableName(), pvals); + try { + tpart = getMSC().appendPartition(tbl.getDbName(), tbl.getTableName(), pvals); + } catch (AlreadyExistsException aee) { + LOG.debug("Caught already exists exception, trying to alter partition instead"); + alterPartitionSpec(tbl, partSpec, tpart, inheritTableSpecs, partPath); + } catch (JDODataStoreException jdoe) { + LOG.debug("Caught JDO exception, trying to alter partition instead"); + alterPartitionSpec(tbl, partSpec, tpart, inheritTableSpecs, partPath); + } } else { - LOG.debug("altering partition for table " + tbl.getTableName() - + " with partition spec : " + partSpec); - if (inheritTableSpecs) { - tpart.getSd().setOutputFormat(tbl.getTTable().getSd().getOutputFormat()); - tpart.getSd().setInputFormat(tbl.getTTable().getSd().getInputFormat()); - tpart.getSd().getSerdeInfo().setSerializationLib(tbl.getSerializationLib()); - tpart.getSd().getSerdeInfo().setParameters( - tbl.getTTable().getSd().getSerdeInfo().getParameters()); - tpart.getSd().setBucketCols(tbl.getBucketCols()); - tpart.getSd().setNumBuckets(tbl.getNumBuckets()); - tpart.getSd().setSortCols(tbl.getSortCols()); - } - if (partPath == null || partPath.trim().equals("")) { - throw new HiveException("new partition path should not be null or empty."); - } - tpart.getSd().setLocation(partPath); - tpart.getParameters().put(StatsSetupConst.STATS_GENERATED_VIA_STATS_TASK,"true"); - String fullName = tbl.getTableName(); - if (!org.apache.commons.lang.StringUtils.isEmpty(tbl.getDbName())) { - fullName = tbl.getDbName() + "." + tbl.getTableName(); - } - alterPartition(fullName, new Partition(tbl, tpart)); + alterPartitionSpec(tbl, partSpec, tpart, inheritTableSpecs, partPath); } } if (tpart == null) { @@ -1769,6 +1758,35 @@ public Partition getPartition(Table tbl, Map partSpec, return new Partition(tbl, tpart); } + private void alterPartitionSpec(Table tbl, + Map partSpec, + org.apache.hadoop.hive.metastore.api.Partition tpart, + boolean inheritTableSpecs, + String partPath) throws HiveException, InvalidOperationException { + LOG.debug("altering partition for table " + tbl.getTableName() + " with partition spec : " + + partSpec); + if (inheritTableSpecs) { + tpart.getSd().setOutputFormat(tbl.getTTable().getSd().getOutputFormat()); + tpart.getSd().setInputFormat(tbl.getTTable().getSd().getInputFormat()); + tpart.getSd().getSerdeInfo().setSerializationLib(tbl.getSerializationLib()); + tpart.getSd().getSerdeInfo().setParameters( + tbl.getTTable().getSd().getSerdeInfo().getParameters()); + tpart.getSd().setBucketCols(tbl.getBucketCols()); + tpart.getSd().setNumBuckets(tbl.getNumBuckets()); + tpart.getSd().setSortCols(tbl.getSortCols()); + } + if (partPath == null || partPath.trim().equals("")) { + throw new HiveException("new partition path should not be null or empty."); + } + tpart.getSd().setLocation(partPath); + tpart.getParameters().put(StatsSetupConst.STATS_GENERATED_VIA_STATS_TASK,"true"); + String fullName = tbl.getTableName(); + if (!org.apache.commons.lang.StringUtils.isEmpty(tbl.getDbName())) { + fullName = tbl.getDbName() + "." + tbl.getTableName(); + } + alterPartition(fullName, new Partition(tbl, tpart)); + } + public boolean dropPartition(String tblName, List part_vals, boolean deleteData) throws HiveException { String[] names = Utilities.getDbTableName(tblName);