Search in sources :

Example 11 with ColumnFamily

use of org.apache.cassandra.db.ColumnFamily in project eiger by wlloyd.

the class RowResolverTest method testResolveSupersetDisjoint.

@Test
public void testResolveSupersetDisjoint() {
    ColumnFamily cf1 = ColumnFamily.create("Keyspace1", "Standard1");
    cf1.addColumn(column("c1", "v1", 0));
    ColumnFamily cf2 = ColumnFamily.create("Keyspace1", "Standard1");
    cf2.addColumn(column("c2", "v2", 1));
    ColumnFamily resolved = RowRepairResolver.resolveSuperset(Arrays.asList(cf1, cf2));
    assertColumns(resolved, "c1", "c2");
    assertColumns(ColumnFamily.diff(cf1, resolved), "c2");
    assertColumns(ColumnFamily.diff(cf2, resolved), "c1");
}
Also used : ColumnFamily(org.apache.cassandra.db.ColumnFamily) TableTest(org.apache.cassandra.db.TableTest) Test(org.junit.Test)

Example 12 with ColumnFamily

use of org.apache.cassandra.db.ColumnFamily in project eiger by wlloyd.

the class RowResolverTest method testResolveDeleted.

@Test
public void testResolveDeleted() {
    // one CF with columns timestamped before a delete in another cf
    ColumnFamily cf1 = ColumnFamily.create("Keyspace1", "Standard1");
    cf1.addColumn(column("one", "A", 0));
    ColumnFamily cf2 = ColumnFamily.create("Keyspace1", "Standard1");
    cf2.delete((int) (System.currentTimeMillis() / 1000), 1);
    ColumnFamily resolved = RowRepairResolver.resolveSuperset(Arrays.asList(cf1, cf2));
    // no columns in the cf
    assertColumns(resolved);
    assertTrue(resolved.isMarkedForDelete());
    assertEquals(1, resolved.getMarkedForDeleteAt());
    ColumnFamily scf1 = ColumnFamily.create("Keyspace1", "Super1");
    scf1.addColumn(superColumn(scf1, "super-foo", column("one", "A", 0)));
    ColumnFamily scf2 = ColumnFamily.create("Keyspace1", "Super1");
    scf2.delete((int) (System.currentTimeMillis() / 1000), 1);
    ColumnFamily superResolved = RowRepairResolver.resolveSuperset(Arrays.asList(scf1, scf2));
    // no columns in the cf
    assertColumns(superResolved);
    assertTrue(superResolved.isMarkedForDelete());
    assertEquals(1, superResolved.getMarkedForDeleteAt());
}
Also used : ColumnFamily(org.apache.cassandra.db.ColumnFamily) TableTest(org.apache.cassandra.db.TableTest) Test(org.junit.Test)

Example 13 with ColumnFamily

use of org.apache.cassandra.db.ColumnFamily in project eiger by wlloyd.

the class RowResolverTest method testResolveDeletedSuper.

@Test
public void testResolveDeletedSuper() {
    // subcolumn is newer than a tombstone on its parent, but not newer than the row deletion
    ColumnFamily scf1 = ColumnFamily.create("Keyspace1", "Super1");
    SuperColumn sc = superColumn(scf1, "super-foo", column("one", "A", 1));
    sc.delete((int) (System.currentTimeMillis() / 1000), 0);
    scf1.addColumn(sc);
    ColumnFamily scf2 = ColumnFamily.create("Keyspace1", "Super1");
    scf2.delete((int) (System.currentTimeMillis() / 1000), 2);
    ColumnFamily superResolved = RowRepairResolver.resolveSuperset(Arrays.asList(scf1, scf2));
    // no columns in the cf
    assertColumns(superResolved);
    assertTrue(superResolved.isMarkedForDelete());
    assertEquals(2, superResolved.getMarkedForDeleteAt());
}
Also used : SuperColumn(org.apache.cassandra.db.SuperColumn) ColumnFamily(org.apache.cassandra.db.ColumnFamily) TableTest(org.apache.cassandra.db.TableTest) Test(org.junit.Test)

Example 14 with ColumnFamily

use of org.apache.cassandra.db.ColumnFamily in project eiger by wlloyd.

the class SSTableExportTest method testEnumeratekeys.

