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 182a77277b..dfce788e44 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 @@ -61,6 +61,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.apache.hadoop.hive.metastore.ReplChangeManager.SOURCE_OF_REPLICATION; +import org.apache.hadoop.hive.ql.parse.EximUtil; public class TestReplicationScenariosAcrossInstances { @Rule @@ -751,7 +752,7 @@ public void testIncrementalReplWithDropAndCreateTableDifferentPartitionTypeAndIn } @Test - public void shouldNotCreateDirectoryForNonNativeTableInDumpDirectory() throws Throwable { + public void testShouldNotCreateDirectoryForNonNativeTableInDumpDirectory() throws Throwable { String createTableQuery = "CREATE TABLE custom_serdes( serde_id bigint COMMENT 'from deserializer', name string " + "COMMENT 'from deserializer', slib string COMMENT 'from deserializer') " @@ -772,6 +773,35 @@ public void shouldNotCreateDirectoryForNonNativeTableInDumpDirectory() throws Th assertFalse(fs.exists(cSerdesTableDumpLocation)); } + @Test + public void testShouldDumpMetaDataForNonNativeTableIfSetMeataDataOnly() throws Throwable { + String tableName = testName.getMethodName() + "_table"; + String createTableQuery = + "CREATE TABLE " + tableName + " ( serde_id bigint COMMENT 'from deserializer', name string " + + "COMMENT 'from deserializer', slib string COMMENT 'from deserializer') " + + "ROW FORMAT SERDE 'org.apache.hive.storage.jdbc.JdbcSerDe' " + + "STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler' " + + "WITH SERDEPROPERTIES ('serialization.format'='1') " + + "TBLPROPERTIES ( " + + "'hive.sql.database.type'='METASTORE', " + + "'hive.sql.query'='SELECT \"SERDE_ID\", \"NAME\", \"SLIB\" FROM \"SERDES\"')"; + + WarehouseInstance.Tuple bootstrapTuple = primary + .run("use " + primaryDbName) + .run(createTableQuery) + .dump(primaryDbName, null, Collections.singletonList("'hive.repl.dump.metadata.only'='true'")); + Path cSerdesTableDumpLocation = new Path( + new Path(bootstrapTuple.dumpLocation, primaryDbName), + tableName); + FileSystem fs = cSerdesTableDumpLocation.getFileSystem(primary.hiveConf); + assertTrue(fs.exists(cSerdesTableDumpLocation)); + FileStatus[] fileInfoList = fs.listStatus(cSerdesTableDumpLocation); + assertTrue(fileInfoList.length != 0); + Path metaPath = new Path(cSerdesTableDumpLocation, EximUtil.METADATA_NAME); + fileInfoList = fs.listStatus(cSerdesTableDumpLocation); + assertTrue(fileInfoList.length != 0); + } + private void verifyIfCkptSet(Map props, String dumpDir) { assertTrue(props.containsKey(ReplUtils.REPL_CHECKPOINT_KEY)); assertTrue(props.get(ReplUtils.REPL_CHECKPOINT_KEY).equals(dumpDir)); diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/repl/dump/Utils.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/repl/dump/Utils.java index 14572ad8ae..e3566077ce 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/parse/repl/dump/Utils.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/repl/dump/Utils.java @@ -172,7 +172,8 @@ public static Boolean shouldReplicate(ReplicationSpec replicationSpec, Table tab return false; } - if (tableHandle.isNonNative()) { + // if its metadata only, then dump metadata of non native tables also. + if (tableHandle.isNonNative() && !replicationSpec.isMetadataOnly()) { return false; }