Package org.apache.avro.Schema

Examples of org.apache.avro.Schema.Field


        createRecord("test", false, schema, Schema$), Schema$));
  }
 
  @Test
  public void generateHasMethod() {
    Field height = new Field("height", Schema.create(Type.INT), null, null);
    Field Height = new Field("Height", Schema.create(Type.INT), null, null);
    Field height_and_width =
        new Field("height_and_width", Schema.create(Type.STRING), null, null);
    Field message =
        new Field("message", Schema.create(Type.STRING), null, null);
    Field Message =
        new Field("Message", Schema.create(Type.STRING), null, null);
    Field cause =
        new Field("cause", Schema.create(Type.STRING), null, null);
    Field clasz =
        new Field("class", Schema.create(Type.STRING), null, null);
    Field schema =
        new Field("schema", Schema.create(Type.STRING), null, null);
    Field Schema$ =
        new Field("Schema", Schema.create(Type.STRING), null, null);
   
    assertEquals("hasHeight", SpecificCompiler.generateHasMethod(
        createRecord("test", false, height), height));
   
    assertEquals("hasHeightAndWidth", SpecificCompiler.generateHasMethod(
        createRecord("test", false, height_and_width), height_and_width));
 
    assertEquals("hasMessage", SpecificCompiler.generateHasMethod(
        createRecord("test", false, message), message));
    message = new Field("message", Schema.create(Type.STRING), null, null);
    assertEquals("hasMessage$", SpecificCompiler.generateHasMethod(
        createRecord("test", true, message), message));
    assertEquals("hasCause", SpecificCompiler.generateHasMethod(
        createRecord("test", false, cause), cause));
    cause = new Field("cause", Schema.create(Type.STRING), null, null);
    assertEquals("hasCause$", SpecificCompiler.generateHasMethod(
        createRecord("test", true, cause), cause));

   
    assertEquals("hasClass$", SpecificCompiler.generateHasMethod(
        createRecord("test", false, clasz), clasz));
    clasz = new Field("class", Schema.create(Type.STRING), null, null);
    assertEquals("hasClass$", SpecificCompiler.generateHasMethod(
        createRecord("test", true, clasz), clasz));

    assertEquals("hasSchema$", SpecificCompiler.generateHasMethod(
        createRecord("test", false, schema), schema));
    schema = new Field("schema", Schema.create(Type.STRING), null, null);
    assertEquals("hasSchema$", SpecificCompiler.generateHasMethod(
        createRecord("test", true, schema), schema));

    height = new Field("height", Schema.create(Type.INT), null, null);
    Height = new Field("Height", Schema.create(Type.INT), null, null);
    assertEquals("hasHeight", SpecificCompiler.generateHasMethod(
        createRecord("test", false, Height), Height));
   
    height = new Field("height", Schema.create(Type.INT), null, null);
    Height = new Field("Height", Schema.create(Type.INT), null, null);
    assertEquals("hasHeight$0", SpecificCompiler.generateHasMethod(
        createRecord("test", false, height, Height), height));
   
    height = new Field("height", Schema.create(Type.INT), null, null);
    Height = new Field("Height", Schema.create(Type.INT), null, null);
    assertEquals("hasHeight$1", SpecificCompiler.generateHasMethod(
        createRecord("test", false, height, Height), Height));
   
    message = new Field("message", Schema.create(Type.STRING), null, null);
    Message = new Field("Message", Schema.create(Type.STRING), null, null);
    assertEquals("hasMessage$", SpecificCompiler.generateHasMethod(
        createRecord("test", true, Message), Message));
   
    message = new Field("message", Schema.create(Type.STRING), null, null);
    Message = new Field("Message", Schema.create(Type.STRING), null, null);
    assertEquals("hasMessage$0", SpecificCompiler.generateHasMethod(
        createRecord("test", true, message, Message), message));
   
    message = new Field("message", Schema.create(Type.STRING), null, null);
    Message = new Field("Message", Schema.create(Type.STRING), null, null);
    assertEquals("hasMessage$1", SpecificCompiler.generateHasMethod(
        createRecord("test", true, message, Message), Message));
   
    schema = new Field("schema", Schema.create(Type.STRING), null, null);
    Schema$ = new Field("Schema", Schema.create(Type.STRING), null, null);
    assertEquals("hasSchema$", SpecificCompiler.generateHasMethod(
        createRecord("test", false, Schema$), Schema$));
   
    schema = new Field("schema", Schema.create(Type.STRING), null, null);
    Schema$ = new Field("Schema", Schema.create(Type.STRING), null, null);
    assertEquals("hasSchema$0", SpecificCompiler.generateHasMethod(
        createRecord("test", false, schema, Schema$), schema));
   
    schema = new Field("schema", Schema.create(Type.STRING), null, null);
    Schema$ = new Field("Schema", Schema.create(Type.STRING), null, null);
    assertEquals("hasSchema$1", SpecificCompiler.generateHasMethod(
        createRecord("test", false, schema, Schema$), Schema$));
  }
