Search in sources :

Example 76 with Keyspace

use of org.apache.cassandra.db.Keyspace in project cassandra by apache.

the class ViewComplexTest method testMVWithDifferentColumns.

private void testMVWithDifferentColumns(boolean flush) throws Throwable {
    createTable("CREATE TABLE %s (a int, b int, c int, d int, e int, f int, PRIMARY KEY(a, b))");
    List<String> viewNames = new ArrayList<>();
    List<String> mvStatements = Arrays.asList(// all selected
    "CREATE MATERIALIZED VIEW %s AS SELECT * FROM %s WHERE a IS NOT NULL AND b IS NOT NULL PRIMARY KEY (a,b)", // unselected e,f
    "CREATE MATERIALIZED VIEW %s AS SELECT a,b,c,d FROM %s WHERE a IS NOT NULL AND b IS NOT NULL PRIMARY KEY (a,b)", // no selected
    "CREATE MATERIALIZED VIEW %s AS SELECT a,b FROM %s WHERE a IS NOT NULL AND b IS NOT NULL PRIMARY KEY (a,b)", // all selected, re-order keys
    "CREATE MATERIALIZED VIEW %s AS SELECT * FROM %s WHERE a IS NOT NULL AND b IS NOT NULL PRIMARY KEY (b,a)", // unselected e,f, re-order keys
    "CREATE MATERIALIZED VIEW %s AS SELECT a,b,c,d FROM %s WHERE a IS NOT NULL AND b IS NOT NULL PRIMARY KEY (b,a)", // no selected, re-order keys
    "CREATE MATERIALIZED VIEW %s AS SELECT a,b FROM %s WHERE a IS NOT NULL AND b IS NOT NULL PRIMARY KEY (b,a)");
    Keyspace ks = Keyspace.open(keyspace());
    for (int i = 0; i < mvStatements.size(); i++) {
        String name = createView(mvStatements.get(i));
        viewNames.add(name);
        ks.getColumnFamilyStore(name).disableAutoCompaction();
    }
    // insert
    updateViewWithFlush("INSERT INTO %s (a,b,c,d,e,f) VALUES(1,1,1,1,1,1) using timestamp 1", flush);
    assertBaseViews(row(1, 1, 1, 1, 1, 1), viewNames);
    updateViewWithFlush("UPDATE %s using timestamp 2 SET c=0, d=0 WHERE a=1 AND b=1", flush);
    assertBaseViews(row(1, 1, 0, 0, 1, 1), viewNames);
    updateViewWithFlush("UPDATE %s using timestamp 2 SET e=0, f=0 WHERE a=1 AND b=1", flush);
    assertBaseViews(row(1, 1, 0, 0, 0, 0), viewNames);
    updateViewWithFlush("DELETE FROM %s using timestamp 2 WHERE a=1 AND b=1", flush);
    assertBaseViews(null, viewNames);
    // partial update unselected, selected
    updateViewWithFlush("UPDATE %s using timestamp 3 SET f=1 WHERE a=1 AND b=1", flush);
    assertBaseViews(row(1, 1, null, null, null, 1), viewNames);
    updateViewWithFlush("UPDATE %s using timestamp 4 SET e = 1, f=null WHERE a=1 AND b=1", flush);
    assertBaseViews(row(1, 1, null, null, 1, null), viewNames);
    updateViewWithFlush("UPDATE %s using timestamp 4 SET e = null WHERE a=1 AND b=1", flush);
    assertBaseViews(null, viewNames);
    updateViewWithFlush("UPDATE %s using timestamp 5 SET c = 1 WHERE a=1 AND b=1", flush);
    assertBaseViews(row(1, 1, 1, null, null, null), viewNames);
    updateViewWithFlush("UPDATE %s using timestamp 5 SET c = null WHERE a=1 AND b=1", flush);
    assertBaseViews(null, viewNames);
    updateViewWithFlush("UPDATE %s using timestamp 6 SET d = 1 WHERE a=1 AND b=1", flush);
    assertBaseViews(row(1, 1, null, 1, null, null), viewNames);
    updateViewWithFlush("UPDATE %s using timestamp 7 SET d = null WHERE a=1 AND b=1", flush);
    assertBaseViews(null, viewNames);
    updateViewWithFlush("UPDATE %s using timestamp 8 SET f = 1 WHERE a=1 AND b=1", flush);
    assertBaseViews(row(1, 1, null, null, null, 1), viewNames);
    updateViewWithFlush("UPDATE %s using timestamp 6 SET c = 1 WHERE a=1 AND b=1", flush);
    assertBaseViews(row(1, 1, 1, null, null, 1), viewNames);
    // view row still alive due to c=1@6
    updateViewWithFlush("UPDATE %s using timestamp 8 SET f = null WHERE a=1 AND b=1", flush);
    assertBaseViews(row(1, 1, 1, null, null, null), viewNames);
    updateViewWithFlush("UPDATE %s using timestamp 6 SET c = null WHERE a=1 AND b=1", flush);
    assertBaseViews(null, viewNames);
}
Also used : Keyspace(org.apache.cassandra.db.Keyspace) ArrayList(java.util.ArrayList)

