private List<CellTsPairInfo> loadNextPage() { try (ConnectionSupplier conns = new ConnectionSupplier(connectionPool); AgnosticLightResultSet resultSet = selectNextPage(conns)) { List<CellTsPairInfo> ret = new ArrayList<>(); for (AgnosticLightResultRow row : resultSet) { byte[] rowName = row.getBytes("row_name"); byte[] colName = row.getBytes("col_name"); if (request.shouldCheckIfLatestValueIsEmpty()) { long[] sortedTimestamps = castAndSortTimestamps((Object[]) row.getArray("timestamps")); boolean isLatestValEmpty = row.getBoolean("latest_val_empty"); for (int i = 0; i < sortedTimestamps.length - 1; ++i) { ret.add(new CellTsPairInfo(rowName, colName, sortedTimestamps[i], false)); } // For the maximum timestamp, we know whether its value is empty or not, // so we handle it separately ret.add(new CellTsPairInfo( rowName, colName, sortedTimestamps[sortedTimestamps.length - 1], isLatestValEmpty)); } else { long ts = row.getLong("ts"); ret.add(new CellTsPairInfo(rowName, colName, ts, false)); } } return ret; } }
private List<CellTsPairInfo> loadPage(boolean singleRow) { FullQuery query = getQuery(singleRow); try (ConnectionSupplier conns = new ConnectionSupplier(connectionPool); AgnosticLightResultSet resultSet = executeQuery(conns.get(), query)) { List<CellTsPairInfo> ret = new ArrayList<>(); for (AgnosticLightResultRow row : resultSet) { ret.add(new CellTsPairInfo( row.getBytes("row_name"), row.getBytes("col_name"), row.getLong("ts"), request.shouldCheckIfLatestValueIsEmpty() && row.getInteger("empty_val") == 1)); } return ret; } }
@SuppressWarnings("deprecation") private List<RawSqlRow> loadSqlRows(ConnectionSupplier conns) { List<RawSqlRow> sqlRows = new ArrayList<>(); try (ClosableIterator<AgnosticLightResultRow> rangeResults = selectNextPage(conns)) { while (rangeResults.hasNext()) { AgnosticLightResultRow row = rangeResults.next(); Cell cell = Cell.create(row.getBytes("row_name"), row.getBytes("col_name")); long ts = row.getLong("ts"); byte[] val = row.getBytes("val"); Long overflowId = haveOverflowValues ? row.getLongObject("overflow") : null; sqlRows.add(new RawSqlRow(cell, ts, val, overflowId)); } } return sqlRows; }
private void store(AgnosticLightResultRow cellResult) { byte[] newRow = cellResult.getBytes(DbKvs.ROW); currentCol = cellResult.getBytes(DbKvs.COL); long timestamp = cellResult.getLong(DbKvs.TIMESTAMP); if (!Arrays.equals(currentRow, newRow)) { flushRowBuffer(); currentRow = newRow; } Cell cell = Cell.create(currentRow, currentCol); rowBuffer.put(cell, timestamp); }
private Map<Sha256Hash, Integer> getColumnCountsUnordered(TableReference tableRef, List<byte[]> rowList, ColumnRangeSelection columnRangeSelection, long timestamp) { return runRead(tableRef, dbReadTable -> { Map<Sha256Hash, Integer> counts = new HashMap<>(rowList.size()); try (ClosableIterator<AgnosticLightResultRow> iter = dbReadTable.getRowsColumnRangeCounts(rowList, timestamp, columnRangeSelection)) { while (iter.hasNext()) { AgnosticLightResultRow row = iter.next(); Sha256Hash rowHash = Sha256Hash.computeHash(row.getBytes(ROW)); counts.put(rowHash, row.getInteger("column_count")); } } return counts; }); }
private boolean finishCellIfNoRowsYet() { if (entries.size() == 0) { flushRowBuffer(); while (currentCellHasEntriesLeft()) { long timestamp = iterator.next().getLong(DbKvs.TIMESTAMP); entries.put(Cell.create(currentRow, currentCol), timestamp); } return true; } return false; }
private static Multimap<Cell, Long> doGetAllTimestamps(DbReadTable table, Iterable<Cell> cells, long timestamp) { try (ClosableIterator<AgnosticLightResultRow> iter = table.getAllCells(cells, timestamp, false)) { Multimap<Cell, Long> results = ArrayListMultimap.create(); while (iter.hasNext()) { AgnosticLightResultRow row = iter.next(); Cell cell = Cell.create(row.getBytes(ROW), row.getBytes(COL)); long ts = row.getLong(TIMESTAMP); results.put(cell, ts); } return results; } }
private boolean finishedSkipping(Token oldToken, AgnosticLightResultRow next) { return !Arrays.equals(next.getBytes(DbKvs.ROW), oldToken.row()) || compareColumns(oldToken, next) > 0; }
private Map<Sha256Hash, Integer> getColumnCountsUnordered(TableReference tableRef, List<byte[]> rowList, ColumnRangeSelection columnRangeSelection, long timestamp) { return runRead(tableRef, dbReadTable -> { Map<Sha256Hash, Integer> counts = new HashMap<>(rowList.size()); try (ClosableIterator<AgnosticLightResultRow> iter = dbReadTable.getRowsColumnRangeCounts(rowList, timestamp, columnRangeSelection)) { while (iter.hasNext()) { AgnosticLightResultRow row = iter.next(); Sha256Hash rowHash = Sha256Hash.computeHash(row.getBytes(ROW)); counts.put(rowHash, row.getInteger("column_count")); } } return counts; }); }
private boolean finishCellIfNoRowsYet() { if (entries.size() == 0) { flushRowBuffer(); while (currentCellHasEntriesLeft()) { long timestamp = iterator.next().getLong(DbKvs.TIMESTAMP); entries.put(Cell.create(currentRow, currentCol), timestamp); } return true; } return false; }
while (iter.hasNext()) { AgnosticLightResultRow row = iter.next(); Cell cell = Cell.create(row.getBytes(ROW), row.getBytes(COL)); Long overflowId = hasOverflow ? row.getLongObject("overflow") : null; if (overflowId == null) { Value value = Value.create(row.getBytes(VAL), row.getLong(TIMESTAMP)); Value oldValue = results.put(cell, value); if (oldValue != null && oldValue.getTimestamp() > value.getTimestamp()) { OverflowValue ov = ImmutableOverflowValue.of(row.getLong(TIMESTAMP), overflowId); OverflowValue oldOv = overflowResults.put(cell, ov); if (oldOv != null && oldOv.ts() > ov.ts()) {
private static Map<Cell, Long> doGetLatestTimestamps(DbReadTable table, Map<Cell, Long> timestampByCell) { try (ClosableIterator<AgnosticLightResultRow> iter = table.getLatestCells(timestampByCell, false)) { Map<Cell, Long> results = Maps.newHashMap(); while (iter.hasNext()) { AgnosticLightResultRow row = iter.next(); Cell cell = Cell.create(row.getBytes(ROW), row.getBytes(COL)); long ts = row.getLong(TIMESTAMP); Long oldTs = results.put(cell, ts); if (oldTs != null && oldTs > ts) { results.put(cell, oldTs); } } return results; } }
private List<CellTsPairInfo> loadNextPage() { try (ConnectionSupplier conns = new ConnectionSupplier(connectionPool); AgnosticLightResultSet resultSet = selectNextPage(conns)) { List<CellTsPairInfo> ret = new ArrayList<>(); for (AgnosticLightResultRow row : resultSet) { byte[] rowName = row.getBytes("row_name"); byte[] colName = row.getBytes("col_name"); if (request.shouldCheckIfLatestValueIsEmpty()) { long[] sortedTimestamps = castAndSortTimestamps((Object[]) row.getArray("timestamps")); boolean isLatestValEmpty = row.getBoolean("latest_val_empty"); for (int i = 0; i < sortedTimestamps.length - 1; ++i) { ret.add(new CellTsPairInfo(rowName, colName, sortedTimestamps[i], false)); } // For the maximum timestamp, we know whether its value is empty or not, // so we handle it separately ret.add(new CellTsPairInfo( rowName, colName, sortedTimestamps[sortedTimestamps.length - 1], isLatestValEmpty)); } else { long ts = row.getLong("ts"); ret.add(new CellTsPairInfo(rowName, colName, ts, false)); } } return ret; } }
private List<CellTsPairInfo> loadPage(boolean singleRow) { FullQuery query = getQuery(singleRow); try (ConnectionSupplier conns = new ConnectionSupplier(connectionPool); AgnosticLightResultSet resultSet = executeQuery(conns.get(), query)) { List<CellTsPairInfo> ret = new ArrayList<>(); for (AgnosticLightResultRow row : resultSet) { ret.add(new CellTsPairInfo( row.getBytes("row_name"), row.getBytes("col_name"), row.getLong("ts"), request.shouldCheckIfLatestValueIsEmpty() && row.getInteger("empty_val") == 1)); } return ret; } }
private static int compareColumns(Token oldToken, AgnosticLightResultRow nextResult) { return UnsignedBytes.lexicographicalComparator().compare(nextResult.getBytes(DbKvs.COL), oldToken.col()); }
while (iter.hasNext()) { AgnosticLightResultRow row = iter.next(); Cell cell = Cell.create(row.getBytes(ROW), row.getBytes(COL)); Sha256Hash rowHash = Sha256Hash.computeHash(cell.getRowName()); cellsByRow.get(rowHash).add(cell); Long overflowId = hasOverflow ? row.getLongObject("overflow") : null; if (overflowId == null) { Value value = Value.create(row.getBytes(VAL), row.getLong(TIMESTAMP)); Value oldValue = values.put(cell, value); if (oldValue != null && oldValue.getTimestamp() > value.getTimestamp()) { OverflowValue ov = ImmutableOverflowValue.of(row.getLong(TIMESTAMP), overflowId); OverflowValue oldOv = overflowValues.put(cell, ov); if (oldOv != null && oldOv.ts() > ov.ts()) {
@Override public Map<Long, byte[]> loadOverflowValues(ConnectionSupplier conns, TableReference tableRef, Collection<Long> overflowIds) { if (overflowIds.isEmpty()) { return Collections.emptyMap(); } else { Map<Long, byte[]> ret = Maps.newHashMapWithExpectedSize(overflowIds.size()); for (FullQuery query : getOverflowQueries(conns, tableRef, overflowIds)) { try (ClosableIterator<AgnosticLightResultRow> overflowIter = select(conns, query)) { while (overflowIter.hasNext()) { AgnosticLightResultRow row = overflowIter.next(); // QA-94468 LONG RAW typed columns ("val" in this case) must be retrieved first from the result // set. See https://docs.oracle.com/cd/B19306_01/java.102/b14355/jstreams.htm#i1007581 byte[] val = row.getBytes("val"); long id = row.getLong("id"); ret.put(id, val); } } } return ret; } }
private List<byte[]> getCurrentValue( PalantirSqlConnection connection, Cell cell, long ts, String prefixedTableName) { String sqlString = "/* SELECT (" + prefixedTableName + ") */" + " SELECT val FROM " + prefixedTableName + " WHERE row_name = ?" + " AND col_name = ?" + " AND ts = ?"; try (AgnosticLightResultSet results = connection.selectLightResultSetUnregisteredQuery( sqlString, cell.getRowName(), cell.getColumnName(), ts)) { List<byte[]> actualValues = Lists.newArrayList(); results.forEach(row -> actualValues.add(row.getBytes(DbKvs.VAL))); return actualValues; } } }
@SuppressWarnings("deprecation") private List<RawSqlRow> loadSqlRows(ConnectionSupplier conns) { List<RawSqlRow> sqlRows = new ArrayList<>(); try (ClosableIterator<AgnosticLightResultRow> rangeResults = selectNextPage(conns)) { while (rangeResults.hasNext()) { AgnosticLightResultRow row = rangeResults.next(); Cell cell = Cell.create(row.getBytes("row_name"), row.getBytes("col_name")); long ts = row.getLong("ts"); byte[] val = row.getBytes("val"); Long overflowId = haveOverflowValues ? row.getLongObject("overflow") : null; sqlRows.add(new RawSqlRow(cell, ts, val, overflowId)); } } return sqlRows; }