Search in sources :

Example 11 with Metadata

use of org.apache.gobblin.metadata.types.Metadata in project incubator-gobblin by apache.

the class EnvelopedRecordWithMetadataToRecordWithMetadataTest method testSuccessWithRecord.

@Test
public void testSuccessWithRecord() throws DataConversionException, IOException {
    ObjectMapper objectMapper = new ObjectMapper();
    String innerRecord = "abracadabra";
    // Build the input record
    HashMap<String, Object> map = new HashMap<>();
    map.put("r", innerRecord);
    Metadata md = new Metadata();
    md.getRecordMetadata().put("test1", "test2");
    map.put("rMd", md);
    JsonNode jsonNode = objectMapper.valueToTree(map);
    RecordWithMetadata<byte[]> inputRecord = new RecordWithMetadata<>(jsonNode.toString().getBytes(), null);
    EnvelopedRecordWithMetadataToRecordWithMetadata converter = new EnvelopedRecordWithMetadataToRecordWithMetadata();
    Iterator<RecordWithMetadata<?>> iterator = converter.convertRecord(null, inputRecord, null).iterator();
    Assert.assertTrue(iterator.hasNext());
    RecordWithMetadata<?> outputRecord = iterator.next();
    Assert.assertEquals(outputRecord.getRecord(), innerRecord);
    Assert.assertEquals(outputRecord.getMetadata().getRecordMetadata().get("test1"), "test2");
}
Also used : RecordWithMetadata(org.apache.gobblin.type.RecordWithMetadata) HashMap(java.util.HashMap) Metadata(org.apache.gobblin.metadata.types.Metadata) RecordWithMetadata(org.apache.gobblin.type.RecordWithMetadata) JsonNode(org.codehaus.jackson.JsonNode) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.testng.annotations.Test)

Example 12 with Metadata

use of org.apache.gobblin.metadata.types.Metadata in project incubator-gobblin by apache.

the class EnvelopedRecordWithMetadataToRecordWithMetadataTest method testFailureWithoutRecord.

@Test(expectedExceptions = DataConversionException.class, expectedExceptionsMessageRegExp = "Input data does not have record.")
public void testFailureWithoutRecord() throws DataConversionException, IOException {
    ObjectMapper objectMapper = new ObjectMapper();
    // Build the input record without data
    HashMap<String, Object> map = new HashMap<>();
    Metadata md = new Metadata();
    md.getRecordMetadata().put("test1", "test2");
    map.put("rMd", md);
    JsonNode jsonNode = objectMapper.valueToTree(map);
    RecordWithMetadata<byte[]> inputRecord = new RecordWithMetadata<>(jsonNode.toString().getBytes(), null);
    EnvelopedRecordWithMetadataToRecordWithMetadata converter = new EnvelopedRecordWithMetadataToRecordWithMetadata();
    converter.convertRecord(null, inputRecord, null);
}
Also used : RecordWithMetadata(org.apache.gobblin.type.RecordWithMetadata) HashMap(java.util.HashMap) Metadata(org.apache.gobblin.metadata.types.Metadata) RecordWithMetadata(org.apache.gobblin.type.RecordWithMetadata) JsonNode(org.codehaus.jackson.JsonNode) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.testng.annotations.Test)

Example 13 with Metadata

use of org.apache.gobblin.metadata.types.Metadata in project incubator-gobblin by apache.

the class RecordWithMetadataSchemaRegistrationConverter method convertRecord.

@Override
public Iterable<RecordWithMetadata<?>> convertRecord(String outputSchema, RecordWithMetadata<?> inputRecord, WorkUnitState workUnit) throws DataConversionException {
    Preconditions.checkNotNull(schemaId);
    Metadata metadata = inputRecord.getMetadata();
    metadata.getGlobalMetadata().setContentType(CONTENT_TYPE);
    metadata.getRecordMetadata().put(SCHEMA_ID_KEY, schemaId);
    return Collections.singleton(new RecordWithMetadata<>(inputRecord.getRecord(), metadata));
}
Also used : Metadata(org.apache.gobblin.metadata.types.Metadata) RecordWithMetadata(org.apache.gobblin.type.RecordWithMetadata)

Example 14 with Metadata

use of org.apache.gobblin.metadata.types.Metadata in project incubator-gobblin by apache.

the class AvroToJsonRecordWithMetadataConverter method convertSchema.

@Override
public String convertSchema(final Schema inputSchema, WorkUnitState workUnit) throws SchemaConversionException {
    this.defaultMetadata = new Metadata();
    defaultMetadata.getGlobalMetadata().setContentType(inputSchema.getFullName() + "+json");
    return innerConverter.convertSchema(inputSchema, workUnit);
}
Also used : Metadata(org.apache.gobblin.metadata.types.Metadata) RecordWithMetadata(org.apache.gobblin.type.RecordWithMetadata)

Example 15 with Metadata

use of org.apache.gobblin.metadata.types.Metadata in project incubator-gobblin by apache.

the class SerializedRecordToEncryptedSerializedRecordConverterTest method setUp.

@BeforeTest
public void setUp() {
    workUnitState = new WorkUnitState();
    converter = new SerializedRecordToEncryptedSerializedRecordConverter();
    sampleRecord = new RecordWithMetadata<>(new byte[] { 'a', 'b', 'c', 'd' }, new Metadata());
    shiftedValue = new byte[] { 'b', 'c', 'd', 'e' };
    insecureShiftTag = InsecureShiftCodec.TAG;
}
Also used : WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) Metadata(org.apache.gobblin.metadata.types.Metadata) RecordWithMetadata(org.apache.gobblin.type.RecordWithMetadata) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

Metadata (org.apache.gobblin.metadata.types.Metadata)15 RecordWithMetadata (org.apache.gobblin.type.RecordWithMetadata)15 Test (org.testng.annotations.Test)8 JsonNode (org.codehaus.jackson.JsonNode)7 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)6 HashMap (java.util.HashMap)3 WorkUnitState (org.apache.gobblin.configuration.WorkUnitState)3 GlobalMetadata (org.apache.gobblin.metadata.types.GlobalMetadata)2 BeforeTest (org.testng.annotations.BeforeTest)2 IOException (java.io.IOException)1 Map (java.util.Map)1 Nullable (javax.annotation.Nullable)1 JsonParser (org.codehaus.jackson.JsonParser)1