pvargacl commented on a change in pull request #1087:
URL: https://github.com/apache/hive/pull/1087#discussion_r450318970



##########
File path: ql/src/test/org/apache/hadoop/hive/ql/TxnCommandsBaseForTests.java
##########
@@ -162,9 +163,23 @@ protected String getWarehouseDir() {
    * takes raw data and turns it into a string as if from Driver.getResults()
    * sorts rows in dictionary order
    */
-  List<String> stringifyValues(int[][] rowsIn) {
-    return TestTxnCommands2.stringifyValues(rowsIn);
+  public static List<String> stringifyValues(int[][] rowsIn) {
+    assert rowsIn.length > 0;
+    int[][] rows = rowsIn.clone();
+    Arrays.sort(rows, new TestTxnCommands2.RowComp());

Review comment:
       fixed

##########
File path: 
ql/src/test/org/apache/hadoop/hive/ql/metadata/TestHiveMetaStoreChecker.java
##########
@@ -252,37 +241,165 @@ public void testInvalidPartitionKeyName()
   @Test
   public void testSkipInvalidPartitionKeyName()
     throws HiveException, AlreadyExistsException, IOException, 
MetastoreException {
-    hive.getConf().set(HiveConf.ConfVars.HIVE_MSCK_PATH_VALIDATION.varname, 
"skip");
+    
hive.getConf().set(MetastoreConf.ConfVars.MSCK_PATH_VALIDATION.getVarname(), 
"skip");
     checker = new HiveMetaStoreChecker(msc, hive.getConf());
-    Table table = createTestTable();
+    Table table = createTestTable(false);
     List<Partition> partitions = hive.getPartitions(table);
     assertEquals(2, partitions.size());
     // add a fake partition dir on fs
     fs = partitions.get(0).getDataLocation().getFileSystem(hive.getConf());
-    Path fakePart =
-        new Path(table.getDataLocation().toString(), 
"fakedate=2009-01-01/fakecity=sanjose");
-    fs.mkdirs(fakePart);
-    fs.deleteOnExit(fakePart);
+    addFolderToPath(fs, 
table.getDataLocation().toString(),"fakedate=2009-01-01/fakecity=sanjose");
     createPartitionsDirectoriesOnFS(table, 2);
-    CheckResult result = new CheckResult();
-    checker.checkMetastore(catName, dbName, tableName, null, null, result);
+    CheckResult result = checker.checkMetastore(catName, dbName, tableName, 
null, null);
     assertEquals(Collections.<String> emptySet(), result.getTablesNotInMs());
     assertEquals(Collections.<String> emptySet(), result.getTablesNotOnFs());
     assertEquals(Collections.<CheckResult.PartitionResult> emptySet(), 
result.getPartitionsNotOnFs());
     // only 2 valid partitions should be added
     assertEquals(2, result.getPartitionsNotInMs().size());
   }
 
-  private Table createTestTable() throws HiveException, AlreadyExistsException 
{
+  /*
+   * Tests the case when we have normal delta_dirs in the partition folder
+   * does not throw HiveException
+   */
+  @Test
+  public void testAddPartitionNormalDeltas() throws Exception {
+    Table table = createTestTable(true);
+    List<Partition> partitions = hive.getPartitions(table);
+    assertEquals(2, partitions.size());
+    // add a partition dir on fs
+    fs = partitions.get(0).getDataLocation().getFileSystem(hive.getConf());
+    Path newPart = addFolderToPath(fs, table.getDataLocation().toString(),
+        partDateName + "=2017-01-01/" + partCityName + "=paloalto");
+
+    // Add a few deltas
+    addFolderToPath(fs, newPart.toString(), "delta_0000001_0000001_0000");
+    addFolderToPath(fs, newPart.toString(), "delta_0000010_0000010_0000");
+    addFolderToPath(fs, newPart.toString(), "delta_0000101_0000101_0000");
+    CheckResult result = checker.checkMetastore(catName, dbName, tableName, 
null, null);
+    assertEquals(Collections.<CheckResult.PartitionResult> emptySet(), 
result.getPartitionsNotOnFs());
+    assertEquals(1, result.getPartitionsNotInMs().size());
+    // Found the highest writeId
+    assertEquals(101, 
result.getPartitionsNotInMs().iterator().next().getMaxWriteId());
+    assertEquals(0, 
result.getPartitionsNotInMs().iterator().next().getMaxTxnId());
+  }
+  /*
+   * Tests the case when we have normal delta_dirs in the partition folder
+   * does not throw HiveException
+   */
+  @Test
+  public void testAddPartitionCompactedDeltas() throws Exception {
+    Table table = createTestTable(true);
+    List<Partition> partitions = hive.getPartitions(table);
+    assertEquals(2, partitions.size());
+    // add a partition dir on fs
+    fs = partitions.get(0).getDataLocation().getFileSystem(hive.getConf());
+    Path newPart = addFolderToPath(fs, table.getDataLocation().toString(),
+        partDateName + "=2017-01-01/" + partCityName + "=paloalto");
+
+    // Add a few deltas
+    addFolderToPath(fs, newPart.toString(), "delta_0000001_0000001_0000");
+    addFolderToPath(fs, newPart.toString(), "delta_0000010_0000015_v0000067");
+    addFolderToPath(fs, newPart.toString(), "delta_0000101_0000120_v0000087");
+    CheckResult result = checker.checkMetastore(catName, dbName, tableName, 
null, null);
+    assertEquals(Collections.<CheckResult.PartitionResult> emptySet(), 
result.getPartitionsNotOnFs());
+    assertEquals(1, result.getPartitionsNotInMs().size());
+    // Found the highest writeId
+    assertEquals(120, 
result.getPartitionsNotInMs().iterator().next().getMaxWriteId());
+    assertEquals(87, 
result.getPartitionsNotInMs().iterator().next().getMaxTxnId());
+  }
+  @Test
+  public void testAddPartitionCompactedBase() throws Exception {
+    Table table = createTestTable(true);
+    List<Partition> partitions = hive.getPartitions(table);
+    assertEquals(2, partitions.size());
+    // add a partition dir on fs
+    fs = partitions.get(0).getDataLocation().getFileSystem(hive.getConf());
+    Path newPart = addFolderToPath(fs, table.getDataLocation().toString(),
+        partDateName + "=2017-01-01/" + partCityName + "=paloalto");
+
+    // Add a few deltas
+    addFolderToPath(fs, newPart.toString(), "delta_0000001_0000001_0000");
+    addFolderToPath(fs, newPart.toString(), "delta_0000002_0000002_0000");
+    addFolderToPath(fs, newPart.toString(), "delta_0000003_0000003_0000");
+    addFolderToPath(fs, newPart.toString(), "base_0000003_v0000200");
+    CheckResult result = checker.checkMetastore(catName, dbName, tableName, 
null, null);
+    assertEquals(Collections.<CheckResult.PartitionResult> emptySet(), 
result.getPartitionsNotOnFs());
+    assertEquals(1, result.getPartitionsNotInMs().size());
+    // Found the highest writeId
+    assertEquals(3, 
result.getPartitionsNotInMs().iterator().next().getMaxWriteId());
+    assertEquals(200, 
result.getPartitionsNotInMs().iterator().next().getMaxTxnId());
+  }
+
+  @Test
+  public void testAddPartitionMMBase() throws Exception {
+    Table table = createTestTable(true);
+    List<Partition> partitions = hive.getPartitions(table);
+    assertEquals(2, partitions.size());
+    // add a partition dir on fs
+    fs = partitions.get(0).getDataLocation().getFileSystem(hive.getConf());
+    Path newPart = addFolderToPath(fs, table.getDataLocation().toString(),
+        partDateName + "=2017-01-01/" + partCityName + "=paloalto");
+
+    // Add a few deltas
+    addFolderToPath(fs, newPart.toString(), "delta_0000001_0000001_0000");
+    addFolderToPath(fs, newPart.toString(), "delta_0000002_0000002_0000");
+    addFolderToPath(fs, newPart.toString(), "delta_0000003_0000003_0000");
+    addFolderToPath(fs, newPart.toString(), "base_0000004");
+    CheckResult result = checker.checkMetastore(catName, dbName, tableName, 
null, null);
+    assertEquals(Collections.<CheckResult.PartitionResult> emptySet(), 
result.getPartitionsNotOnFs());
+    assertEquals(1, result.getPartitionsNotInMs().size());
+    // Found the highest writeId
+    assertEquals(4, 
result.getPartitionsNotInMs().iterator().next().getMaxWriteId());
+    assertEquals(0, 
result.getPartitionsNotInMs().iterator().next().getMaxTxnId());
+  }
+
+  @Test
+  public void testNoNPartitionedTable() throws Exception {
+    Table table = createNonPartitionedTable();
+    // add a partition dir on fs
+    fs = table.getDataLocation().getFileSystem(hive.getConf());
+
+    Path tablePath = table.getDataLocation();
+
+    // Add a few deltas
+    addFolderToPath(fs, tablePath.toString(), "delta_0000001_0000001_0000");
+    addFolderToPath(fs, tablePath.toString(), "delta_0000002_0000002_0000");
+    addFolderToPath(fs, tablePath.toString(), "delta_0000003_0000003_0000");
+    addFolderToPath(fs, tablePath.toString(), "base_0000003_v0000200");
+    CheckResult result = checker.checkMetastore(catName, dbName, tableName, 
null, null);
+    assertEquals(Collections.<CheckResult.PartitionResult> emptySet(), 
result.getPartitionsNotOnFs());
+    assertEquals(Collections.<CheckResult.PartitionResult> emptySet(), 
result.getPartitionsNotInMs());
+    // Found the highest writeId
+    assertEquals(3, result.getMaxWriteId());
+    assertEquals(200, result.getMaxTxnId());
+  }
+
+  private Path addFolderToPath(FileSystem fs, String rootPath, String folder) 
throws IOException{

Review comment:
       fixed




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org
For additional commands, e-mail: gitbox-h...@hive.apache.org

Reply via email to