Search in sources :

Example 16 with Key

use of com.google.datastore.v1.Key in project beam by apache.

the class DatastoreV1Test method testDeleteEntities.

/**
   * Test that entities with valid keys are transformed to delete mutations.
   */
@Test
public void testDeleteEntities() throws Exception {
    Key key = makeKey("bird", "finch").build();
    Entity entity = Entity.newBuilder().setKey(key).build();
    DeleteEntityFn deleteEntityFn = new DeleteEntityFn();
    Mutation exceptedMutation = makeDelete(entity.getKey()).build();
    assertEquals(deleteEntityFn.apply(entity), exceptedMutation);
}
Also used : Entity(com.google.datastore.v1.Entity) DeleteEntity(org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.DeleteEntity) DeleteEntityFn(org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.DeleteEntityFn) Mutation(com.google.datastore.v1.Mutation) DeleteKey(org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.DeleteKey) Key(com.google.datastore.v1.Key) DatastoreHelper.makeKey(com.google.datastore.v1.client.DatastoreHelper.makeKey) DatastoreV1.isValidKey(org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.isValidKey) Test(org.junit.Test)

Example 17 with Key

use of com.google.datastore.v1.Key in project beam by apache.

the class DatastoreV1 method isValidKey.

/**
   * Returns true if a Cloud Datastore key is complete. A key is complete if its last element
   * has either an id or a name.
   */
static boolean isValidKey(Key key) {
    List<PathElement> elementList = key.getPathList();
    if (elementList.isEmpty()) {
        return false;
    }
    PathElement lastElement = elementList.get(elementList.size() - 1);
    return (lastElement.getId() != 0 || !lastElement.getName().isEmpty());
}
Also used : PathElement(com.google.datastore.v1.Key.PathElement)

Aggregations

Test (org.junit.Test)10 Key (com.google.datastore.v1.Key)8 DatastoreHelper.makeKey (com.google.datastore.v1.client.DatastoreHelper.makeKey)7 DeleteKey (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.DeleteKey)7 DatastoreV1.isValidKey (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.isValidKey)7 Entity (com.google.datastore.v1.Entity)6 Mutation (com.google.datastore.v1.Mutation)5 DeleteEntity (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.DeleteEntity)5 ArrayList (java.util.ArrayList)3 CommitRequest (com.google.datastore.v1.CommitRequest)2 QueryResultBatch (com.google.datastore.v1.QueryResultBatch)2 DatastoreException (com.google.datastore.v1.client.DatastoreException)2 Status (com.yahoo.ycsb.Status)2 StringByteIterator (com.yahoo.ycsb.StringByteIterator)2 DatastoreWriterFn (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.DatastoreWriterFn)2 DeleteEntityFn (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.DeleteEntityFn)2 DeleteKeyFn (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.DeleteKeyFn)2 UpsertFn (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.UpsertFn)2 Credential (com.google.api.client.auth.oauth2.Credential)1 PathElement (com.google.datastore.v1.Key.PathElement)1