hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From na...@apache.org
Subject svn commit: r1308399 - in /hive/trunk: common/src/java/org/apache/hadoop/hive/conf/ metastore/src/java/org/apache/hadoop/hive/metastore/ metastore/src/java/org/apache/hadoop/hive/metastore/events/ metastore/src/test/org/apache/hadoop/hive/metastore/
Date Mon, 02 Apr 2012 15:52:00 GMT
Author: namit
Date: Mon Apr  2 15:51:59 2012
New Revision: 1308399

URL: http://svn.apache.org/viewvc?rev=1308399&view=rev
Log:
HIVE-2853 Add pre event listeners to metastore
(Kevin Wilfong via namit)


Added:
    hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStorePreEventListener.java
    hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreAddPartitionEvent.java
    hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreAlterPartitionEvent.java
    hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreAlterTableEvent.java
    hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreCreateDatabaseEvent.java
    hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreCreateTableEvent.java
    hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreDropDatabaseEvent.java
    hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreDropPartitionEvent.java
    hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreDropTableEvent.java
    hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreEventContext.java
    hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreLoadPartitionDoneEvent.java
    hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/DummyPreListener.java
Modified:
    hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
    hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
    hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/TestMetaStoreEventListener.java

Modified: hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
URL: http://svn.apache.org/viewvc/hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java?rev=1308399&r1=1308398&r2=1308399&view=diff
==============================================================================
--- hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java (original)
+++ hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java Mon Apr  2 15:51:59 2012
@@ -122,6 +122,7 @@ public class HiveConf extends Configurat
       HiveConf.ConfVars.METASTORE_RAW_STORE_IMPL,
       HiveConf.ConfVars.METASTORE_END_FUNCTION_LISTENERS,
       HiveConf.ConfVars.METASTORE_PART_INHERIT_TBL_PROPS,