Example 77 with Keyspace

use of org.apache.cassandra.db.Keyspace in project cassandra by apache.

the class ViewComplexUpdatesTest method testUpdateColumnNotInView.

private void testUpdateColumnNotInView(boolean flush) throws Throwable {
    // CASSANDRA-13127: if base column not selected in view are alive, then pk of view row should be alive
    String baseTable = createTable("create table %s (p int, c int, v1 int, v2 int, primary key(p, c))");
    Keyspace ks = Keyspace.open(keyspace());
    String mv = createView("CREATE MATERIALIZED VIEW %s AS SELECT p, c from %s " + "WHERE p IS NOT NULL AND c IS NOT NULL PRIMARY KEY (c, p)");
    ks.getColumnFamilyStore(mv).disableAutoCompaction();
    updateView("UPDATE %s USING TIMESTAMP 0 SET v1 = 1 WHERE p = 0 AND c = 0");
    if (flush)
        Util.flush(ks);
    assertRowsIgnoringOrder(execute("SELECT * from %s WHERE c = ? AND p = ?", 0, 0), row(0, 0, 1, null));
    assertRowsIgnoringOrder(executeView("SELECT * from %s WHERE c = ? AND p = ?", 0, 0), row(0, 0));
    updateView("DELETE v1 FROM %s USING TIMESTAMP 1 WHERE p = 0 AND c = 0");
    if (flush)
        Util.flush(ks);
    assertEmpty(execute("SELECT * from %s WHERE c = ? AND p = ?", 0, 0));
    assertEmpty(executeView("SELECT * from %s WHERE c = ? AND p = ?", 0, 0));
    // shadowed by tombstone
    updateView("UPDATE %s USING TIMESTAMP 1 SET v1 = 1 WHERE p = 0 AND c = 0");
    if (flush)
        Util.flush(ks);
    assertEmpty(execute("SELECT * from %s WHERE c = ? AND p = ?", 0, 0));
    assertEmpty(executeView("SELECT * from %s WHERE c = ? AND p = ?", 0, 0));
    updateView("UPDATE %s USING TIMESTAMP 2 SET v2 = 1 WHERE p = 0 AND c = 0");
    if (flush)
        Util.flush(ks);
    assertRowsIgnoringOrder(execute("SELECT * from %s WHERE c = ? AND p = ?", 0, 0), row(0, 0, null, 1));
    assertRowsIgnoringOrder(executeView("SELECT * from %s WHERE c = ? AND p = ?", 0, 0), row(0, 0));
    updateView("DELETE v1 FROM %s USING TIMESTAMP 3 WHERE p = 0 AND c = 0");
    if (flush)
        Util.flush(ks);
    assertRowsIgnoringOrder(execute("SELECT * from %s WHERE c = ? AND p = ?", 0, 0), row(0, 0, null, 1));
    assertRowsIgnoringOrder(executeView("SELECT * from %s WHERE c = ? AND p = ?", 0, 0), row(0, 0));
    updateView("DELETE v2 FROM %s USING TIMESTAMP 4 WHERE p = 0 AND c = 0");
    if (flush)
        Util.flush(ks);
    assertEmpty(execute("SELECT * from %s WHERE c = ? AND p = ?", 0, 0));
    assertEmpty(executeView("SELECT * from %s WHERE c = ? AND p = ?", 0, 0));
    updateView("UPDATE %s USING TTL 3 SET v2 = 1 WHERE p = 0 AND c = 0");
    if (flush)
        Util.flush(ks);
    assertRowsIgnoringOrder(execute("SELECT * from %s WHERE c = ? AND p = ?", 0, 0), row(0, 0, null, 1));
    assertRowsIgnoringOrder(executeView("SELECT * from %s WHERE c = ? AND p = ?", 0, 0), row(0, 0));
    Thread.sleep(TimeUnit.SECONDS.toMillis(3));
    assertRowsIgnoringOrder(execute("SELECT * from %s WHERE c = ? AND p = ?", 0, 0));
    assertRowsIgnoringOrder(executeView("SELECT * from %s WHERE c = ? AND p = ?", 0, 0));
    updateView("UPDATE %s SET v2 = 1 WHERE p = 0 AND c = 0");
    if (flush)
        Util.flush(ks);
    assertRowsIgnoringOrder(execute("SELECT * from %s WHERE c = ? AND p = ?", 0, 0), row(0, 0, null, 1));
    assertRowsIgnoringOrder(executeView("SELECT * from %s WHERE c = ? AND p = ?", 0, 0), row(0, 0));
    assertInvalidMessage(String.format("Cannot drop column v2 on base table %s with materialized views", baseTable), "ALTER TABLE %s DROP v2");
// // drop unselected base column, unselected metadata should be removed, thus view row is dead
// updateView("ALTER TABLE %s DROP v2");
// assertRowsIgnoringOrder(execute("SELECT * from %s WHERE c = ? AND p = ?", 0, 0));
// assertRowsIgnoringOrder(executeView("SELECT * from %s WHERE c = ? AND p = ?", 0, 0));
// assertRowsIgnoringOrder(execute("SELECT * from %s"));
// assertRowsIgnoringOrder(executeView("SELECT * from %s"));
}
Also used : Keyspace(org.apache.cassandra.db.Keyspace)

