@Override public ResultSet readUsingIndex( String table, String index, KeySet keys, Iterable<String> columns, ReadOption... options) { return wrap(delegate.readUsingIndex(table, index, keys, columns, options)); }
ResultSet readUsingIndex() { // [START read_context_read_index] ReadContext readContext = dbClient.singleUse(); ResultSet resultSet = readContext.readUsingIndex( "Albums", "AlbumsByAlbumTitle", KeySet.all(), Arrays.asList("AlbumId", "AlbumTitle")); // [END read_context_read_index] return resultSet; }
@Test public void indexEmptyRead() { ResultSet resultSet = client .singleUse(TimestampBound.strong()) .readUsingIndex( TABLE_NAME, INDEX_NAME, KeySet.range(KeyRange.closedOpen(Key.of("v99"), Key.of("z"))), ALL_COLUMNS); assertThat(resultSet.next()).isFalse(); assertThat(resultSet.getType()).isEqualTo(TABLE_TYPE); }
? client .singleUse(TimestampBound.strong()) .readUsingIndex( TABLE_NAME, INDEX_NAME, keySet, ALL_COLUMNS, Options.limit(limit)) : client .singleUse(TimestampBound.strong()) .readUsingIndex(TABLE_NAME, INDEX_NAME, keySet, ALL_COLUMNS); break; case DESC_INDEX: ? client .singleUse(TimestampBound.strong()) .readUsingIndex( TABLE_NAME, DESC_INDEX_NAME, keySet, ALL_COLUMNS, Options.limit(limit)) : client .singleUse(TimestampBound.strong()) .readUsingIndex(TABLE_NAME, DESC_INDEX_NAME, keySet, ALL_COLUMNS); break; case BASE_TABLE:
static void readUsingIndex(DatabaseClient dbClient) { ResultSet resultSet = dbClient .singleUse() .readUsingIndex( "Albums", "AlbumsByAlbumTitle", KeySet.all(), Arrays.asList("AlbumId", "AlbumTitle")); while (resultSet.next()) { System.out.printf("%d %s\n", resultSet.getLong(0), resultSet.getString(1)); } } // [END spanner_read_data_with_index]
static void readStoringIndex(DatabaseClient dbClient) { // We can read MarketingBudget also from the index since it stores a copy of MarketingBudget. ResultSet resultSet = dbClient .singleUse() .readUsingIndex( "Albums", "AlbumsByAlbumTitle2", KeySet.all(), Arrays.asList("AlbumId", "AlbumTitle", "MarketingBudget")); while (resultSet.next()) { System.out.printf( "%d %s %s\n", resultSet.getLong(0), resultSet.getString(1), resultSet.isNull("MarketingBudget") ? "NULL" : resultSet.getLong("MarketingBudget")); } } // [END spanner_read_data_with_storing_index]
@Override public ResultSet readUsingIndex( String s, String s1, KeySet keySet, Iterable<String> iterable, Options.ReadOption... readOptions) { return targetTransactionContext.readUsingIndex(s, s1, keySet, iterable, readOptions); }
@Override public ResultSet readUsingIndex( String s, String s1, KeySet keySet, Iterable<String> iterable, Options.ReadOption... readOptions) { return targetTransactionContext.readUsingIndex(s, s1, keySet, iterable, readOptions); }
@Override public ResultSet readUsingIndex( String table, String index, KeySet keys, Iterable<String> columns, ReadOption... options) { return wrap(delegate.readUsingIndex(table, index, keys, columns, options)); }
private ResultSet executeRead(String tableName, KeySet keys, Iterable<String> columns, SpannerReadOptions options) { long startTime = LOGGER.isDebugEnabled() ? System.currentTimeMillis() : 0; ResultSet resultSet; ReadContext readContext = (options != null && options.getTimestamp() != null) ? getReadContext(options.getTimestamp()) : getReadContext(); if (options == null) { resultSet = getReadContext().read(tableName, keys, columns); } else if (options.getIndex() != null) { resultSet = readContext.readUsingIndex(tableName, options.getIndex(), keys, columns, options.getReadOptions()); } else { resultSet = readContext.read(tableName, keys, columns, options.getReadOptions()); } if (LOGGER.isDebugEnabled()) { StringBuilder logs = logColumns(tableName, keys, columns); logReadOptions(options, logs); LOGGER.debug(logs.toString()); LOGGER.debug("Read elapsed milliseconds: " + (System.currentTimeMillis() - startTime)); } return resultSet; }
resultSet = readContext.readUsingIndex(tableName, options.getIndex(), keys, columns, options.getReadOptions());