public static String conflictingArchiveNameOrNull(Hive db, Table tbl,
        LinkedHashMap<String, String> partSpec)
      throws HiveException {

    List<FieldSchema> partKeys = tbl.getPartitionKeys();
    int partSpecLevel = 0;
    for (FieldSchema partKey : partKeys) {
      if (!partSpec.containsKey(partKey.getName())) {
        break;
      }
      partSpecLevel++;
    }

    if (partSpecLevel != partSpec.size()) {
      throw new HiveException(
          "partspec " + partSpec + " is wrong for table " + tbl.getTableName());
    }

    Map<String, String> spec = new HashMap<String, String>(partSpec);
    List<String> reversedKeys = new ArrayList<String>();
    for (FieldSchema fs : tbl.getPartCols()) {
      if (spec.containsKey(fs.getName())) {
        reversedKeys.add(fs.getName());
      }
    }

    Collections.reverse(reversedKeys);

    for (String rk : reversedKeys) {
      List<Partition> parts = db.getPartitions(tbl, spec, (short) 1);
      if (parts.size() != 0) {
        Partition p = parts.get(0);
        if (!isArchived(p)) {
          // if archiving was done at this or at upper level, every matched
          // partition would be archived, so it not being archived means
          // no archiving was done neither at this nor at upper level
          return null;
        }
        if (getArchivingLevel(p) > spec.size()) {
          // if archiving was done at this or at upper level its level
          // would be lesser or equal to specification size
          // it is not, which means no archiving at this or upper level
          return null;
        }
        return getPartialName(p, getArchivingLevel(p));
      }
      spec.remove(rk);
    }
    return null;
  }
Determines if one can insert into partition(s), or there's a conflict with
archive. It can be because partition is itself archived, or it is to be
created inside existing archive. The second case is when partition doesn't
exist yet, but it would be inside an archive if it existed. This one is
quite tricky to check, we need to find at least one partition inside
the parent directory. If it is archived and archiving level tells that
the archival was done of directory partition is in it means we cannot
insert; otherwise we can.
This method works both for full specifications and partial ones - in second
case it checks if any partition that could possibly match such
specification is inside archive.

@param db - Hive object
@param tbl - table where partition is
@param partSpec - partition specification with possible nulls in case of
dynamic partiton inserts
@return null if partition can be inserted, string with colliding archive
name when it can't
@throws HiveException
ql/src/java/org/apache/hadoop/hive/ql/exec/ArchiveUtils.java