Search in sources :

Example 51 with UntypedResultSet

use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.

the class SchemaKeyspaceTest method checkInverses.

private static void checkInverses(TableMetadata metadata) throws Exception {
    KeyspaceMetadata keyspace = Schema.instance.getKeyspaceMetadata(metadata.keyspace);
    // Test schema conversion
    Mutation rm = SchemaKeyspace.makeCreateTableMutation(keyspace, metadata, FBUtilities.timestampMicros()).build();
    PartitionUpdate serializedCf = rm.getPartitionUpdate(Schema.instance.getTableMetadata(SchemaConstants.SCHEMA_KEYSPACE_NAME, SchemaKeyspaceTables.TABLES));
    PartitionUpdate serializedCD = rm.getPartitionUpdate(Schema.instance.getTableMetadata(SchemaConstants.SCHEMA_KEYSPACE_NAME, SchemaKeyspaceTables.COLUMNS));
    UntypedResultSet.Row tableRow = QueryProcessor.resultify(String.format("SELECT * FROM %s.%s", SchemaConstants.SCHEMA_KEYSPACE_NAME, SchemaKeyspaceTables.TABLES), UnfilteredRowIterators.filter(serializedCf.unfilteredIterator(), FBUtilities.nowInSeconds())).one();
    TableParams params = SchemaKeyspace.createTableParamsFromRow(tableRow);
    UntypedResultSet columnsRows = QueryProcessor.resultify(String.format("SELECT * FROM %s.%s", SchemaConstants.SCHEMA_KEYSPACE_NAME, SchemaKeyspaceTables.COLUMNS), UnfilteredRowIterators.filter(serializedCD.unfilteredIterator(), FBUtilities.nowInSeconds()));
    Set<ColumnMetadata> columns = new HashSet<>();
    for (UntypedResultSet.Row row : columnsRows) columns.add(SchemaKeyspace.createColumnFromRow(row, Types.none()));
    assertEquals(metadata.params, params);
    assertEquals(new HashSet<>(metadata.columns()), columns);
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) Mutation(org.apache.cassandra.db.Mutation) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate) HashSet(java.util.HashSet)

Example 52 with UntypedResultSet

use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.

the class SASIIndexTest method testClusteringIndexes.