+      HiveConf.ConfVars.METASTORE_PRE_EVENT_LISTENERS,
       };
 
   /**
@@ -288,6 +289,7 @@ public class HiveConf extends Configurat
     METASTORE_IDENTIFIER_FACTORY("datanucleus.identifierFactory", "datanucleus"),
     METASTORE_PLUGIN_REGISTRY_BUNDLE_CHECK("datanucleus.plugin.pluginRegistryBundleCheck", "LOG"),
     METASTORE_BATCH_RETRIEVE_MAX("hive.metastore.batch.retrieve.max", 300),
+    METASTORE_PRE_EVENT_LISTENERS("hive.metastore.pre.event.listeners", ""),
     METASTORE_EVENT_LISTENERS("hive.metastore.event.listeners", ""),
     // should we do checks against the storage (usually hdfs) for operations like drop_partition
     METASTORE_AUTHORIZATION_STORAGE_AUTH_CHECKS("hive.metastore.authorization.storage.checks", false),

Modified: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java?rev=1308399&r1=1308398&r2=1308399&view=diff
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java (original)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java Mon Apr  2 15:51:59 2012
@@ -91,6 +91,15 @@ import org.apache.hadoop.hive.metastore.
 import org.apache.hadoop.hive.metastore.events.DropTableEvent;
 import org.apache.hadoop.hive.metastore.events.EventCleanerTask;
 import org.apache.hadoop.hive.metastore.events.LoadPartitionDoneEvent;
+import org.apache.hadoop.hive.metastore.events.PreAddPartitionEvent;
+import org.apache.hadoop.hive.metastore.events.PreAlterPartitionEvent;
+import org.apache.hadoop.hive.metastore.events.PreAlterTableEvent;
+import org.apache.hadoop.hive.metastore.events.PreCreateDatabaseEvent;
+import org.apache.hadoop.hive.metastore.events.PreCreateTableEvent;
+import org.apache.hadoop.hive.metastore.events.PreDropDatabaseEvent;
+import org.apache.hadoop.hive.metastore.events.PreDropPartitionEvent;
+import org.apache.hadoop.hive.metastore.events.PreDropTableEvent;
+import org.apache.hadoop.hive.metastore.events.PreLoadPartitionDoneEvent;
 import org.apache.hadoop.hive.metastore.model.MDBPrivilege;
 import org.apache.hadoop.hive.metastore.model.MGlobalPrivilege;
 import org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege;
@@ -245,6 +254,7 @@ public class HiveMetaStore extends Thrif
 
     private ClassLoader classLoader;
     private AlterHandler alterHandler;
+    private List<MetaStorePreEventListener> preListeners;
     private List<MetaStoreEventListener> listeners;
     private List<MetaStoreEndFunctionListener> endFunctionListeners;
 
@@ -279,6 +289,8 @@ public class HiveMetaStore extends Thrif
         }
       }
 
+      preListeners = MetaStoreUtils.getMetaStoreListeners(MetaStorePreEventListener.class, hiveConf,
+          hiveConf.getVar(HiveConf.ConfVars.METASTORE_PRE_EVENT_LISTENERS));
       listeners = MetaStoreUtils.getMetaStoreListeners(MetaStoreEventListener.class, hiveConf,
           hiveConf.getVar(HiveConf.ConfVars.METASTORE_EVENT_LISTENERS));
       endFunctionListeners = MetaStoreUtils.getMetaStoreListeners(
@@ -479,6 +491,16 @@ public class HiveMetaStore extends Thrif
       boolean success = false;
       boolean madeDir = false;
       try {
+        try {
+          for (MetaStorePreEventListener listener : preListeners) {
+            listener.onEvent(new PreCreateDatabaseEvent(db, this));
+          }
+        } catch (NoSuchObjectException e) {
+          throw new MetaException(e.getMessage());
+        } catch (InvalidOperationException e) {
+          throw new MetaException(e.getMessage());
+        }
+
         if (!wh.isDir(dbPath)) {
           if (!wh.mkdirs(dbPath)) {
             throw new MetaException("Unable to create database path " + dbPath +
@@ -566,6 +588,11 @@ public class HiveMetaStore extends Thrif
       try {
         ms.openTransaction();
         db = ms.getDatabase(name);
+
+        for (MetaStorePreEventListener listener : preListeners) {
+          listener.onEvent(new PreDropDatabaseEvent(db, this));
+        }
+
         List<String> allTables = get_all_tables(db.getName());
         if (!cascade && !allTables.isEmpty()) {
           throw new InvalidOperationException("Database " + db.getName() + " is not empty");
@@ -745,6 +772,14 @@ public class HiveMetaStore extends Thrif
       Path tblPath = null;
       boolean success = false, madeDir = false;
       try {
+        try {
+          for (MetaStorePreEventListener listener : preListeners) {
+            listener.onEvent(new PreCreateTableEvent(tbl, this));
+          }
+        } catch (InvalidOperationException e) {
+          throw new MetaException(e.getMessage());
+        }
+
         ms.openTransaction();
 
         if (ms.getDatabase(tbl.getDbName()) == null) {
@@ -848,6 +883,14 @@ public class HiveMetaStore extends Thrif
           throw new MetaException("Table metadata is corrupted");
         }
 
+        try {
+          for(MetaStorePreEventListener listener : preListeners){
+            listener.onEvent(new PreDropTableEvent(tbl, this));
+          }
+        } catch (InvalidOperationException e) {
+          throw new MetaException(e.getMessage());
+        }
+
         isIndexTable = isIndexTable(tbl);
         if (isIndexTable) {
           throw new RuntimeException(
@@ -1157,6 +1200,16 @@ public class HiveMetaStore extends Thrif
       boolean success = false, madeDir = false;
       Path partLocation = null;
       try {
+        try {
+          for(MetaStorePreEventListener listener : preListeners){
+            listener.onEvent(new PreAddPartitionEvent(part, this));
+          }
+        } catch (NoSuchObjectException e) {
+          throw new MetaException(e.getMessage());
+        } catch (InvalidOperationException e) {
+          throw new MetaException(e.getMessage());
+        }
+
         Partition old_part = null;
         try {
           old_part = ms.getPartition(part.getDbName(), part
@@ -1303,6 +1356,14 @@ public class HiveMetaStore extends Thrif
         ms.openTransaction();
         part = ms.getPartition(db_name, tbl_name, part_vals);
 
+        try {
+          for(MetaStorePreEventListener listener : preListeners){
+            listener.onEvent(new PreDropPartitionEvent(part, this));
+          }
+        } catch (InvalidOperationException e) {
+          throw new MetaException(e.getMessage());
+        }
+
         if (part == null) {
           throw new NoSuchObjectException("Partition doesn't exist. "
               + part_vals);
@@ -1474,6 +1535,15 @@ public class HiveMetaStore extends Thrif
 
       Partition oldPart = null;
       try {
+        try {
+          for (MetaStorePreEventListener listener : preListeners) {
+            listener.onEvent(
+                new PreAlterPartitionEvent(db_name, tbl_name, part_vals, new_part, this));
+          }
+        } catch (NoSuchObjectException e) {
+          throw new MetaException(e.getMessage());
+        }
+
         oldPart = alterHandler.alterPartition(getMS(), wh, db_name, tbl_name, part_vals, new_part);
 
         for (MetaStoreEventListener listener : listeners) {
@@ -1535,6 +1605,14 @@ public class HiveMetaStore extends Thrif
       boolean success = false;
       try {
         Table oldt = get_table(dbname, name);
+
+        try {
+          for (MetaStorePreEventListener listener : preListeners) {
+            listener.onEvent(new PreAlterTableEvent(oldt, newTable, this));
+          }
+        } catch (NoSuchObjectException e) {
+          throw new MetaException(e.getMessage());
+        }
         alterHandler.alterTable(getMS(), wh, dbname, name, newTable);
         success = true;
 
@@ -2669,6 +2747,10 @@ public class HiveMetaStore extends Thrif
       try {
         startPartitionFunction("markPartitionForEvent", db_name, tbl_name, partName);
         try {
+          for(MetaStorePreEventListener listener : preListeners){
+            listener.onEvent(
+                new PreLoadPartitionDoneEvent(this, db_name, tbl_name, partName));
+          }
           tbl = getMS().markPartitionForEvent(db_name, tbl_name, partName, evtType);
         } catch (Exception original) {
           LOG.error(original);

Added: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStorePreEventListener.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStorePreEventListener.java?rev=1308399&view=auto
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStorePreEventListener.java (added)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStorePreEventListener.java Mon Apr  2 15:51:59 2012
@@ -0,0 +1,54 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.metastore;
+
+import org.apache.hadoop.conf.Configurable;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.metastore.api.InvalidOperationException;
+import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
+import org.apache.hadoop.hive.metastore.events.PreEventContext;
+
+/**
+ * This abstract class needs to be extended to  provide implementation of actions that needs
+ * to be performed before a particular event occurs on a metastore. These methods
+ * are called before an event occurs on metastore.
+ */
+
+public abstract class MetaStorePreEventListener implements Configurable {
+
+  private Configuration conf;
+
+  public MetaStorePreEventListener(Configuration config){
+    this.conf = config;
+  }
+
+  public abstract void onEvent(PreEventContext context)
+      throws MetaException, NoSuchObjectException, InvalidOperationException;
+
+  @Override
+  public Configuration getConf() {
+    return this.conf;
+  }
+
+  @Override
+  public void setConf(Configuration config) {
+    this.conf = config;
+  }
+}

