/** {@inheritDoc} */ @Override public Long apply(AvroSchema avroSchema) { if (avroSchema.getJson() != null) { final Schema schema = new Schema.Parser().parse(avroSchema.getJson()); try { return mSchemaTable.getOrCreateSchemaId(schema); } catch (IOException ioe) { throw new FijiIOException(ioe); } } else if (avroSchema.getUid() != null) { return avroSchema.getUid(); } else { throw new FijiIOException( "AvroSchema neither has a schema UID nor a schema JSON descriptor."); } } }
/** {@inheritDoc} */ @Override public Schema apply(AvroSchema avroSchema) { if (avroSchema.getJson() != null) { return new Schema.Parser().parse(avroSchema.getJson()); } else if (avroSchema.getUid() != null) { try { final Schema schema = mSchemaTable.getSchema(avroSchema.getUid()); if (schema == null) { throw new FijiIOException(String.format( "Schema UID %d unknown in Fiji instance '%s'.", avroSchema.getUid(), mSchemaTable)); } return schema; } catch (IOException ioe) { throw new FijiIOException(ioe); } } else { throw new FijiIOException( "AvroSchema neither has a schema UID nor a schema JSON descriptor."); } } }
final boolean hasJson = (avroSchema.getJson() != null); final boolean hasUid = (avroSchema.getUid() != null); schema = new Schema.Parser().parse(avroSchema.getJson()); final Schema schemaFromId = mSchemaTable.getSchema(avroSchema.getUid()); if (!Objects.equal(schema, schemaFromId)) { throw new InvalidLayoutException(String.format( "Inconsistent AvroSchema: '%s' : UID %d does not match with JSON descriptor '%s'.", avroSchema, avroSchema.getUid(), avroSchema.getJson())); schema = new Schema.Parser().parse(avroSchema.getJson());