use of com.google.cloud.spanner.Mutation in project beam by apache.
the class SpannerReadIT method makeTestData.
private void makeTestData() {
DatabaseClient databaseClient = getDatabaseClient();
List<Mutation> mutations = new ArrayList<>();
for (int i = 0; i < 5L; i++) {
mutations.add(Mutation.newInsertOrUpdateBuilder(options.getTable()).set("key").to((long) i).set("value").to(RandomUtils.randomAlphaNumeric(100)).build());
}
databaseClient.writeAtLeastOnce(mutations);
}
use of com.google.cloud.spanner.Mutation in project beam by apache.
the class MutationSizeEstimatorTest method strings.
@Test
public void strings() throws Exception {
Mutation emptyString = Mutation.newInsertOrUpdateBuilder("test").set("one").to("").build();
Mutation nullString = Mutation.newInsertOrUpdateBuilder("test").set("one").to((String) null).build();
Mutation sampleString = Mutation.newInsertOrUpdateBuilder("test").set("one").to("abc").build();
Mutation sampleArray = Mutation.newInsertOrUpdateBuilder("test").set("one").toStringArray(Arrays.asList("one", "two", null)).build();
Mutation nullArray = Mutation.newInsertOrUpdateBuilder("test").set("one").toStringArray(null).build();
assertThat(MutationSizeEstimator.sizeOf(emptyString), is(0L));
assertThat(MutationSizeEstimator.sizeOf(nullString), is(0L));
assertThat(MutationSizeEstimator.sizeOf(sampleString), is(3L));
assertThat(MutationSizeEstimator.sizeOf(sampleArray), is(6L));
assertThat(MutationSizeEstimator.sizeOf(nullArray), is(0L));
}
use of com.google.cloud.spanner.Mutation in project beam by apache.
the class MutationSizeEstimatorTest method primitives.
@Test
public void primitives() 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();
Mutation numeric = Mutation.newInsertOrUpdateBuilder("test").set("one").to(new BigDecimal("12345678901234567890.123456789")).build();
Mutation json = Mutation.newInsertOrUpdateBuilder("test").set("one").to(Value.json("{\"key1\":\"value1\", \"key2\":\"value2\"}")).build();
assertThat(MutationSizeEstimator.sizeOf(int64), is(8L));
assertThat(MutationSizeEstimator.sizeOf(float64), is(8L));
assertThat(MutationSizeEstimator.sizeOf(bool), is(1L));
assertThat(MutationSizeEstimator.sizeOf(numeric), is(30L));
assertThat(MutationSizeEstimator.sizeOf(json), is(34L));
}
use of com.google.cloud.spanner.Mutation in project beam by apache.
the class MutationSizeEstimatorTest method dates.
@Test
public void dates() throws Exception {
Mutation timestamp = Mutation.newInsertOrUpdateBuilder("test").set("one").to(Timestamp.now()).build();
Mutation nullTimestamp = Mutation.newInsertOrUpdateBuilder("test").set("one").to((Timestamp) null).build();
Mutation date = Mutation.newInsertOrUpdateBuilder("test").set("one").to(Date.fromYearMonthDay(2017, 10, 10)).build();
Mutation nullDate = Mutation.newInsertOrUpdateBuilder("test").set("one").to((Date) null).build();
Mutation timestampArray = Mutation.newInsertOrUpdateBuilder("test").set("one").toTimestampArray(Arrays.asList(Timestamp.now(), null)).build();
Mutation dateArray = Mutation.newInsertOrUpdateBuilder("test").set("one").toDateArray(Arrays.asList(null, Date.fromYearMonthDay(2017, 1, 1), null, Date.fromYearMonthDay(2017, 1, 2))).build();
Mutation nullTimestampArray = Mutation.newInsertOrUpdateBuilder("test").set("one").toTimestampArray(null).build();
Mutation nullDateArray = Mutation.newInsertOrUpdateBuilder("test").set("one").toDateArray(null).build();
assertThat(MutationSizeEstimator.sizeOf(timestamp), is(12L));
assertThat(MutationSizeEstimator.sizeOf(date), is(12L));
assertThat(MutationSizeEstimator.sizeOf(nullTimestamp), is(12L));
assertThat(MutationSizeEstimator.sizeOf(nullDate), is(12L));
assertThat(MutationSizeEstimator.sizeOf(timestampArray), is(24L));
assertThat(MutationSizeEstimator.sizeOf(dateArray), is(48L));
assertThat(MutationSizeEstimator.sizeOf(nullTimestampArray), is(0L));
assertThat(MutationSizeEstimator.sizeOf(nullDateArray), is(0L));
}
use of com.google.cloud.spanner.Mutation in project beam by apache.
the class MutationSizeEstimatorTest method primitiveArrays.
@Test
public void primitiveArrays() throws Exception {
Mutation int64 = Mutation.newInsertOrUpdateBuilder("test").set("one").toInt64Array(new long[] { 1L, 2L, 3L }).build();
Mutation float64 = Mutation.newInsertOrUpdateBuilder("test").set("one").toFloat64Array(new double[] { 1., 2. }).build();
Mutation bool = Mutation.newInsertOrUpdateBuilder("test").set("one").toBoolArray(new boolean[] { true, true, false, true }).build();
Mutation numeric = Mutation.newInsertOrUpdateBuilder("test").set("one").toNumericArray(ImmutableList.of(new BigDecimal("12345678901234567890.123456789"), new BigDecimal("12345678901234567890123.1234567890123"), new BigDecimal("123456789012345678901234.1234567890123456"), new BigDecimal("1234567890123456789012345.1234567890123456789"))).build();
Mutation json = Mutation.newInsertOrUpdateBuilder("test").set("one").toJsonArray(ImmutableList.of("{\"key1\":\"value1\", \"key2\":\"value2\"}", "{\"key1\":\"value1\", \"key2\":20}")).build();
assertThat(MutationSizeEstimator.sizeOf(int64), is(24L));
assertThat(MutationSizeEstimator.sizeOf(float64), is(16L));
assertThat(MutationSizeEstimator.sizeOf(bool), is(4L));
assertThat(MutationSizeEstimator.sizeOf(numeric), is(153L));
assertThat(MutationSizeEstimator.sizeOf(json), is(62L));
}
Aggregations