@Override public void visit(Map<ByteBuffer, List<ColumnOrSuperColumn>> results) { extractor.extractResults(results, startTs, ColumnSelection.all()); } }
public TableMigratorBuilder() { srcTable = null; partitions = 8; partitioners = ImmutableList.of(); readBatchSize = 1000; executor = null; checkpointer = null; progress = new NullTaskProgress(); columnSelection = ColumnSelection.all(); rangeMigrator = null; }
public static ColumnSelection valueOf(String serialized) { Set<byte[]> columns = Sets.newTreeSet(UnsignedBytes.lexicographicalComparator()); for (String columnString : serialized.split("\\s*,\\s*")) { String trimmedColumnString = columnString.trim(); if (trimmedColumnString.isEmpty()) { continue; } byte[] column = PtBytes.decodeBase64(trimmedColumnString); assert !columns.contains(column); columns.add(column); } if (columns.isEmpty()) { return all(); } return ColumnSelection.create(columns); }
private byte[] getRowsForCell(Cell cell) { return keyValueService.getRows(TEST_TABLE, ImmutableSet.of(cell.getRowName()), ColumnSelection.all(), TEST_TIMESTAMP + 3) .get(cell).getContents(); }
public static ColumnSelection extractColumnSelection(RangeRequest rangeRequest) { if (rangeRequest.getColumnNames().isEmpty()) { return ColumnSelection.all(); } return ColumnSelection.create(rangeRequest.getColumnNames()); }
@Override public Map<Cell, Value> apply(CassandraClient client) throws Exception { // We want to get all the columns in the row so set start and end to empty. SlicePredicate pred = SlicePredicates.create(Range.ALL, Limit.NO_LIMIT); List<ByteBuffer> rowNames = wrap(batch); Map<ByteBuffer, List<ColumnOrSuperColumn>> results = wrappingQueryRunner.multiget( "getRows", client, tableRef, rowNames, pred, readConsistency); Map<Cell, Value> ret = Maps.newHashMapWithExpectedSize(batch.size()); new ValueExtractor(metricsManager, ret) .extractResults(results, startTs, ColumnSelection.all()); return ret; }
private Map<RangeRequest, TokenBackedBasicResultsPage<RowResult<Value>, byte[]>> getFirstPagesFromDb( TableReference tableRef, List<RangeRequest> requests, long timestamp, String query, Object[] args) { SortedSetMultimap<Integer, byte[]> rowsForBatches = getRowsForBatches(connectionSupplier, query, args); Map<Cell, Value> cells = kvs.getRows(tableRef, rowsForBatches.values(), ColumnSelection.all(), timestamp); NavigableMap<byte[], SortedMap<byte[], Value>> cellsByRow = Cells.breakCellsUpByRow(cells); log.info("getRange actualRowsReturned: {}", cellsByRow.size()); return breakUpByBatch(requests, rowsForBatches, cellsByRow); }
@Benchmark @Threads(1) @Warmup(time = 6, timeUnit = TimeUnit.SECONDS) @Measurement(time = 60, timeUnit = TimeUnit.SECONDS) public Object getAllColumnsImplicitly(ModeratelyWideRowTable table) throws UnsupportedEncodingException { Map<Cell, Value> result = table.getKvs().getRows( table.getTableRef(), Collections.singleton(Tables.ROW_BYTES.array()), ColumnSelection.all(), Long.MAX_VALUE); Preconditions.checkState(result.size() == table.getNumCols(), "Should be %s columns, but were: %s", table.getNumCols(), result.size()); return result; }
@Override public TableRowSelection deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { JsonNode node = jp.readValueAsTree(); String tableName = node.get("table").textValue(); TableMetadata metadata = metadataCache.getMetadata(tableName); Iterable<byte[]> rows = AtlasDeserializers.deserializeRows(metadata.getRowMetadata(), node.get("rows")); Iterable<byte[]> columns = AtlasDeserializers.deserializeNamedCols(metadata.getColumns(), node.get("cols")); if (Iterables.isEmpty(columns)) { return new TableRowSelection(tableName, rows, ColumnSelection.all()); } else { return new TableRowSelection(tableName, rows, ColumnSelection.create(columns)); } } }
private RowResult<byte[]> readRow(byte[] defaultRow) { Transaction readTransaction = txManager.createNewTransaction(); SortedMap<byte[], RowResult<byte[]>> allRows = readTransaction.getRows(TABLE, ImmutableSet.of(defaultRow), ColumnSelection.all()); return allRows.get(defaultRow); }
@Benchmark @Threads(1) @Warmup(time = 10, timeUnit = TimeUnit.SECONDS) @Measurement(time = 65, timeUnit = TimeUnit.SECONDS) public Object getAllColumnsImplicitly(ModeratelyWideRowTable table) { return table.getTransactionManager().runTaskThrowOnConflict(txn -> { SortedMap<byte[], RowResult<byte[]>> result = txn.getRows(table.getTableRef(), Collections.singleton(Tables.ROW_BYTES.array()), ColumnSelection.all()); int count = Iterables.getOnlyElement(result.values()).getColumns().size(); Preconditions.checkState(count == table.getNumCols(), "Should be %s columns, but were: %s", table.getNumCols(), count); return result; }); }
@Override public SortedMap<byte[], RowResult<byte[]>> getRowsIgnoringLocalWrites( TableReference tableRef, Iterable<byte[]> rows) { checkGetPreconditions(tableRef); if (Iterables.isEmpty(rows)) { return AbstractTransaction.EMPTY_SORTED_ROWS; } hasReads = true; Map<Cell, Value> rawResults = Maps.newHashMap(keyValueService.getRows(tableRef, rows, ColumnSelection.all(), getStartTimestamp())); validatePreCommitRequirementsOnReadIfNecessary(tableRef, getStartTimestamp()); return filterRowResults(tableRef, rawResults, ImmutableMap.builderWithExpectedSize(rawResults.size())); }
@Test public void getRows() throws Exception { ImmutableList<byte[]> rows = ImmutableList.of(ROW_NAME); Map<Cell, Value> expectedResult = ImmutableMap.of(); when(delegate.getRows(TABLE_REF, rows, ColumnSelection.all(), TIMESTAMP)).thenReturn(expectedResult); Map<Cell, Value> result = kvs.getRows(TABLE_REF, rows, ColumnSelection.all(), TIMESTAMP); assertThat(result, equalTo(expectedResult)); checkSpan("atlasdb-kvs.getRows({table}, 1 rows, ts 1)"); verify(delegate).getRows(TABLE_REF, rows, ColumnSelection.all(), TIMESTAMP); verifyNoMoreInteractions(delegate); }
@Benchmark @Threads(1) @Warmup(time = 5) @Measurement(time = 40) public Object getManyRowsWithGetRows(ConsecutiveNarrowTable.CleanNarrowTable table) { Map<Cell, Value> result = table.getKvs().getRows( table.getTableRef(), table.getRowList(), ColumnSelection.all(), Long.MAX_VALUE ); Preconditions.checkState(result.size() == table.getRowList().size(), "Should be %s rows, but were: %s", table.getRowList().size(), result.size()); return result; } }
public CassandraRangePagingIterable( RowGetter rowGetter, SlicePredicate slicePredicate, ColumnGetter columnGetter, RangeRequest rangeRequest, Supplier<ResultsExtractor<T>> resultsExtractor, long timestamp) { this.rowGetter = rowGetter; this.slicePredicate = slicePredicate; this.columnGetter = columnGetter; this.rangeRequest = rangeRequest; this.resultsExtractor = resultsExtractor; this.timestamp = timestamp; batchHint = rangeRequest.getBatchHint() == null ? 100 : rangeRequest.getBatchHint(); selection = rangeRequest.getColumnNames().isEmpty() ? ColumnSelection.all() : ColumnSelection.create(rangeRequest.getColumnNames()); }
@Test public void canGetRows() { Map<Cell, Value> row = getTestKvs() .getRows(TEST_TABLE, ImmutableList.of(FIRST_ROW), ColumnSelection.all(), Long.MAX_VALUE); assertThat(row.entrySet()).hasSameElementsAs(expectedRowEntries); }
private RangeRequest computeRangeRequestForRows(byte[] startRowInclusive, byte[] endRowInclusive) { return RangeRequest.builder() .startRowInclusive(startRowInclusive) .endRowExclusive(RangeRequests.nextLexicographicName(endRowInclusive)) .retainColumns(ColumnSelection.all()) .build(); }
@Test public void getRowsThrows() { assertThrowsAtlasDbDependencyExceptionAndDoesNotChangeCassandraSchema(() -> getTestKvs().getRows(TEST_TABLE, ImmutableList.of(FIRST_ROW), ColumnSelection.all(), Long.MAX_VALUE)); }
@Test public void testGetRowsAllColumns() { putTestDataForSingleTimestamp(); Map<Cell, Value> values = keyValueService.getRows(TEST_TABLE, Arrays.asList(row(1), row(2)), ColumnSelection.all(), TEST_TIMESTAMP + 1); assertEquals(4, values.size()); assertNull(values.get(Cell.create(row(1), column(1)))); assertArrayEquals(val(1, 0), values.get(Cell.create(row(1), column(0))).getContents()); assertArrayEquals(val(1, 2), values.get(Cell.create(row(1), column(2))).getContents()); assertArrayEquals(val(2, 1), values.get(Cell.create(row(2), column(1))).getContents()); assertArrayEquals(val(2, 2), values.get(Cell.create(row(2), column(2))).getContents()); }
/** * Deletes the entire row of the Sweepable Timestamps table. * @param shardStrategy desired shard and strategy * @param partitionCoarse coarse partition for which the row should be deleted */ void deleteRow(ShardAndStrategy shardStrategy, long partitionCoarse) { byte[] rowBytes = computeRowBytes(shardStrategy, partitionCoarse); RangeRequest request = RangeRequest.builder() .startRowInclusive(rowBytes) .endRowExclusive(RangeRequests.nextLexicographicName(rowBytes)) .retainColumns(ColumnSelection.all()) .build(); deleteRange(request); } }