@Test
  public void testCompactionForFileInSratchDir() throws Exception {
    String dbName = "default";
    String tblName = "cfs";
    String createQuery = "CREATE TABLE " + tblName + "(a INT, b STRING) " + "STORED AS ORC  TBLPROPERTIES ('transactional'='true',"
            + "'transactional_properties'='default')";
    dropTables(tblName);
    executeStatementOnDriver(createQuery, driver);



    // Insert some data -> this will generate only insert deltas
    executeStatementOnDriver("INSERT INTO " + tblName + "(a,b) VALUES(1, 'foo')", driver);

    // Insert some data -> this will again generate only insert deltas
    executeStatementOnDriver("INSERT INTO " + tblName + "(a,b) VALUES(2, 'bar')", driver);

    // Find the location of the table
    IMetaStoreClient msClient = new HiveMetaStoreClient(conf);
    Table table = msClient.getTable(dbName, tblName);
    FileSystem fs = FileSystem.get(conf);

    Map<String, String> tblProperties = new HashMap<>();
    tblProperties.put("compactor.hive.compactor.input.tmp.dir",table.getSd().getLocation() + "/" + "_tmp");

    //Create empty file in ScratchDir under table location
    String scratchDirPath = table.getSd().getLocation() + "/" + "_tmp";
    Path dir = new Path(scratchDirPath + "/base_0000002_v0000005");
    fs.mkdirs(dir);
    Path emptyFile = AcidUtils.createBucketFile(dir, 0);
    fs.create(emptyFile);

    //Run MajorCompaction
    TxnStore txnHandler = TxnUtils.getTxnStore(conf);
    Worker t = new Worker();
    t.setConf(conf);
    t.init(new AtomicBoolean(true));
    CompactionRequest Cr = new CompactionRequest(dbName, tblName, CompactionType.MAJOR);
    Cr.setProperties(tblProperties);
    txnHandler.compact(Cr);
    t.run();

    ShowCompactResponse rsp = txnHandler.showCompact(new ShowCompactRequest());
    Assert.assertEquals(1, rsp.getCompacts().size());
    Assert.assertEquals(TxnStore.CLEANING_RESPONSE, rsp.getCompacts().get(0).getState());

  }
Insert overwrite and major compact an mm table with only original files.

@param format file format for table
@throws Exception
itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/txn/compactor/TestCompactor.java