public void testClusteringIndexes(boolean forceFlush) {
    ColumnFamilyStore store = Keyspace.open(KS_NAME).getColumnFamilyStore(CLUSTERING_CF_NAME_1);
    executeCQL(CLUSTERING_CF_NAME_1, "INSERT INTO %s.%s (name, nickname, location, age, height, score) VALUES (?, ?, ?, ?, ?, ?)", "Pavel", "xedin", "US", 27, 183, 1.0);
    executeCQL(CLUSTERING_CF_NAME_1, "INSERT INTO %s.%s (name, nickname, location, age, height, score) VALUES (?, ?, ?, ?, ?, ?)", "Pavel", "xedin", "BY", 28, 182, 2.0);
    executeCQL(CLUSTERING_CF_NAME_1, "INSERT INTO %s.%s (name, nickname, location, age, height, score) VALUES (?, ?, ?, ?, ?, ?)", "Jordan", "jrwest", "US", 27, 182, 1.0);
    if (forceFlush)
        store.forceBlockingFlush();
    UntypedResultSet results;
    results = executeCQL(CLUSTERING_CF_NAME_1, "SELECT * FROM %s.%s WHERE location = ? ALLOW FILTERING", "US");
    Assert.assertNotNull(results);
    Assert.assertEquals(2, results.size());
    results = executeCQL(CLUSTERING_CF_NAME_1, "SELECT * FROM %s.%s WHERE age >= ? AND height = ? ALLOW FILTERING", 27, 182);
    Assert.assertNotNull(results);
    Assert.assertEquals(2, results.size());
    results = executeCQL(CLUSTERING_CF_NAME_1, "SELECT * FROM %s.%s WHERE age = ? AND height = ? ALLOW FILTERING", 28, 182);
    Assert.assertNotNull(results);
    Assert.assertEquals(1, results.size());
    results = executeCQL(CLUSTERING_CF_NAME_1, "SELECT * FROM %s.%s WHERE age >= ? AND height = ? AND score >= ? ALLOW FILTERING", 27, 182, 1.0);
    Assert.assertNotNull(results);
    Assert.assertEquals(2, results.size());
    results = executeCQL(CLUSTERING_CF_NAME_1, "SELECT * FROM %s.%s WHERE age >= ? AND height = ? AND score = ? ALLOW FILTERING", 27, 182, 1.0);
    Assert.assertNotNull(results);
    Assert.assertEquals(1, results.size());
    results = executeCQL(CLUSTERING_CF_NAME_1, "SELECT * FROM %s.%s WHERE location = ? AND age >= ? ALLOW FILTERING", "US", 27);
    Assert.assertNotNull(results);
    Assert.assertEquals(2, results.size());
    results = executeCQL(CLUSTERING_CF_NAME_1, "SELECT * FROM %s.%s WHERE location = ? ALLOW FILTERING", "BY");
    Assert.assertNotNull(results);
    Assert.assertEquals(1, results.size());
    results = executeCQL(CLUSTERING_CF_NAME_1, "SELECT * FROM %s.%s WHERE location LIKE 'U%%' ALLOW FILTERING");
    Assert.assertNotNull(results);
    Assert.assertEquals(2, results.size());
    results = executeCQL(CLUSTERING_CF_NAME_1, "SELECT * FROM %s.%s WHERE location LIKE 'U%%' AND height >= 183 ALLOW FILTERING");
    Assert.assertNotNull(results);
    Assert.assertEquals(1, results.size());
    results = executeCQL(CLUSTERING_CF_NAME_1, "SELECT * FROM %s.%s WHERE location LIKE 'US%%' ALLOW FILTERING");
    Assert.assertNotNull(results);
    Assert.assertEquals(2, results.size());
    results = executeCQL(CLUSTERING_CF_NAME_1, "SELECT * FROM %s.%s WHERE location LIKE 'US' ALLOW FILTERING");
    Assert.assertNotNull(results);
    Assert.assertEquals(2, results.size());
    try {
        executeCQL(CLUSTERING_CF_NAME_1, "SELECT * FROM %s.%s WHERE location LIKE '%%U' ALLOW FILTERING");
        Assert.fail();
    } catch (InvalidRequestException e) {
        Assert.assertTrue(e.getMessage().contains("only supported"));
    // expected
    }
    try {
        executeCQL(CLUSTERING_CF_NAME_1, "SELECT * FROM %s.%s WHERE location LIKE '%%' ALLOW FILTERING");
        Assert.fail();
    } catch (InvalidRequestException e) {
        Assert.assertTrue(e.getMessage().contains("empty"));
    // expected
    }
    try {
        executeCQL(CLUSTERING_CF_NAME_1, "SELECT * FROM %s.%s WHERE location LIKE '%%%%' ALLOW FILTERING");
        Assert.fail();
    } catch (InvalidRequestException e) {
        Assert.assertTrue(e.getMessage().contains("empty"));
    // expected
    }
    // check restrictions on non-indexed clustering columns when preceding columns are indexed
    store = Keyspace.open(KS_NAME).getColumnFamilyStore(CLUSTERING_CF_NAME_2);
    executeCQL(CLUSTERING_CF_NAME_2, "INSERT INTO %s.%s (name, nickname, location, age, height, score) VALUES (?, ?, ?, ?, ?, ?)", "Tony", "tony", "US", 43, 184, 2.0);
    executeCQL(CLUSTERING_CF_NAME_2, "INSERT INTO %s.%s (name, nickname, location, age, height, score) VALUES (?, ?, ?, ?, ?, ?)", "Christopher", "chis", "US", 27, 180, 1.0);
    if (forceFlush)
        store.forceBlockingFlush();
    results = executeCQL(CLUSTERING_CF_NAME_2, "SELECT * FROM %s.%s WHERE location LIKE 'US' AND age = 43 ALLOW FILTERING");
    Assert.assertNotNull(results);
    Assert.assertEquals(1, results.size());
    Assert.assertEquals("Tony", results.one().getString("name"));
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException)

Example 53 with UntypedResultSet

use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.

the class SASIIndexTest method testConditionalsWithReversedType.