Added: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreAddPartitionEvent.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreAddPartitionEvent.java?rev=1308399&view=auto
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreAddPartitionEvent.java (added)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreAddPartitionEvent.java Mon Apr  2 15:51:59 2012
@@ -0,0 +1,39 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.metastore.events;
+
+import org.apache.hadoop.hive.metastore.HiveMetaStore.HMSHandler;
+import org.apache.hadoop.hive.metastore.api.Partition;
+
+public class PreAddPartitionEvent extends PreEventContext {
+
+  private final Partition partition;
+
+  public PreAddPartitionEvent (Partition partition, HMSHandler handler) {
+    super(PreEventType.ADD_PARTITION, handler);
+    this.partition = partition;
+  }
+
+  /**
+   * @return the partition
+   */
+  public Partition getPartition() {
+    return partition;
+  }
+}

Added: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreAlterPartitionEvent.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreAlterPartitionEvent.java?rev=1308399&view=auto
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreAlterPartitionEvent.java (added)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreAlterPartitionEvent.java Mon Apr  2 15:51:59 2012
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.metastore.events;
+
+import java.util.List;
+
+import org.apache.hadoop.hive.metastore.HiveMetaStore.HMSHandler;
+import org.apache.hadoop.hive.metastore.api.Partition;
+
+public class PreAlterPartitionEvent extends PreEventContext {
+
+  private final String dbName;
+  private final String tableName;
+  private final List<String> oldPartVals;
+  private final Partition newPart;
+
+  public PreAlterPartitionEvent(String dbName, String tableName, List<String> oldPartVals,
+      Partition newPart, HMSHandler handler) {
+    super(PreEventType.ALTER_PARTITION, handler);
+    this.dbName = dbName;
+    this.tableName = tableName;
+    this.oldPartVals = oldPartVals;
+    this.newPart = newPart;
+  }
+
+  public String getDbName() {
+    return dbName;
+  }
+
+  public String getTableName() {
+    return tableName;
+  }
+
+  public List<String> getOldPartVals() {
+    return oldPartVals;
+  }
+
+  /**
+   *
+   * @return the new partition
+   */
+  public Partition getNewPartition() {
+    return newPart;
+  }
+}

Added: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreAlterTableEvent.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreAlterTableEvent.java?rev=1308399&view=auto
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreAlterTableEvent.java (added)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreAlterTableEvent.java Mon Apr  2 15:51:59 2012
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.metastore.events;
+
+import org.apache.hadoop.hive.metastore.HiveMetaStore.HMSHandler;
+import org.apache.hadoop.hive.metastore.api.Table;
+
+public class PreAlterTableEvent extends PreEventContext {
+
+  private final Table newTable;
+  private final Table oldTable;
+
+  public PreAlterTableEvent (Table oldTable, Table newTable, HMSHandler handler) {
+    super (PreEventType.ALTER_TABLE, handler);
+    this.oldTable = oldTable;
+    this.newTable = newTable;
+  }
+
+  /**
+   * @return the old table
+   */
+  public Table getOldTable() {
+    return oldTable;
+  }
+
+  /**
+   * @return the new table
+   */
+  public Table getNewTable() {
+    return newTable;
+  }
+}

Added: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreCreateDatabaseEvent.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreCreateDatabaseEvent.java?rev=1308399&view=auto
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreCreateDatabaseEvent.java (added)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreCreateDatabaseEvent.java Mon Apr  2 15:51:59 2012
@@ -0,0 +1,39 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.metastore.events;
+
+import org.apache.hadoop.hive.metastore.HiveMetaStore.HMSHandler;
+import org.apache.hadoop.hive.metastore.api.Database;
+
+public class PreCreateDatabaseEvent extends PreEventContext {
+
+  private final Database db;
+
+  public PreCreateDatabaseEvent (Database db, HMSHandler handler) {
+    super (PreEventType.CREATE_DATABASE, handler);
+    this.db = db;
+  }
+
+  /**
+   * @return the db
+   */
+  public Database getDatabase () {
+    return db;
+  }
+}

