public static CqlQuery constructCheckAndSetMultipleQuery(Map<String, Pair<byte[], byte[]>> checkAndSetRequest) { StringBuilder builder = new StringBuilder(); builder.append("BEGIN UNLOGGED BATCH\n"); // Safe, because all updates are on the same partition key // Safe, because ordering does not apply in batches checkAndSetRequest.forEach((columnName, value) -> { byte[] expected = value.getLhSide(); byte[] target = value.getRhSide(); builder.append(constructCheckAndSetQuery(columnName, expected, target)); }); builder.append("APPLY BATCH;"); // This looks awkward. However, we know that all expressions in this String pertain to timestamps and known // table references, hence this is actually safe. Doing this quickly owing to priority. // TODO (jkong): Build up a query by passing around legitimate formats and args. return CqlQuery.builder() .safeQueryFormat(builder.toString()) .build(); }
/** * Returns a list of {@link CellWithTimestamp}s within the given {@code row}, starting at the (column, timestamp) * pair represented by ({@code startColumnInclusive}, {@code startTimestampExclusive}). */ @Override public List<CellWithTimestamp> getTimestampsWithinRow( TableReference tableRef, byte[] row, byte[] startColumnInclusive, long startTimestampExclusive, int limit) { long invertedTimestamp = ~startTimestampExclusive; String selQuery = "SELECT column1, column2 FROM %s WHERE key = %s AND (column1, column2) > (%s, %s) LIMIT %s;"; CqlQuery query = CqlQuery.builder() .safeQueryFormat(selQuery) .addArgs( quotedTableName(tableRef), key(row), column1(startColumnInclusive), column2(invertedTimestamp), limit(limit)) .build(); return executeAndGetCells(query, row, result -> CqlExecutorImpl.getCellFromKeylessRow(result, row)); }
public static CqlQuery constructCheckAndSetMultipleQuery(Map<String, Pair<byte[], byte[]>> checkAndSetRequest) { StringBuilder builder = new StringBuilder(); builder.append("BEGIN UNLOGGED BATCH\n"); // Safe, because all updates are on the same partition key // Safe, because ordering does not apply in batches checkAndSetRequest.forEach((columnName, value) -> { byte[] expected = value.getLhSide(); byte[] target = value.getRhSide(); builder.append(constructCheckAndSetQuery(columnName, expected, target)); }); builder.append("APPLY BATCH;"); // This looks awkward. However, we know that all expressions in this String pertain to timestamps and known // table references, hence this is actually safe. Doing this quickly owing to priority. // TODO (jkong): Build up a query by passing around legitimate formats and args. return CqlQuery.builder() .safeQueryFormat(builder.toString()) .build(); }
private void putDummyValueAtCellAndTimestamp( TableReference tableReference, Cell cell, long atlasTimestamp, long cassandraTimestamp) throws TException { CassandraKeyValueServiceImpl ckvs = (CassandraKeyValueServiceImpl) keyValueService; ckvs.getClientPool().runWithRetry(input -> { CqlQuery cqlQuery = CqlQuery.builder() .safeQueryFormat("INSERT INTO \"%s\".\"%s\" (key, column1, column2, value)" + " VALUES (%s, %s, %s, %s) USING TIMESTAMP %s;") .addArgs( SafeArg.of("keyspace", CASSANDRA.getConfig().getKeyspaceOrThrow()), LoggingArgs.internalTableName(tableReference), UnsafeArg.of("row", convertBytesToHexString(cell.getRowName())), UnsafeArg.of("column", convertBytesToHexString(cell.getColumnName())), SafeArg.of("atlasTimestamp", ~atlasTimestamp), UnsafeArg.of("value", convertBytesToHexString(PtBytes.toBytes("testtesttest"))), SafeArg.of("cassandraTimestamp", cassandraTimestamp)) .build(); return input.execute_cql3_query( cqlQuery, Compression.NONE, ConsistencyLevel.QUORUM); }); }
.buildInternal(); return CqlQuery.builder() .safeQueryFormat(query + " AND id = '%s'") .addArgs(SafeArg.of("cfId", getUuidForTable(tableRef)))
/** * Returns a list of {@link CellWithTimestamp}s within the given {@code row}, starting at the (column, timestamp) * pair represented by ({@code startColumnInclusive}, {@code startTimestampExclusive}). */ @Override public List<CellWithTimestamp> getTimestampsWithinRow( TableReference tableRef, byte[] row, byte[] startColumnInclusive, long startTimestampExclusive, int limit) { long invertedTimestamp = ~startTimestampExclusive; String selQuery = "SELECT column1, column2 FROM %s WHERE key = %s AND (column1, column2) > (%s, %s) LIMIT %s;"; CqlQuery query = CqlQuery.builder() .safeQueryFormat(selQuery) .addArgs( quotedTableName(tableRef), key(row), column1(startColumnInclusive), column2(invertedTimestamp), limit(limit)) .build(); return executeAndGetCells(query, row, result -> CqlExecutorImpl.getCellFromKeylessRow(result, row)); }
.buildInternal(); return CqlQuery.builder() .safeQueryFormat(query + " AND id = '%s'") .addArgs(SafeArg.of("cfId", getUuidForTable(tableRef)))