コード例 #1
0
  @Override
  public void write(E entity) {
    Preconditions.checkState(
        state.equals(ReaderWriterState.OPEN), "Attempt to write to a writer in state:%s", state);

    reusedKey.reuseFor(entity);

    DatasetWriter<E> writer = cachedWriters.getIfPresent(reusedKey);
    if (writer == null) {
      // avoid checking in every whether the entity belongs in the view by only
      // checking when a new writer is created
      Preconditions.checkArgument(
          view.includes(entity), "View %s does not include entity %s", view, entity);
      // get a new key because it is stored in the cache
      StorageKey key = StorageKey.copy(reusedKey);
      try {
        writer = cachedWriters.getUnchecked(key);
      } catch (UncheckedExecutionException ex) {
        throw new IllegalArgumentException(
            "Problem creating view for entity: " + entity, ex.getCause());
      }
    }

    writer.write(entity);
  }
コード例 #2
0
  @Test
  @SuppressWarnings("unchecked")
  public void toDirNameIdentityWithSlashes() {
    PartitionStrategy strategy =
        new PartitionStrategy.Builder().identity("name").identity("address").build();

    StorageKey key = new StorageKey(strategy);
    key.replaceValues((List) Lists.newArrayList("John Doe", "NY/USA"));

    Assert.assertEquals(new Path("name_copy=John+Doe/address_copy=NY%2FUSA"), convert.fromKey(key));
  }
コード例 #3
0
  @Test
  @SuppressWarnings("unchecked")
  public void toDirNameIdentityWithNonString() {
    PartitionStrategy strategy = new PartitionStrategy.Builder().identity("id").build();

    StorageKey expected = new StorageKey(strategy);
    expected.replace(0, 0L);

    Assert.assertEquals(
        "Should convert to schema type",
        expected,
        convert.toKey(new Path("id=0"), new StorageKey(strategy)));
  }
コード例 #4
0
  @Test
  @SuppressWarnings("unchecked")
  public void testFromKey() {
    PartitionStrategy strategy =
        new PartitionStrategy.Builder()
            .year("timestamp")
            .month("timestamp")
            .day("timestamp")
            .build();

    StorageKey key = new StorageKey(strategy);
    key.replaceValues((List) Lists.newArrayList(2013, 11, 5));

    Assert.assertEquals(new Path("year=2013/month=11/day=05"), convert.fromKey(key));
  }
コード例 #5
0
ファイル: CrunchDatasets.java プロジェクト: rbrush/kite
 @Override
 public Object get(int i) {
   return key.get(i);
 }
コード例 #6
0
ファイル: CrunchDatasets.java プロジェクト: rbrush/kite
 @Override
 public void put(int i, Object v) {
   key.replace(i, v);
 }