Search in sources :

Example 1 with V1TestWriter

use of org.apache.beam.sdk.io.gcp.datastore.V1TestUtil.V1TestWriter in project beam by apache.

the class V1ReadIT method writeEntitiesToDatastore.

// Creates entities and write them to datastore
private static void writeEntitiesToDatastore(V1TestOptions options, String project, String ancestor, long numEntities) throws Exception {
    Datastore datastore = getDatastore(options, project);
    // Write test entities to datastore
    V1TestWriter writer = new V1TestWriter(datastore, new UpsertMutationBuilder());
    Key ancestorKey = makeAncestorKey(options.getNamespace(), options.getKind(), ancestor);
    for (long i = 0; i < numEntities; i++) {
        Entity entity = makeEntity(i, ancestorKey, options.getKind(), options.getNamespace(), 0);
        writer.write(entity);
    }
    writer.close();
}
Also used : Entity(com.google.datastore.v1.Entity) V1TestUtil.makeEntity(org.apache.beam.sdk.io.gcp.datastore.V1TestUtil.makeEntity) UpsertMutationBuilder(org.apache.beam.sdk.io.gcp.datastore.V1TestUtil.UpsertMutationBuilder) V1TestUtil.getDatastore(org.apache.beam.sdk.io.gcp.datastore.V1TestUtil.getDatastore) Datastore(com.google.datastore.v1.client.Datastore) V1TestWriter(org.apache.beam.sdk.io.gcp.datastore.V1TestUtil.V1TestWriter) V1TestUtil.makeAncestorKey(org.apache.beam.sdk.io.gcp.datastore.V1TestUtil.makeAncestorKey) Key(com.google.datastore.v1.Key)

Aggregations

Entity (com.google.datastore.v1.Entity)1 Key (com.google.datastore.v1.Key)1 Datastore (com.google.datastore.v1.client.Datastore)1 UpsertMutationBuilder (org.apache.beam.sdk.io.gcp.datastore.V1TestUtil.UpsertMutationBuilder)1 V1TestWriter (org.apache.beam.sdk.io.gcp.datastore.V1TestUtil.V1TestWriter)1 V1TestUtil.getDatastore (org.apache.beam.sdk.io.gcp.datastore.V1TestUtil.getDatastore)1 V1TestUtil.makeAncestorKey (org.apache.beam.sdk.io.gcp.datastore.V1TestUtil.makeAncestorKey)1 V1TestUtil.makeEntity (org.apache.beam.sdk.io.gcp.datastore.V1TestUtil.makeEntity)1