Review Board 1.7.22


Include Table information in Hive's AddPartitionEvent

Review Request #7910 - Created Nov. 7, 2012 and submitted

Mithun Radhakrishnan
Reviewers
hive
ashutoshc, francisliu
hive
This has to do with a minor overhaul of the HCatalog notifications that we're attempting in HCATALOG-546.
It is proposed that HCatalog's notifications (on Add/Drop of Partitions) provide details to identify the affected partitions.
Using the Partition object in AddPartitionEvent, one is able to retrieve the values of the partition-keys and the name of the Table. However, the partition-keys themselves aren't available (since the Table instance isn't part of the AddPartitionEvent).
Adding the table-reference to the AddPartitionEvent and DropPartitionEvent classes will expose all the info we need. (The alternative is to query the metastore for the table's schema and use the partition-keys from there. :/)

 
http://svn.apache.org/repos/asf/hive/branches/branch-0.9/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
Revision 1405924 New Change
[20] 1192 lines
[+20] [+] public int add_partitions(final List<Partition> parts) throws MetaException,
1193
    private Entry<Partition, Boolean> add_partition_core_notxn(
1193
    private Entry<Partition, Boolean> add_partition_core_notxn(
1194
        final RawStore ms, final Partition part)
1194
        final RawStore ms, final Partition part)
1195
        throws InvalidObjectException, AlreadyExistsException, MetaException {
1195
        throws InvalidObjectException, AlreadyExistsException, MetaException {
1196
      boolean success = false, madeDir = false;
1196
      boolean success = false, madeDir = false;
1197
      Path partLocation = null;
1197
      Path partLocation = null;

    
   
1198
      Table tbl = null;
1198
      try {
1199
      try {
1199
        try {
1200
        try {
1200
          for(MetaStorePreEventListener listener : preListeners){
1201
          for(MetaStorePreEventListener listener : preListeners){
1201
            listener.onEvent(new PreAddPartitionEvent(part, this));
1202
            listener.onEvent(new PreAddPartitionEvent(part, this));
1202
          }
1203
          }
[+20] [20] 12 lines
[+20] public int add_partitions(final List<Partition> parts) throws MetaException,
1215
          old_part = null;
1216
          old_part = null;
1216
        }
1217
        }
1217
        if (old_part != null) {
1218
        if (old_part != null) {
1218
          throw new AlreadyExistsException("Partition already exists:" + part);
1219
          throw new AlreadyExistsException("Partition already exists:" + part);
1219
        }
1220
        }
1220
        Table tbl = ms.getTable(part.getDbName(), part.getTableName());
1221
        tbl = ms.getTable(part.getDbName(), part.getTableName());
1221
        if (tbl == null) {
1222
        if (tbl == null) {
1222
          throw new InvalidObjectException(
1223
          throw new InvalidObjectException(
1223
              "Unable to add partition because table or database do not exist");
1224
              "Unable to add partition because table or database do not exist");
1224
        }
1225
        }
1225

    
   
1226

   
[+20] [20] 66 lines
[+20] public int add_partitions(final List<Partition> parts) throws MetaException,
1292
          if (madeDir) {
1293
          if (madeDir) {
1293
            wh.deleteDir(partLocation, true);
1294
            wh.deleteDir(partLocation, true);
1294
          }
1295
          }
1295
        }
1296
        }
1296
        for (MetaStoreEventListener listener : listeners) {
1297
        for (MetaStoreEventListener listener : listeners) {
1297
          listener.onAddPartition(new AddPartitionEvent(part, success, this));
1298
          listener.onAddPartition(new AddPartitionEvent(tbl, part, success, this));
1298
        }
1299
        }
1299
      }
1300
      }
1300
      Map<Partition, Boolean> returnVal = new HashMap<Partition, Boolean>();
1301
      Map<Partition, Boolean> returnVal = new HashMap<Partition, Boolean>();
1301
      returnVal.put(part, madeDir);
1302
      returnVal.put(part, madeDir);
1302
      return returnVal.entrySet().iterator().next();
1303
      return returnVal.entrySet().iterator().next();
[+20] [20] 97 lines
[+20] [+] private boolean drop_partition_common(RawStore ms, String db_name, String tbl_name,
1400
            }
1401
            }
1401
            // ok even if the data is not deleted
1402
            // ok even if the data is not deleted
1402
          }
1403
          }
1403
        }
1404
        }
1404
        for (MetaStoreEventListener listener : listeners) {
1405
        for (MetaStoreEventListener listener : listeners) {
1405
          listener.onDropPartition(new DropPartitionEvent(part, success, this));
1406
          listener.onDropPartition(new DropPartitionEvent(tbl, part, success, this));
1406
        }
1407
        }
1407
      }
1408
      }
1408
      return true;
1409
      return true;
1409
    }
1410
    }
1410

    
   
1411

   
[+20] [20] 1641 lines
http://svn.apache.org/repos/asf/hive/branches/branch-0.9/metastore/src/java/org/apache/hadoop/hive/metastore/events/AddPartitionEvent.java
Revision 1405924 New Change
 
http://svn.apache.org/repos/asf/hive/branches/branch-0.9/metastore/src/java/org/apache/hadoop/hive/metastore/events/DropPartitionEvent.java
Revision 1405924 New Change
 
  1. http://svn.apache.org/repos/asf/hive/branches/branch-0.9/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java: Loading...
  2. http://svn.apache.org/repos/asf/hive/branches/branch-0.9/metastore/src/java/org/apache/hadoop/hive/metastore/events/AddPartitionEvent.java: Loading...
  3. http://svn.apache.org/repos/asf/hive/branches/branch-0.9/metastore/src/java/org/apache/hadoop/hive/metastore/events/DropPartitionEvent.java: Loading...