Example 78 with Keyspace

use of org.apache.cassandra.db.Keyspace in project cassandra by apache.

the class ViewComplexUpdatesTest method testPartialUpdateWithUnselectedCollections.

private void testPartialUpdateWithUnselectedCollections(boolean flush) throws Throwable {
    String baseTable = createTable("CREATE TABLE %s (k int, c int, a int, b int, l list<int>, s set<int>, m map<int,int>, PRIMARY KEY (k, c))");
    String mv = createView("CREATE MATERIALIZED VIEW %s AS SELECT a, b, c, k from %s " + "WHERE k IS NOT NULL AND c IS NOT NULL PRIMARY KEY (c, k)");
    Keyspace ks = Keyspace.open(keyspace());
    ks.getColumnFamilyStore(mv).disableAutoCompaction();
    updateView("UPDATE %s SET l=l+[1,2,3] WHERE k = 1 AND c = 1");
    if (flush)
        Util.flush(ks);
    assertRows(executeView("SELECT * from %s"), row(1, 1, null, null));
    updateView("UPDATE %s SET l=l-[1,2] WHERE k = 1 AND c = 1");
    if (flush)
        Util.flush(ks);
    assertRows(executeView("SELECT * from %s"), row(1, 1, null, null));
    updateView("UPDATE %s SET b=3 WHERE k=1 AND c=1");
    if (flush)
        Util.flush(ks);
    assertRows(executeView("SELECT * from %s"), row(1, 1, null, 3));
    updateView("UPDATE %s SET b=null, l=l-[3], s=s-{3} WHERE k = 1 AND c = 1");
    if (flush) {
        Util.flush(ks);
        ks.getColumnFamilyStore(mv).forceMajorCompaction();
    }
    assertRowsIgnoringOrder(execute("SELECT k,c,a,b from %s"));
    assertRowsIgnoringOrder(executeView("SELECT * from %s"));
    updateView("UPDATE %s SET m=m+{3:3}, l=l-[1], s=s-{2} WHERE k = 1 AND c = 1");
    if (flush)
        Util.flush(ks);
    assertRowsIgnoringOrder(execute("SELECT k,c,a,b from %s"), row(1, 1, null, null));
    assertRowsIgnoringOrder(executeView("SELECT * from %s"), row(1, 1, null, null));
    assertInvalidMessage(String.format("Cannot drop column m on base table %s with materialized views", baseTable), "ALTER TABLE %s DROP m");
// executeNet(version, "ALTER TABLE %s DROP m");
// ks.getColumnFamilyStore(mv).forceMajorCompaction();
// assertRowsIgnoringOrder(execute("SELECT k,c,a,b from %s WHERE k = 1 AND c = 1"));
// assertRowsIgnoringOrder(executeView("SELECT * from %s WHERE k = 1 AND c = 1"));
// assertRowsIgnoringOrder(execute("SELECT k,c,a,b from %s"));
// assertRowsIgnoringOrder(executeView("SELECT * from %s"));
}
Also used : Keyspace(org.apache.cassandra.db.Keyspace)

Example 79 with Keyspace

