當前位置: 首頁>>代碼示例>>Java>>正文


Java TimestampBound類代碼示例

本文整理匯總了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"));
}
 
開發者ID:apache,項目名稱:beam,代碼行數:26,代碼來源:SpannerIOReadTest.java

示例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"));
}
 
開發者ID:apache,項目名稱:beam,代碼行數:26,代碼來源:SpannerIOReadTest.java

示例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();
}
 
開發者ID:apache,項目名稱:beam,代碼行數:14,代碼來源:SpannerIO.java

示例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();
}
 
開發者ID:apache,項目名稱:beam,代碼行數:13,代碼來源:SpannerIO.java

示例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"));
}
 
開發者ID:apache,項目名稱:beam,代碼行數:28,代碼來源:SpannerIOReadTest.java

示例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();
}
 
開發者ID:apache,項目名稱:beam,代碼行數:41,代碼來源:SpannerReadIT.java

示例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"));
  }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:14,代碼來源:SpannerSample.java

示例8: getTimestampBound

import com.google.cloud.spanner.TimestampBound; //導入依賴的package包/類
@Nullable
abstract TimestampBound getTimestampBound();
 
開發者ID:apache,項目名稱:beam,代碼行數:3,代碼來源:SpannerIO.java

示例9: withTimestamp

import com.google.cloud.spanner.TimestampBound; //導入依賴的package包/類
public Read withTimestamp(Timestamp timestamp) {
  return withTimestampBound(TimestampBound.ofReadTimestamp(timestamp));
}
 
開發者ID:apache,項目名稱:beam,代碼行數:4,代碼來源:SpannerIO.java

示例10: withTimestampBound

import com.google.cloud.spanner.TimestampBound; //導入依賴的package包/類
public Read withTimestampBound(TimestampBound timestampBound) {
  return toBuilder().setTimestampBound(timestampBound).build();
}
 
開發者ID:apache,項目名稱:beam,代碼行數:4,代碼來源:SpannerIO.java

示例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));
}
 
開發者ID:apache,項目名稱:beam,代碼行數:53,代碼來源:SpannerIOReadTest.java

示例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));
}
 
開發者ID:apache,項目名稱:beam,代碼行數:45,代碼來源:SpannerIOReadTest.java

示例13: setTimestampBound

import com.google.cloud.spanner.TimestampBound; //導入依賴的package包/類
abstract Builder setTimestampBound(TimestampBound timestampBound); 
開發者ID:apache,項目名稱:beam,代碼行數:2,代碼來源:SpannerIO.java


注:本文中的com.google.cloud.spanner.TimestampBound類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。