Package com.cloudera.cdk.data

Examples of com.cloudera.cdk.data.Key


    // Get the timestamp we'll use to set the value of the profile_updated
    // action.
    long ts = System.currentTimeMillis();

    // Construct the key we'll use to fetch the user.
    Key key = new Key.Builder(userProfileActionsDataset)
        .add("firstName", firstName)
        .add("lastName", lastName)
        .build();

    // Get the profile and actions entity from the composite dao.
View Full Code Here


    compositeEntity.put("SubEntity2", subEntity2);

    // Test put and get
    ds.put(compositeEntity);

    Key key = new Key.Builder(ds).add("part1", "1").add("part2", "1").build();
    Map<String, SpecificRecord> returnedCompositeEntity = ds.get(key);
    assertNotNull("found entity", returnedCompositeEntity);
    assertEquals("field1_1", ((SubEntity1)returnedCompositeEntity.get("SubEntity1")).getField1());
    assertEquals("field1_2", ((SubEntity1)returnedCompositeEntity.get("SubEntity1")).getField2());
    assertEquals("field2_1", ((SubEntity2)returnedCompositeEntity.get("SubEntity2")).getField1());
View Full Code Here

    ds = (DaoDataset) repo.load(tableName);

    // ensure the new entities are what we expect with get operations
    for (int i = 0; i < 10; ++i) {
      String iStr = Long.toString(i);
      Key key = new Key.Builder(ds)
          .add("part1", "part1_" + iStr)
          .add("part2", "part2_" + iStr).build();
      compareEntitiesWithUtf8(i, ds.get(key));
    }

    // ensure the new entities are what we expect with scan operations
    int cnt = 0;
    DatasetReader<GenericRecord> reader = ds.newReader();
    assertFalse("Reader should not be open before calling open", reader.isOpen());
    reader.open();
    assertTrue("Reader should be open after calling open", reader.isOpen());
    try {
      for (GenericRecord entity : reader) {
        compareEntitiesWithUtf8(cnt, entity);
        cnt++;
      }
      assertEquals(10, cnt);
    } finally {
      reader.close();
      assertFalse("Reader should be closed after calling close", reader.isOpen());
    }

    // test a partial scan
    cnt = 3;
    reader = new DaoView<GenericRecord>(ds)
        .from(new Marker.Builder().add("part1", "part1_3").add("part2", "part2_3").build())
        .to(new Marker.Builder().add("part1", "part1_7").add("part2", "part2_7").build())
        .newReader();
    reader.open();
    try {
      for (GenericRecord entity : reader) {
        compareEntitiesWithUtf8(cnt, entity);
        cnt++;
      }
      assertEquals(8, cnt);
    } finally {
      reader.close();
    }

    Key key = new Key.Builder(ds)
        .add("part1", "part1_5")
        .add("part2", "part2_5").build();

    // test delete
    ds.delete(key);
View Full Code Here

    }

    // ensure the new entities are what we expect with get operations
    for (int i = 0; i < 10; ++i) {
      String iStr = Long.toString(i);
      Key key = new Key.Builder(ds)
          .add("part1", "part1_" + iStr)
          .add("part2", "part2_" + iStr).build();
      compareEntitiesWithString(i, ds.get(key));
    }

    // ensure the new entities are what we expect with scan operations
    int cnt = 0;
    DatasetReader<TestEntity> reader = ds.newReader();
    reader.open();
    try {
      for (TestEntity entity : reader) {
        compareEntitiesWithString(cnt, entity);
        cnt++;
      }
      assertEquals(10, cnt);
    } finally {
      reader.close();
    }

    Key key = new Key.Builder(ds)
        .add("part1", "part1_5")
        .add("part2", "part2_5").build();

    // test delete
    ds.delete(key);
View Full Code Here

    // Create a new entity
    ds.put(createGenericEntity(0));

    // Retrieve the entity
    String iStr = Long.toString(0);
    Key key = new Key.Builder(ds)
        .add("part1", "part1_" + iStr)
        .add("part2", "part2_" + iStr).build();
    compareEntitiesWithUtf8(0, ds.get(key));

    // delete dataset
View Full Code Here

    // Load the users dataset
    RandomAccessDataset<User> users = repo.load("users");

    // Get an accessor for the dataset and look up a user by username
    Key key = new Key.Builder(users).add("username", "bill").build();
    System.out.println(users.get(key));

    // Get a reader for the dataset and read all the users
    DatasetReader<User> reader = users.newReader();
    try {
View Full Code Here

TOP

Related Classes of com.cloudera.cdk.data.Key

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.