/** {@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."); } } }
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()); schema = mSchemaTable.getSchema(avroSchema.getUid()); case UID: { final long schemaId = mSchemaTable.getOrCreateSchemaId(schema); avroSchema.setUid(schemaId); avroSchema.setJson(null); break; avroSchema.setUid(null); avroSchema.setJson(schema.toString()); break;
/** * Register a (READER | WRITER | WRITTEN) schema to a column. * * <p> The Schema is added even if it already exists. </p> * * @param columnName at which to register the schema. * @param schema to register. * @param schemaRegistrationType of the schema to register: (READER, WRITER, WRITTEN). * @throws IOException If the parameters are invalid. * @return this builder. */ private TableLayoutBuilder withSchema( final FijiColumnName columnName, final Schema schema, final SchemaRegistrationType schemaRegistrationType) throws IOException { Preconditions.checkNotNull(columnName); Preconditions.checkNotNull(schema); Preconditions.checkNotNull(schemaRegistrationType); final long schemaId = mSchemaTable.getOrCreateSchemaId(schema); final List<AvroSchema> schemas = getMutableRegisteredSchemaList(columnName, schemaRegistrationType); schemas.add(AvroSchema.newBuilder().setUid(schemaId).build()); return this; }
/** {@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."); } } }