com.datastax.driver.core.ResultSet.getExecutionInfo()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(13.4k)|赞(0)|评价(0)|浏览(70)

本文整理了Java中com.datastax.driver.core.ResultSet.getExecutionInfo方法的一些代码示例,展示了ResultSet.getExecutionInfo的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ResultSet.getExecutionInfo方法的具体详情如下:
包路径:com.datastax.driver.core.ResultSet
类名称:ResultSet
方法名:getExecutionInfo

ResultSet.getExecutionInfo介绍

[英]Returns information on the execution of the last query made for this ResultSet.

Note that in most cases, a ResultSet is fetched with only one query, but large result sets can be paged and thus be retrieved by multiple queries. In that case this method return the ExecutionInfo for the last query performed. To retrieve the information for all queries, use #getAllExecutionInfo.

The returned object includes basic information such as the queried hosts, but also the Cassandra query trace if tracing was enabled for the query.
[中]返回上次为此结果集执行查询的信息。
请注意,在大多数情况下,一个结果集只能通过一个查询获取,但大的结果集可以分页,因此可以通过多个查询检索。在这种情况下,此方法返回上次执行的查询的ExecutionInfo。要检索所有查询的信息,请使用#getAllExecutionInfo。
返回的对象包括基本信息,例如查询的主机,如果查询启用了跟踪,还包括Cassandra查询跟踪。

代码示例

代码示例来源:origin: apache/usergrid

@Override
public MapKeyResults getAllKeys(final MapScope scope, final String cursor, final int limit ){
  final int[] buckets = BUCKET_LOCATOR.getAllBuckets( scope.getName() );
  final List<ByteBuffer> partitionKeys = new ArrayList<>(NUM_BUCKETS.length);
  for (int bucket : buckets) {
    partitionKeys.add(getMapKeyPartitionKey(scope, bucket));
  }
  Clause in = QueryBuilder.in("key", partitionKeys);
  Statement statement;
  if( isBlank(cursor) ){
    statement = QueryBuilder.select().all().from(MAP_KEYS_TABLE)
      .where(in)
      .setFetchSize(limit);
  }else{
    statement = QueryBuilder.select().all().from(MAP_KEYS_TABLE)
      .where(in)
      .setFetchSize(limit)
      .setPagingState(PagingState.fromString(cursor));
  }
  ResultSet resultSet = session.execute(statement);
  PagingState pagingState = resultSet.getExecutionInfo().getPagingState();
  final List<String> keys = new ArrayList<>();
  Iterator<Row> resultIterator = resultSet.iterator();
  int size = 0;
  while( resultIterator.hasNext() && size < limit){
    size++;
    keys.add((String)DataType.text().deserialize(resultIterator.next().getBytes("column1"), ProtocolVersion.NEWEST_SUPPORTED));
  }
  return new MapKeyResults(pagingState != null ? pagingState.toString() : null, keys);
}

代码示例来源:origin: apache/usergrid

final PagingState newPagingState = rs.getExecutionInfo().getPagingState();

代码示例来源:origin: hugegraph/hugegraph

@Override
  protected String pageState() {
    PagingState page = this.results.getExecutionInfo().getPagingState();
    if (page == null || this.results.isExhausted()) {
      return null;
    }
    return page.toString();
  }
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

