Search in sources :

Example 41 with WorkUnitState

use of org.apache.gobblin.configuration.WorkUnitState in project incubator-gobblin by apache.

the class NoopPublisher method publishData.

/**
 * Publish the data for the given tasks.
 *
 * @param states
 */
@Override
public void publishData(Collection<? extends WorkUnitState> states) throws IOException {
    for (WorkUnitState state : states) {
        if (state.getWorkingState() == WorkUnitState.WorkingState.SUCCESSFUL) {
            state.setWorkingState(WorkUnitState.WorkingState.COMMITTED);
            log.info("Marking state committed");
        }
    }
}
Also used : WorkUnitState(org.apache.gobblin.configuration.WorkUnitState)

Example 42 with WorkUnitState

use of org.apache.gobblin.configuration.WorkUnitState in project incubator-gobblin by apache.

the class CsvToJsonConverterV2Test method convertOutput.

public void convertOutput() throws IOException {
    JsonParser parser = new JsonParser();
    JsonElement jsonElement = parser.parse(new InputStreamReader(getClass().getResourceAsStream("/converter/csv/schema_with_10_fields.json")));
    JsonArray outputSchema = jsonElement.getAsJsonArray();
    CSVParser csvParser = new CSVParser();
    String[] inputRecord = csvParser.parseLine(row10Cols);
    CsvToJsonConverterV2 converter = new CsvToJsonConverterV2();
    converter.init(new WorkUnitState());
    JsonObject actual = converter.createOutput(outputSchema, inputRecord);
    JsonObject expected = parser.parse(new InputStreamReader(getClass().getResourceAsStream("/converter/csv/10_fields.json"))).getAsJsonObject();
    Assert.assertEquals(expected, actual);
    converter.close();
}
Also used : JsonArray(com.google.gson.JsonArray) InputStreamReader(java.io.InputStreamReader) JsonElement(com.google.gson.JsonElement) WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) CSVParser(com.opencsv.CSVParser) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Example 43 with WorkUnitState

use of org.apache.gobblin.configuration.WorkUnitState in project incubator-gobblin by apache.

the class CsvToJsonConverterV2Test method convertOutputAddingNull.

public void convertOutputAddingNull() throws IOException, DataConversionException {
    JsonParser parser = new JsonParser();
    JsonElement jsonElement = parser.parse(new InputStreamReader(getClass().getResourceAsStream("/converter/csv/schema_with_11_fields.json")));
    JsonArray outputSchema = jsonElement.getAsJsonArray();
    CSVParser csvParser = new CSVParser();
    String[] inputRecord = csvParser.parseLine(row11Cols);
    CsvToJsonConverterV2 converter = new CsvToJsonConverterV2();
    WorkUnitState wuState = new WorkUnitState();
    wuState.setProp(CsvToJsonConverterV2.CUSTOM_ORDERING, "0,1,-1,3,4,5,6,7,8,9,10");
    converter.init(wuState);
    JsonObject actual = converter.convertRecord(outputSchema, inputRecord, wuState).iterator().next();
    JsonObject expected = parser.parse(new InputStreamReader(getClass().getResourceAsStream("/converter/csv/11_fields_with_null.json"))).getAsJsonObject();
    Assert.assertEquals(expected, actual);
    converter.close();
}
Also used : JsonArray(com.google.gson.JsonArray) InputStreamReader(java.io.InputStreamReader) JsonElement(com.google.gson.JsonElement) WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) CSVParser(com.opencsv.CSVParser) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Example 44 with WorkUnitState

use of org.apache.gobblin.configuration.WorkUnitState in project incubator-gobblin by apache.

the class AvroFieldsPickConverterTest method testFieldsPick.

@Test
public void testFieldsPick() throws Exception {
    Schema inputSchema = new Schema.Parser().parse(getClass().getResourceAsStream("/converter/fieldPickInput.avsc"));
    WorkUnitState workUnitState = new WorkUnitState();
    workUnitState.setProp(ConfigurationKeys.CONVERTER_AVRO_FIELD_PICK_FIELDS, "name,favorite_number,favorite_color");
    try (AvroFieldsPickConverter converter = new AvroFieldsPickConverter()) {
        Schema converted = converter.convertSchema(inputSchema, workUnitState);
        Schema expected = new Schema.Parser().parse(getClass().getResourceAsStream("/converter/fieldPickExpected.avsc"));
        JSONAssert.assertEquals(expected.toString(), converted.toString(), false);
    }
}
Also used : WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) Schema(org.apache.avro.Schema) Test(org.testng.annotations.Test)

Example 45 with WorkUnitState

use of org.apache.gobblin.configuration.WorkUnitState in project incubator-gobblin by apache.

the class AvroToRestJsonEntryConverterTest method testEqualConversion.

public void testEqualConversion() throws DataConversionException, IOException, JSONException {
    JsonParser parser = new JsonParser();
    String expectedResourceKey = "/sobject/user/John";
    String expectedJsonStr = "{ \"name\" : \"John\", \"favorite_number\" : 9, \"favorite_color\" : \"blue\", \"date_of_birth\" : 1462387756716, \"last_modified\" : 0, \"created\" : 1462387756716, \"address\" : {\"city\" : \"Mountain view\", \"street_number\" : 2029 } }";
    RestEntry<JsonObject> expected = new RestEntry<JsonObject>(expectedResourceKey, parser.parse(expectedJsonStr).getAsJsonObject());
    WorkUnitState workUnitState = new WorkUnitState();
    workUnitState.setProp(AvroToRestJsonEntryConverter.CONVERTER_AVRO_REST_ENTRY_RESOURCE_KEY, "/sobject/user/${name}");
    testConversion(expected, workUnitState);
}
Also used : WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Aggregations

WorkUnitState (org.apache.gobblin.configuration.WorkUnitState)222 Test (org.testng.annotations.Test)143 State (org.apache.gobblin.configuration.State)48 SourceState (org.apache.gobblin.configuration.SourceState)39 WorkUnit (org.apache.gobblin.source.workunit.WorkUnit)39 Schema (org.apache.avro.Schema)29 Path (org.apache.hadoop.fs.Path)26 GenericRecord (org.apache.avro.generic.GenericRecord)19 JsonObject (com.google.gson.JsonObject)17 ArrayList (java.util.ArrayList)16 File (java.io.File)14 TaskState (org.apache.hadoop.mapreduce.v2.api.records.TaskState)12 List (java.util.List)11 Configuration (org.apache.hadoop.conf.Configuration)11 IOException (java.io.IOException)10 LongWatermark (org.apache.gobblin.source.extractor.extract.LongWatermark)10 Extract (org.apache.gobblin.source.workunit.Extract)10 FileSystem (org.apache.hadoop.fs.FileSystem)10 Closer (com.google.common.io.Closer)8 JsonParser (com.google.gson.JsonParser)8