/** * Returns a {@link org.apache.gobblin.fork.CopyableSchema} wrapper around the given {@link Schema}. * {@inheritDoc} * @see org.apache.gobblin.converter.Converter#convertSchema(java.lang.Object, org.apache.gobblin.configuration.WorkUnitState) */ @Override public CopyableSchema convertSchema(Schema inputSchema, WorkUnitState workUnit) throws SchemaConversionException { return new CopyableSchema(inputSchema); }
@Test public void testCopy() throws CopyNotSupportedException { Schema schema = new Schema.Parser().parse(AVRO_SCHEMA); CopyableSchema copyableSchema = new CopyableSchema(schema); Schema copy = copyableSchema.copy(); Assert.assertEquals(schema, copy); copy.addProp("foo", "bar"); Assert.assertNotEquals(schema, copy); } }
@Override public Iterable<CopyableGenericRecord> convertRecord(CopyableSchema schema, String inputRecord, WorkUnitState workUnit) throws DataConversionException { JsonElement element = GSON.fromJson(inputRecord, JsonElement.class); Map<String, Object> fields = GSON.fromJson(element, FIELD_ENTRY_TYPE); try { Schema avroSchema = schema.copy(); GenericRecord record = new GenericData.Record(avroSchema); for (Map.Entry<String, Object> entry : fields.entrySet()) { if (entry.getValue() instanceof Double) { // Gson reads the integers in the input Json documents as doubles, so we have // to convert doubles to integers here as the Avro schema specifies integers. record.put(entry.getKey(), ((Double) entry.getValue()).intValue()); } else { record.put(entry.getKey(), entry.getValue()); } } return new SingleRecordIterable<CopyableGenericRecord>(new CopyableGenericRecord(record)); } catch (CopyNotSupportedException cnse) { throw new DataConversionException(cnse); } } }
@Override public CopyableSchema convertSchema(String schema, WorkUnitState workUnit) { return new CopyableSchema(new Schema.Parser().parse(schema)); }
/** * Returns a {@link org.apache.gobblin.fork.CopyableSchema} wrapper around the given {@link Schema}. * {@inheritDoc} * @see org.apache.gobblin.converter.Converter#convertSchema(java.lang.Object, org.apache.gobblin.configuration.WorkUnitState) */ @Override public CopyableSchema convertSchema(Schema inputSchema, WorkUnitState workUnit) throws SchemaConversionException { return new CopyableSchema(inputSchema); }