use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.
the class LocalSessions method loadUnsafe.
/**
* Loads a session directly from the table. Should be used for testing only
*/
@VisibleForTesting
LocalSession loadUnsafe(UUID sessionId) {
String query = "SELECT * FROM %s.%s WHERE parent_id=?";
UntypedResultSet result = QueryProcessor.executeInternal(String.format(query, keyspace, table), sessionId);
if (result.isEmpty())
return null;
UntypedResultSet.Row row = result.one();
return load(row);
}
use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.
the class VirtualTableFromInternode method readCommandAccessVirtualTableMultiplePartition.
@Test
public void readCommandAccessVirtualTableMultiplePartition() {
CLUSTER.get(1).runOnInstance(() -> {
boolean didWork = false;
for (InetAddressAndPort address : Gossiper.instance.getLiveMembers()) {
didWork = true;
UntypedResultSet rs = QueryProcessor.executeAsync(address, "SELECT * FROM system_views.settings WHERE name IN (?, ?)", "rpc_address", "broadcast_address").syncUninterruptibly().getNow();
assertThat(rs.isEmpty()).isFalse();
Set<String> columns = new HashSet<>();
for (UntypedResultSet.Row row : rs) {
columns.add(row.getString("name"));
assertThat(row.getString("value")).isEqualTo(address.getAddress().getHostAddress());
}
assertThat(columns).isEqualTo(ImmutableSet.of("rpc_address", "broadcast_address"));
}
assertThat(didWork).isTrue();
});
}
use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.
the class VirtualTableFromInternode method readCommandAccessVirtualTableSinglePartition.
@Test
public void readCommandAccessVirtualTableSinglePartition() {
CLUSTER.get(1).runOnInstance(() -> {
boolean didWork = false;
for (InetAddressAndPort address : Gossiper.instance.getLiveMembers()) {
didWork = true;
UntypedResultSet rs = QueryProcessor.executeAsync(address, "SELECT * FROM system_views.settings WHERE name=?", "rpc_address").syncUninterruptibly().getNow();
assertThat(rs.isEmpty()).isFalse();
assertThat(rs.one().getString("value")).isEqualTo(address.getAddress().getHostAddress());
}
assertThat(didWork).isTrue();
});
}
use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.
the class LongStreamingTest method testStream.
private void testStream(boolean useSstableCompression) throws InvalidRequestException, IOException, ExecutionException, InterruptedException {
String KS = useSstableCompression ? "sstable_compression_ks" : "stream_compression_ks";
String TABLE = "table1";
File tempdir = new File(Files.createTempDir());
File dataDir = new File(tempdir.absolutePath() + File.pathSeparator() + KS + File.pathSeparator() + TABLE);
assert dataDir.tryCreateDirectories();
String schema = "CREATE TABLE " + KS + '.' + TABLE + " (" + " k int PRIMARY KEY," + " v1 text," + " v2 int" + ") with compression = " + (useSstableCompression ? "{'class': 'LZ4Compressor'};" : "{};");
String insert = "INSERT INTO " + KS + '.' + TABLE + " (k, v1, v2) VALUES (?, ?, ?)";
CQLSSTableWriter writer = CQLSSTableWriter.builder().sorted().inDirectory(dataDir).forTable(schema).using(insert).build();
CompressionParams compressionParams = Keyspace.open(KS).getColumnFamilyStore(TABLE).metadata().params.compression;
Assert.assertEquals(useSstableCompression, compressionParams.isEnabled());
long start = nanoTime();
for (int i = 0; i < 10_000_000; i++) writer.addRow(i, "test1", 24);
writer.close();
System.err.println(String.format("Writer finished after %d seconds....", TimeUnit.NANOSECONDS.toSeconds(nanoTime() - start)));
File[] dataFiles = dataDir.tryList((dir, name) -> name.endsWith("-Data.db"));
long dataSizeInBytes = 0l;
for (File file : dataFiles) {
System.err.println("File : " + file.absolutePath());
dataSizeInBytes += file.length();
}
SSTableLoader loader = new SSTableLoader(dataDir, new SSTableLoader.Client() {
private String ks;
public void init(String keyspace) {
for (Replica range : StorageService.instance.getLocalReplicas(KS)) addRangeForEndpoint(range.range(), FBUtilities.getBroadcastAddressAndPort());
this.ks = keyspace;
}
public TableMetadataRef getTableMetadata(String cfName) {
return Schema.instance.getTableMetadataRef(ks, cfName);
}
}, new OutputHandler.SystemOutput(false, false));
start = nanoTime();
loader.stream().get();
long millis = TimeUnit.NANOSECONDS.toMillis(nanoTime() - start);
System.err.println(String.format("Finished Streaming in %.2f seconds: %.2f MiBsec", millis / 1000d, (dataSizeInBytes / (1 << 20) / (millis / 1000d)) * 8));
// Stream again
loader = new SSTableLoader(dataDir, new SSTableLoader.Client() {
private String ks;
public void init(String keyspace) {
for (Replica range : StorageService.instance.getLocalReplicas(KS)) addRangeForEndpoint(range.range(), FBUtilities.getBroadcastAddressAndPort());
this.ks = keyspace;
}
public TableMetadataRef getTableMetadata(String cfName) {
return Schema.instance.getTableMetadataRef(ks, cfName);
}
}, new OutputHandler.SystemOutput(false, false));
start = nanoTime();
loader.stream().get();
millis = TimeUnit.NANOSECONDS.toMillis(nanoTime() - start);
System.err.println(String.format("Finished Streaming in %.2f seconds: %.2f MiBsec", millis / 1000d, (dataSizeInBytes / (1 << 20) / (millis / 1000d)) * 8));
// Compact them both
start = nanoTime();
Keyspace.open(KS).getColumnFamilyStore(TABLE).forceMajorCompaction();
millis = TimeUnit.NANOSECONDS.toMillis(nanoTime() - start);
System.err.println(String.format("Finished Compacting in %.2f seconds: %.2f MiBsec", millis / 1000d, (dataSizeInBytes * 2 / (1 << 20) / (millis / 1000d)) * 8));
UntypedResultSet rs = QueryProcessor.executeInternal("SELECT * FROM " + KS + '.' + TABLE + " limit 100;");
assertEquals(100, rs.size());
}
use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.
the class SinglePartitionReadCommandCQLTest method partitionLevelDeletionTest.
@Test
public void partitionLevelDeletionTest() throws Throwable {
createTable("CREATE TABLE %s (bucket_id TEXT,name TEXT,data TEXT,PRIMARY KEY (bucket_id, name))");
execute("insert into %s (bucket_id, name, data) values ('8772618c9009cf8f5a5e0c18', 'test', 'hello')");
getCurrentColumnFamilyStore().forceBlockingFlush();
execute("insert into %s (bucket_id, name, data) values ('8772618c9009cf8f5a5e0c19', 'test2', 'hello');");
execute("delete from %s where bucket_id = '8772618c9009cf8f5a5e0c18'");
getCurrentColumnFamilyStore().forceBlockingFlush();
UntypedResultSet res = execute("select * from %s where bucket_id = '8772618c9009cf8f5a5e0c18' and name = 'test'");
assertTrue(res.isEmpty());
}
Aggregations