Search in sources :

Example 26 with ColumnFamily

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

the class SSTableImportTest method testImportSuperCf.

@Test
public void testImportSuperCf() throws IOException, ParseException, URISyntaxException {
    String jsonUrl = resourcePath("SuperCF.json");
    File tempSS = tempSSTableFile("Keyspace1", "Super4");
    SSTableImport.importJson(jsonUrl, "Keyspace1", "Super4", tempSS.getPath());
    // Verify results
    SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(tempSS.getPath()));
    QueryFilter qf = QueryFilter.getNamesFilter(Util.dk("rowA"), new QueryPath("Super4", null, null), ByteBufferUtil.bytes("superA"));
    ColumnFamily cf = qf.getSSTableColumnIterator(reader).getColumnFamily();
    IColumn superCol = cf.getColumn(ByteBufferUtil.bytes("superA"));
    assert superCol != null;
    assert superCol.getSubColumns().size() > 0;
    IColumn subColumn = superCol.getSubColumn(ByteBufferUtil.bytes("636f6c4141"));
    assert subColumn.value().equals(hexToBytes("76616c75654141"));
}
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) File(java.io.File) SSTableUtils.tempSSTableFile(org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile) ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

Example 27 with ColumnFamily

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

the class SSTableImportTest method testImportCounterCf.

@Test
public void testImportCounterCf() throws IOException, URISyntaxException {
    // Import JSON to temp SSTable file
    String jsonUrl = resourcePath("CounterCF.json");
    File tempSS = tempSSTableFile("Keyspace1", "Counter1");
    SSTableImport.importJson(jsonUrl, "Keyspace1", "Counter1", tempSS.getPath());
    // Verify results
    SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(tempSS.getPath()));
    QueryFilter qf = QueryFilter.getIdentityFilter(Util.dk("rowA"), new QueryPath("Counter1"));
    IColumnIterator iter = qf.getSSTableColumnIterator(reader);
    ColumnFamily cf = iter.getColumnFamily();
    while (iter.hasNext()) cf.addColumn(iter.next());
    IColumn c = cf.getColumn(ByteBufferUtil.bytes("colAA"));
    assert c instanceof CounterColumn : c;
    assert ((CounterColumn) c).total() == 42;
}
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) IColumnIterator(org.apache.cassandra.db.columniterator.IColumnIterator) CounterColumn(org.apache.cassandra.db.CounterColumn) File(java.io.File) SSTableUtils.tempSSTableFile(org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile) ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

Example 28 with ColumnFamily

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

the class SSTableImportTest method testImportUnsortedMode.

@Test
public void testImportUnsortedMode() throws IOException, URISyntaxException {
    String jsonUrl = resourcePath("UnsortedSuperCF.json");
    File tempSS = tempSSTableFile("Keyspace1", "Super4");
    ColumnFamily columnFamily = ColumnFamily.create("Keyspace1", "Super4");
    IPartitioner<?> partitioner = DatabaseDescriptor.getPartitioner();
    SSTableImport.setKeyCountToImport(3);
    int result = SSTableImport.importSorted(jsonUrl, columnFamily, tempSS.getPath(), partitioner);
    assert result == -1;
}
Also used : File(java.io.File) SSTableUtils.tempSSTableFile(org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile) ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

Example 29 with ColumnFamily

use of org.apache.cassandra.db.ColumnFamily 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 30 with ColumnFamily

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

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