Package org.apache.avro.specific

Examples of org.apache.avro.specific.SpecificRecord


  //@Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (!(o instanceof SpecificRecord)) return false;

    SpecificRecord r2 = (SpecificRecord)o;
    if (!this.getSchema().equals(r2.getSchema())) return false;

    return this.hashCode() == r2.hashCode();
  }
View Full Code Here


  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (!(o instanceof SpecificRecord)) return false;

    SpecificRecord r2 = (SpecificRecord)o;
    if (!this.getSchema().equals(r2.getSchema())) return false;

    return this.hashCode() == r2.hashCode();
  }
View Full Code Here

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (!(o instanceof SpecificRecord)) return false;

    SpecificRecord r2 = (SpecificRecord)o;
    if (!this.getSchema().equals(r2.getSchema())) return false;

    return this.hashCode() == r2.hashCode();
  }
View Full Code Here

    }
    return key;
  }

  private SpecificRecord applyFields(Entity entity, Schema schema) {
    SpecificRecord sr;
    try {
      sr = (SpecificRecord) aClass.newInstance();
    } catch (Exception e) {
      throw new AvroBaseException("Failed to instantiate", e);
    }
    if (schema.getType() != Schema.Type.RECORD) {
      throw new AvroBaseException("Schema is not a record");
    }
    for (Schema.Field field : schema.getFields()) {
      sr.put(field.pos(), getValue(field.schema(), entity.getProperty(field.name())));
    }
    return sr;
  }
View Full Code Here

        Object o = value.get(f.pos());
        if (o instanceof GenericArray) {
          GenericArray ga = (GenericArray) o;
          for (Object e : ga) {
            if (e instanceof SpecificRecord) {
              SpecificRecord sr = (SpecificRecord) e;
              addField(sr, sr.getSchema(), document, field, solrfield);
            } else {
              throw new AvroBaseException("Invalid field name" + solrfield);
            }
          }
          return;
        }
      } else {
        throw new AvroBaseException("Invalid field name" + solrfield);
      }
    }
    f = schema.getField(field);
    if (f != null) {
      Object o = value.get(f.pos());
      if (o instanceof GenericArray) {
        GenericArray ga = (GenericArray) o;
        for (Object e : ga) {
          if (e instanceof SpecificRecord) {
            SpecificRecord sr = (SpecificRecord) e;
            Schema.Field idField = sr.getSchema().getField("id");
            if (idField != null) {
              document.addField(solrfield, sr.get(idField.pos()));
            }
          } else {
            document.addField(solrfield, e);
          }
        }
View Full Code Here

        throw new IOException(String.format(
            "Avro schema specifies '%s' but got JSON value: '%s'.",
            schema, json));
      }
      final Set<String> fields = Sets.newHashSet(json.getFieldNames());
      final SpecificRecord record = newSpecificRecord(schema.getFullName());
      for (Schema.Field field : schema.getFields()) {
        final String fieldName = field.name();
        final JsonNode fieldElement = json.get(fieldName);
        if (fieldElement != null) {
          final Object fieldValue = fromJsonNode(fieldElement, field.schema());
          record.put(field.pos(), fieldValue);
        } else if (field.defaultValue() != null) {
          record.put(field.pos(), fromJsonNode(field.defaultValue(), field.schema()));
        } else {
          throw new IOException(String.format(
              "Error parsing Avro record '%s' with missing field '%s'.",
              schema.getFullName(), field.name()));
        }
View Full Code Here

TOP

Related Classes of org.apache.avro.specific.SpecificRecord

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.