Added: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreCreateTableEvent.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreCreateTableEvent.java?rev=1308399&view=auto
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreCreateTableEvent.java (added)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreCreateTableEvent.java Mon Apr  2 15:51:59 2012
@@ -0,0 +1,39 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.metastore.events;
+
+import org.apache.hadoop.hive.metastore.HiveMetaStore.HMSHandler;
+import org.apache.hadoop.hive.metastore.api.Table;
+
+public class PreCreateTableEvent extends PreEventContext {
+
+  private final Table table;
+
+  public PreCreateTableEvent (Table table, HMSHandler handler) {
+    super (PreEventType.CREATE_TABLE, handler);
+    this.table = table;
+  }
+
+  /**
+   * @return the table
+   */
+  public Table getTable () {
+    return table;
+  }
+}

Added: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreDropDatabaseEvent.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreDropDatabaseEvent.java?rev=1308399&view=auto
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreDropDatabaseEvent.java (added)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreDropDatabaseEvent.java Mon Apr  2 15:51:59 2012
@@ -0,0 +1,39 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.metastore.events;
+
+import org.apache.hadoop.hive.metastore.HiveMetaStore.HMSHandler;
+import org.apache.hadoop.hive.metastore.api.Database;
+
+public class PreDropDatabaseEvent extends PreEventContext {
+
+  private final Database db;
+
+  public PreDropDatabaseEvent(Database db, HMSHandler handler) {
+    super (PreEventType.DROP_DATABASE, handler);
+    this.db = db;
+  }
+
+  /**
+   * @return the db
+   */
+  public Database getDatabase() {
+    return db;
+  }
+}

Added: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreDropPartitionEvent.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreDropPartitionEvent.java?rev=1308399&view=auto
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreDropPartitionEvent.java (added)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreDropPartitionEvent.java Mon Apr  2 15:51:59 2012
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.metastore.events;
+
+import org.apache.hadoop.hive.metastore.HiveMetaStore.HMSHandler;
+import org.apache.hadoop.hive.metastore.api.Partition;
+
+public class PreDropPartitionEvent extends PreEventContext {
+
+  private final Partition partition;
+
+  public PreDropPartitionEvent (Partition partition, HMSHandler handler) {
+    super (PreEventType.DROP_PARTITION, handler);
+    this.partition = partition;
+  }
+
+  /**
+   * @return the partition
+   */
+  public Partition getPartition() {
+
+    return partition;
+  }
+}

Added: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreDropTableEvent.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreDropTableEvent.java?rev=1308399&view=auto
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreDropTableEvent.java (added)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreDropTableEvent.java Mon Apr  2 15:51:59 2012
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.metastore.events;
+
+import org.apache.hadoop.hive.metastore.HiveMetaStore.HMSHandler;
+import org.apache.hadoop.hive.metastore.api.Table;
+
+public class PreDropTableEvent extends PreEventContext{
+
+  private final Table table;
+
+  public PreDropTableEvent (Table table, HMSHandler handler) {
+    super (PreEventType.DROP_TABLE, handler);
+    this.table = table;
+  }
+  /**
+   * @return the table
+   */
+  public Table getTable () {
+    return table;
+  }
+}

Added: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreEventContext.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreEventContext.java?rev=1308399&view=auto
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreEventContext.java (added)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreEventContext.java Mon Apr  2 15:51:59 2012
@@ -0,0 +1,62 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.metastore.events;
+
+import org.apache.hadoop.hive.metastore.HiveMetaStore.HMSHandler;
+
+/**
+ * Base class for all the events which are defined for metastore.
+ */
+
+public abstract class PreEventContext {
+
+  public static enum PreEventType {
+    CREATE_TABLE,
+    DROP_TABLE,
+    ALTER_TABLE,
+    ADD_PARTITION,
+    DROP_PARTITION,
+    ALTER_PARTITION,
+    CREATE_DATABASE,
+    DROP_DATABASE,
+    LOAD_PARTITION_DONE,
+  }
+
+  private final PreEventType eventType;
+  private final HMSHandler handler;
+
+  public PreEventContext(PreEventType eventType, HMSHandler handler) {
+    this.eventType = eventType;
+    this.handler = handler;
+  }
+
+  /**
+   * @return the event type
+   */
+  public PreEventType getEventType() {
+    return eventType;
+  }
+
+  /**
+   * @return the handler
+   */
+  public HMSHandler getHandler() {
+    return handler;
+  }
+}