use of org.apache.cassandra.db.Keyspace in project cassandra by apache.

the class ViewComplexUpdatesTest method testUpdateWithColumnTimestampBiggerThanPk.

private void testUpdateWithColumnTimestampBiggerThanPk(boolean flush) throws Throwable {
    // CASSANDRA-11500 able to shadow old view row with column ts greater tahn pk's ts and re-insert the view row
    String baseTable = createTable("CREATE TABLE %s (k int PRIMARY KEY, a int, b int);");
    Keyspace ks = Keyspace.open(keyspace());
    String mv = createView("CREATE MATERIALIZED VIEW %s AS SELECT * from %s " + "WHERE k IS NOT NULL AND a IS NOT NULL PRIMARY KEY (k, a)");
    ks.getColumnFamilyStore(mv).disableAutoCompaction();
    updateView("DELETE FROM %s USING TIMESTAMP 0 WHERE k = 1;");
    if (flush)
        Util.flush(ks);
    // sstable-1, Set initial values TS=1
    updateView("INSERT INTO %s(k, a, b) VALUES (1, 1, 1) USING TIMESTAMP 1;");
    if (flush)
        Util.flush(ks);
    assertRowsIgnoringOrder(executeView("SELECT k,a,b from %s"), row(1, 1, 1));
    updateView("UPDATE %s USING TIMESTAMP 10 SET b = 2 WHERE k = 1;");
    assertRowsIgnoringOrder(executeView("SELECT k,a,b from %s"), row(1, 1, 2));
    if (flush)
        Util.flush(ks);
    assertRowsIgnoringOrder(executeView("SELECT k,a,b from %s"), row(1, 1, 2));
    updateView("UPDATE %s USING TIMESTAMP 2 SET a = 2 WHERE k = 1;");
    assertRowsIgnoringOrder(executeView("SELECT k,a,b from %s"), row(1, 2, 2));
    if (flush)
        Util.flush(ks);
    ks.getColumnFamilyStore(mv).forceMajorCompaction();
    assertRowsIgnoringOrder(executeView("SELECT k,a,b from %s"), row(1, 2, 2));
    assertRowsIgnoringOrder(executeView("SELECT k,a,b from %s limit 1"), row(1, 2, 2));
    updateView("UPDATE %s USING TIMESTAMP 11 SET a = 1 WHERE k = 1;");
    if (flush)
        Util.flush(ks);
    assertRowsIgnoringOrder(executeView("SELECT k,a,b from %s"), row(1, 1, 2));
    assertRowsIgnoringOrder(execute("SELECT k,a,b from %s"), row(1, 1, 2));
    // set non-key base column as tombstone, view row is removed with shadowable
    updateView("UPDATE %s USING TIMESTAMP 12 SET a = null WHERE k = 1;");
    if (flush)
        Util.flush(ks);
    assertRowsIgnoringOrder(executeView("SELECT k,a,b from %s"));
    assertRowsIgnoringOrder(execute("SELECT k,a,b from %s"), row(1, null, 2));
    // column b should be alive
    updateView("UPDATE %s USING TIMESTAMP 13 SET a = 1 WHERE k = 1;");
    if (flush)
        Util.flush(ks);
    assertRowsIgnoringOrder(executeView("SELECT k,a,b from %s"), row(1, 1, 2));
    assertRowsIgnoringOrder(execute("SELECT k,a,b from %s"), row(1, 1, 2));
    assertInvalidMessage(String.format("Cannot drop column a on base table %s with materialized views", baseTable), "ALTER TABLE %s DROP a");
}
Also used : Keyspace(org.apache.cassandra.db.Keyspace)

Example 80 with Keyspace

use of org.apache.cassandra.db.Keyspace in project cassandra by apache.

the class ViewFiltering1Test method testViewFiltering.

