Package org.apache.avro.Schema

Examples of org.apache.avro.Schema.Field


    private FieldAssembler<R> completeField(Schema schema) {
      return completeField(schema, null);
    }
   
    private FieldAssembler<R> completeField(Schema schema, JsonNode defaultVal) {
      Field field = new Field(name(), schema, doc(), defaultVal, order);
      addPropsTo(field);
      addAliasesTo(field);
      return fields.addField(field);
    }
View Full Code Here


      values[field.pos()] = value;
    }
    @Override public void put(int i, Object v) { values[i] = v; }
    @Override public Object get(String key) {
      Field field = schema.getField(key);
      if (field == null) return null;
      return values[field.pos()];
    }
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

    assertEquals(Schema.Type.UNION, response.getType());
    assertEquals(Schema.Type.NULL, response.getTypes().get(0).getType());
    assertEquals(Schema.Type.STRING, response.getTypes().get(1).getType());
    // check request schema is union
    Schema request = message.getRequest();
    Field field = request.getField("s");
    assertNotNull("field 's' should not be null", field);
    Schema param = field.schema();
    assertEquals(Schema.Type.UNION, param.getType());
    assertEquals(Schema.Type.NULL, param.getTypes().get(0).getType());
    assertEquals(Schema.Type.STRING, param.getTypes().get(1).getType());
    // check union erasure
    assertEquals(String.class, ReflectData.get().getClass(response));
View Full Code Here

    assertEquals(Schema.Type.UNION, response.getType());
    assertEquals(Schema.Type.NULL, response.getTypes().get(0).getType());
    assertEquals(Schema.Type.STRING, response.getTypes().get(1).getType());
    // check request schema is union
    Schema request = message.getRequest();
    Field field = request.getField("s");
    assertNotNull("field 's' should not be null", field);
    Schema param = field.schema();
    assertEquals(Schema.Type.UNION, param.getType());
    assertEquals(Schema.Type.NULL, param.getTypes().get(0).getType());
    assertEquals(Schema.Type.STRING, param.getTypes().get(1).getType());
    // check union erasure
    assertEquals(String.class, ReflectData.get().getClass(response));
View Full Code Here

  @Test public void testP2() throws Exception {
    Schema e1 = ReflectData.get().getSchema(E1.class);
    assertEquals(Schema.Type.RECORD, e1.getType());
    assertTrue(e1.isError());
    Field message = e1.getField("detailMessage");
    assertNotNull("field 'detailMessage' should not be null", message);
    Schema messageSchema = message.schema();
    assertEquals(Schema.Type.UNION, messageSchema.getType());
    assertEquals(Schema.Type.NULL, messageSchema.getTypes().get(0).getType());
    assertEquals(Schema.Type.STRING, messageSchema.getTypes().get(1).getType());

    Protocol p2 = ReflectData.get().getProtocol(P2.class);
View Full Code Here

  }

  private Schema createAvroSchema() {
    Schema avroSchema = Schema.createRecord("Doc", "adoc", null, false);
    List<Field> fields = new ArrayList<Field>();
    fields.add(new Field("id", Schema.create(Type.STRING), null, null));
    fields.add(new Field("user_friends_count",
                         createOptional(Schema.create(Type.INT)),
                         null, null));
    fields.add(new Field("user_location",
                         createOptional(Schema.create(Type.STRING)),
                         null, null));
    fields.add(new Field("user_description",
                         createOptional(Schema.create(Type.STRING)),
                         null, null));
    fields.add(new Field("user_statuses_count",
                         createOptional(Schema.create(Type.INT)),
                         null, null));
    fields.add(new Field("user_followers_count",
                         createOptional(Schema.create(Type.INT)),
                         null, null));
    fields.add(new Field("user_name",
                         createOptional(Schema.create(Type.STRING)),
                         null, null));
    fields.add(new Field("user_screen_name",
                         createOptional(Schema.create(Type.STRING)),
                         null, null));
    fields.add(new Field("created_at",
                         createOptional(Schema.create(Type.STRING)),
                         null, null));
    fields.add(new Field("text",
                         createOptional(Schema.create(Type.STRING)),
                         null, null));
    fields.add(new Field("retweet_count",
                         createOptional(Schema.create(Type.LONG)),
                         null, null));
    fields.add(new Field("retweeted",
                         createOptional(Schema.create(Type.BOOLEAN)),
                         null, null));
    fields.add(new Field("in_reply_to_user_id",
                         createOptional(Schema.create(Type.LONG)),
                         null, null));
    fields.add(new Field("source",
                         createOptional(Schema.create(Type.STRING)),
                         null, null));
    fields.add(new Field("in_reply_to_status_id",
                         createOptional(Schema.create(Type.LONG)),
                         null, null));
    fields.add(new Field("media_url_https",
                         createOptional(Schema.create(Type.STRING)),
                         null, null));
    fields.add(new Field("expanded_url",
                         createOptional(Schema.create(Type.STRING)),
                         null, null));
    avroSchema.setFields(fields);
    return avroSchema;
  }
View Full Code Here

  public static Schema getPairSchema(ArrayList<ColumnInfo> columnInfo) {
    Schema pair = Schema.createRecord(Pair.class.getName(), null, null,
        false);
    List<Field> fields = new ArrayList<Field>();
    fields.add(new Field("key", getLongWritableSchema(), "", null));
    fields.add(new Field("value", getSchema(columnInfo), "", null,
        Field.Order.IGNORE));
    pair.setFields(fields);
    return pair;
  }
View Full Code Here

    longWritableSchema.setFields(fields);

    Schema pair = Schema.createRecord(Pair.class.getName(), null, null,
        false);
    List<Field> pairFields = new ArrayList<Field>();
    pairFields.add(new Field("key", longWritableSchema, "", null));
    pairFields.add(new Field("value", dBMapper.getSchema(columns), "",
        null, Field.Order.IGNORE));
    pair.setFields(pairFields);

    assertEquals(pair, schema);
  }
View Full Code Here

      tlist.add(fakeField);
      Schema fakeSchema = Schema.createRecord(tlist);
      GenericRecord tempRecord  = new GenericData.Record(fakeSchema);  
      SchemaFiller schemaFill = SchemaFiller.createRandomField(fakeField);
      */
      Field fakeField = new Field(field.name()+"fake", innerElementSchema, null, null);
      SchemaFiller schemaFill = SchemaFiller.createRandomField(fakeField)//Safe from infinite recursion (array within an array, assuming nullable)
      array.add(schemaFill.generateRandomObject());
    }
    return array;
  }
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.