View Full Code Here


        createRecord("test", false, schema, Schema$), Schema$));
  }
 
  @Test
  public void generateClearMethod() {
    Field height = new Field("height", Schema.create(Type.INT), null, null);
    Field Height = new Field("Height", Schema.create(Type.INT), null, null);
    Field height_and_width =
        new Field("height_and_width", Schema.create(Type.STRING), null, null);
    Field message =
        new Field("message", Schema.create(Type.STRING), null, null);
    Field Message =
        new Field("Message", Schema.create(Type.STRING), null, null);
    Field cause =
        new Field("cause", Schema.create(Type.STRING), null, null);
    Field clasz =
        new Field("class", Schema.create(Type.STRING), null, null);
    Field schema =
        new Field("schema", Schema.create(Type.STRING), null, null);
    Field Schema$ =
        new Field("Schema", Schema.create(Type.STRING), null, null);
   
    assertEquals("clearHeight", SpecificCompiler.generateClearMethod(
        createRecord("test", false, height), height));
   
    assertEquals("clearHeightAndWidth", SpecificCompiler.generateClearMethod(
        createRecord("test", false, height_and_width), height_and_width));
 
    assertEquals("clearMessage", SpecificCompiler.generateClearMethod(
        createRecord("test", false, message), message));
    message = new Field("message", Schema.create(Type.STRING), null, null);
    assertEquals("clearMessage$", SpecificCompiler.generateClearMethod(
        createRecord("test", true, message), message));
    assertEquals("clearCause", SpecificCompiler.generateClearMethod(
        createRecord("test", false, cause), cause));
    cause = new Field("cause", Schema.create(Type.STRING), null, null);
    assertEquals("clearCause$", SpecificCompiler.generateClearMethod(
        createRecord("test", true, cause), cause));

   
    assertEquals("clearClass$", SpecificCompiler.generateClearMethod(
        createRecord("test", false, clasz), clasz));
    clasz = new Field("class", Schema.create(Type.STRING), null, null);
    assertEquals("clearClass$", SpecificCompiler.generateClearMethod(
        createRecord("test", true, clasz), clasz));

    assertEquals("clearSchema$", SpecificCompiler.generateClearMethod(
        createRecord("test", false, schema), schema));
    schema = new Field("schema", Schema.create(Type.STRING), null, null);
    assertEquals("clearSchema$", SpecificCompiler.generateClearMethod(
        createRecord("test", true, schema), schema));

    height = new Field("height", Schema.create(Type.INT), null, null);
    Height = new Field("Height", Schema.create(Type.INT), null, null);
    assertEquals("clearHeight", SpecificCompiler.generateClearMethod(
        createRecord("test", false, Height), Height));
   
    height = new Field("height", Schema.create(Type.INT), null, null);
    Height = new Field("Height", Schema.create(Type.INT), null, null);
    assertEquals("clearHeight$0", SpecificCompiler.generateClearMethod(
        createRecord("test", false, height, Height), height));
   
    height = new Field("height", Schema.create(Type.INT), null, null);
    Height = new Field("Height", Schema.create(Type.INT), null, null);
    assertEquals("clearHeight$1", SpecificCompiler.generateClearMethod(
        createRecord("test", false, height, Height), Height));
   
    message = new Field("message", Schema.create(Type.STRING), null, null);
    Message = new Field("Message", Schema.create(Type.STRING), null, null);
    assertEquals("clearMessage$", SpecificCompiler.generateClearMethod(
        createRecord("test", true, Message), Message));
   
    message = new Field("message", Schema.create(Type.STRING), null, null);
    Message = new Field("Message", Schema.create(Type.STRING), null, null);
    assertEquals("clearMessage$0", SpecificCompiler.generateClearMethod(
        createRecord("test", true, message, Message), message));
   
    message = new Field("message", Schema.create(Type.STRING), null, null);
    Message = new Field("Message", Schema.create(Type.STRING), null, null);
    assertEquals("clearMessage$1", SpecificCompiler.generateClearMethod(
        createRecord("test", true, message, Message), Message));
   
    schema = new Field("schema", Schema.create(Type.STRING), null, null);
    Schema$ = new Field("Schema", Schema.create(Type.STRING), null, null);
    assertEquals("clearSchema$", SpecificCompiler.generateClearMethod(
        createRecord("test", false, Schema$), Schema$));
   
    schema = new Field("schema", Schema.create(Type.STRING), null, null);
    Schema$ = new Field("Schema", Schema.create(Type.STRING), null, null);
    assertEquals("clearSchema$0", SpecificCompiler.generateClearMethod(
        createRecord("test", false, schema, Schema$), schema));
   
    schema = new Field("schema", Schema.create(Type.STRING), null, null);
    Schema$ = new Field("Schema", Schema.create(Type.STRING), null, null);
    assertEquals("clearSchema$1", SpecificCompiler.generateClearMethod(
        createRecord("test", false, schema, Schema$), Schema$));
  }
