use of org.apache.gobblin.converter.json.JsonSchema 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"));
}
use of org.apache.gobblin.converter.json.JsonSchema in project incubator-gobblin by apache.
the class JsonElementConversionFactory method getConvertor.
/**
* Backward Compatible form of {@link JsonElementConverter#getConvertor(JsonSchema, String, WorkUnitState)}
* @param fieldName
* @param fieldType
* @param schemaNode
* @param state
* @param nullable
* @return
* @throws UnsupportedDateTypeException
*/
public static JsonElementConverter getConvertor(String fieldName, String fieldType, JsonObject schemaNode, WorkUnitState state, boolean nullable) throws UnsupportedDateTypeException {
if (!schemaNode.has(COLUMN_NAME_KEY)) {
schemaNode.addProperty(COLUMN_NAME_KEY, fieldName);
}
if (!schemaNode.has(DATA_TYPE_KEY)) {
schemaNode.add(DATA_TYPE_KEY, new JsonObject());
}
JsonObject dataType = schemaNode.get(DATA_TYPE_KEY).getAsJsonObject();
if (!dataType.has(TYPE_KEY)) {
dataType.addProperty(TYPE_KEY, fieldType);
}
if (!schemaNode.has(IS_NULLABLE_KEY)) {
schemaNode.addProperty(IS_NULLABLE_KEY, nullable);
}
JsonSchema schema = new JsonSchema(schemaNode);
return getConvertor(schema, null, state);
}
use of org.apache.gobblin.converter.json.JsonSchema 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;
}
use of org.apache.gobblin.converter.json.JsonSchema in project incubator-gobblin by apache.
the class JsonElementConversionFactoryTest method schemaWithMapValuesAsJsonNull.
@Test(expectedExceptions = UnsupportedOperationException.class)
public void schemaWithMapValuesAsJsonNull() throws Exception {
String testName = "schemaWithMapValuesAsJsonNull";
JsonObject schema = getSchemaData(testName).getAsJsonObject();
new RecordConverter(new JsonSchema(schema), state, buildNamespace(state.getExtract().getNamespace(), "something"));
}
use of org.apache.gobblin.converter.json.JsonSchema in project incubator-gobblin by apache.
the class JsonElementConversionFactoryTest method schemaWithRecordIsNullable.
@Test
public void schemaWithRecordIsNullable() throws Exception {
String testName = "schemaWithRecordIsNullable";
JsonObject schema = getSchemaData(testName).getAsJsonObject();
JsonArray expected = getExpectedSchema(testName).getAsJsonArray();
RecordConverter converter = new RecordConverter(new JsonSchema(schema), state, buildNamespace(state.getExtract().getNamespace(), "something"));
Assert.assertEquals(avroSchemaToJsonElement(converter), expected);
}
Aggregations