Search in sources :

Example 16 with IColumn

use of org.apache.cassandra.db.IColumn 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)

Example 17 with IColumn

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

the class SSTableUtils method assertContentEquals.

public static void assertContentEquals(IColumnIterator lhs, IColumnIterator rhs) throws IOException {
    assertEquals(lhs.getKey(), rhs.getKey());
    // check metadata
    ColumnFamily lcf = lhs.getColumnFamily();
    ColumnFamily rcf = rhs.getColumnFamily();
    if (lcf == null) {
        if (rcf == null)
            return;
        throw new AssertionError("LHS had no content for " + rhs.getKey());
    } else if (rcf == null)
        throw new AssertionError("RHS had no content for " + lhs.getKey());
    assertEquals(lcf.getMarkedForDeleteAt(), rcf.getMarkedForDeleteAt());
    assertEquals(lcf.getLocalDeletionTime(), rcf.getLocalDeletionTime());
    // iterate columns
    while (lhs.hasNext()) {
        IColumn clhs = lhs.next();
        assert rhs.hasNext() : "LHS contained more columns than RHS for " + lhs.getKey();
        IColumn crhs = rhs.next();
        assertEquals("Mismatched columns for " + lhs.getKey(), clhs, crhs);
    }
    assert !rhs.hasNext() : "RHS contained more columns than LHS for " + lhs.getKey();
}
Also used : IColumn(org.apache.cassandra.db.IColumn) ColumnFamily(org.apache.cassandra.db.ColumnFamily)

Example 18 with IColumn

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

the class CassandraStorage method columnToTuple.

private Tuple columnToTuple(ByteBuffer name, IColumn col, CfDef cfDef) throws IOException {
    Tuple pair = TupleFactory.getInstance().newTuple(2);
    List<AbstractType> marshallers = getDefaultMarshallers(cfDef);
    Map<ByteBuffer, AbstractType> validators = getValidatorMap(cfDef);
    setTupleValue(pair, 0, marshallers.get(0).compose(name));
    if (col instanceof Column) {
        // standard
        if (validators.get(name) == null)
            setTupleValue(pair, 1, marshallers.get(1).compose(col.value()));
        else
            setTupleValue(pair, 1, validators.get(name).compose(col.value()));
        return pair;
    }
    // super
    ArrayList<Tuple> subcols = new ArrayList<Tuple>();
    for (IColumn subcol : col.getSubColumns()) subcols.add(columnToTuple(subcol.name(), subcol, cfDef));
    pair.set(1, new DefaultDataBag(subcols));
    return pair;
}
Also used : Column(org.apache.cassandra.db.Column) IColumn(org.apache.cassandra.db.IColumn) ColumnOrSuperColumn(org.apache.cassandra.thrift.ColumnOrSuperColumn) IColumn(org.apache.cassandra.db.IColumn) ByteBuffer(java.nio.ByteBuffer)

Example 19 with IColumn

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

the class CompactionsPurgeTest method testCompactionPurgeCachedRow.

@Test
public void testCompactionPurgeCachedRow() throws IOException, ExecutionException, InterruptedException {
    CompactionManager.instance.disableAutoCompaction();
    String tableName = "RowCacheSpace";
    String cfName = "CachedCF";
    Table table = Table.open(tableName);
    ColumnFamilyStore cfs = table.getColumnFamilyStore(cfName);
    DecoratedKey key = Util.dk("key3");
    RowMutation rm;
    // inserts
    rm = new RowMutation(tableName, key.key);
    for (int i = 0; i < 10; i++) {
        rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0);
    }
    rm.apply();
    // move the key up in row cache
    cfs.getColumnFamily(QueryFilter.getIdentityFilter(key, new QueryPath(cfName)));
    // deletes row
    rm = new RowMutation(tableName, key.key);
    rm.delete(new QueryPath(cfName, null, null), 1);
    rm.apply();
    // flush and major compact
    cfs.forceBlockingFlush();
    Util.compactAll(cfs).get();
    // re-inserts with timestamp lower than delete
    rm = new RowMutation(tableName, key.key);
    for (int i = 0; i < 10; i++) {
        rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0);
    }
    rm.apply();
    // Check that the second insert did went in
    ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(key, new QueryPath(cfName)));
    assertEquals(10, cf.getColumnCount());
    for (IColumn c : cf) assert !c.isMarkedForDelete();
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) Table(org.apache.cassandra.db.Table) IColumn(org.apache.cassandra.db.IColumn) DecoratedKey(org.apache.cassandra.db.DecoratedKey) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) RowMutation(org.apache.cassandra.db.RowMutation) ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

Example 20 with IColumn

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

the class CompactionsPurgeTest method testCompactionPurgeTombstonedRow.

@Test
public void testCompactionPurgeTombstonedRow() throws IOException, ExecutionException, InterruptedException {
    CompactionManager.instance.disableAutoCompaction();
    String tableName = "Keyspace1";
    String cfName = "Standard1";
    Table table = Table.open(tableName);
    ColumnFamilyStore cfs = table.getColumnFamilyStore(cfName);
    DecoratedKey key = Util.dk("key3");
    RowMutation rm;
    // inserts
    rm = new RowMutation(tableName, key.key);
    for (int i = 0; i < 10; i++) {
        rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), ByteBufferUtil.EMPTY_BYTE_BUFFER, i);
    }
    rm.apply();
    // deletes row with timestamp such that not all columns are deleted
    rm = new RowMutation(tableName, key.key);
    rm.delete(new QueryPath(cfName, null, null), 4);
    rm.apply();
    // flush and major compact (with tombstone purging)
    cfs.forceBlockingFlush();
    Util.compactAll(cfs).get();
    // re-inserts with timestamp lower than delete
    rm = new RowMutation(tableName, key.key);
    for (int i = 0; i < 5; i++) {
        rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), ByteBufferUtil.EMPTY_BYTE_BUFFER, i);
    }
    rm.apply();
    // Check that the second insert did went in
    ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(key, new QueryPath(cfName)));
    assertEquals(10, cf.getColumnCount());
    for (IColumn c : cf) assert !c.isMarkedForDelete();
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) Table(org.apache.cassandra.db.Table) IColumn(org.apache.cassandra.db.IColumn) DecoratedKey(org.apache.cassandra.db.DecoratedKey) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) RowMutation(org.apache.cassandra.db.RowMutation) ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

Aggregations

IColumn (org.apache.cassandra.db.IColumn)20 ColumnFamily (org.apache.cassandra.db.ColumnFamily)8 QueryPath (org.apache.cassandra.db.filter.QueryPath)6 Test (org.junit.Test)6 ByteBuffer (java.nio.ByteBuffer)5 File (java.io.File)4 QueryFilter (org.apache.cassandra.db.filter.QueryFilter)4 SSTableReader (org.apache.cassandra.io.sstable.SSTableReader)4 SSTableUtils.tempSSTableFile (org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile)4 IOException (java.io.IOException)3 Column (org.apache.cassandra.db.Column)3 IColumnIterator (org.apache.cassandra.db.columniterator.IColumnIterator)3 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)2 DecoratedKey (org.apache.cassandra.db.DecoratedKey)2 DeletedColumn (org.apache.cassandra.db.DeletedColumn)2 ExpiringColumn (org.apache.cassandra.db.ExpiringColumn)2 Row (org.apache.cassandra.db.Row)2 RowMutation (org.apache.cassandra.db.RowMutation)2 Table (org.apache.cassandra.db.Table)2 AbstractType (org.apache.cassandra.db.marshal.AbstractType)2