本文整理汇总了Java中com.google.cloud.spanner.KeyRange类的典型用法代码示例。如果您正苦于以下问题:Java KeyRange类的具体用法?Java KeyRange怎么用?Java KeyRange使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
KeyRange类属于com.google.cloud.spanner包,在下文中一共展示了KeyRange类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testMutationSerialization
import com.google.cloud.spanner.KeyRange; //导入依赖的package包/类
@Test
public void testMutationSerialization() throws IOException, ClassNotFoundException, NoSuchMethodException,
SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
{
Mutation original = Mutation.newInsertBuilder("FOO").set("BAR").to("test").build();
Mutation deserialized = serializeDeserialize(original);
assertEquals(original, deserialized);
original = Mutation.newUpdateBuilder("FOO").set("BAR").to("bla").build();
deserialized = serializeDeserialize(original);
assertEquals(original, deserialized);
original = Mutation.delete("FOO", Key.of("bla"));
deserialized = serializeDeserialize(original);
assertEquals(original, deserialized);
original = Mutation.delete("FOO", KeySet.all());
deserialized = serializeDeserialize(original);
assertEquals(original, deserialized);
original = Mutation.delete("FOO", KeySet.range(KeyRange.closedClosed(Key.of("foo"), Key.of("bar"))));
deserialized = serializeDeserialize(original);
assertEquals(original, deserialized);
}
示例2: testDeletes
import com.google.cloud.spanner.KeyRange; //导入依赖的package包/类
@Test
public void testDeletes() throws Exception {
encodeAndVerify(g(Mutation.delete("test", Key.of(1L))));
encodeAndVerify(g(Mutation.delete("test", Key.of((Long) null))));
KeySet allTypes = KeySet.newBuilder()
.addKey(Key.of(1L))
.addKey(Key.of((Long) null))
.addKey(Key.of(1.2))
.addKey(Key.of((Double) null))
.addKey(Key.of("one"))
.addKey(Key.of((String) null))
.addKey(Key.of(ByteArray.fromBase64("abcd")))
.addKey(Key.of((ByteArray) null))
.addKey(Key.of(Timestamp.now()))
.addKey(Key.of((Timestamp) null))
.addKey(Key.of(Date.fromYearMonthDay(2012, 1, 1)))
.addKey(Key.of((Date) null))
.build();
encodeAndVerify(g(Mutation.delete("test", allTypes)));
encodeAndVerify(
g(Mutation
.delete("test", KeySet.range(KeyRange.closedClosed(Key.of(1L), Key.of(2L))))));
}
示例3: sizeOf
import com.google.cloud.spanner.KeyRange; //导入依赖的package包/类
private static long sizeOf(KeySet keySet) {
long result = 0;
for (Key k : keySet.getKeys()) {
result += sizeOf(k);
}
for (KeyRange kr : keySet.getRanges()) {
result += sizeOf(kr);
}
return result;
}
示例4: testAllTypesMultipleMutations
import com.google.cloud.spanner.KeyRange; //导入依赖的package包/类
@Test
public void testAllTypesMultipleMutations() throws Exception {
encodeAndVerify(g(
appendAllTypes(Mutation.newInsertOrUpdateBuilder("test")).build(),
appendAllTypes(Mutation.newInsertBuilder("test")).build(),
appendAllTypes(Mutation.newUpdateBuilder("test")).build(),
appendAllTypes(Mutation.newReplaceBuilder("test")).build(),
Mutation
.delete("test", KeySet.range(KeyRange.closedClosed(Key.of(1L), Key.of(2L))))));
}
示例5: noBatchingRangeDelete
import com.google.cloud.spanner.KeyRange; //导入依赖的package包/类
@Test
@Category(NeedsRunner.class)
public void noBatchingRangeDelete() throws Exception {
Mutation all = Mutation.delete("test", KeySet.all());
Mutation prefix = Mutation.delete("test", KeySet.prefixRange(Key.of(1L)));
Mutation range = Mutation.delete("test", KeySet.range(KeyRange.openOpen(Key.of(1L), Key
.newBuilder().build())));
PCollection<MutationGroup> mutations = pipeline.apply(Create
.of(
g(m(1L)),
g(m(2L)),
g(del(5L, 6L)),
g(delRange(50L, 55L)),
g(delRange(11L, 20L)),
g(all),
g(prefix), g(range)
)
);
mutations.apply(SpannerIO.write()
.withProjectId("test-project")
.withInstanceId("test-instance")
.withDatabaseId("test-database")
.withServiceFactory(serviceFactory)
.withBatchSizeBytes(1000000000)
.withSampler(fakeSampler(m(1000L)))
.grouped());
pipeline.run();
verifyBatches(
batch(m(1L), m(2L)),
batch(del(5L, 6L)),
batch(delRange(11L, 20L)),
batch(delRange(50L, 55L)),
batch(all),
batch(prefix),
batch(range)
);
}
示例6: delRange
import com.google.cloud.spanner.KeyRange; //导入依赖的package包/类
private static Mutation delRange(Long start, Long end) {
return Mutation.delete("test", KeySet.range(KeyRange.closedClosed(Key.of(start), Key.of(end))));
}