public void testViewFiltering(boolean flush) throws Throwable {
    // CASSANDRA-13547: able to shadow entire view row if base column used in filter condition is modified
    createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a))");
    String mv1 = createView("CREATE MATERIALIZED VIEW %s AS SELECT * FROM %s " + "WHERE a IS NOT NULL AND b IS NOT NULL and c = 1  PRIMARY KEY (a, b)");
    String mv2 = createView("CREATE MATERIALIZED VIEW %s AS SELECT c, d FROM %s " + "WHERE a IS NOT NULL AND b IS NOT NULL and c = 1 and d = 1 PRIMARY KEY (a, b)");
    String mv3 = createView("CREATE MATERIALIZED VIEW %s AS SELECT a, b, c, d FROM %%s " + "WHERE a IS NOT NULL AND b IS NOT NULL PRIMARY KEY (a, b)");
    String mv4 = createView("CREATE MATERIALIZED VIEW %s AS SELECT c FROM %s " + "WHERE a IS NOT NULL AND b IS NOT NULL and c = 1 PRIMARY KEY (a, b)");
    String mv5 = createView("CREATE MATERIALIZED VIEW %s AS SELECT c FROM %s " + "WHERE a IS NOT NULL and d = 1 PRIMARY KEY (a, d)");
    String mv6 = createView("CREATE MATERIALIZED VIEW %s AS SELECT c FROM %s " + "WHERE a = 1 and d IS NOT NULL PRIMARY KEY (a, d)");
    Keyspace ks = Keyspace.open(keyspace());
    ks.getColumnFamilyStore(mv1).disableAutoCompaction();
    ks.getColumnFamilyStore(mv2).disableAutoCompaction();
    ks.getColumnFamilyStore(mv3).disableAutoCompaction();
    ks.getColumnFamilyStore(mv4).disableAutoCompaction();
    ks.getColumnFamilyStore(mv5).disableAutoCompaction();
    ks.getColumnFamilyStore(mv6).disableAutoCompaction();
    execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?) using timestamp 0", 1, 1, 1, 1);
    if (flush)
        Util.flush(ks);
    // views should be updated.
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv1), row(1, 1, 1, 1));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv2), row(1, 1, 1, 1));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv3), row(1, 1, 1, 1));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv4), row(1, 1, 1));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv5), row(1, 1, 1));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv6), row(1, 1, 1));
    updateView("UPDATE %s using timestamp 1 set c = ? WHERE a=?", 0, 1);
    if (flush)
        Util.flush(ks);
    assertRowCount(execute("SELECT * FROM " + mv1), 0);
    assertRowCount(execute("SELECT * FROM " + mv2), 0);
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv3), row(1, 1, 0, 1));
    assertRowCount(execute("SELECT * FROM " + mv4), 0);
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv5), row(1, 1, 0));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv6), row(1, 1, 0));
    updateView("UPDATE %s using timestamp 2 set c = ? WHERE a=?", 1, 1);
    if (flush)
        Util.flush(ks);
    // row should be back in views.
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv1), row(1, 1, 1, 1));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv2), row(1, 1, 1, 1));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv3), row(1, 1, 1, 1));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv4), row(1, 1, 1));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv5), row(1, 1, 1));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv6), row(1, 1, 1));
    updateView("UPDATE %s using timestamp 3 set d = ? WHERE a=?", 0, 1);
    if (flush)
        Util.flush(ks);
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv1), row(1, 1, 1, 0));
    assertRowCount(execute("SELECT * FROM " + mv2), 0);
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv3), row(1, 1, 1, 0));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv4), row(1, 1, 1));
    assertRowCount(execute("SELECT * FROM " + mv5), 0);
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv6), row(1, 0, 1));
    updateView("UPDATE %s using timestamp 4 set c = ? WHERE a=?", 0, 1);
    if (flush)
        Util.flush(ks);
    assertRowCount(execute("SELECT * FROM " + mv1), 0);
    assertRowCount(execute("SELECT * FROM " + mv2), 0);
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv3), row(1, 1, 0, 0));
    assertRowCount(execute("SELECT * FROM " + mv4), 0);
    assertRowCount(execute("SELECT * FROM " + mv5), 0);
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv6), row(1, 0, 0));
    updateView("UPDATE %s using timestamp 5 set d = ? WHERE a=?", 1, 1);
    if (flush)
        Util.flush(ks);
    // should not update as c=0
    assertRowCount(execute("SELECT * FROM " + mv1), 0);
    assertRowCount(execute("SELECT * FROM " + mv2), 0);
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv3), row(1, 1, 0, 1));
    assertRowCount(execute("SELECT * FROM " + mv4), 0);
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv5), row(1, 1, 0));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv6), row(1, 1, 0));
    updateView("UPDATE %s using timestamp 6 set c = ? WHERE a=?", 1, 1);
    // row should be back in views.
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv1), row(1, 1, 1, 1));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv2), row(1, 1, 1, 1));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv3), row(1, 1, 1, 1));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv4), row(1, 1, 1));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv5), row(1, 1, 1));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv6), row(1, 1, 1));
    updateView("UPDATE %s using timestamp 7 set b = ? WHERE a=?", 2, 1);
    if (flush) {
        Util.flush(ks);
        for (String view : getViews()) ks.getColumnFamilyStore(view).forceMajorCompaction();
    }
    // row should be back in views.
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv1), row(1, 2, 1, 1));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv2), row(1, 2, 1, 1));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv3), row(1, 2, 1, 1));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv4), row(1, 2, 1));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv5), row(1, 1, 1));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv6), row(1, 1, 1));
    updateView("DELETE b, c FROM %s using timestamp 6 WHERE a=?", 1);
    if (flush)
        Util.flush(ks);
    assertRowsIgnoringOrder(execute("SELECT * FROM %s"), row(1, 2, null, 1));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv1));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv2));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv3), row(1, 2, null, 1));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv4));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv5), row(1, 1, null));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv6), row(1, 1, null));
    updateView("DELETE FROM %s using timestamp 8 where a=?", 1);
    if (flush)
        Util.flush(ks);
    assertRowCount(execute("SELECT * FROM " + mv1), 0);
    assertRowCount(execute("SELECT * FROM " + mv2), 0);
    assertRowCount(execute("SELECT * FROM " + mv3), 0);
    assertRowCount(execute("SELECT * FROM " + mv4), 0);
    assertRowCount(execute("SELECT * FROM " + mv5), 0);
    assertRowCount(execute("SELECT * FROM " + mv6), 0);
    // upsert
    updateView("UPDATE %s using timestamp 9 set b = ?,c = ? where a=?", 1, 1, 1);
    if (flush)
        Util.flush(ks);
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv1), row(1, 1, 1, null));
    assertRows(execute("SELECT * FROM " + mv2));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv3), row(1, 1, 1, null));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv4), row(1, 1, 1));
    assertRows(execute("SELECT * FROM " + mv5));
    assertRows(execute("SELECT * FROM " + mv6));
    updateView("DELETE FROM %s using timestamp 10 where a=?", 1);
    if (flush)
        Util.flush(ks);
    assertRowCount(execute("SELECT * FROM " + mv1), 0);
    assertRowCount(execute("SELECT * FROM " + mv2), 0);
    assertRowCount(execute("SELECT * FROM " + mv3), 0);
    assertRowCount(execute("SELECT * FROM " + mv4), 0);
    assertRowCount(execute("SELECT * FROM " + mv5), 0);
    assertRowCount(execute("SELECT * FROM " + mv6), 0);
    execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?) using timestamp 11", 1, 1, 1, 1);
    if (flush)
        Util.flush(ks);
    // row should be back in views.
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv1), row(1, 1, 1, 1));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv2), row(1, 1, 1, 1));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv3), row(1, 1, 1, 1));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv4), row(1, 1, 1));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv5), row(1, 1, 1));
    assertRowsIgnoringOrder(execute("SELECT * FROM " + mv6), row(1, 1, 1));
    updateView("DELETE FROM %s using timestamp 12 where a=?", 1);
    if (flush)
        Util.flush(ks);
    assertRowCount(execute("SELECT * FROM " + mv1), 0);
    assertRowCount(execute("SELECT * FROM " + mv2), 0);
    assertRowCount(execute("SELECT * FROM " + mv3), 0);
    assertRowCount(execute("SELECT * FROM " + mv4), 0);
    assertRowCount(execute("SELECT * FROM " + mv5), 0);
    assertRowCount(execute("SELECT * FROM " + mv6), 0);
    dropView(mv1);
    dropView(mv2);
    dropView(mv3);
    dropView(mv4);
    dropView(mv5);
    dropView(mv6);
    dropTable("DROP TABLE %s");
}
Also used : Keyspace(org.apache.cassandra.db.Keyspace)

Aggregations

Keyspace (org.apache.cassandra.db.Keyspace)173 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)107 Test (org.junit.Test)77 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)66 Token (org.apache.cassandra.dht.Token)35 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)29 LifecycleTransaction (org.apache.cassandra.db.lifecycle.LifecycleTransaction)27 DecoratedKey (org.apache.cassandra.db.DecoratedKey)23 TableMetadata (org.apache.cassandra.schema.TableMetadata)21 Range (org.apache.cassandra.dht.Range)19 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)19 ArrayList (java.util.ArrayList)18 SystemKeyspace (org.apache.cassandra.db.SystemKeyspace)18 Set (java.util.Set)17 HashMap (java.util.HashMap)16 List (java.util.List)16 Map (java.util.Map)16 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)16 Collectors (java.util.stream.Collectors)15 TableId (org.apache.cassandra.schema.TableId)15