本文整理汇总了Java中com.google.cloud.spanner.TimestampBound类的典型用法代码示例。如果您正苦于以下问题:Java TimestampBound类的具体用法?Java TimestampBound怎么用?Java TimestampBound使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TimestampBound类属于com.google.cloud.spanner包,在下文中一共展示了TimestampBound类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runQuery
import com.google.cloud.spanner.TimestampBound; //导入依赖的package包/类
@Test
public void runQuery() throws Exception {
SpannerIO.Read read =
SpannerIO.read()
.withProjectId("test")
.withInstanceId("123")
.withDatabaseId("aaa")
.withQuery("SELECT * FROM users")
.withServiceFactory(serviceFactory);
NaiveSpannerReadFn readFn = new NaiveSpannerReadFn(read.getSpannerConfig());
DoFnTester<ReadOperation, Struct> fnTester = DoFnTester.of(readFn);
when(serviceFactory.mockDatabaseClient().readOnlyTransaction(any(TimestampBound.class)))
.thenReturn(mockTx);
when(mockTx.executeQuery(any(Statement.class)))
.thenReturn(ResultSets.forRows(FAKE_TYPE, FAKE_ROWS));
List<Struct> result = fnTester.processBundle(read.getReadOperation());
assertThat(result, Matchers.containsInAnyOrder(FAKE_ROWS.toArray()));
verify(serviceFactory.mockDatabaseClient()).readOnlyTransaction(TimestampBound
.strong());
verify(mockTx).executeQuery(Statement.of("SELECT * FROM users"));
}
示例2: runRead
import com.google.cloud.spanner.TimestampBound; //导入依赖的package包/类
@Test
public void runRead() throws Exception {
SpannerIO.Read read =
SpannerIO.read()
.withProjectId("test")
.withInstanceId("123")
.withDatabaseId("aaa")
.withTable("users")
.withColumns("id", "name")
.withServiceFactory(serviceFactory);
NaiveSpannerReadFn readFn = new NaiveSpannerReadFn(read.getSpannerConfig());
DoFnTester<ReadOperation, Struct> fnTester = DoFnTester.of(readFn);
when(serviceFactory.mockDatabaseClient().readOnlyTransaction(any(TimestampBound.class)))
.thenReturn(mockTx);
when(mockTx.read("users", KeySet.all(), Arrays.asList("id", "name")))
.thenReturn(ResultSets.forRows(FAKE_TYPE, FAKE_ROWS));
List<Struct> result = fnTester.processBundle(read.getReadOperation());
assertThat(result, Matchers.containsInAnyOrder(FAKE_ROWS.toArray()));
verify(serviceFactory.mockDatabaseClient()).readOnlyTransaction(TimestampBound.strong());
verify(mockTx).read("users", KeySet.all(), Arrays.asList("id", "name"));
}
示例3: read
import com.google.cloud.spanner.TimestampBound; //导入依赖的package包/类
/**
* Creates an uninitialized instance of {@link Read}. Before use, the {@link Read} must be
* configured with a {@link Read#withInstanceId} and {@link Read#withDatabaseId} that identify the
* Cloud Spanner database.
*/
@Experimental(Experimental.Kind.SOURCE_SINK)
public static Read read() {
return new AutoValue_SpannerIO_Read.Builder()
.setSpannerConfig(SpannerConfig.create())
.setTimestampBound(TimestampBound.strong())
.setReadOperation(ReadOperation.create())
.build();
}
示例4: createTransaction
import com.google.cloud.spanner.TimestampBound; //导入依赖的package包/类
/**
* Returns a transform that creates a batch transaction. By default,
* {@link TimestampBound#strong()} transaction is created, to override this use
* {@link CreateTransaction#withTimestampBound(TimestampBound)}.
*/
@Experimental
public static CreateTransaction createTransaction() {
return new AutoValue_SpannerIO_CreateTransaction.Builder()
.setSpannerConfig(SpannerConfig.create())
.setTimestampBound(TimestampBound.strong())
.build();
}
示例5: runReadUsingIndex
import com.google.cloud.spanner.TimestampBound; //导入依赖的package包/类
@Test
public void runReadUsingIndex() throws Exception {
SpannerIO.Read read =
SpannerIO.read()
.withProjectId("test")
.withInstanceId("123")
.withDatabaseId("aaa")
.withTimestamp(Timestamp.now())
.withTable("users")
.withColumns("id", "name")
.withIndex("theindex")
.withServiceFactory(serviceFactory);
NaiveSpannerReadFn readFn = new NaiveSpannerReadFn(read.getSpannerConfig());
DoFnTester<ReadOperation, Struct> fnTester = DoFnTester.of(readFn);
when(serviceFactory.mockDatabaseClient().readOnlyTransaction(any(TimestampBound.class)))
.thenReturn(mockTx);
when(mockTx.readUsingIndex("users", "theindex", KeySet.all(), Arrays.asList("id", "name")))
.thenReturn(ResultSets.forRows(FAKE_TYPE, FAKE_ROWS));
List<Struct> result = fnTester.processBundle(read.getReadOperation());
assertThat(result, Matchers.containsInAnyOrder(FAKE_ROWS.toArray()));
verify(serviceFactory.mockDatabaseClient()).readOnlyTransaction(TimestampBound.strong());
verify(mockTx).readUsingIndex("users", "theindex", KeySet.all(), Arrays.asList("id", "name"));
}
示例6: testRead
import com.google.cloud.spanner.TimestampBound; //导入依赖的package包/类
@Test
public void testRead() throws Exception {
DatabaseClient databaseClient =
spanner.getDatabaseClient(
DatabaseId.of(
project, options.getInstanceId(), databaseName));
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);
SpannerConfig spannerConfig = SpannerConfig.create()
.withProjectId(project)
.withInstanceId(options.getInstanceId())
.withDatabaseId(databaseName);
PCollectionView<Transaction> tx =
p.apply(
SpannerIO.createTransaction()
.withSpannerConfig(spannerConfig)
.withTimestampBound(TimestampBound.strong()));
PCollection<Struct> output =
p.apply(
SpannerIO.read()
.withSpannerConfig(spannerConfig)
.withQuery("SELECT * FROM " + options.getTable())
.withTransaction(tx));
PAssert.thatSingleton(output.apply("Count rows", Count.<Struct>globally())).isEqualTo(5L);
p.run();
}
示例7: readStaleData
import com.google.cloud.spanner.TimestampBound; //导入依赖的package包/类
static void readStaleData(DatabaseClient dbClient) {
ResultSet resultSet =
dbClient
.singleUse(TimestampBound.ofExactStaleness(15, TimeUnit.SECONDS))
.read("Albums",
KeySet.all(),
Arrays.asList("SingerId", "AlbumId", "MarketingBudget"));
while (resultSet.next()) {
System.out.printf(
"%d %d %s\n", resultSet.getLong(0), resultSet.getLong(1),
resultSet.isNull(2) ? "NULL" : resultSet.getLong("MarketingBudget"));
}
}
示例8: getTimestampBound
import com.google.cloud.spanner.TimestampBound; //导入依赖的package包/类
@Nullable
abstract TimestampBound getTimestampBound();
示例9: withTimestamp
import com.google.cloud.spanner.TimestampBound; //导入依赖的package包/类
public Read withTimestamp(Timestamp timestamp) {
return withTimestampBound(TimestampBound.ofReadTimestamp(timestamp));
}
示例10: withTimestampBound
import com.google.cloud.spanner.TimestampBound; //导入依赖的package包/类
public Read withTimestampBound(TimestampBound timestampBound) {
return toBuilder().setTimestampBound(timestampBound).build();
}
示例11: readPipeline
import com.google.cloud.spanner.TimestampBound; //导入依赖的package包/类
@Test
@Category(NeedsRunner.class)
public void readPipeline() throws Exception {
Timestamp timestamp = Timestamp.ofTimeMicroseconds(12345);
SpannerConfig spannerConfig =
SpannerConfig.create()
.withProjectId("test")
.withInstanceId("123")
.withDatabaseId("aaa")
.withServiceFactory(serviceFactory);
PCollectionView<Transaction> tx =
pipeline.apply("tx", SpannerIO.createTransaction().withSpannerConfig(spannerConfig));
PCollection<Struct> one =
pipeline.apply(
"read q",
SpannerIO.read()
.withSpannerConfig(spannerConfig)
.withQuery("SELECT * FROM users")
.withTransaction(tx));
PCollection<Struct> two =
pipeline.apply(
"read r",
SpannerIO.read()
.withSpannerConfig(spannerConfig)
.withTimestamp(Timestamp.now())
.withTable("users")
.withColumns("id", "name")
.withTransaction(tx));
when(serviceFactory.mockDatabaseClient().readOnlyTransaction(any(TimestampBound.class)))
.thenReturn(mockTx);
when(mockTx.executeQuery(Statement.of("SELECT 1"))).thenReturn(ResultSets.forRows(Type.struct(),
Collections.<Struct>emptyList()));
when(mockTx.executeQuery(Statement.of("SELECT * FROM users")))
.thenReturn(ResultSets.forRows(FAKE_TYPE, FAKE_ROWS));
when(mockTx.read("users", KeySet.all(), Arrays.asList("id", "name")))
.thenReturn(ResultSets.forRows(FAKE_TYPE, FAKE_ROWS));
when(mockTx.getReadTimestamp()).thenReturn(timestamp);
PAssert.that(one).containsInAnyOrder(FAKE_ROWS);
PAssert.that(two).containsInAnyOrder(FAKE_ROWS);
pipeline.run();
verify(serviceFactory.mockDatabaseClient(), times(2))
.readOnlyTransaction(TimestampBound.ofReadTimestamp(timestamp));
}
示例12: readAllPipeline
import com.google.cloud.spanner.TimestampBound; //导入依赖的package包/类
@Test
@Category(NeedsRunner.class)
public void readAllPipeline() throws Exception {
Timestamp timestamp = Timestamp.ofTimeMicroseconds(12345);
SpannerConfig spannerConfig =
SpannerConfig.create()
.withProjectId("test")
.withInstanceId("123")
.withDatabaseId("aaa")
.withServiceFactory(serviceFactory);
PCollectionView<Transaction> tx =
pipeline.apply("tx", SpannerIO.createTransaction().withSpannerConfig(spannerConfig));
PCollection<ReadOperation> reads =
pipeline.apply(
Create.of(
ReadOperation.create().withQuery("SELECT * FROM users"),
ReadOperation.create().withTable("users").withColumns("id", "name")));
PCollection<Struct> one =
reads.apply(
"read all", SpannerIO.readAll().withSpannerConfig(spannerConfig).withTransaction(tx));
when(serviceFactory.mockDatabaseClient().readOnlyTransaction(any(TimestampBound.class)))
.thenReturn(mockTx);
when(mockTx.executeQuery(Statement.of("SELECT 1")))
.thenReturn(ResultSets.forRows(Type.struct(), Collections.<Struct>emptyList()));
when(mockTx.executeQuery(Statement.of("SELECT * FROM users")))
.thenReturn(ResultSets.forRows(FAKE_TYPE, FAKE_ROWS.subList(0, 2)));
when(mockTx.read("users", KeySet.all(), Arrays.asList("id", "name")))
.thenReturn(ResultSets.forRows(FAKE_TYPE, FAKE_ROWS.subList(2, 4)));
when(mockTx.getReadTimestamp()).thenReturn(timestamp);
PAssert.that(one).containsInAnyOrder(FAKE_ROWS);
pipeline.run();
verify(serviceFactory.mockDatabaseClient(), times(2))
.readOnlyTransaction(TimestampBound.ofReadTimestamp(timestamp));
}
示例13: setTimestampBound
import com.google.cloud.spanner.TimestampBound; //导入依赖的package包/类
abstract Builder setTimestampBound(TimestampBound timestampBound);