use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.
the class ReadMessageTest method testGetColumn.
@Test
public void testGetColumn() {
ColumnFamilyStore cfs = Keyspace.open(KEYSPACE1).getColumnFamilyStore(CF);
new RowUpdateBuilder(cfs.metadata(), 0, ByteBufferUtil.bytes("key1")).clustering("Column1").add("val", ByteBufferUtil.bytes("abcd")).build().apply();
ColumnMetadata col = cfs.metadata().getColumn(ByteBufferUtil.bytes("val"));
int found = 0;
for (FilteredPartition partition : Util.getAll(Util.cmd(cfs).build())) {
for (Row r : partition) {
if (r.getCell(col).value().equals(ByteBufferUtil.bytes("abcd")))
++found;
}
}
assertEquals(1, found);
}
use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.
the class RecoveryManagerTest method testRecoverCounter.
@Test
public void testRecoverCounter() throws IOException {
CommitLog.instance.resetUnsafe(true);
Keyspace keyspace1 = Keyspace.open(KEYSPACE1);
ColumnFamilyStore cfs = keyspace1.getColumnFamilyStore(CF_COUNTER1);
for (int i = 0; i < 10; ++i) {
new CounterMutation(new RowUpdateBuilder(cfs.metadata(), 1L, 0, "key").clustering("cc").add("val", CounterContext.instance().createLocal(1L)).build(), ConsistencyLevel.ALL).apply();
}
keyspace1.getColumnFamilyStore("Counter1").clearUnsafe();
int replayed = CommitLog.instance.resetUnsafe(false);
ColumnMetadata counterCol = cfs.metadata().getColumn(ByteBufferUtil.bytes("val"));
Row row = Util.getOnlyRow(Util.cmd(cfs).includeRow("cc").columns("val").build());
assertEquals(10L, CounterContext.instance().total(row.getCell(counterCol).value()));
}
use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.
the class RangeTombstoneTest method testOverwritesToDeletedColumns.
@Test
public void testOverwritesToDeletedColumns() throws Exception {
Keyspace table = Keyspace.open(KSNAME);
ColumnFamilyStore cfs = table.getColumnFamilyStore(CFNAME);
ByteBuffer key = ByteBufferUtil.bytes("k6");
ByteBuffer indexedColumnName = ByteBufferUtil.bytes("val");
cfs.truncateBlocking();
cfs.disableAutoCompaction();
ColumnMetadata cd = cfs.metadata().getColumn(indexedColumnName).copy();
IndexMetadata indexDef = IndexMetadata.fromIndexTargets(Collections.singletonList(new IndexTarget(cd.name, IndexTarget.Type.VALUES)), "test_index", IndexMetadata.Kind.CUSTOM, ImmutableMap.of(IndexTarget.CUSTOM_INDEX_OPTION_NAME, StubIndex.class.getName()));
TableMetadata current = cfs.metadata();
if (!current.indexes.get("test_index").isPresent()) {
TableMetadata updated = current.unbuild().indexes(current.indexes.with(indexDef)).build();
MigrationManager.announceTableUpdate(updated, true);
}
Future<?> rebuild = cfs.indexManager.addIndex(indexDef);
// If rebuild there is, wait for the rebuild to finish so it doesn't race with the following insertions
if (rebuild != null)
rebuild.get();
StubIndex index = (StubIndex) cfs.indexManager.getIndexByName("test_index");
index.reset();
UpdateBuilder.create(cfs.metadata(), key).withTimestamp(0).newRow(1).add("val", 1).applyUnsafe();
// add a RT which hides the column we just inserted
new RowUpdateBuilder(cfs.metadata(), 1, key).addRangeTombstone(0, 1).build().applyUnsafe();
// now re-insert that column
UpdateBuilder.create(cfs.metadata(), key).withTimestamp(2).newRow(1).add("val", 1).applyUnsafe();
cfs.forceBlockingFlush();
// We should have 1 insert and 1 update to the indexed "1" column
// CASSANDRA-6640 changed index update to just update, not insert then delete
assertEquals(1, index.rowsInserted.size());
assertEquals(1, index.rowsUpdated.size());
}
use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.
the class CellTest method testValidateNonFrozenUDT.
@Test
public void testValidateNonFrozenUDT() {
// has field position 0
FieldIdentifier f1 = field("f1");
// has field position 1
FieldIdentifier f2 = field("f2");
UserType udt = new UserType("ks", bb("myType"), asList(f1, f2), asList(Int32Type.instance, UTF8Type.instance), true);
ColumnMetadata c;
// Valid cells
c = fakeColumn("c", udt);
assertValid(BufferCell.live(c, 0, bb(1), CellPath.create(bbs(0))));
assertValid(BufferCell.live(c, 0, bb("foo"), CellPath.create(bbs(1))));
assertValid(BufferCell.expiring(c, 0, 4, 4, bb(1), CellPath.create(bbs(0))));
assertValid(BufferCell.expiring(c, 0, 4, 4, bb("foo"), CellPath.create(bbs(1))));
assertValid(BufferCell.tombstone(c, 0, 4, CellPath.create(bbs(0))));
// Invalid value (text in an int field)
assertInvalid(BufferCell.live(c, 0, bb("foo"), CellPath.create(bbs(0))));
// Invalid ttl
assertInvalid(BufferCell.expiring(c, 0, -4, 4, bb(1), CellPath.create(bbs(0))));
// Invalid local deletion times
assertInvalid(BufferCell.expiring(c, 0, 4, -5, bb(1), CellPath.create(bbs(0))));
assertInvalid(BufferCell.expiring(c, 0, 4, Cell.NO_DELETION_TIME, bb(1), CellPath.create(bbs(0))));
// Invalid cell path (int values should be 0 or 2 bytes)
assertInvalid(BufferCell.live(c, 0, bb(1), CellPath.create(ByteBufferUtil.bytes((long) 4))));
}
use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.
the class CellTest method testComplexCellReconcile.
@Test
public void testComplexCellReconcile() {
ColumnMetadata m = cfm2.getColumn(new ColumnIdentifier("m", false));
int now1 = FBUtilities.nowInSeconds();
long ts1 = now1 * 1000000;
Cell r1m1 = BufferCell.live(m, ts1, bb(1), CellPath.create(bb(1)));
Cell r1m2 = BufferCell.live(m, ts1, bb(2), CellPath.create(bb(2)));
List<Cell> cells1 = Lists.newArrayList(r1m1, r1m2);
int now2 = now1 + 1;
long ts2 = now2 * 1000000;
Cell r2m2 = BufferCell.live(m, ts2, bb(1), CellPath.create(bb(2)));
Cell r2m3 = BufferCell.live(m, ts2, bb(2), CellPath.create(bb(3)));
Cell r2m4 = BufferCell.live(m, ts2, bb(3), CellPath.create(bb(4)));
List<Cell> cells2 = Lists.newArrayList(r2m2, r2m3, r2m4);
RowBuilder builder = new RowBuilder();
Cells.reconcileComplex(m, cells1.iterator(), cells2.iterator(), DeletionTime.LIVE, builder, now2 + 1);
Assert.assertEquals(Lists.newArrayList(r1m1, r2m2, r2m3, r2m4), builder.cells);
}
Aggregations