Search in sources :

Example 1 with ExpiringColumn

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

the class SSTableImportTest method testImportSimpleCf.

@Test
public void testImportSimpleCf() throws IOException, URISyntaxException {
    // Import JSON to temp SSTable file
    String jsonUrl = resourcePath("SimpleCF.json");
    File tempSS = tempSSTableFile("Keyspace1", "Standard1");
    SSTableImport.importJson(jsonUrl, "Keyspace1", "Standard1", tempSS.getPath());
    // Verify results
    SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(tempSS.getPath()));
    QueryFilter qf = QueryFilter.getIdentityFilter(Util.dk("rowA"), new QueryPath("Standard1"));
    IColumnIterator iter = qf.getSSTableColumnIterator(reader);
    ColumnFamily cf = iter.getColumnFamily();
    while (iter.hasNext()) cf.addColumn(iter.next());
    assert cf.getColumn(ByteBufferUtil.bytes("colAA")).value().equals(hexToBytes("76616c4141"));
    assert !(cf.getColumn(ByteBufferUtil.bytes("colAA")) instanceof DeletedColumn);
    IColumn expCol = cf.getColumn(ByteBufferUtil.bytes("colAC"));
    assert expCol.value().equals(hexToBytes("76616c4143"));
    assert expCol instanceof ExpiringColumn;
    assert ((ExpiringColumn) expCol).getTimeToLive() == 42 && expCol.getLocalDeletionTime() == 2000000000;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) QueryFilter(org.apache.cassandra.db.filter.QueryFilter) IColumn(org.apache.cassandra.db.IColumn) ExpiringColumn(org.apache.cassandra.db.ExpiringColumn) IColumnIterator(org.apache.cassandra.db.columniterator.IColumnIterator) DeletedColumn(org.apache.cassandra.db.DeletedColumn) File(java.io.File) SSTableUtils.tempSSTableFile(org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile) ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

Example 2 with ExpiringColumn

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

the class SSTableExportTest method testExportSimpleCf.

@Test
public void testExportSimpleCf() throws IOException {
    File tempSS = tempSSTableFile("Keyspace1", "Standard1");
    ColumnFamily cfamily = ColumnFamily.create("Keyspace1", "Standard1");
    SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2);
    // live for 42 seconds
    int nowInSec = (int) (System.currentTimeMillis() / 1000) + 42;
    // Add rowA
    cfamily.addColumn(new QueryPath("Standard1", null, ByteBufferUtil.bytes("colA")), ByteBufferUtil.bytes("valA"), System.currentTimeMillis());
    cfamily.addColumn(null, new ExpiringColumn(ByteBufferUtil.bytes("colExp"), ByteBufferUtil.bytes("valExp"), System.currentTimeMillis(), 42, nowInSec));
    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();
    // Add rowExclude
    cfamily.addColumn(new QueryPath("Standard1", null, ByteBufferUtil.bytes("colX")), ByteBufferUtil.bytes("valX"), System.currentTimeMillis());
    writer.append(Util.dk("rowExclude"), cfamily);
    cfamily.clear();
    SSTableReader reader = writer.closeAndOpenReader();
    // Export to JSON and verify
    File tempJson = File.createTempFile("Standard1", ".json");
    SSTableExport.export(reader, new PrintStream(tempJson.getPath()), new String[] { asHex("rowExclude") });
    JSONObject json = (JSONObject) JSONValue.parse(new FileReader(tempJson));
    JSONArray rowA = (JSONArray) json.get(asHex("rowA"));
    JSONArray colA = (JSONArray) rowA.get(0);
    assert hexToBytes((String) colA.get(1)).equals(ByteBufferUtil.bytes("valA"));
    JSONArray colExp = (JSONArray) rowA.get(1);
    assert ((Long) colExp.get(4)) == 42;
    assert ((Long) colExp.get(5)) == nowInSec;
    JSONArray rowB = (JSONArray) json.get(asHex("rowB"));
    JSONArray colB = (JSONArray) rowB.get(0);
    assert colB.size() == 3;
    JSONArray rowExclude = (JSONArray) json.get(asHex("rowExclude"));
    assert rowExclude == null;
}
Also used : PrintStream(java.io.PrintStream) SSTableWriter(org.apache.cassandra.io.sstable.SSTableWriter) JSONArray(org.json.simple.JSONArray) ColumnFamily(org.apache.cassandra.db.ColumnFamily) QueryPath(org.apache.cassandra.db.filter.QueryPath) SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) JSONObject(org.json.simple.JSONObject) ExpiringColumn(org.apache.cassandra.db.ExpiringColumn) FileReader(java.io.FileReader) File(java.io.File) SSTableUtils.tempSSTableFile(org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile) Test(org.junit.Test)

Example 3 with ExpiringColumn

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

the class SSTableImportTest method testImportSimpleCfOldFormat.

@Test
public void testImportSimpleCfOldFormat() throws IOException, URISyntaxException {
    // Import JSON to temp SSTable file
    String jsonUrl = resourcePath("SimpleCF.oldformat.json");
    File tempSS = tempSSTableFile("Keyspace1", "Standard1");
    SSTableImport.importJson(jsonUrl, "Keyspace1", "Standard1", tempSS.getPath());
    // Verify results
    SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(tempSS.getPath()));
    QueryFilter qf = QueryFilter.getIdentityFilter(Util.dk("rowA"), new QueryPath("Standard1"));
    IColumnIterator iter = qf.getSSTableColumnIterator(reader);
    ColumnFamily cf = iter.getColumnFamily();
    while (iter.hasNext()) cf.addColumn(iter.next());
    assert cf.getColumn(ByteBufferUtil.bytes("colAA")).value().equals(hexToBytes("76616c4141"));
    assert !(cf.getColumn(ByteBufferUtil.bytes("colAA")) instanceof DeletedColumn);
    IColumn expCol = cf.getColumn(ByteBufferUtil.bytes("colAC"));
    assert expCol.value().equals(hexToBytes("76616c4143"));
    assert expCol instanceof ExpiringColumn;
    assert ((ExpiringColumn) expCol).getTimeToLive() == 42 && expCol.getLocalDeletionTime() == 2000000000;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) QueryFilter(org.apache.cassandra.db.filter.QueryFilter) IColumn(org.apache.cassandra.db.IColumn) ExpiringColumn(org.apache.cassandra.db.ExpiringColumn) IColumnIterator(org.apache.cassandra.db.columniterator.IColumnIterator) DeletedColumn(org.apache.cassandra.db.DeletedColumn) File(java.io.File) SSTableUtils.tempSSTableFile(org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile) ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

Aggregations

File (java.io.File)3 ColumnFamily (org.apache.cassandra.db.ColumnFamily)3 ExpiringColumn (org.apache.cassandra.db.ExpiringColumn)3 QueryPath (org.apache.cassandra.db.filter.QueryPath)3 SSTableReader (org.apache.cassandra.io.sstable.SSTableReader)3 SSTableUtils.tempSSTableFile (org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile)3 Test (org.junit.Test)3 DeletedColumn (org.apache.cassandra.db.DeletedColumn)2 IColumn (org.apache.cassandra.db.IColumn)2 IColumnIterator (org.apache.cassandra.db.columniterator.IColumnIterator)2 QueryFilter (org.apache.cassandra.db.filter.QueryFilter)2 FileReader (java.io.FileReader)1 PrintStream (java.io.PrintStream)1 SSTableWriter (org.apache.cassandra.io.sstable.SSTableWriter)1 JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1