Added: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreLoadPartitionDoneEvent.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreLoadPartitionDoneEvent.java?rev=1308399&view=auto
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreLoadPartitionDoneEvent.java (added)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreLoadPartitionDoneEvent.java Mon Apr  2 15:51:59 2012
@@ -0,0 +1,54 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.metastore.events;
+
+import java.util.Map;
+
+import org.apache.hadoop.hive.metastore.HiveMetaStore.HMSHandler;
+
+public class PreLoadPartitionDoneEvent extends PreEventContext {
+
+  private final String dbName;
+  private final String tableName;
+  private final Map<String,String> partSpec;
+
+  public PreLoadPartitionDoneEvent(HMSHandler handler, String dbName, String tableName,
+      Map<String, String> partSpec) {
+    super(PreEventType.LOAD_PARTITION_DONE, handler);
+    this.dbName = dbName;
+    this.tableName = tableName;
+    this.partSpec = partSpec;
+  }
+
+  public String getDbName() {
+    return dbName;
+  }
+
+  public String getTableName() {
+    return tableName;
+  }
+
+  /**
+   * @return the partition Name
+   */
+  public Map<String,String> getPartitionName() {
+    return partSpec;
+  }
+
+}

Added: hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/DummyPreListener.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/DummyPreListener.java?rev=1308399&view=auto
==============================================================================
--- hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/DummyPreListener.java (added)
+++ hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/DummyPreListener.java Mon Apr  2 15:51:59 2012
@@ -0,0 +1,32 @@
+package org.apache.hadoop.hive.metastore;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.metastore.api.InvalidOperationException;
+import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
+import org.apache.hadoop.hive.metastore.events.PreEventContext;
+
+/**
+ *
+ * DummyPreListener.
+ *
+ * An implemenation of MetaStorePreEventListener which stores the Events it's seen in a list.
+ */
+public class DummyPreListener extends MetaStorePreEventListener {
+
+  public static final List<PreEventContext> notifyList = new ArrayList<PreEventContext>();
+
+  public DummyPreListener(Configuration config) {
+    super(config);
+  }
+
+  @Override
+  public void onEvent(PreEventContext context) throws MetaException, NoSuchObjectException,
+      InvalidOperationException {
+    notifyList.add(context);
+  }
+
+}

Modified: hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/TestMetaStoreEventListener.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/TestMetaStoreEventListener.java?rev=1308399&r1=1308398&r2=1308399&view=diff
==============================================================================
--- hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/TestMetaStoreEventListener.java (original)
+++ hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/TestMetaStoreEventListener.java Mon Apr  2 15:51:59 2012
@@ -28,7 +28,6 @@ import org.apache.hadoop.hive.cli.CliSes
 import org.apache.hadoop.hive.conf.HiveConf;
 import org.apache.hadoop.hive.conf.HiveConf.ConfVars;
 import org.apache.hadoop.hive.metastore.api.Database;
-import org.apache.hadoop.hive.metastore.api.FieldSchema;
 import org.apache.hadoop.hive.metastore.api.Partition;
 import org.apache.hadoop.hive.metastore.api.PartitionEventType;
 import org.apache.hadoop.hive.metastore.api.Table;
@@ -42,12 +41,23 @@ import org.apache.hadoop.hive.metastore.
 import org.apache.hadoop.hive.metastore.events.DropTableEvent;
 import org.apache.hadoop.hive.metastore.events.ListenerEvent;
 import org.apache.hadoop.hive.metastore.events.LoadPartitionDoneEvent;
+import org.apache.hadoop.hive.metastore.events.PreAddPartitionEvent;
+import org.apache.hadoop.hive.metastore.events.PreAlterPartitionEvent;
+import org.apache.hadoop.hive.metastore.events.PreAlterTableEvent;
+import org.apache.hadoop.hive.metastore.events.PreCreateDatabaseEvent;
+import org.apache.hadoop.hive.metastore.events.PreCreateTableEvent;
+import org.apache.hadoop.hive.metastore.events.PreDropDatabaseEvent;
+import org.apache.hadoop.hive.metastore.events.PreDropPartitionEvent;
+import org.apache.hadoop.hive.metastore.events.PreDropTableEvent;
+import org.apache.hadoop.hive.metastore.events.PreEventContext;
+import org.apache.hadoop.hive.metastore.events.PreLoadPartitionDoneEvent;
 import org.apache.hadoop.hive.ql.Driver;
 import org.apache.hadoop.hive.ql.session.SessionState;
 
 /**
  * TestMetaStoreEventListener. Test case for
- * {@link org.apache.hadoop.hive.metastore.MetaStoreEventListener}
+ * {@link org.apache.hadoop.hive.metastore.MetaStoreEventListener} and
+ * {@link org.apache.hadoop.hive.metastore.MetaStorePreEventListener}
  */
 public class TestMetaStoreEventListener extends TestCase {
   private static final String msPort = "20001";
@@ -74,6 +84,8 @@ public class TestMetaStoreEventListener 
     super.setUp();
     System.setProperty(ConfVars.METASTORE_EVENT_LISTENERS.varname,
         DummyListener.class.getName());
+    System.setProperty(ConfVars.METASTORE_PRE_EVENT_LISTENERS.varname,
+        DummyPreListener.class.getName());
     Thread t = new Thread(new RunMS());
     t.start();
     Thread.sleep(40000);
@@ -94,6 +106,75 @@ public class TestMetaStoreEventListener 
     super.tearDown();
   }
 
