@Override // Since Options mandates checking hasXX() before XX() is called, the equals & hashCode look more // complicated than usual. public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Options that = (Options) o; return (!hasLimit() && !that.hasLimit() || hasLimit() && that.hasLimit() && Objects.equals(limit(), that.limit())) && (!hasPrefetchChunks() && !that.hasPrefetchChunks() || hasPrefetchChunks() && that.hasPrefetchChunks() && Objects.equals(prefetchChunks(), that.prefetchChunks())) && (!hasPageSize() && !that.hasPageSize() || hasPageSize() && that.hasPageSize() && Objects.equals(pageSize(), that.pageSize())) && Objects.equals(pageToken(), that.pageToken()) && Objects.equals(filter(), that.filter()); }
ResultSet executeQueryInternalWithOptions( Statement statement, com.google.spanner.v1.ExecuteSqlRequest.QueryMode queryMode, Options readOptions, ByteString partitionToken) { beforeReadOrQuery(); final ExecuteSqlRequest.Builder request = getExecuteSqlRequestBuilder(statement, queryMode); if (partitionToken != null) { request.setPartitionToken(partitionToken); } final int prefetchChunks = readOptions.hasPrefetchChunks() ? readOptions.prefetchChunks() : defaultPrefetchChunks; ResumableStreamIterator stream = new ResumableStreamIterator(MAX_BUFFERED_CHUNKS, QUERY, span) { @Override CloseableIterator<PartialResultSet> startStream(@Nullable ByteString resumeToken) { GrpcStreamIterator stream = new GrpcStreamIterator(prefetchChunks); if (resumeToken != null) { request.setResumeToken(resumeToken); } SpannerRpc.StreamingCall call = rpc.executeQuery(request.build(), stream.consumer(), session.options); call.request(prefetchChunks); stream.setCall(call); return stream; } }; return new GrpcResultSet(stream, this, queryMode); }
@Test public void allOptionsPresent() { Options options = Options.fromReadOptions(Options.limit(10), Options.prefetchChunks(1)); assertThat(options.hasLimit()).isTrue(); assertThat(options.limit()).isEqualTo(10); assertThat(options.hasPrefetchChunks()).isTrue(); assertThat(options.prefetchChunks()).isEqualTo(1); }
@Test public void allOptionsAbsent() { Options options = Options.fromReadOptions(); assertThat(options.hasLimit()).isFalse(); assertThat(options.hasPrefetchChunks()).isFalse(); assertThat(options.hasFilter()).isFalse(); assertThat(options.hasPageToken()).isFalse(); assertThat(options.toString()).isEqualTo(""); assertThat(options.equals(options)).isTrue(); assertThat(options.equals(null)).isFalse(); assertThat(options.equals(this)).isFalse(); assertThat(options.hashCode()).isEqualTo(31); }
readOptions.hasPrefetchChunks() ? readOptions.prefetchChunks() : defaultPrefetchChunks; ResumableStreamIterator stream = new ResumableStreamIterator(MAX_BUFFERED_CHUNKS, READ, span) {
@Test public void statementInstance() { Partition p = Partition.createQueryPartition(partitionToken, partitionOptions, stmt, queryOptions); assertThat(p.getPartitionToken()).isEqualTo(partitionToken); assertThat(p.getStatement()).isEqualTo(stmt); assertThat(p.getQueryOptions().hasPrefetchChunks()).isTrue(); assertThat(p.getQueryOptions().prefetchChunks()).isEqualTo(10); assertNull(p.getTable()); assertNull(p.getColumns()); assertNull(p.getKeys()); assertNull(p.getIndex()); assertNull(p.getReadOptions()); // Test serialization. reserializeAndAssert(p); }
@Override // Since Options mandates checking hasXX() before XX() is called, the equals & hashCode look more // complicated than usual. public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Options that = (Options) o; return (!hasLimit() && !that.hasLimit() || hasLimit() && that.hasLimit() && Objects.equals(limit(), that.limit())) && (!hasPrefetchChunks() && !that.hasPrefetchChunks() || hasPrefetchChunks() && that.hasPrefetchChunks() && Objects.equals(prefetchChunks(), that.prefetchChunks())) && (!hasPageSize() && !that.hasPageSize() || hasPageSize() && that.hasPageSize() && Objects.equals(pageSize(), that.pageSize())) && Objects.equals(pageToken(), that.pageToken()) && Objects.equals(filter(), that.filter()); }
ResultSet executeQueryInternalWithOptions( Statement statement, com.google.spanner.v1.ExecuteSqlRequest.QueryMode queryMode, Options readOptions, ByteString partitionToken) { beforeReadOrQuery(); final ExecuteSqlRequest.Builder request = getExecuteSqlRequestBuilder(statement, queryMode); if (partitionToken != null) { request.setPartitionToken(partitionToken); } final int prefetchChunks = readOptions.hasPrefetchChunks() ? readOptions.prefetchChunks() : defaultPrefetchChunks; ResumableStreamIterator stream = new ResumableStreamIterator(MAX_BUFFERED_CHUNKS, QUERY, span) { @Override CloseableIterator<PartialResultSet> startStream(@Nullable ByteString resumeToken) { GrpcStreamIterator stream = new GrpcStreamIterator(prefetchChunks); if (resumeToken != null) { request.setResumeToken(resumeToken); } SpannerRpc.StreamingCall call = rpc.executeQuery(request.build(), stream.consumer(), session.options); call.request(prefetchChunks); stream.setCall(call); return stream; } }; return new GrpcResultSet(stream, this, queryMode); }
readOptions.hasPrefetchChunks() ? readOptions.prefetchChunks() : defaultPrefetchChunks; ResumableStreamIterator stream = new ResumableStreamIterator(MAX_BUFFERED_CHUNKS, READ, span) {