Search in sources :

Example 76 with QueryPath

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

the class CompositeTypeTest method testFullRound.

@Test
public void testFullRound() throws Exception {
    Table table = Table.open("Keyspace1");
    ColumnFamilyStore cfs = table.getColumnFamilyStore(cfName);
    ByteBuffer cname1 = createCompositeKey("test1", null, -1, false);
    ByteBuffer cname2 = createCompositeKey("test1", uuids[0], 24, false);
    ByteBuffer cname3 = createCompositeKey("test1", uuids[0], 42, false);
    ByteBuffer cname4 = createCompositeKey("test2", uuids[0], -1, false);
    ByteBuffer cname5 = createCompositeKey("test2", uuids[1], 42, false);
    ByteBuffer key = ByteBufferUtil.bytes("k");
    RowMutation rm = new RowMutation("Keyspace1", key);
    addColumn(rm, cname5);
    addColumn(rm, cname1);
    addColumn(rm, cname4);
    addColumn(rm, cname2);
    addColumn(rm, cname3);
    rm.apply();
    ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(Util.dk("k"), new QueryPath(cfName, null, null)));
    Iterator<IColumn> iter = cf.getSortedColumns().iterator();
    assert iter.next().name().equals(cname1);
    assert iter.next().name().equals(cname2);
    assert iter.next().name().equals(cname3);
    assert iter.next().name().equals(cname4);
    assert iter.next().name().equals(cname5);
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 77 with QueryPath

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

the class TableTest method testGetSliceWithCutoff.

@Test
public void testGetSliceWithCutoff() throws Throwable {
    // tests slicing against data from one row in a memtable and then flushed to an sstable
    final Table table = Table.open("Keyspace1");
    final ColumnFamilyStore cfStore = table.getColumnFamilyStore("Standard1");
    final DecoratedKey ROW = Util.dk("row4");
    final NumberFormat fmt = new DecimalFormat("000");
    RowMutation rm = new RowMutation("Keyspace1", ROW.key);
    ColumnFamily cf = ColumnFamily.create("Keyspace1", "Standard1");
    // so if we go to 300, we'll get at least 4 blocks, which is plenty for testing.
    for (int i = 0; i < 300; i++) cf.addColumn(column("col" + fmt.format(i), "omg!thisisthevalue!" + i, 1L));
    rm.add(cf);
    rm.apply();
    Runnable verify = new WrappedRunnable() {

        public void runMayThrow() throws Exception {
            ColumnFamily cf;
            // blocks are partitioned like this: 000-097, 098-193, 194-289, 290-299, assuming a 4k column index size.
            assert DatabaseDescriptor.getColumnIndexSize() == 4096 : "Unexpected column index size, block boundaries won't be where tests expect them.";
            // test forward, spanning a segment.
            cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ByteBufferUtil.bytes("col096"), ByteBufferUtil.bytes("col099"), false, 4);
            assertColumns(cf, "col096", "col097", "col098", "col099");
            // test reversed, spanning a segment.
            cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ByteBufferUtil.bytes("col099"), ByteBufferUtil.bytes("col096"), true, 4);
            assertColumns(cf, "col096", "col097", "col098", "col099");
            // test forward, within a segment.
            cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ByteBufferUtil.bytes("col100"), ByteBufferUtil.bytes("col103"), false, 4);
            assertColumns(cf, "col100", "col101", "col102", "col103");
            // test reversed, within a segment.
            cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ByteBufferUtil.bytes("col103"), ByteBufferUtil.bytes("col100"), true, 4);
            assertColumns(cf, "col100", "col101", "col102", "col103");
            // test forward from beginning, spanning a segment.
            // col000-col099
            String[] strCols = new String[100];
            for (int i = 0; i < 100; i++) strCols[i] = "col" + fmt.format(i);
            cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.bytes("col099"), false, 100);
            assertColumns(cf, strCols);
            // test reversed, from end, spanning a segment.
            cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.bytes("col288"), true, 12);
            assertColumns(cf, "col288", "col289", "col290", "col291", "col292", "col293", "col294", "col295", "col296", "col297", "col298", "col299");
        }
    };
    reTest(table.getColumnFamilyStore("Standard1"), verify);
}
Also used : WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) DecimalFormat(java.text.DecimalFormat) QueryPath(org.apache.cassandra.db.filter.QueryPath) WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) NumberFormat(java.text.NumberFormat) Test(org.junit.Test)

Example 78 with QueryPath

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

the class TableTest method testGetSliceFromBasic.

