Search in sources :

Example 26 with Mutation

use of com.google.cloud.spanner.Mutation in project beam by apache.

the class MutationUtilsTest method testCreateDeleteMutationFromRow.

@Test
public void testCreateDeleteMutationFromRow() {
    Mutation expectedMutation = createDeleteMutation();
    Mutation mutation = beamRowToMutationFn(Mutation.Op.DELETE, TABLE).apply(KEY_ROW);
    assertEquals(expectedMutation, mutation);
}
Also used : Mutation(com.google.cloud.spanner.Mutation) Test(org.junit.Test)

Example 27 with Mutation

use of com.google.cloud.spanner.Mutation in project beam by apache.

the class MutationUtilsTest method testCreateInsertMutationFromRow.

@Test
public void testCreateInsertMutationFromRow() {
    Mutation expectedMutation = createMutation(Mutation.Op.INSERT);
    Mutation mutation = beamRowToMutationFn(Mutation.Op.INSERT, TABLE).apply(WRITE_ROW);
    assertEquals(expectedMutation, mutation);
}
Also used : Mutation(com.google.cloud.spanner.Mutation) Test(org.junit.Test)

Example 28 with Mutation

use of com.google.cloud.spanner.Mutation in project beam by apache.

the class MutationUtilsTest method testCreateInsertMutationFromRowWithNulls.

@Test
public void testCreateInsertMutationFromRowWithNulls() {
    Mutation expectedMutation = createMutationNulls(Mutation.Op.INSERT);
    Mutation mutation = beamRowToMutationFn(Mutation.Op.INSERT, TABLE).apply(WRITE_ROW_NULLS);
    assertEquals(expectedMutation, mutation);
}
Also used : Mutation(com.google.cloud.spanner.Mutation) Test(org.junit.Test)

Example 29 with Mutation

use of com.google.cloud.spanner.Mutation in project beam by apache.

the class MutationSizeEstimatorTest method group.

@Test
public void group() throws Exception {
    Mutation int64 = Mutation.newInsertOrUpdateBuilder("test").set("one").to(1).build();
    Mutation float64 = Mutation.newInsertOrUpdateBuilder("test").set("one").to(2.9).build();
    Mutation bool = Mutation.newInsertOrUpdateBuilder("test").set("one").to(false).build();
    MutationGroup group = MutationGroup.create(int64, float64, bool);
    assertThat(MutationSizeEstimator.sizeOf(group), is(17L));
}
Also used : Mutation(com.google.cloud.spanner.Mutation) Test(org.junit.Test)

Example 30 with Mutation

use of com.google.cloud.spanner.Mutation in project beam by apache.

the class MutationSizeEstimatorTest method nullPrimitiveArrays.

@Test
public void nullPrimitiveArrays() throws Exception {
    Mutation int64 = Mutation.newInsertOrUpdateBuilder("test").set("one").toInt64Array((long[]) null).build();
    Mutation float64 = Mutation.newInsertOrUpdateBuilder("test").set("one").toFloat64Array((double[]) null).build();
    Mutation bool = Mutation.newInsertOrUpdateBuilder("test").set("one").toBoolArray((boolean[]) null).build();
    Mutation numeric = Mutation.newInsertOrUpdateBuilder("test").set("one").toNumericArray((Iterable<BigDecimal>) null).build();
    Mutation json = Mutation.newInsertOrUpdateBuilder("test").set("one").toJsonArray(null).build();
    assertThat(MutationSizeEstimator.sizeOf(int64), is(0L));
    assertThat(MutationSizeEstimator.sizeOf(float64), is(0L));
    assertThat(MutationSizeEstimator.sizeOf(bool), is(0L));
    assertThat(MutationSizeEstimator.sizeOf(numeric), is(0L));
    assertThat(MutationSizeEstimator.sizeOf(json), is(0L));
}
Also used : Mutation(com.google.cloud.spanner.Mutation) Test(org.junit.Test)

Aggregations

Mutation (com.google.cloud.spanner.Mutation)70 Test (org.junit.Test)53 ArrayList (java.util.ArrayList)11 CommitResponse (com.google.cloud.spanner.CommitResponse)4 KeySet (com.google.cloud.spanner.KeySet)4 ReadQueryUpdateTransactionOption (com.google.cloud.spanner.Options.ReadQueryUpdateTransactionOption)4 Timestamp (com.google.cloud.Timestamp)3 DatabaseClient (com.google.cloud.spanner.DatabaseClient)3 ResultSet (com.google.cloud.spanner.ResultSet)3 TransactionContext (com.google.cloud.spanner.TransactionContext)3 BatchableMutationFilterFn (org.apache.beam.sdk.io.gcp.spanner.SpannerIO.BatchableMutationFilterFn)3 Sleeper (org.apache.beam.sdk.util.Sleeper)3 Database (com.google.cloud.spanner.Database)2 DatabaseAdminClient (com.google.cloud.spanner.DatabaseAdminClient)2 Key (com.google.cloud.spanner.Key)2 WriteBuilder (com.google.cloud.spanner.Mutation.WriteBuilder)2 SpannerException (com.google.cloud.spanner.SpannerException)2 TransactionRunner (com.google.cloud.spanner.TransactionRunner)2 CreateDatabaseMetadata (com.google.spanner.admin.database.v1.CreateDatabaseMetadata)2 BigDecimal (java.math.BigDecimal)2