@Test
public void testEnumeratekeys() throws IOException {
    File tempSS = tempSSTableFile("Keyspace1", "Standard1");
    ColumnFamily cfamily = ColumnFamily.create("Keyspace1", "Standard1");
    SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2);
    // Add rowA
    cfamily.addColumn(new QueryPath("Standard1", null, ByteBufferUtil.bytes("colA")), ByteBufferUtil.bytes("valA"), System.currentTimeMillis());
    writer.append(Util.dk("rowA"), cfamily);
    cfamily.clear();
    // Add rowB
    cfamily.addColumn(new QueryPath("Standard1", null, ByteBufferUtil.bytes("colB")), ByteBufferUtil.bytes("valB"), System.currentTimeMillis());
    writer.append(Util.dk("rowB"), cfamily);
    cfamily.clear();
    writer.closeAndOpenReader();
    // Enumerate and verify
    File temp = File.createTempFile("Standard1", ".txt");
    SSTableExport.enumeratekeys(writer.getFilename(), new PrintStream(temp.getPath()));
    FileReader file = new FileReader(temp);
    char[] buf = new char[(int) temp.length()];
    file.read(buf);
    String output = new String(buf);
    String sep = System.getProperty("line.separator");
    assert output.equals(asHex("rowA") + sep + asHex("rowB") + sep) : output;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) PrintStream(java.io.PrintStream) SSTableWriter(org.apache.cassandra.io.sstable.SSTableWriter) FileReader(java.io.FileReader) File(java.io.File) SSTableUtils.tempSSTableFile(org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile) ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

Example 15 with ColumnFamily

use of org.apache.cassandra.db.ColumnFamily in project eiger by wlloyd.

the class SSTableExportTest method testEscapingDoubleQuotes.

@Test
public void testEscapingDoubleQuotes() throws IOException {
    File tempSS = tempSSTableFile("Keyspace1", "ValuesWithQuotes");
    ColumnFamily cfamily = ColumnFamily.create("Keyspace1", "ValuesWithQuotes");
    SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2);
    // Add rowA
    cfamily.addColumn(null, new Column(ByteBufferUtil.bytes("data"), UTF8Type.instance.fromString("{\"foo\":\"bar\"}")));
    writer.append(Util.dk("rowA"), cfamily);
    cfamily.clear();
    SSTableReader reader = writer.closeAndOpenReader();
    // Export to JSON and verify
    File tempJson = File.createTempFile("ValuesWithQuotes", ".json");
    SSTableExport.export(reader, new PrintStream(tempJson.getPath()), new String[0]);
    JSONObject json = (JSONObject) JSONValue.parse(new FileReader(tempJson));
    JSONArray rowA = (JSONArray) json.get(asHex("rowA"));
    JSONArray data = (JSONArray) rowA.get(0);
    assert hexToBytes((String) data.get(0)).equals(ByteBufferUtil.bytes("data"));
    assert data.get(1).equals("{\"foo\":\"bar\"}");
}
Also used : PrintStream(java.io.PrintStream) SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) JSONObject(org.json.simple.JSONObject) Column(org.apache.cassandra.db.Column) ExpiringColumn(org.apache.cassandra.db.ExpiringColumn) CounterColumn(org.apache.cassandra.db.CounterColumn) SSTableWriter(org.apache.cassandra.io.sstable.SSTableWriter) JSONArray(org.json.simple.JSONArray) FileReader(java.io.FileReader) File(java.io.File) SSTableUtils.tempSSTableFile(org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile) ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

Aggregations

ColumnFamily (org.apache.cassandra.db.ColumnFamily)36 Test (org.junit.Test)26 QueryPath (org.apache.cassandra.db.filter.QueryPath)14 File (java.io.File)11 SSTableUtils.tempSSTableFile (org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile)11 SSTableReader (org.apache.cassandra.io.sstable.SSTableReader)10 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)8 DecoratedKey (org.apache.cassandra.db.DecoratedKey)8 IColumn (org.apache.cassandra.db.IColumn)8 TableTest (org.apache.cassandra.db.TableTest)7 PrintStream (java.io.PrintStream)6 RowMutation (org.apache.cassandra.db.RowMutation)6 Table (org.apache.cassandra.db.Table)6 QueryFilter (org.apache.cassandra.db.filter.QueryFilter)6 SSTableWriter (org.apache.cassandra.io.sstable.SSTableWriter)6 FileReader (java.io.FileReader)5 ExpiringColumn (org.apache.cassandra.db.ExpiringColumn)4 JSONArray (org.json.simple.JSONArray)4 JSONObject (org.json.simple.JSONObject)4 ByteBuffer (java.nio.ByteBuffer)3