View Full Code Here

      seen.put(descriptor, result);
       
      List<Field> fields = new ArrayList<Field>();
      for (FieldDescriptor f : descriptor.getFields())
        fields.add(new Field(f.getName(), getSchema(f), null, getDefault(f)));
      result.setFields(fields);
      return result;

    } finally {
      if (first)
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

  }

  @Test public void testEquals2() {
   Schema schema1 = Schema.createRecord("r", null, "x", false);
   List<Field> fields1 = new ArrayList<Field>();
   fields1.add(new Field("a", Schema.create(Schema.Type.STRING), null, null,
                         Field.Order.IGNORE));
   schema1.setFields(fields1);

   // only differs in field order
   Schema schema2 = Schema.createRecord("r", null, "x", false);
   List<Field> fields2 = new ArrayList<Field>();
   fields2.add(new Field("a", Schema.create(Schema.Type.STRING), null, null,
                         Field.Order.ASCENDING));
   schema2.setFields(fields2);

   GenericRecord record1 = new GenericData.Record(schema1);
   record1.put("a", "1");
View Full Code Here

    assertEquals(new Integer(55), array.get(5));
  }
 
  @Test
  public void testToStringIsJson() throws JsonParseException, IOException {
    Field stringField = new Field("string", Schema.create(Type.STRING), null, null);
    Field enumField = new Field("enum", Schema.createEnum("my_enum", "doc", null, Arrays.asList("a", "b", "c")), null, null);
    Schema schema = Schema.createRecord("my_record", "doc", "mytest", false);
    schema.setFields(Arrays.asList(stringField, enumField));
   
    GenericRecord r = new GenericData.Record(schema);
    // \u2013 is EN DASH
    r.put(stringField.name(), "hello\nthere\"\tyou\u2013}");
    r.put(enumField.name(), new GenericData.EnumSymbol(enumField.schema(),"a"));
   
    String json = r.toString();
    JsonFactory factory = new JsonFactory();
    JsonParser parser = factory.createJsonParser(json);
    ObjectMapper mapper = new ObjectMapper();
View Full Code Here

  }

  @Test
  public void testCompare() {
    // Prepare a schema for testing.
    Field integerField = new Field("test", Schema.create(Type.INT), null, null);
    List<Field> fields = new ArrayList<Field>();
    fields.add(integerField);
    Schema record = Schema.createRecord("test", null, null, false);
    record.setFields(fields);
   
View Full Code Here

    // Test that a deep copy of a byte buffer respects the byte buffer
    // limits and capacity.
    byte[] buffer_value = {0, 1, 2, 3, 0, 0, 0};
    ByteBuffer buffer = ByteBuffer.wrap(buffer_value, 1, 4);
    Schema schema = Schema.createRecord("my_record", "doc", "mytest", false);
    Field byte_field =
      new Field("bytes", Schema.create(Type.BYTES), null, null);
    schema.setFields(Arrays.asList(byte_field));
   
    GenericRecord record = new GenericData.Record(schema);
    record.put(byte_field.name(), buffer);
   
    GenericRecord copy =
      (GenericRecord) GenericData.get().deepCopy(schema, record);
    ByteBuffer buffer_copy = (ByteBuffer) copy.get(byte_field.name());

    assertEquals(buffer, buffer_copy);
  }
View Full Code Here

        throw new SchemaParseException("No param name: "+field);
      JsonNode fieldTypeNode = field.get("type");
      if (fieldTypeNode == null)
        throw new SchemaParseException("No param type: "+field);
      String name = fieldNameNode.getTextValue();
      fields.add(new Field(name, Schema.parse(fieldTypeNode,types),
                           null /* message fields don't have docs */,
                           field.get("default")));
    }
    Schema request = Schema.createRecord(fields);
   
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

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.