@Test
public void testGetSliceFromBasic() throws Throwable {
    // tests slicing against data from one row in a memtable and then flushed to an sstable
    final Table table = Table.open("Keyspace1");
    final ColumnFamilyStore cfStore = table.getColumnFamilyStore("Standard1");
    final DecoratedKey ROW = Util.dk("row1");
    RowMutation rm = new RowMutation("Keyspace1", ROW.key);
    ColumnFamily cf = ColumnFamily.create("Keyspace1", "Standard1");
    cf.addColumn(column("col1", "val1", 1L));
    cf.addColumn(column("col3", "val3", 1L));
    cf.addColumn(column("col4", "val4", 1L));
    cf.addColumn(column("col5", "val5", 1L));
    cf.addColumn(column("col7", "val7", 1L));
    cf.addColumn(column("col9", "val9", 1L));
    rm.add(cf);
    rm.apply();
    rm = new RowMutation("Keyspace1", ROW.key);
    rm.delete(new QueryPath("Standard1", null, ByteBufferUtil.bytes("col4")), 2L);
    rm.apply();
    Runnable verify = new WrappedRunnable() {

        public void runMayThrow() throws Exception {
            ColumnFamily cf;
            cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ByteBufferUtil.bytes("col5"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 2);
            assertColumns(cf, "col5", "col7");
            cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ByteBufferUtil.bytes("col4"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 2);
            assertColumns(cf, "col4", "col5", "col7");
            assertColumns(ColumnFamilyStore.removeDeleted(cf, Integer.MAX_VALUE), "col5", "col7");
            cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ByteBufferUtil.bytes("col5"), ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 2);
            assertColumns(cf, "col3", "col4", "col5");
            cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ByteBufferUtil.bytes("col6"), ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 2);
            assertColumns(cf, "col3", "col4", "col5");
            cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 2);
            assertColumns(cf, "col7", "col9");
            cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ByteBufferUtil.bytes("col95"), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 2);
            assertColumns(cf);
            cf = cfStore.getColumnFamily(ROW, new QueryPath("Standard1"), ByteBufferUtil.bytes("col0"), ByteBufferUtil.EMPTY_BYTE_BUFFER, true, 2);
            assertColumns(cf);
        }
    };
    reTest(table.getColumnFamilyStore("Standard1"), verify);
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) Test(org.junit.Test)

Example 79 with QueryPath

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

the class TableTest method testGetRowNoColumns.

@Test
public void testGetRowNoColumns() throws Throwable {
    final Table table = Table.open("Keyspace2");
    final ColumnFamilyStore cfStore = table.getColumnFamilyStore("Standard3");
    RowMutation rm = new RowMutation("Keyspace2", TEST_KEY.key);
    ColumnFamily cf = ColumnFamily.create("Keyspace2", "Standard3");
    cf.addColumn(column("col1", "val1", 1L));
    rm.add(cf);
    rm.apply();
    Runnable verify = new WrappedRunnable() {

        public void runMayThrow() throws Exception {
            ColumnFamily cf;
            cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter(TEST_KEY, new QueryPath("Standard3"), new TreeSet<ByteBuffer>()));
            assertColumns(cf);
            cf = cfStore.getColumnFamily(QueryFilter.getSliceFilter(TEST_KEY, new QueryPath("Standard3"), ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 0));
            assertColumns(cf);
            cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter(TEST_KEY, new QueryPath("Standard3"), ByteBufferUtil.bytes("col99")));
            assertColumns(cf);
        }
    };
    reTest(table.getColumnFamilyStore("Standard3"), verify);
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 80 with QueryPath

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

the class RecoveryManagerTruncateTest method getFromTable.

private IColumn getFromTable(Table table, String cfName, String keyName, String columnName) {
    ColumnFamily cf;
    ColumnFamilyStore cfStore = table.getColumnFamilyStore(cfName);
    if (cfStore == null) {
        return null;
    }
    cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter(Util.dk(keyName), new QueryPath(cfName), ByteBufferUtil.bytes(columnName)));
    if (cf == null) {
        return null;
    }
    return cf.getColumn(ByteBufferUtil.bytes(columnName));
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath)

Aggregations

QueryPath (org.apache.cassandra.db.filter.QueryPath)127 Test (org.junit.Test)67 ByteBuffer (java.nio.ByteBuffer)40 QueryFilter (org.apache.cassandra.db.filter.QueryFilter)22 ColumnFamily (org.apache.cassandra.db.ColumnFamily)14 RowMutation (org.apache.cassandra.db.RowMutation)12 File (java.io.File)10 SSTableReader (org.apache.cassandra.io.sstable.SSTableReader)10 IOException (java.io.IOException)8 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)8 DecoratedKey (org.apache.cassandra.db.DecoratedKey)8 Table (org.apache.cassandra.db.Table)8 SSTableUtils.tempSSTableFile (org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile)8 WrappedRunnable (org.apache.cassandra.utils.WrappedRunnable)8 ArrayList (java.util.ArrayList)5 IColumn (org.apache.cassandra.db.IColumn)5 PrintStream (java.io.PrintStream)4 UnknownHostException (java.net.UnknownHostException)4 HashSet (java.util.HashSet)4 DropColumnFamily (org.apache.cassandra.db.migration.DropColumnFamily)4