diff --git a/hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java b/hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java index 717cc8a..ce37035 100644 --- a/hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java +++ b/hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java @@ -38,6 +38,7 @@ import org.apache.hadoop.hive.metastore.RawStore; import org.apache.hadoop.hive.metastore.RawStoreProxy; import org.apache.hadoop.hive.metastore.ReplChangeManager; +import org.apache.hadoop.hive.metastore.TableType; import org.apache.hadoop.hive.metastore.TransactionalMetaStoreEventListener; import org.apache.hadoop.hive.metastore.Warehouse; import org.apache.hadoop.hive.metastore.api.Database; @@ -155,9 +156,11 @@ public void onConfigChange(ConfigChangeEvent tableEvent) throws MetaException { @Override public void onCreateTable(CreateTableEvent tableEvent) throws MetaException { Table t = tableEvent.getTable(); + FileIterator fileIter = t.getTableType().equals(TableType.EXTERNAL_TABLE.toString()) + ? null : new FileIterator(t.getSd().getLocation()); NotificationEvent event = - new NotificationEvent(0, now(), EventType.CREATE_TABLE.toString(), msgFactory - .buildCreateTableMessage(t, new FileIterator(t.getSd().getLocation())).toString()); + new NotificationEvent(0, now(), EventType.CREATE_TABLE.toString(), + msgFactory.buildCreateTableMessage(t, fileIter).toString()); event.setCatName(t.isSetCatName() ? t.getCatName() : DEFAULT_CATALOG_NAME); event.setDbName(t.getDbName()); event.setTableName(t.getTableName()); @@ -301,9 +304,10 @@ public void remove() { @Override public void onAddPartition(AddPartitionEvent partitionEvent) throws MetaException { Table t = partitionEvent.getTable(); + PartitionFilesIterator fileIter = t.getTableType().equals(TableType.EXTERNAL_TABLE.toString()) + ? null : new PartitionFilesIterator(partitionEvent.getPartitionIterator(), t); String msg = msgFactory - .buildAddPartitionMessage(t, partitionEvent.getPartitionIterator(), - new PartitionFilesIterator(partitionEvent.getPartitionIterator(), t)).toString(); + .buildAddPartitionMessage(t, partitionEvent.getPartitionIterator(), fileIter).toString(); NotificationEvent event = new NotificationEvent(0, now(), EventType.ADD_PARTITION.toString(), msg); event.setCatName(t.isSetCatName() ? t.getCatName() : DEFAULT_CATALOG_NAME); diff --git a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenariosAcrossInstances.java b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenariosAcrossInstances.java index b2e1e25..6c45641 100644 --- a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenariosAcrossInstances.java +++ b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenariosAcrossInstances.java @@ -1387,6 +1387,7 @@ public void testDumpExternalTableSetTrue() throws Throwable { tuple = primary.run("use " + primaryDbName) .run("create external table t3 (id int)") .run("insert into table t3 values (10)") + .run("create external table t4 as select id from t3") .dump("repl dump " + primaryDbName + " from " + tuple.lastReplicationId + " with ('hive.repl.include.external.tables'='true')"); @@ -1395,6 +1396,8 @@ public void testDumpExternalTableSetTrue() throws Throwable { .run("show tables like 't3'") .verifyResult("t3") .run("select id from t3") - .verifyResult("10"); + .verifyResult("10") + .run("select id from t4") + .verifyResult(null); // Returns null as create table event doesn't list files } } diff --git a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONAddPartitionMessage.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONAddPartitionMessage.java index 11921f2..bb2093b 100644 --- a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONAddPartitionMessage.java +++ b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONAddPartitionMessage.java @@ -88,7 +88,8 @@ public JSONAddPartitionMessage(String server, String servicePrincipal, Table tab } catch (TException e) { throw new IllegalArgumentException("Could not serialize: ", e); } - this.partitionFiles = Lists.newArrayList(partitionFileIter); + this.partitionFiles = (partitionFileIter != null) ? Lists.newArrayList(partitionFileIter) + : Lists.newArrayList(); checkValid(); } diff --git a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONCreateTableMessage.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONCreateTableMessage.java index d0f4b86..b80003b 100644 --- a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONCreateTableMessage.java +++ b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONCreateTableMessage.java @@ -72,7 +72,7 @@ public JSONCreateTableMessage(String server, String servicePrincipal, Table tabl } catch (TException e) { throw new IllegalArgumentException("Could not serialize: ", e); } - this.files = Lists.newArrayList(fileIter); + this.files = (fileIter != null) ? Lists.newArrayList(fileIter) : Lists.newArrayList(); } @Override