package gobblin.compaction.hivebasedconstructs;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import gobblin.compaction.listeners.CompactorListener;
import gobblin.compaction.mapreduce.MRCompactor;
import gobblin.metrics.Tag;
import gobblin.writer.DataWriter;
import gobblin.compaction.mapreduce.avro.ConfBasedDeltaFieldProvider;


/**
 * {@link DataWriter} that launches an {@link MRCompactor} job given an {@link MRCompactionEntity} specifying config
 * for compaction
 *
 * Delta field is passed using {@link ConfBasedDeltaFieldProvider}
 */
public class CompactionLauncherWriter implements DataWriter<MRCompactionEntity> {
  @Override
  public void write(MRCompactionEntity compactionEntity) throws IOException {
    Preconditions.checkNotNull(compactionEntity);

    List<? extends Tag<?>> list = new ArrayList<>();

    Properties props = new Properties();
    props.putAll(compactionEntity.getProps());
    props.setProperty(ConfBasedDeltaFieldProvider.DELTA_FIELDS_KEY,
        compactionEntity.getDeltaList().toString().replace("[", "").replace("]", ""));
    props.setProperty(MRCompactor.COMPACTION_INPUT_DIR, compactionEntity.getDataFilesPath().toString());

    MRCompactor compactor = new MRCompactor(props, list, Optional.<CompactorListener>absent());
    compactor.compact();
  }

  @Override
  public void commit() throws IOException {}

  @Override
  public void cleanup() throws IOException {}

  @Override
  public long recordsWritten() {
    return 0;
  }

  @Override
  public long bytesWritten() throws IOException {
    return 0;
  }

  @Override
  public void close() throws IOException {}
}

@@ -235,16 +235,54 @@
 itions;%0A
+import com.google.common.base.Joiner;%0A
 import g
@@ -1161,24 +1161,44 @@
 EY,%0A        
+Joiner.on(',').join(
 compactionEn
@@ -1220,52 +1220,8 @@
 st()
-.toString().replace(%22%5B%22, %22%22).replace(%22%5D%22, %22%22
 ));%0A

Address comment