+  private void validateCreateDb(Database expectedDb, Database actualDb) {
+    assertEquals(expectedDb.getName(), actualDb.getName());
+    assertEquals(expectedDb.getLocationUri(), actualDb.getLocationUri());
+  }
+
+  private void validateTable(Table expectedTable, Table actualTable) {
+    assertEquals(expectedTable.getTableName(), actualTable.getTableName());
+    assertEquals(expectedTable.getDbName(), actualTable.getDbName());
+    assertEquals(expectedTable.getSd().getLocation(), actualTable.getSd().getLocation());
+  }
+
+  private void validateCreateTable(Table expectedTable, Table actualTable) {
+    validateTable(expectedTable, actualTable);
+  }
+
+  private void validateAddPartition(Partition expectedPartition, Partition actualPartition) {
+    assertEquals(expectedPartition, actualPartition);
+  }
+
+  private void validatePartition(Partition expectedPartition, Partition actualPartition) {
+    assertEquals(expectedPartition.getValues(), actualPartition.getValues());
+    assertEquals(expectedPartition.getDbName(), actualPartition.getDbName());
+    assertEquals(expectedPartition.getTableName(), actualPartition.getTableName());
+  }
+
+  private void validateAlterPartition(Partition expectedOldPartition,
+      Partition expectedNewPartition, String actualOldPartitionDbName,
+      String actualOldPartitionTblName,List<String> actualOldPartitionValues,
+      Partition actualNewPartition) {
+    assertEquals(expectedOldPartition.getValues(), actualOldPartitionValues);
+    assertEquals(expectedOldPartition.getDbName(), actualOldPartitionDbName);
+    assertEquals(expectedOldPartition.getTableName(), actualOldPartitionTblName);
+
+    validatePartition(expectedNewPartition, actualNewPartition);
+  }
+
+  private void validateAlterTable(Table expectedOldTable, Table expectedNewTable,
+      Table actualOldTable, Table actualNewTable) {
+    validateTable(expectedOldTable, actualOldTable);
+    validateTable(expectedNewTable, actualNewTable);
+  }
+
+  private void validateAlterTableColumns(Table expectedOldTable, Table expectedNewTable,
+      Table actualOldTable, Table actualNewTable) {
+    validateAlterTable(expectedOldTable, expectedNewTable, actualOldTable, actualNewTable);
+
+    assertEquals(expectedOldTable.getSd().getCols(), actualOldTable.getSd().getCols());
+    assertEquals(expectedNewTable.getSd().getCols(), actualNewTable.getSd().getCols());
+  }
+
+  private void validateLoadPartitionDone(String expectedTableName,
+      Map<String,String> expectedPartitionName, String actualTableName,
+      Map<String,String> actualPartitionName) {
+    assertEquals(expectedPartitionName, actualPartitionName);
+    assertEquals(expectedTableName, actualTableName);
+  }
+
+  private void validateDropPartition(Partition expectedPartition, Partition actualPartition) {
+    validatePartition(expectedPartition, actualPartition);
+  }
+
+  private void validateDropTable(Table expectedTable, Table actualTable) {
+    validateTable(expectedTable, actualTable);
+  }
+
+  private void validateDropDb(Database expectedDb, Database actualDb) {
+    assertEquals(expectedDb, actualDb);
+  }
+
   public void testListener() throws Exception {
     String dbName = "tmpdb";
     String tblName = "tmptbl";
@@ -102,126 +183,158 @@ public class TestMetaStoreEventListener 
 
     List<ListenerEvent> notifyList = DummyListener.notifyList;
     assertEquals(notifyList.size(), listSize);
+    List<PreEventContext> preNotifyList = DummyPreListener.notifyList;
+    assertEquals(preNotifyList.size(), listSize);
 
     driver.run("create database " + dbName);
     listSize++;
     Database db = msc.getDatabase(dbName);
     assertEquals(listSize, notifyList.size());
+    assertEquals(listSize, preNotifyList.size());
+
     CreateDatabaseEvent dbEvent = (CreateDatabaseEvent)(notifyList.get(listSize - 1));
     assert dbEvent.getStatus();
-    assertEquals(db.getName(), dbEvent.getDatabase().getName());
-    assertEquals(db.getLocationUri(), dbEvent.getDatabase().getLocationUri());
+    validateCreateDb(db, dbEvent.getDatabase());
+
+    PreCreateDatabaseEvent preDbEvent = (PreCreateDatabaseEvent)(preNotifyList.get(listSize - 1));
+    validateCreateDb(db, preDbEvent.getDatabase());
 
     driver.run("use " + dbName);
     driver.run(String.format("create table %s (a string) partitioned by (b string)", tblName));
     listSize++;
     Table tbl = msc.getTable(dbName, tblName);
     assertEquals(notifyList.size(), listSize);
+    assertEquals(preNotifyList.size(), listSize);
+
     CreateTableEvent tblEvent = (CreateTableEvent)(notifyList.get(listSize - 1));
     assert tblEvent.getStatus();
-    assertEquals(tbl.getTableName(), tblEvent.getTable().getTableName());
-    assertEquals(tbl.getDbName(), tblEvent.getTable().getDbName());
-    assertEquals(tbl.getSd().getLocation(), tblEvent.getTable().getSd().getLocation());
+    validateCreateTable(tbl, tblEvent.getTable());
+
+    PreCreateTableEvent preTblEvent = (PreCreateTableEvent)(preNotifyList.get(listSize - 1));
+    validateCreateTable(tbl, preTblEvent.getTable());
 
     driver.run("alter table tmptbl add partition (b='2011')");
     listSize++;
     Partition part = msc.getPartition("tmpdb", "tmptbl", "b=2011");
     assertEquals(notifyList.size(), listSize);
+    assertEquals(preNotifyList.size(), listSize);
+
     AddPartitionEvent partEvent = (AddPartitionEvent)(notifyList.get(listSize-1));
     assert partEvent.getStatus();
-    assertEquals(part, partEvent.getPartition());
+    validateAddPartition(part, partEvent.getPartition());
+
+    PreAddPartitionEvent prePartEvent = (PreAddPartitionEvent)(preNotifyList.get(listSize-1));
+    validateAddPartition(part, prePartEvent.getPartition());
 
     driver.run(String.format("alter table %s touch partition (%s)", tblName, "b='2011'"));
     listSize++;
     assertEquals(notifyList.size(), listSize);
-    AlterPartitionEvent alterPartEvent = (AlterPartitionEvent)notifyList.get(listSize - 1);
-    assert alterPartEvent.getStatus();
-    Partition origP = msc.getPartition(dbName, tblName, "b=2011");
-    assertEquals(origP.getValues(), alterPartEvent.getOldPartition().getValues());
-    assertEquals(origP.getDbName(), alterPartEvent.getOldPartition().getDbName());
-    assertEquals(origP.getTableName(), alterPartEvent.getOldPartition().getTableName());
+    assertEquals(preNotifyList.size(), listSize);
+
     //the partition did not change,
     // so the new partition should be similar to the original partition
-    assertEquals(origP.getValues(), alterPartEvent.getNewPartition().getValues());
-    assertEquals(origP.getDbName(), alterPartEvent.getNewPartition().getDbName());
-    assertEquals(origP.getTableName(), alterPartEvent.getNewPartition().getTableName());
+    Partition origP = msc.getPartition(dbName, tblName, "b=2011");
+
+    AlterPartitionEvent alterPartEvent = (AlterPartitionEvent)notifyList.get(listSize - 1);
+    assert alterPartEvent.getStatus();
+    validateAlterPartition(origP, origP, alterPartEvent.getOldPartition().getDbName(),
+        alterPartEvent.getOldPartition().getTableName(),
+        alterPartEvent.getOldPartition().getValues(), alterPartEvent.getNewPartition());
+
+    PreAlterPartitionEvent preAlterPartEvent =
+        (PreAlterPartitionEvent)preNotifyList.get(listSize - 1);
+    validateAlterPartition(origP, origP, preAlterPartEvent.getDbName(),
+        preAlterPartEvent.getTableName(), preAlterPartEvent.getNewPartition().getValues(),
+        preAlterPartEvent.getNewPartition());
 
     driver.run(String.format("alter table %s rename to %s", tblName, renamed));
     listSize++;
     assertEquals(notifyList.size(), listSize);
+    assertEquals(preNotifyList.size(), listSize);
+
     Table renamedTable = msc.getTable(dbName, renamed);
+
     AlterTableEvent alterTableE = (AlterTableEvent) notifyList.get(listSize-1);
     assert alterTableE.getStatus();
-    Table oldTable = alterTableE.getOldTable();
-    Table newTable = alterTableE.getNewTable();
-    assertEquals(tbl.getDbName(), oldTable.getDbName());
-    assertEquals(tbl.getTableName(), oldTable.getTableName());
-    assertEquals(tbl.getSd().getLocation(), oldTable.getSd().getLocation());
-    assertEquals(renamedTable.getDbName(), newTable.getDbName());
-    assertEquals(renamedTable.getTableName(), newTable.getTableName());
-    assertEquals(renamedTable.getSd().getLocation(), newTable.getSd().getLocation());
+    validateAlterTable(tbl, renamedTable, alterTableE.getOldTable(), alterTableE.getNewTable());
+
+    PreAlterTableEvent preAlterTableE = (PreAlterTableEvent) preNotifyList.get(listSize-1);
+    validateAlterTable(tbl, renamedTable, preAlterTableE.getOldTable(),
+        preAlterTableE.getNewTable());
 
     //change the table name back
     driver.run(String.format("alter table %s rename to %s", renamed, tblName));
     listSize++;
     assertEquals(notifyList.size(), listSize);
+    assertEquals(preNotifyList.size(), listSize);
 
     driver.run(String.format("alter table %s ADD COLUMNS (c int)", tblName));
     listSize++;
     assertEquals(notifyList.size(), listSize);
+    assertEquals(preNotifyList.size(), listSize);
+
     Table altTable = msc.getTable(dbName, tblName);
+
     alterTableE = (AlterTableEvent) notifyList.get(listSize-1);
     assert alterTableE.getStatus();
-    oldTable = alterTableE.getOldTable();
-    List<FieldSchema> origCols = tbl.getSd().getCols();
-    List<FieldSchema> oldCols = oldTable.getSd().getCols();
-    List<FieldSchema> altCols = altTable.getSd().getCols();
-    List<FieldSchema> newCols = altTable.getSd().getCols();
-
-    assertEquals(origCols, oldCols);
-    assertEquals(altCols, newCols);
-
-    newTable = alterTableE.getNewTable();
-    assertEquals(tbl.getDbName(), oldTable.getDbName());
-    assertEquals(tbl.getTableName(), oldTable.getTableName());
-    assertEquals(tbl.getSd().getLocation(), oldTable.getSd().getLocation());
-    assertEquals(altTable.getDbName(), newTable.getDbName());
-    assertEquals(altTable.getTableName(), newTable.getTableName());
-    assertEquals(altTable.getSd().getLocation(), newTable.getSd().getLocation());
+    validateAlterTableColumns(tbl, altTable, alterTableE.getOldTable(), alterTableE.getNewTable());
+
+    preAlterTableE = (PreAlterTableEvent) preNotifyList.get(listSize-1);
+    validateAlterTableColumns(tbl, altTable, preAlterTableE.getOldTable(),
+        preAlterTableE.getNewTable());
 
     Map<String,String> kvs = new HashMap<String, String>(1);
     kvs.put("b", "2011");
     msc.markPartitionForEvent("tmpdb", "tmptbl", kvs, PartitionEventType.LOAD_DONE);
     listSize++;
     assertEquals(notifyList.size(), listSize);
+    assertEquals(preNotifyList.size(), listSize);
+
     LoadPartitionDoneEvent partMarkEvent = (LoadPartitionDoneEvent)notifyList.get(listSize - 1);
     assert partMarkEvent.getStatus();
-    assertEquals(partMarkEvent.getPartitionName(), kvs);
-    assertEquals(partMarkEvent.getTable().getTableName(), "tmptbl");
+    validateLoadPartitionDone("tmptbl", kvs, partMarkEvent.getTable().getTableName(),
+        partMarkEvent.getPartitionName());
+
+    PreLoadPartitionDoneEvent prePartMarkEvent =
+        (PreLoadPartitionDoneEvent)preNotifyList.get(listSize - 1);
+    validateLoadPartitionDone("tmptbl", kvs, prePartMarkEvent.getTableName(),
+        prePartMarkEvent.getPartitionName());
 
     driver.run(String.format("alter table %s drop partition (b='2011')", tblName));
     listSize++;
     assertEquals(notifyList.size(), listSize);
+    assertEquals(preNotifyList.size(), listSize);
+
     DropPartitionEvent dropPart = (DropPartitionEvent)notifyList.get(listSize - 1);
     assert dropPart.getStatus();
-    assertEquals(part.getValues(), dropPart.getPartition().getValues());
-    assertEquals(part.getDbName(), dropPart.getPartition().getDbName());
-    assertEquals(part.getTableName(), dropPart.getPartition().getTableName());
+    validateDropPartition(part, dropPart.getPartition());
+
+    PreDropPartitionEvent preDropPart = (PreDropPartitionEvent)preNotifyList.get(listSize - 1);
+    validateDropPartition(part, preDropPart.getPartition());
 
     driver.run("drop table " + tblName);
     listSize++;
     assertEquals(notifyList.size(), listSize);
+    assertEquals(preNotifyList.size(), listSize);
+
     DropTableEvent dropTbl = (DropTableEvent)notifyList.get(listSize-1);
     assert dropTbl.getStatus();
-    assertEquals(tbl.getTableName(), dropTbl.getTable().getTableName());
-    assertEquals(tbl.getDbName(), dropTbl.getTable().getDbName());
-    assertEquals(tbl.getSd().getLocation(), dropTbl.getTable().getSd().getLocation());
+    validateDropTable(tbl, dropTbl.getTable());
+
+    PreDropTableEvent preDropTbl = (PreDropTableEvent)preNotifyList.get(listSize-1);
+    validateDropTable(tbl, preDropTbl.getTable());
 
     driver.run("drop database " + dbName);
     listSize++;
     assertEquals(notifyList.size(), listSize);
+    assertEquals(preNotifyList.size(), listSize);
+
     DropDatabaseEvent dropDB = (DropDatabaseEvent)notifyList.get(listSize-1);
     assert dropDB.getStatus();
-    assertEquals(db, dropDB.getDatabase());
+    validateDropDb(db, dropDB.getDatabase());
+
+    PreDropDatabaseEvent preDropDB = (PreDropDatabaseEvent)preNotifyList.get(listSize-1);
+    assert dropDB.getStatus();
+    validateDropDb(db, preDropDB.getDatabase());
   }
 }



Mime
View raw message