Search in sources :

Example 61 with UntypedResultSet

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);
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 62 with UntypedResultSet

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();
    });
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 63 with UntypedResultSet

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();
    });
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) Test(org.junit.Test)

Example 64 with UntypedResultSet

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());
}
Also used : Replica(org.apache.cassandra.locator.Replica) CompressionParams(org.apache.cassandra.schema.CompressionParams) UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) SSTableLoader(org.apache.cassandra.io.sstable.SSTableLoader) TableMetadataRef(org.apache.cassandra.schema.TableMetadataRef) CQLSSTableWriter(org.apache.cassandra.io.sstable.CQLSSTableWriter) OutputHandler(org.apache.cassandra.utils.OutputHandler) File(org.apache.cassandra.io.util.File)

Example 65 with UntypedResultSet

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());
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) Test(org.junit.Test)

Aggregations

UntypedResultSet (org.apache.cassandra.cql3.UntypedResultSet)107 Test (org.junit.Test)35 UUID (java.util.UUID)8 ByteBuffer (java.nio.ByteBuffer)6 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)6 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)6 HashSet (java.util.HashSet)5 Mutation (org.apache.cassandra.db.Mutation)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 HashMap (java.util.HashMap)4 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)4 TableMetadata (org.apache.cassandra.schema.TableMetadata)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)3 ResultMessage (org.apache.cassandra.transport.messages.ResultMessage)3 Predicate (com.google.common.base.Predicate)2 IOException (java.io.IOException)2 InetAddress (java.net.InetAddress)2 ArrayList (java.util.ArrayList)2