Search in sources :

Example 1 with RecordConverter

use of org.apache.gobblin.converter.avro.JsonElementConversionFactory.RecordConverter in project incubator-gobblin by apache.

the class JsonElementConversionFactoryTest method schemaWithRecordOfEnum.

@Test
public void schemaWithRecordOfEnum() throws Exception {
    String testName = "schemaWithRecordOfEnum";
    JsonObject schema = getSchemaData(testName).getAsJsonObject();
    JsonObject expected = getExpectedSchema(testName).getAsJsonObject();
    RecordConverter converter = new RecordConverter(new JsonSchema(schema), state, buildNamespace(state.getExtract().getNamespace(), "something"));
    Assert.assertEquals(avroSchemaToJsonElement(converter), expected);
}
Also used : RecordConverter(org.apache.gobblin.converter.avro.JsonElementConversionFactory.RecordConverter) JsonSchema(org.apache.gobblin.converter.json.JsonSchema) JsonObject(com.google.gson.JsonObject) Test(org.testng.annotations.Test)

Example 2 with RecordConverter

use of org.apache.gobblin.converter.avro.JsonElementConversionFactory.RecordConverter in project incubator-gobblin by apache.

the class JsonElementConversionFactoryTest method schemaWithRecordOfRecord.

@Test
public void schemaWithRecordOfRecord() throws Exception {
    String testName = "schemaWithRecordOfRecord";
    JsonObject schema = getSchemaData(testName).getAsJsonObject();
    JsonObject expected = getExpectedSchema(testName).getAsJsonObject();
    RecordConverter converter = new RecordConverter(new JsonSchema(schema), state, buildNamespace(state.getExtract().getNamespace(), "something"));
    Assert.assertEquals(avroSchemaToJsonElement(converter), expected);
}
Also used : RecordConverter(org.apache.gobblin.converter.avro.JsonElementConversionFactory.RecordConverter) JsonSchema(org.apache.gobblin.converter.json.JsonSchema) JsonObject(com.google.gson.JsonObject) Test(org.testng.annotations.Test)

Example 3 with RecordConverter

use of org.apache.gobblin.converter.avro.JsonElementConversionFactory.RecordConverter in project incubator-gobblin by apache.

the class JsonElementConversionFactoryTest method schemaWithRecord.

@Test
public void schemaWithRecord() throws DataConversionException, SchemaConversionException, UnsupportedDateTypeException {
    String testName = "schemaWithRecord";
    JsonObject schema = getSchemaData(testName).getAsJsonObject();
    JsonObject expected = getExpectedSchema(testName).getAsJsonObject();
    JsonSchema jsonSchema = new JsonSchema(schema);
    jsonSchema.setColumnName("dummy1");
    RecordConverter converter = new RecordConverter(jsonSchema, state, buildNamespace(state.getExtract().getNamespace(), "something"));
    Assert.assertEquals(avroSchemaToJsonElement(converter), expected);
}
Also used : RecordConverter(org.apache.gobblin.converter.avro.JsonElementConversionFactory.RecordConverter) JsonSchema(org.apache.gobblin.converter.json.JsonSchema) JsonObject(com.google.gson.JsonObject) Test(org.testng.annotations.Test)

Example 4 with RecordConverter

use of org.apache.gobblin.converter.avro.JsonElementConversionFactory.RecordConverter in project incubator-gobblin by apache.

the class JsonElementConversionFactoryTest method schemaWithMapValuesAsJsonArray.

@Test(expectedExceptions = IllegalStateException.class)
public void schemaWithMapValuesAsJsonArray() throws Exception {
    String testName = "schemaWithMapValuesAsJsonArray";
    JsonObject schema = getSchemaData(testName).getAsJsonObject();
    new RecordConverter(new JsonSchema(schema), state, buildNamespace(state.getExtract().getNamespace(), "something"));
}
Also used : RecordConverter(org.apache.gobblin.converter.avro.JsonElementConversionFactory.RecordConverter) JsonSchema(org.apache.gobblin.converter.json.JsonSchema) JsonObject(com.google.gson.JsonObject) Test(org.testng.annotations.Test)

Example 5 with RecordConverter

use of org.apache.gobblin.converter.avro.JsonElementConversionFactory.RecordConverter in project incubator-gobblin by apache.

the class JsonIntermediateToAvroConverter method convertSchema.

@Override
public Schema convertSchema(JsonArray schema, WorkUnitState workUnit) throws SchemaConversionException {
    try {
        JsonSchema jsonSchema = new JsonSchema(schema);
        jsonSchema.setColumnName(workUnit.getExtract().getTable());
        recordConverter = new RecordConverter(jsonSchema, workUnit, workUnit.getExtract().getNamespace());
    } catch (UnsupportedDateTypeException e) {
        throw new SchemaConversionException(e);
    }
    Schema recordSchema = recordConverter.schema();
    if (workUnit.getPropAsBoolean(CONVERTER_AVRO_NULLIFY_FIELDS_ENABLED, DEFAULT_CONVERTER_AVRO_NULLIFY_FIELDS_ENABLED)) {
        return this.generateSchemaWithNullifiedField(workUnit, recordSchema);
    }
    return recordSchema;
}
Also used : SchemaConversionException(org.apache.gobblin.converter.SchemaConversionException) RecordConverter(org.apache.gobblin.converter.avro.JsonElementConversionFactory.RecordConverter) JsonSchema(org.apache.gobblin.converter.json.JsonSchema) JsonSchema(org.apache.gobblin.converter.json.JsonSchema) Schema(org.apache.avro.Schema)

Aggregations

RecordConverter (org.apache.gobblin.converter.avro.JsonElementConversionFactory.RecordConverter)11 JsonSchema (org.apache.gobblin.converter.json.JsonSchema)11 JsonObject (com.google.gson.JsonObject)10 Test (org.testng.annotations.Test)10 JsonArray (com.google.gson.JsonArray)1 Schema (org.apache.avro.Schema)1 SchemaConversionException (org.apache.gobblin.converter.SchemaConversionException)1