use of org.apache.gobblin.configuration.WorkUnitState in project incubator-gobblin by apache.
the class HiveConvertPublisher method preservePartitionParams.
@VisibleForTesting
public void preservePartitionParams(Collection<? extends WorkUnitState> states) {
for (WorkUnitState wus : states) {
if (wus.getWorkingState() != WorkingState.COMMITTED) {
continue;
}
if (!wus.contains(COMPLETE_SOURCE_PARTITION_NAME)) {
continue;
}
if (!wus.contains(COMPLETE_DEST_PARTITION_NAME)) {
continue;
}
if (!(wus.contains(PARTITION_PARAMETERS_WHITELIST) || wus.contains(PARTITION_PARAMETERS_BLACKLIST))) {
continue;
}
List<String> whitelist = COMMA_SPLITTER.splitToList(wus.getProp(PARTITION_PARAMETERS_WHITELIST, StringUtils.EMPTY));
List<String> blacklist = COMMA_SPLITTER.splitToList(wus.getProp(PARTITION_PARAMETERS_BLACKLIST, StringUtils.EMPTY));
String completeSourcePartitionName = wus.getProp(COMPLETE_SOURCE_PARTITION_NAME);
String completeDestPartitionName = wus.getProp(COMPLETE_DEST_PARTITION_NAME);
if (!copyPartitionParams(completeSourcePartitionName, completeDestPartitionName, whitelist, blacklist)) {
log.warn("Unable to copy partition parameters from " + completeSourcePartitionName + " to " + completeDestPartitionName);
}
}
}
use of org.apache.gobblin.configuration.WorkUnitState in project incubator-gobblin by apache.
the class HiveSerDeTest method testAvroOrcSerDes.
/**
* This test uses Avro SerDe to deserialize data from Avro files, and use ORC SerDe
* to serialize them into ORC files.
*/
@Test(groups = { "gobblin.serde" })
public void testAvroOrcSerDes() throws IOException, DataRecordException, DataConversionException {
Properties properties = new Properties();
properties.load(new FileReader("gobblin-core/src/test/resources/serde/serde.properties"));
SourceState sourceState = new SourceState(new State(properties), ImmutableList.<WorkUnitState>of());
OldApiWritableFileSource source = new OldApiWritableFileSource();
List<WorkUnit> workUnits = source.getWorkunits(sourceState);
Assert.assertEquals(workUnits.size(), 1);
WorkUnitState wus = new WorkUnitState(workUnits.get(0));
wus.addAll(sourceState);
Closer closer = Closer.create();
HiveWritableHdfsDataWriter writer = null;
try {
OldApiWritableFileExtractor extractor = closer.register((OldApiWritableFileExtractor) source.getExtractor(wus));
HiveSerDeConverter converter = closer.register(new HiveSerDeConverter());
writer = closer.register((HiveWritableHdfsDataWriter) new HiveWritableHdfsDataWriterBuilder<>().withBranches(1).withWriterId("0").writeTo(Destination.of(DestinationType.HDFS, sourceState)).writeInFormat(WriterOutputFormat.ORC).build());
converter.init(wus);
Writable record;
while ((record = extractor.readRecord(null)) != null) {
Iterable<Writable> convertedRecordIterable = converter.convertRecordImpl(null, record, wus);
Assert.assertEquals(Iterators.size(convertedRecordIterable.iterator()), 1);
writer.write(convertedRecordIterable.iterator().next());
}
} catch (Throwable t) {
throw closer.rethrow(t);
} finally {
closer.close();
if (writer != null) {
writer.commit();
}
Assert.assertTrue(this.fs.exists(new Path(sourceState.getProp(ConfigurationKeys.WRITER_OUTPUT_DIR), sourceState.getProp(ConfigurationKeys.WRITER_FILE_NAME))));
HadoopUtils.deletePath(this.fs, new Path(sourceState.getProp(ConfigurationKeys.WRITER_OUTPUT_DIR)), true);
}
}
use of org.apache.gobblin.configuration.WorkUnitState in project incubator-gobblin by apache.
the class QueryBasedExtractorTest method testDataPullUpperBoundsRemovedInLastWorkUnit.
@Test
public void testDataPullUpperBoundsRemovedInLastWorkUnit() {
int totalCount = 5;
ArrayList<DataRecord> records = this.generateRecords(totalCount);
WorkUnit workUnit = WorkUnit.createEmpty();
workUnit.setProp(Partition.IS_LAST_PARTIITON, true);
workUnit.setProp(ConfigurationKeys.SOURCE_QUERYBASED_EXTRACT_TYPE, "SNAPSHOT");
WorkUnitState workUnitState = new WorkUnitState(workUnit, new State());
workUnitState.setId("testDataPullUpperBoundsRemovedInLastWorkUnit");
TestQueryBasedExtractor testExtractor = new TestQueryBasedExtractor(workUnitState, records);
testExtractor.setRangePredicates(1, 3);
this.verify(testExtractor, totalCount);
}
use of org.apache.gobblin.configuration.WorkUnitState in project incubator-gobblin by apache.
the class QueryBasedExtractorTest method testDataPullUpperBoundsNotRemovedInLastWorkUnit.
@Test
public void testDataPullUpperBoundsNotRemovedInLastWorkUnit() {
int totalCount = 5;
ArrayList<DataRecord> records = this.generateRecords(totalCount);
WorkUnit workUnit = WorkUnit.createEmpty();
WorkUnitState workUnitState = new WorkUnitState(workUnit, new State());
workUnitState.setId("testDataPullUpperBoundsNotRemovedInLastWorkUnit");
// It's not a last work unit
TestQueryBasedExtractor testExtractor = new TestQueryBasedExtractor(workUnitState, records);
testExtractor.setRangePredicates(1, 3);
this.verify(testExtractor, 3);
// It's a last work unit but user specifies high watermark
workUnit.setProp(Partition.IS_LAST_PARTIITON, true);
workUnit.setProp(Partition.HAS_USER_SPECIFIED_HIGH_WATERMARK, true);
testExtractor.reset();
testExtractor.setRangePredicates(1, 3);
this.verify(testExtractor, 3);
// It's a last work unit but it has WORK_UNIT_STATE_ACTUAL_HIGH_WATER_MARK_KEY on record
workUnit.removeProp(Partition.HAS_USER_SPECIFIED_HIGH_WATERMARK);
workUnit.setProp(ConfigurationKeys.WORK_UNIT_STATE_ACTUAL_HIGH_WATER_MARK_KEY, "3");
testExtractor.reset();
testExtractor.setRangePredicates(1, 3);
this.verify(testExtractor, 3);
}
use of org.apache.gobblin.configuration.WorkUnitState in project incubator-gobblin by apache.
the class FileBasedExtractorTest method testReadRecordWithNoFiles.
public void testReadRecordWithNoFiles() throws DataRecordException, IOException {
WorkUnitState state = new WorkUnitState();
state.setProp(ConfigurationKeys.SOURCE_FILEBASED_FILES_TO_PULL, "");
FileBasedHelper fsHelper = Mockito.mock(FileBasedHelper.class);
FileBasedExtractor<String, String> extractor = new DummyFileBasedExtractor<String, String>(state, fsHelper);
Assert.assertEquals(getNumRecords(extractor), 0);
}
Aggregations