Package org.apache.avro.Schema

Examples of org.apache.avro.Schema.Field


  @Test
  public void testNestedNullNamespace() throws Exception {
    Schema inner =
      Schema.parse("{\"type\":\"record\",\"name\":\"Inner\",\"fields\":[]}");
    Schema outer = Schema.createRecord("Outer", null, "space", false);
    outer.setFields(Arrays.asList(new Field("f", inner, null, null)));
    assertEquals(outer, Schema.parse(outer.toString()));
  }
View Full Code Here


  @Test
  public void testNestedNullNamespaceReferencing() {
    Schema inner =
        Schema.parse("{\"type\":\"record\",\"name\":\"Inner\",\"fields\":[]}");
    Schema outer = Schema.createRecord("Outer", null, "space", false);
    outer.setFields(Arrays.asList(new Field("f1", inner, null, null),
                                  new Field("f2", inner, null, null)));
    assertEquals(outer, Schema.parse(outer.toString()));
  }
View Full Code Here

  public void testNestedNullNamespaceReferencingWithUnion() {
    Schema inner =
        Schema.parse("{\"type\":\"record\",\"name\":\"Inner\",\"fields\":[]}");
    Schema innerUnion = Schema.createUnion(Arrays.asList(inner, Schema.create(Type.NULL)));
    Schema outer = Schema.createRecord("Outer", null, "space", false);
    outer.setFields(Arrays.asList(new Field("f1", innerUnion, null, null),
                                  new Field("f2", innerUnion, null, null)));
    assertEquals(outer, Schema.parse(outer.toString()));
  }
View Full Code Here

  public void testNestedNonNullNamespace1() throws Exception {
    Schema inner1 = Schema.createEnum("InnerEnum", null, "space", Arrays.asList("x"));
    Schema inner2 = Schema.parse("{\"type\":\"record\",\"namespace\":\"space\",\"name\":"
      +"\"InnerRecord\",\"fields\":[]}");
    Schema nullOuter = Schema.createRecord("Outer", null, null, false);
    nullOuter.setFields(Arrays.asList(new Field("f1", inner1, null, null),
                                      new Field("f2", inner2, null, null)));
    assertEquals(nullOuter, Schema.parse(nullOuter.toString()));
  }
View Full Code Here

  public void testNestedNonNullNamespace2() throws Exception {
    Schema inner1 = Schema.createFixed("InnerFixed", null, "space", 1);
    Schema inner2 = Schema.parse("{\"type\":\"record\",\"namespace\":\"space\",\"name\":"
      +"\"InnerRecord\",\"fields\":[]}");
    Schema nullOuter = Schema.createRecord("Outer", null, null, false);
    nullOuter.setFields(Arrays.asList(new Field("f1", inner1, null, null),
                                      new Field("f2", inner2, null, null)));
    assertEquals(nullOuter, Schema.parse(nullOuter.toString()));
  }
View Full Code Here

    protected void readInternal(Decoder d) throws IOException {
      ResolvingDecoder r = (ResolvingDecoder) d;
      Field[] ff = r.readFieldOrder();
      for (int i = 0; i < count; i++) {
        for (int j = 0; j < ff.length; j++) {
          Field f = ff[j];
          switch (f.pos()) {
          case 0:
          case 1:
          case 2:
            r.readDouble();
            break;
View Full Code Here

    protected void readInternal(Decoder d) throws IOException {
      ResolvingDecoder r = (ResolvingDecoder) d;
      Field[] ff = r.readFieldOrder();
      for (int i = 0; i < count; i++) {
        for (int j = 0; j < ff.length; j++) {
          Field f = ff[j];
          switch (f.pos()) {
          case 0:
          case 1:
          case 3:
            r.readDouble();
            break;
View Full Code Here

    protected void readInternal(Decoder d) throws IOException {
      ResolvingDecoder r = (ResolvingDecoder) d;
      Field[] ff = r.readFieldOrder();
      for (int i = 0; i < count; i++) {
        for (int j = 0; j < ff.length; j++) {
          Field f = ff[j];
          switch (f.pos()) {
          case 0:
          case 1:
          case 2:
            r.readDouble();
            break;
View Full Code Here

  @Test
  public void testDuplicateRecordFieldName() {
    final Schema schema = Schema.createRecord("RecordName", null, null, false);
    final List<Field> fields = new ArrayList<Field>();
    fields.add(new Field("field_name", Schema.create(Type.NULL), null, null));
    fields.add(new Field("field_name", Schema.create(Type.INT), null, null));
    try {
      schema.setFields(fields);
      fail("Should not be able to create a record with duplicate field name.");
    } catch (AvroRuntimeException are) {
      assertTrue(are.getMessage().contains("Duplicate field field_name in record RecordName"));
View Full Code Here

    assertEquals(r1, r2);
  }
 
  private Schema recordSchema() {
    List<Field> fields = new ArrayList<Field>();
    fields.add(new Field("anArray", Schema.createArray(Schema.create(Type.STRING)), null, null));
    Schema schema = Schema.createRecord("arrayFoo", "test", "mytest", false);
    schema.setFields(fields);
   
    return schema;
  }
View Full Code Here

TOP

Related Classes of org.apache.avro.Schema.Field

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.