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());
}
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());
}
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();
}
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);
}
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();
}
}
Aggregations