Example #1
0
 @Override
 public TimestampedValue<String> score(KijiRowData input, FreshenerContext context)
     throws IOException {
   KeyValueStoreReader<String, String> reader = context.getStore("cats");
   String newName = reader.get("Jennyanydots");
   assertEquals("Old Gumbie Cat", newName);
   return TimestampedValue.create(newName);
 }
Example #2
0
 @Override
 public TimestampedValue<String> score(KijiRowData input, FreshenerContext context)
     throws IOException {
   final String newName = mReader.get("Skimbleshanks");
   assertEquals("Railway Cat", newName);
   return TimestampedValue.create(newName);
 }
Example #3
0
 @Override
 public boolean isFresh(KijiRowData rowData, FreshenerContext context) {
   final KeyValueStoreReader<String, String> cats;
   try {
     cats = context.getStore("cats");
   } catch (IOException ioe) {
     throw new KijiIOException(ioe);
   }
   if (cats != null) {
     try {
       return cats.get("Skimbleshanks").equals("Railway Cat");
     } catch (IOException ioe) {
       throw new KijiIOException(ioe);
     }
   } else {
     throw new RuntimeException("Could not retrieve KVStoreReader \"cats\" test is broken.");
   }
 }
  @Test
  public void testGenericAvroKVRecordKeyValueStore() throws Exception {
    // Only read the key and value fields (skip the 'blah' field).
    final Schema readerSchema = Schema.createRecord("record", null, null, false);
    readerSchema.setFields(
        Lists.newArrayList(
            new Schema.Field("key", Schema.create(Schema.Type.INT), null, null),
            new Schema.Field("value", Schema.create(Schema.Type.STRING), null, null)));

    // Open the store.
    final Path avroFilePath = writeGenericRecordAvroFile();
    final AvroKVRecordKeyValueStore<Integer, CharSequence> store =
        AvroKVRecordKeyValueStore.builder()
            .withConfiguration(getConf())
            .withInputPath(avroFilePath)
            .withReaderSchema(readerSchema)
            .build();
    final KeyValueStoreReader<Integer, CharSequence> reader = store.open();
    try {
      assertTrue(reader.containsKey(1));
      assertEquals("one", reader.get(1).toString());
      assertTrue(reader.containsKey(2));
      assertEquals("two", reader.get(2).toString()); // First field in wins.
    } finally {
      reader.close();
    }
  }