Search in sources :

Example 21 with QueryPath

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

the class DefsTest method createEmptyKsAddNewCf.

@Test
public void createEmptyKsAddNewCf() throws ConfigurationException, IOException, ExecutionException, InterruptedException {
    assert Schema.instance.getTableDefinition("EmptyKeyspace") == null;
    KSMetaData newKs = KSMetaData.testMetadata("EmptyKeyspace", SimpleStrategy.class, KSMetaData.optsWithRF(5));
    new AddKeyspace(newKs).apply();
    assert Schema.instance.getTableDefinition("EmptyKeyspace") != null;
    CFMetaData newCf = addTestCF("EmptyKeyspace", "AddedLater", "A new CF to add to an empty KS");
    //should not exist until apply
    assert !Schema.instance.getTableDefinition(newKs.name).cfMetaData().containsKey(newCf.cfName);
    //add the new CF to the empty space
    new AddColumnFamily(newCf).apply();
    assert Schema.instance.getTableDefinition(newKs.name).cfMetaData().containsKey(newCf.cfName);
    assert Schema.instance.getTableDefinition(newKs.name).cfMetaData().get(newCf.cfName).equals(newCf);
    // now read and write to it.
    DecoratedKey dk = Util.dk("key0");
    RowMutation rm = new RowMutation(newKs.name, dk.key);
    rm.add(new QueryPath(newCf.cfName, null, ByteBufferUtil.bytes("col0")), ByteBufferUtil.bytes("value0"), 1L);
    rm.apply();
    ColumnFamilyStore store = Table.open(newKs.name).getColumnFamilyStore(newCf.cfName);
    assert store != null;
    store.forceBlockingFlush();
    ColumnFamily cfam = store.getColumnFamily(QueryFilter.getNamesFilter(dk, new QueryPath(newCf.cfName), ByteBufferUtil.bytes("col0")));
    assert cfam.getColumn(ByteBufferUtil.bytes("col0")) != null;
    IColumn col = cfam.getColumn(ByteBufferUtil.bytes("col0"));
    assert ByteBufferUtil.bytes("value0").equals(col.value());
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) AddKeyspace(org.apache.cassandra.db.migration.AddKeyspace) AddColumnFamily(org.apache.cassandra.db.migration.AddColumnFamily) UpdateColumnFamily(org.apache.cassandra.db.migration.UpdateColumnFamily) AddColumnFamily(org.apache.cassandra.db.migration.AddColumnFamily) DropColumnFamily(org.apache.cassandra.db.migration.DropColumnFamily) Test(org.junit.Test)

Example 22 with QueryPath

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

the class DefsTest method addNewKS.

@Test
public void addNewKS() throws ConfigurationException, IOException, ExecutionException, InterruptedException {
    DecoratedKey dk = Util.dk("key0");
    CFMetaData newCf = addTestCF("NewKeyspace1", "AddedStandard1", "A new cf for a new ks");
    KSMetaData newKs = KSMetaData.testMetadata(newCf.ksName, SimpleStrategy.class, KSMetaData.optsWithRF(5), newCf);
    new AddKeyspace(newKs).apply();
    assert Schema.instance.getTableDefinition(newCf.ksName) != null;
    assert Schema.instance.getTableDefinition(newCf.ksName) == newKs;
    // test reads and writes.
    RowMutation rm = new RowMutation(newCf.ksName, dk.key);
    rm.add(new QueryPath(newCf.cfName, null, ByteBufferUtil.bytes("col0")), ByteBufferUtil.bytes("value0"), 1L);
    rm.apply();
    ColumnFamilyStore store = Table.open(newCf.ksName).getColumnFamilyStore(newCf.cfName);
    assert store != null;
    store.forceBlockingFlush();
    ColumnFamily cfam = store.getColumnFamily(QueryFilter.getNamesFilter(dk, new QueryPath(newCf.cfName), ByteBufferUtil.bytes("col0")));
    assert cfam.getColumn(ByteBufferUtil.bytes("col0")) != null;
    IColumn col = cfam.getColumn(ByteBufferUtil.bytes("col0"));
    assert ByteBufferUtil.bytes("value0").equals(col.value());
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) AddKeyspace(org.apache.cassandra.db.migration.AddKeyspace) UpdateColumnFamily(org.apache.cassandra.db.migration.UpdateColumnFamily) AddColumnFamily(org.apache.cassandra.db.migration.AddColumnFamily) DropColumnFamily(org.apache.cassandra.db.migration.DropColumnFamily) Test(org.junit.Test)

