Package org.apache.avro.generic.GenericData

Examples of org.apache.avro.generic.GenericData.Record


    }
  }

  @Test(expected = IllegalStateException.class)
  public void testWriteToClosedWriterFails() throws IOException {
    Record record = new GenericRecordBuilder(USER_SCHEMA)
        .set("username", "test1").set("email", "a@example.com").build();
    writer.initialize();
    writer.close();
    writer.write(record);
  }
View Full Code Here


  public static class ToAvro implements
      PairFunction<Tuple2<String, Integer>, Record, Void> {

    @Override
    public Tuple2<Record, Void> call(Tuple2<String, Integer> t) throws Exception {
      Record record = new Record(TestMapReduce.STATS_SCHEMA);
      record.put("name", t._1());
      record.put("count", t._2());

      return new Tuple2<Record, Void>(record, null);
    }
View Full Code Here

    writer.close();
  }

  @Test
  public void testWriter() throws IOException {
    Record record = new GenericRecordBuilder(USER_SCHEMA)
        .set("username", "test1").set("email", "a@example.com").build();
    try {
      writer.open();
      writer.write(record);
      writer.flush();
View Full Code Here

    }
  }

  @Test(expected = IllegalStateException.class)
  public void testWriteToClosedWriterFails() throws IOException {
    Record record = new GenericRecordBuilder(USER_SCHEMA)
        .set("username", "test1").set("email", "a@example.com").build();
    writer.open();
    writer.close();
    writer.write(record);
  }
View Full Code Here

    // write a file using generic objects
    DataFileWriter<Record> writer
      = new DataFileWriter<Record>(new GenericDatumWriter<Record>(s1))
      .create(s1, FILE);
    for (int i = 0; i < 10; i++) {
      Record r = new Record(s1);
      r.put("label", ""+i);
      r.put("id", i);
      writer.append(r);
    }
    writer.close();

    // read using a 'new SpecificDatumReader<T>()' to force inference of
View Full Code Here

    }

    @Test
    public void testSerialization() throws Exception {
        Schema testSchema = getTestSchema();
        GenericRecord message = new Record(testSchema);
        message.put("name", "testValue");

        byte[] data = getSerializedMessage(message, testSchema);

        GenericDatumReader<IndexedRecord> reader = new GenericDatumReader<IndexedRecord>(testSchema);
View Full Code Here

  }

  @Test(expected=AvroRuntimeException.class)
  public void testRecordCreateEmptySchema() throws Exception {
    Schema s = Schema.createRecord("schemaName", "schemaDoc", "namespace", false);
    Record r = new GenericData.Record(s);
  }
View Full Code Here

  public void testRecordPutInvalidField() throws Exception {
    Schema s = Schema.createRecord("schemaName", "schemaDoc", "namespace", false);
    List<Schema.Field> fields = new ArrayList<Schema.Field>();
    fields.add(new Schema.Field("someFieldName", s, "docs", null));
    s.setFields(fields);
    Record r = new GenericData.Record(s);
    r.put("invalidFieldName", "someValue");
  }
View Full Code Here

    ByteArrayOutputStream b1 = new ByteArrayOutputStream(5);
    ByteArrayOutputStream b2 = new ByteArrayOutputStream(5);
    BinaryEncoder b1Enc = EncoderFactory.get().binaryEncoder(b1, null);
    BinaryEncoder b2Enc = EncoderFactory.get().binaryEncoder(b2, null);
    // Prepare two different datums
    Record testDatum1 = new Record(record);
    testDatum1.put(0, 1);
    Record testDatum2 = new Record(record);
    testDatum2.put(0, 2);
    GenericDatumWriter<Record> gWriter = new GenericDatumWriter<Record>(record);
    Integer start1 = 0, start2 = 0;
    try {
      // Write two datums in each stream
      // and get the offset length after the first write in each.
View Full Code Here

    Assert.assertEquals(anArray, builder.get("anArray"));
    Assert.assertFalse("id should not be set", builder.has("id"));
    Assert.assertNull(builder.get("id"));
   
    // Build the record, and verify that fields are set:
    Record record = builder.build();
    Assert.assertEquals(new Integer(1), record.get("intField"));
    Assert.assertEquals(anArray, record.get("anArray"));
    Assert.assertNotNull(record.get("id"));
    Assert.assertEquals("0", record.get("id").toString());
   
    // Test copy constructors:
    Assert.assertEquals(builder, new GenericRecordBuilder(builder));
    Assert.assertEquals(record, new GenericRecordBuilder(record).build());
   
View Full Code Here

TOP

Related Classes of org.apache.avro.generic.GenericData.Record

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.