@Test
public void testConditionalsWithReversedType() {
    final String TABLE_NAME = "reversed_clustering";
    QueryProcessor.executeOnceInternal(String.format("CREATE TABLE IF NOT EXISTS %s.%s (pk text, ck int, v int, PRIMARY KEY (pk, ck)) " + "WITH CLUSTERING ORDER BY (ck DESC);", KS_NAME, TABLE_NAME));
    QueryProcessor.executeOnceInternal(String.format("CREATE CUSTOM INDEX ON %s.%s (ck) USING 'org.apache.cassandra.index.sasi.SASIIndex'", KS_NAME, TABLE_NAME));
    QueryProcessor.executeOnceInternal(String.format("CREATE CUSTOM INDEX ON %s.%s (v) USING 'org.apache.cassandra.index.sasi.SASIIndex'", KS_NAME, TABLE_NAME));
    QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (pk, ck, v) VALUES ('Alex', 1, 1);", KS_NAME, TABLE_NAME));
    QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (pk, ck, v) VALUES ('Alex', 2, 2);", KS_NAME, TABLE_NAME));
    QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (pk, ck, v) VALUES ('Alex', 3, 3);", KS_NAME, TABLE_NAME));
    QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (pk, ck, v) VALUES ('Tom', 1, 1);", KS_NAME, TABLE_NAME));
    QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (pk, ck, v) VALUES ('Tom', 2, 2);", KS_NAME, TABLE_NAME));
    QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (pk, ck, v) VALUES ('Tom', 3, 3);", KS_NAME, TABLE_NAME));
    UntypedResultSet resultSet = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE ck <= 2;", KS_NAME, TABLE_NAME));
    CQLTester.assertRowsIgnoringOrder(resultSet, CQLTester.row("Alex", 1, 1), CQLTester.row("Alex", 2, 2), CQLTester.row("Tom", 1, 1), CQLTester.row("Tom", 2, 2));
    resultSet = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE ck <= 2 AND v > 1 ALLOW FILTERING;", KS_NAME, TABLE_NAME));
    CQLTester.assertRowsIgnoringOrder(resultSet, CQLTester.row("Alex", 2, 2), CQLTester.row("Tom", 2, 2));
    resultSet = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE ck < 2;", KS_NAME, TABLE_NAME));
    CQLTester.assertRowsIgnoringOrder(resultSet, CQLTester.row("Alex", 1, 1), CQLTester.row("Tom", 1, 1));
    resultSet = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE ck >= 2;", KS_NAME, TABLE_NAME));
    CQLTester.assertRowsIgnoringOrder(resultSet, CQLTester.row("Alex", 2, 2), CQLTester.row("Alex", 3, 3), CQLTester.row("Tom", 2, 2), CQLTester.row("Tom", 3, 3));
    resultSet = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE ck >= 2 AND v < 3 ALLOW FILTERING;", KS_NAME, TABLE_NAME));
    CQLTester.assertRowsIgnoringOrder(resultSet, CQLTester.row("Alex", 2, 2), CQLTester.row("Tom", 2, 2));
    resultSet = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE ck > 2;", KS_NAME, TABLE_NAME));
    CQLTester.assertRowsIgnoringOrder(resultSet, CQLTester.row("Alex", 3, 3), CQLTester.row("Tom", 3, 3));
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet)

Example 54 with UntypedResultSet

use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.

the class SASIIndexTest method testLIKEAndEQSemanticsWithDifferenceKindsOfIndexes.