/** Coordinator management/count */
protected void addCoordinator(ResultSet rs) {
 InetAddress coordinator = rs.getExecutionInfo().getQueriedHost().getAddress();
 Integer n = coordinators.get(coordinator);
 coordinators.put(coordinator, n == null ? 1 : n + 1);
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void should_set_flag_on_successful_agreement() {
 ProtocolOptions protocolOptions = cluster().getConfiguration().getProtocolOptions();
 protocolOptions.maxSchemaAgreementWaitSeconds = 10;
 ResultSet rs = session().execute(String.format(CREATE_TABLE, COUNTER.getAndIncrement()));
 assertThat(rs.getExecutionInfo().isSchemaInAgreement()).isTrue();
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short", priority = 1)
public void should_unset_flag_on_failed_agreement() {
 // Setting to 0 results in no query being set, so agreement fails
 ProtocolOptions protocolOptions = cluster().getConfiguration().getProtocolOptions();
 protocolOptions.maxSchemaAgreementWaitSeconds = 0;
 ResultSet rs = session().execute(String.format(CREATE_TABLE, COUNTER.getAndIncrement()));
 assertThat(rs.getExecutionInfo().isSchemaInAgreement()).isFalse();
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
 public void should_expose_warnings_on_execution_info() {
  // the default batch size warn threshold is 5 * 1024 bytes, but after CASSANDRA-10876 there must
  // be
  // multiple mutations in a batch to trigger this warning so the batch includes 2 different
  // inserts.
  ResultSet rs =
    session()
      .execute(
        String.format(
          "BEGIN UNLOGGED BATCH\n"
            + "INSERT INTO foo (k, v) VALUES (1, '%s')\n"
            + "INSERT INTO foo (k, v) VALUES (2, '%s')\n"
            + "APPLY BATCH",
          Strings.repeat("1", 2 * 1024), Strings.repeat("1", 3 * 1024)));

  List<String> warnings = rs.getExecutionInfo().getWarnings();
  assertThat(warnings).hasSize(1);
 }
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void should_encode_null_values() throws Exception {
 Map<String, ByteBuffer> payload = new HashMap<String, ByteBuffer>();
 payload.put("k1", Statement.NULL_PAYLOAD_VALUE);
 Statement statement = new SimpleStatement("SELECT c2 FROM t1 where c1 = ?", 1);
 statement.setOutgoingPayload(payload);
 ResultSet rows = session().execute(statement);
 Map<String, ByteBuffer> actual = rows.getExecutionInfo().getIncomingPayload();
 assertThat(actual).isEqualTo(payload);
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
@CassandraVersion(value = "2.0.0")
public void should_reuse_wrapped_simple_statement_for_multipage_query() {
 loadBalancingPolicy.customStatementsHandled.set(0);
 for (int v = 1; v <= 100; v++)
  session().execute(new SimpleStatement(INSERT_MULTIPAGE_QUERY, "key_simple_multipage", v));
 SimpleStatement s = new SimpleStatement(SELECT_MULTIPAGE_QUERY, "key_simple_multipage");
 s.setFetchSize(1);
 CustomStatement customStatement = new CustomStatement(s);
 ResultSet rs = session().execute(customStatement);
 assertThat(loadBalancingPolicy.customStatementsHandled.get()).isEqualTo(1);
 Iterator<Row> it = rs.iterator();
 assertThat(it.hasNext()).isTrue();
 it.next();
 assertThat(rs.getExecutionInfo().getStatement()).isEqualTo(customStatement);
 assertThat(loadBalancingPolicy.customStatementsHandled.get()).isEqualTo(1);
 assertThat(it.hasNext()).isTrue();
 it.next();
 assertThat(rs.getExecutionInfo().getStatement()).isEqualTo(customStatement);
 assertThat(loadBalancingPolicy.customStatementsHandled.get()).isEqualTo(2);
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void should_set_flag_on_non_schema_altering_statement() {
 ProtocolOptions protocolOptions = cluster().getConfiguration().getProtocolOptions();
 protocolOptions.maxSchemaAgreementWaitSeconds = 10;
 ResultSet rs = session().execute("select release_version from system.local");
 assertThat(rs.getExecutionInfo().isSchemaInAgreement()).isTrue();
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void should_echo_custom_payload_when_executing_statement() throws Exception {
 Statement statement = new SimpleStatement("SELECT c2 FROM t1 where c1 = ?", 1);
 statement.setOutgoingPayload(payload1);
 ResultSet rows = session().execute(statement);
 Map<String, ByteBuffer> actual = rows.getExecutionInfo().getIncomingPayload();
 assertThat(actual).isEqualTo(payload1);
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Override
 public ListenableFuture<ResultSet> apply(ResultSet rs) throws Exception {
  int remainingInPage = rs.getAvailableWithoutFetching();
  for (Row row : rs) {
   all.add(row.getInt(0));
   if (--remainingInPage == 0) break;
  }
  boolean wasLastPage = rs.getExecutionInfo().getPagingState() == null;
  if (wasLastPage) return Futures.immediateFuture(rs);
  else return GuavaCompatibility.INSTANCE.transformAsync(rs.fetchMoreResults(), this);
 }
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void should_echo_custom_payload_when_executing_batch_statement() throws Exception {
 Statement statement =
   new BatchStatement().add(new SimpleStatement("INSERT INTO t1 (c1, c2) values (1, 'foo')"));
 statement.setOutgoingPayload(payload1);
 ResultSet rows = session().execute(statement);
 Map<String, ByteBuffer> actual = rows.getExecutionInfo().getIncomingPayload();
 assertThat(actual).isEqualTo(payload1);
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void should_echo_custom_payload_when_building_statement() throws Exception {
 Statement statement = select("c2").from("t1").where(eq("c1", 1)).setOutgoingPayload(payload1);
 ResultSet rows = session().execute(statement);
 Map<String, ByteBuffer> actual = rows.getExecutionInfo().getIncomingPayload();
 assertThat(actual).isEqualTo(payload1);
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

/**
 * Validates that the "unsafe" paging state can be reused with the same Statement.
 *
 * @test_category paging
 * @expected_result {@link ResultSet} from the query with the provided raw paging state starts
 *     from the subsequent row from the first query.
 */
@Test(groups = "short")
public void should_complete_when_using_unsafe_paging_state() {
 SimpleStatement st = new SimpleStatement(String.format("SELECT v FROM test WHERE k='%s'", KEY));
 ResultSet result = session().execute(st.setFetchSize(20));
 int pageSize = result.getAvailableWithoutFetching();
 byte[] savedPagingState = result.getExecutionInfo().getPagingStateUnsafe();
 st = new SimpleStatement(String.format("SELECT v FROM test WHERE k='%s'", KEY));
 result = session().execute(st.setFetchSize(20).setPagingStateUnsafe(savedPagingState));
 // We have the result starting from the next page we stopped
 assertThat(result.one().getInt("v")).isEqualTo(pageSize);
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void should_use_host_on_statement() {
 for (int i = 0; i < 10; i++) {
  int hostIndex = i % 3 + 1;
  Host host = TestUtils.findHost(cluster, hostIndex);
  // given a statement with host explicitly set.
  Statement statement = new SimpleStatement("select * system.local").setHost(host);
  // when statement is executed
  ResultSet result = session.execute(statement);
  // then the query should have been sent to the configured host.
  assertThat(result.getExecutionInfo().getQueriedHost()).isSameAs(host);
  verifyNoLbpInteractions();
 }
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

/**
 * Validates that {@link PagingState} can be reused with the same {@link BoundStatement}.
 *
 * @test_category paging
 * @expected_result {@link ResultSet} from the query with the provided paging state starts from
 *     the subsequent row from the first query.
 */
@Test(groups = "short")
@CassandraVersion("2.0.0")
public void should_be_able_to_use_state_with_bound_statement() {
 PreparedStatement prepared = session().prepare("SELECT v from test where k=?");
 BoundStatement bs = prepared.bind(KEY);
 ResultSet result = session().execute(bs.setFetchSize(20));
 int pageSize = result.getAvailableWithoutFetching();
 PagingState pagingState = result.getExecutionInfo().getPagingState();
 result = session().execute(bs.setFetchSize(20).setPagingState(pagingState));
 // We have the result starting from the next page we stopped
 assertThat(result.one().getInt("v")).isEqualTo(pageSize);
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

/**
 * Validates that {@link PagingState} can be reused with a wrapped Statement.
 *
 * @test_category paging
 * @expected_result {@link ResultSet} from the query with the provided {@link PagingState} starts
 *     from the subsequent row from the first query.
 */
@Test(groups = "short")
public void should_use_state_with_wrapped_statement() {
 Statement st =
   new TestWrapper(new SimpleStatement(String.format("SELECT v FROM test WHERE k='%s'", KEY)));
 ResultSet result = session().execute(st.setFetchSize(20));
 int pageSize = result.getAvailableWithoutFetching();
 String savedPagingStateString = result.getExecutionInfo().getPagingState().toString();
 st =
   new TestWrapper(new SimpleStatement(String.format("SELECT v FROM test WHERE k='%s'", KEY)));
 result =
   session()
     .execute(
       st.setFetchSize(20).setPagingState(PagingState.fromString(savedPagingStateString)));
 // We have the result starting from the next page we stopped
 assertThat(result.one().getInt("v")).isEqualTo(pageSize);
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

/**
 * Validates that {@link PagingState} cannot be reused with a different {@link BoundStatement}
 * than the original, even if its source {@link PreparedStatement} was the same.
 *
 * @test_category paging
 * @expected_result A failure is thrown when setting paging state on a different {@link
 *     BoundStatement}.
 */
@Test(
  groups = "short",
  expectedExceptions = {PagingStateException.class})
@CassandraVersion("2.0.0")
public void should_not_be_able_to_use_state_with_different_bound_statement() {
 PreparedStatement prepared = session().prepare("SELECT v from test where k=?");
 BoundStatement bs0 = prepared.bind(KEY);
 ResultSet result = session().execute(bs0.setFetchSize(20));
 PagingState pagingState = result.getExecutionInfo().getPagingState();
 BoundStatement bs1 = prepared.bind("different_key");
 session().execute(bs1.setFetchSize(20).setPagingState(pagingState));
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void should_not_start_speculative_execution_if_first_execution_completes_successfully() {
 scassandras
   .node(1)
   .primingClient()
   .prime(
     PrimingRequest.queryBuilder()
       .withQuery("mock query")
       .withThen(then().withRows(row("result", "result1")))
       .build());
 long execStartCount = errors.getSpeculativeExecutions().getCount();
 ResultSet rs = session.execute("mock query");
 Row row = rs.one();
 assertThat(row.getString("result")).isEqualTo("result1");
 assertThat(errors.getSpeculativeExecutions().getCount()).isEqualTo(execStartCount);
 ExecutionInfo executionInfo = rs.getExecutionInfo();
 assertThat(executionInfo.getTriedHosts()).containsOnly(host1);
 assertThat(executionInfo.getQueriedHost()).isEqualTo(host1);
 assertThat(executionInfo.getSpeculativeExecutions()).isEqualTo(0);
 assertThat(executionInfo.getSuccessfulExecutionIndex()).isEqualTo(0);
}

相关文章