Example 23 with QueryPath

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

the class DefsTest method testDropIndex.

@Test
public void testDropIndex() throws IOException, ExecutionException, InterruptedException, ConfigurationException {
    // insert some data.  save the sstable descriptor so we can make sure it's marked for delete after the drop
    RowMutation rm = new RowMutation("Keyspace6", ByteBufferUtil.bytes("k1"));
    rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("notbirthdate")), ByteBufferUtil.bytes(1L), 0);
    rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(1L), 0);
    rm.apply();
    ColumnFamilyStore cfs = Table.open("Keyspace6").getColumnFamilyStore("Indexed1");
    cfs.forceBlockingFlush();
    ColumnFamilyStore indexedCfs = cfs.indexManager.getIndexForColumn(cfs.indexManager.getIndexedColumns().iterator().next()).getIndexCfs();
    Descriptor desc = indexedCfs.getSSTables().iterator().next().descriptor;
    // drop the index
    // abusing rename to clone
    CFMetaData meta = CFMetaData.rename(cfs.metadata, cfs.metadata.cfName);
    ColumnDefinition cdOld = meta.getColumn_metadata().values().iterator().next();
    ColumnDefinition cdNew = new ColumnDefinition(cdOld.name, cdOld.getValidator(), null, null, null);
    meta.columnMetadata(Collections.singletonMap(cdOld.name, cdNew));
    UpdateColumnFamily update = new UpdateColumnFamily(meta.toAvro());
    update.apply();
    // check
    assert cfs.indexManager.getIndexedColumns().isEmpty();
    SSTableDeletingTask.waitForDeletions();
    assert !new File(desc.filenameFor(Component.DATA)).exists();
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) UpdateColumnFamily(org.apache.cassandra.db.migration.UpdateColumnFamily) Descriptor(org.apache.cassandra.io.sstable.Descriptor) File(java.io.File) Test(org.junit.Test)

Example 24 with QueryPath

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

the class NameSortTest method testNameSort.

private void testNameSort(int N) throws IOException, ExecutionException, InterruptedException {
    Table table = Table.open("Keyspace1");
    for (int i = 0; i < N; ++i) {
        ByteBuffer key = ByteBufferUtil.bytes(Integer.toString(i));
        RowMutation rm;
        // standard
        for (int j = 0; j < 8; ++j) {
            ByteBuffer bytes = j % 2 == 0 ? ByteBufferUtil.bytes("a") : ByteBufferUtil.bytes("b");
            rm = new RowMutation("Keyspace1", key);
            rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes(("Column-" + j))), bytes, j);
            rm.applyUnsafe();
        }
        // super
        for (int j = 0; j < 8; ++j) {
            rm = new RowMutation("Keyspace1", key);
            for (int k = 0; k < 4; ++k) {
                String value = (j + k) % 2 == 0 ? "a" : "b";
                addMutation(rm, "Super1", "SuperColumn-" + j, k, value, k);
            }
            rm.applyUnsafe();
        }
    }
    validateNameSort(table, N);
    table.getColumnFamilyStore("Standard1").forceBlockingFlush();
    table.getColumnFamilyStore("Super1").forceBlockingFlush();
    validateNameSort(table, N);
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) ByteBuffer(java.nio.ByteBuffer)

Example 25 with QueryPath

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

the class CleanupHelper method insertData.

protected void insertData(String keyspace, String columnFamily, int offset, int numberOfRows) throws IOException {
    for (int i = offset; i < offset + numberOfRows; i++) {
        ByteBuffer key = ByteBufferUtil.bytes("key" + i);
        RowMutation rowMutation = new RowMutation(keyspace, key);
        QueryPath path = new QueryPath(columnFamily, null, ByteBufferUtil.bytes("col" + i));
        rowMutation.add(path, ByteBufferUtil.bytes("val" + i), System.currentTimeMillis());
        rowMutation.applyUnsafe();
    }
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) RowMutation(org.apache.cassandra.db.RowMutation) ByteBuffer(java.nio.ByteBuffer)

Aggregations

QueryPath (org.apache.cassandra.db.filter.QueryPath)123 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)11 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 IColumn (org.apache.cassandra.db.IColumn)6 ArrayList (java.util.ArrayList)5 PrintStream (java.io.PrintStream)4 UnknownHostException (java.net.UnknownHostException)4 HashSet (java.util.HashSet)4 DropColumnFamily (org.apache.cassandra.db.migration.DropColumnFamily)4