private void testLIKEAndEQSemanticsWithDifferenceKindsOfIndexes(String containsTable, String prefixTable, String analyzedPrefixTable, String tokenizedContainsTable, boolean forceFlush) {
    QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (k, v) VALUES (?, ?);", KS_NAME, containsTable), 0, "Pavel");
    QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (k, v) VALUES (?, ?);", KS_NAME, prefixTable), 0, "Jean-Claude");
    QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (k, v) VALUES (?, ?);", KS_NAME, analyzedPrefixTable), 0, "Jean-Claude");
    QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (k, v) VALUES (?, ?);", KS_NAME, tokenizedContainsTable), 0, "Pavel");
    if (forceFlush) {
        Keyspace keyspace = Keyspace.open(KS_NAME);
        for (String table : Arrays.asList(containsTable, prefixTable, analyzedPrefixTable)) keyspace.getColumnFamilyStore(table).forceBlockingFlush();
    }
    UntypedResultSet results;
    // CONTAINS
    results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE 'Pav';", KS_NAME, containsTable));
    Assert.assertNotNull(results);
    Assert.assertEquals(0, results.size());
    results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE 'Pav%%';", KS_NAME, containsTable));
    Assert.assertNotNull(results);
    Assert.assertEquals(1, results.size());
    results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE 'Pavel';", KS_NAME, containsTable));
    Assert.assertNotNull(results);
    Assert.assertEquals(1, results.size());
    results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v = 'Pav';", KS_NAME, containsTable));
    Assert.assertNotNull(results);
    Assert.assertEquals(0, results.size());
    results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v = 'Pavel';", KS_NAME, containsTable));
    Assert.assertNotNull(results);
    Assert.assertEquals(1, results.size());
    try {
        QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v = 'Pav';", KS_NAME, tokenizedContainsTable));
        Assert.fail();
    } catch (InvalidRequestException e) {
    // expected since CONTAINS + analyzed indexes only support LIKE
    }
    try {
        QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE 'Pav%%';", KS_NAME, tokenizedContainsTable));
        Assert.fail();
    } catch (InvalidRequestException e) {
    // expected since CONTAINS + analyzed only support LIKE
    }
    results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE 'Pav%%';", KS_NAME, containsTable));
    Assert.assertNotNull(results);
    Assert.assertEquals(1, results.size());
    results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE '%%Pav';", KS_NAME, containsTable));
    Assert.assertNotNull(results);
    Assert.assertEquals(0, results.size());
    results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE '%%Pav%%';", KS_NAME, containsTable));
    Assert.assertNotNull(results);
    Assert.assertEquals(1, results.size());
    // PREFIX
    results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v = 'Jean';", KS_NAME, prefixTable));
    Assert.assertNotNull(results);
    Assert.assertEquals(0, results.size());
    results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v = 'Jean-Claude';", KS_NAME, prefixTable));
    Assert.assertNotNull(results);
    Assert.assertEquals(1, results.size());
    results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE 'Jea';", KS_NAME, prefixTable));
    Assert.assertNotNull(results);
    Assert.assertEquals(0, results.size());
    results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE 'Jea%%';", KS_NAME, prefixTable));
    Assert.assertNotNull(results);
    Assert.assertEquals(1, results.size());
    try {
        QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE '%%Jea';", KS_NAME, prefixTable));
        Assert.fail();
    } catch (InvalidRequestException e) {
    // expected since PREFIX indexes only support LIKE '<term>%'
    }
    try {
        QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE '%%Jea%%';", KS_NAME, prefixTable));
        Assert.fail();
    } catch (InvalidRequestException e) {
    // expected since PREFIX indexes only support LIKE '<term>%'
    }
    try {
        QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v = 'Jean';", KS_NAME, analyzedPrefixTable));
        Assert.fail();
    } catch (InvalidRequestException e) {
    // expected since PREFIX indexes only support EQ without tokenization
    }
    results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE 'Jean';", KS_NAME, analyzedPrefixTable));
    Assert.assertNotNull(results);
    Assert.assertEquals(1, results.size());
    results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE 'Claude';", KS_NAME, analyzedPrefixTable));
    Assert.assertNotNull(results);
    Assert.assertEquals(1, results.size());
    results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE 'Jean-Claude';", KS_NAME, analyzedPrefixTable));
    Assert.assertNotNull(results);
    Assert.assertEquals(1, results.size());
    results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE 'Jean%%';", KS_NAME, analyzedPrefixTable));
    Assert.assertNotNull(results);
    Assert.assertEquals(1, results.size());
    results = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE 'Claude%%';", KS_NAME, analyzedPrefixTable));
    Assert.assertNotNull(results);
    Assert.assertEquals(1, results.size());
    try {
        QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE '%%Jean';", KS_NAME, analyzedPrefixTable));
        Assert.fail();
    } catch (InvalidRequestException e) {
    // expected since PREFIX indexes only support LIKE '<term>%' and LIKE '<term>'
    }
    try {
        QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE v LIKE '%%Claude%%';", KS_NAME, analyzedPrefixTable));
        Assert.fail();
    } catch (InvalidRequestException e) {
    // expected since PREFIX indexes only support LIKE '<term>%' and LIKE '<term>'
    }
    for (String table : Arrays.asList(containsTable, prefixTable, analyzedPrefixTable)) QueryProcessor.executeOnceInternal(String.format("TRUNCATE TABLE %s.%s", KS_NAME, table));
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException)

Example 55 with UntypedResultSet

use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.

the class SASIIndexTest method testStaticIndex.

