@Override public void setSchema(Schema schema) { if (!SCHEMA.equals(schema)) throw new RuntimeException("Not the Json schema: "+schema); }
public boolean equals(Object o) { if (o == this) return true; if (!(o instanceof Message)) return false; Message that = (Message)o; return this.name.equals(that.name) && this.request.equals(that.request) && props.equals(that.props); }
/* package private */Schema stripOptionalTypeUnion(Schema schema) { if(schema.getType() == Schema.Type.UNION && schema.getTypes().size() == 2 && schema.getTypes().contains(NULL_TYPE_SCHEMA)) { return schema.getTypes().get(0).equals(NULL_TYPE_SCHEMA) ? schema.getTypes().get(1) : schema.getTypes().get(0); } return schema; }
/** Utility for template use. For a two-branch union type with * one null branch, returns the index of the null branch. It's an * error to use on anything other than a two-branch union with on * null branch. */ public int getNonNullIndex(Schema s) { if (s.getType() != Schema.Type.UNION || s.getTypes().size() != 2 || ! s.getTypes().contains(NULL_SCHEMA)) throw new IllegalArgumentException("Can only be used on 2-branch union with a null branch: " + s); return (s.getTypes().get(0).equals(NULL_SCHEMA) ? 1 : 0); }
public boolean equals(Object o) { if (o == this) return true; if (!(o instanceof MapSchema)) return false; MapSchema that = (MapSchema)o; return equalCachedHash(that) && valueType.equals(that.valueType) && props.equals(that.props); } @Override int computeHash() {
@Override public boolean equals(Object o) { if (o == this) return true; // identical object if (!(o instanceof Pair)) return false; // not a pair Pair that = (Pair)o; if (!this.schema.equals(that.schema)) return false; // not the same schema return this.compareTo(that) == 0; } @Override public int hashCode() {
public boolean equals(Object o) { if (o == this) return true; if (!(o instanceof Message)) return false; Message that = (Message)o; return this.name.equals(that.name) && this.request.equals(that.request) && propsEqual(that); }
public boolean equals(Object other) { if (other == this) return true; if (!(other instanceof Field)) return false; Field that = (Field) other; return (name.equals(that.name)) && (schema.equals(that.schema)) && defaultValueEquals(that.defaultValue) && (order == that.order) && props.equals(that.props); } public int hashCode() { return name.hashCode() + schema.computeHash(); }
public boolean equals(Object o) { if (o == this) return true; if (!(o instanceof ArraySchema)) return false; ArraySchema that = (ArraySchema)o; return equalCachedHash(that) && elementType.equals(that.elementType) && props.equals(that.props); } @Override int computeHash() {
private Integer getSchemaVersion(Schema s) throws SerializationException { for(Entry<Integer, String> entry: typeDefVersions.entrySet()) { Schema version = Schema.parse(entry.getValue()); if(s.equals(version)) return entry.getKey(); } throw new SerializationException("Writer's schema invalid!"); }
public boolean equals(Object other) { if (other == this) return true; if (!(other instanceof Field)) return false; Field that = (Field) other; return (name.equals(that.name)) && (schema.equals(that.schema)) && defaultValueEquals(that.defaultValue) && (order == that.order) && propsEqual(that); } public int hashCode() { return name.hashCode() + schema.computeHash(); }
@Override public boolean equals(Object o) { if (o == this) return true; // identical object if (!(o instanceof Record)) return false; // not a record Record that = (Record)o; if (!this.schema.equals(that.schema)) return false; // not the same schema return GenericData.get().compare(this, that, schema, true) == 0; } @Override public int hashCode() {
public boolean equals(Object o) { if (o == this) return true; if (!(o instanceof ArraySchema)) return false; ArraySchema that = (ArraySchema)o; return equalCachedHash(that) && elementType.equals(that.elementType) && propsEqual(that); } @Override int computeHash() {
public boolean equals(Object o) { if (o == this) return true; if (!(o instanceof MapSchema)) return false; MapSchema that = (MapSchema)o; return equalCachedHash(that) && valueType.equals(that.valueType) && propsEqual(that); } @Override int computeHash() {
@Override public boolean equals(Object o) { if (o == this) return true; // identical object if (!(o instanceof Record)) return false; // not a record Record that = (Record)o; if (!this.schema.equals(that.schema)) return false; // not the same schema return GenericData.get().compare(this, that, schema, true) == 0; } @Override public int hashCode() {
private void nextInput() throws IOException{ currentInput++; Path path = inFiles.get(currentInput); FSDataInputStream input = new FSDataInputStream(Util.openFromFS(path)); reader = new DataFileStream<>(input, new GenericDatumReader<>()); if (schema == null) { // if this is the first file, the schema gets saved schema = reader.getSchema(); } else if (!schema.equals(reader.getSchema())) { // subsequent files have to have equal schemas throw new IOException("schemas dont match"); } }
private void serializeAndDeserialize(final AvroOutputFormat.Codec codec, final Schema schema) throws IOException, ClassNotFoundException { // given final AvroOutputFormat<User> outputFormat = new AvroOutputFormat<>(User.class); if (codec != null) { outputFormat.setCodec(codec); } if (schema != null) { outputFormat.setSchema(schema); } final ByteArrayOutputStream bos = new ByteArrayOutputStream(); // when try (final ObjectOutputStream oos = new ObjectOutputStream(bos)) { oos.writeObject(outputFormat); } try (final ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()))) { // then Object o = ois.readObject(); assertTrue(o instanceof AvroOutputFormat); @SuppressWarnings("unchecked") final AvroOutputFormat<User> restored = (AvroOutputFormat<User>) o; final AvroOutputFormat.Codec restoredCodec = (AvroOutputFormat.Codec) Whitebox.getInternalState(restored, "codec"); final Schema restoredSchema = (Schema) Whitebox.getInternalState(restored, "userDefinedSchema"); assertTrue(codec != null ? restoredCodec == codec : restoredCodec == null); assertTrue(schema != null ? restoredSchema.equals(schema) : restoredSchema == null); } }