public void testStaticIndex(boolean shouldFlush) {
    ColumnFamilyStore store = Keyspace.open(KS_NAME).getColumnFamilyStore(STATIC_CF_NAME);
    executeCQL(STATIC_CF_NAME, "INSERT INTO %s.%s (sensor_id,sensor_type) VALUES(?, ?)", 1, "TEMPERATURE");
    executeCQL(STATIC_CF_NAME, "INSERT INTO %s.%s (sensor_id,date,value,variance) VALUES(?, ?, ?, ?)", 1, 20160401L, 24.46, 2);
    executeCQL(STATIC_CF_NAME, "INSERT INTO %s.%s (sensor_id,date,value,variance) VALUES(?, ?, ?, ?)", 1, 20160402L, 25.62, 5);
    executeCQL(STATIC_CF_NAME, "INSERT INTO %s.%s (sensor_id,date,value,variance) VALUES(?, ?, ?, ?)", 1, 20160403L, 24.96, 4);
    if (shouldFlush)
        store.forceBlockingFlush();
    executeCQL(STATIC_CF_NAME, "INSERT INTO %s.%s (sensor_id,sensor_type) VALUES(?, ?)", 2, "PRESSURE");
    executeCQL(STATIC_CF_NAME, "INSERT INTO %s.%s (sensor_id,date,value,variance) VALUES(?, ?, ?, ?)", 2, 20160401L, 1.03, 9);
    executeCQL(STATIC_CF_NAME, "INSERT INTO %s.%s (sensor_id,date,value,variance) VALUES(?, ?, ?, ?)", 2, 20160402L, 1.04, 7);
    executeCQL(STATIC_CF_NAME, "INSERT INTO %s.%s (sensor_id,date,value,variance) VALUES(?, ?, ?, ?)", 2, 20160403L, 1.01, 4);
    if (shouldFlush)
        store.forceBlockingFlush();
    UntypedResultSet results;
    // Prefix search on static column only
    results = executeCQL(STATIC_CF_NAME, "SELECT * FROM %s.%s WHERE sensor_type LIKE 'temp%%'");
    Assert.assertNotNull(results);
    Assert.assertEquals(3, results.size());
    Iterator<UntypedResultSet.Row> iterator = results.iterator();
    UntypedResultSet.Row row1 = iterator.next();
    Assert.assertEquals(20160401L, row1.getLong("date"));
    Assert.assertEquals(24.46, row1.getDouble("value"), 0.0);
    Assert.assertEquals(2, row1.getInt("variance"));
    UntypedResultSet.Row row2 = iterator.next();
    Assert.assertEquals(20160402L, row2.getLong("date"));
    Assert.assertEquals(25.62, row2.getDouble("value"), 0.0);
    Assert.assertEquals(5, row2.getInt("variance"));
    UntypedResultSet.Row row3 = iterator.next();
    Assert.assertEquals(20160403L, row3.getLong("date"));
    Assert.assertEquals(24.96, row3.getDouble("value"), 0.0);
    Assert.assertEquals(4, row3.getInt("variance"));
    // Combined static and non static filtering
    results = executeCQL(STATIC_CF_NAME, "SELECT * FROM %s.%s WHERE sensor_type=? AND value >= ? AND value <= ? AND variance=? ALLOW FILTERING", "pressure", 1.02, 1.05, 7);
    Assert.assertNotNull(results);
    Assert.assertEquals(1, results.size());
    row1 = results.one();
    Assert.assertEquals(20160402L, row1.getLong("date"));
    Assert.assertEquals(1.04, row1.getDouble("value"), 0.0);
    Assert.assertEquals(7, row1.getInt("variance"));
    // Only non statc columns filtering
    results = executeCQL(STATIC_CF_NAME, "SELECT * FROM %s.%s WHERE value >= ? AND variance <= ? ALLOW FILTERING", 1.02, 7);
    Assert.assertNotNull(results);
    Assert.assertEquals(4, results.size());
    iterator = results.iterator();
    row1 = iterator.next();
    Assert.assertEquals("TEMPERATURE", row1.getString("sensor_type"));
    Assert.assertEquals(20160401L, row1.getLong("date"));
    Assert.assertEquals(24.46, row1.getDouble("value"), 0.0);
    Assert.assertEquals(2, row1.getInt("variance"));
    row2 = iterator.next();
    Assert.assertEquals("TEMPERATURE", row2.getString("sensor_type"));
    Assert.assertEquals(20160402L, row2.getLong("date"));
    Assert.assertEquals(25.62, row2.getDouble("value"), 0.0);
    Assert.assertEquals(5, row2.getInt("variance"));
    row3 = iterator.next();
    Assert.assertEquals("TEMPERATURE", row3.getString("sensor_type"));
    Assert.assertEquals(20160403L, row3.getLong("date"));
    Assert.assertEquals(24.96, row3.getDouble("value"), 0.0);
    Assert.assertEquals(4, row3.getInt("variance"));
    UntypedResultSet.Row row4 = iterator.next();
    Assert.assertEquals("PRESSURE", row4.getString("sensor_type"));
    Assert.assertEquals(20160402L, row4.getLong("date"));
    Assert.assertEquals(1.04, row4.getDouble("value"), 0.0);
    Assert.assertEquals(7, row4.getInt("variance"));
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet)

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