use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.
the class ColumnConditionTest method conditionApplies.
private static boolean conditionApplies(List<ByteBuffer> rowValue, Operator op, List<ByteBuffer> conditionValue) {
ColumnMetadata definition = ColumnMetadata.regularColumn("ks", "cf", "c", ListType.getInstance(Int32Type.instance, true));
ColumnCondition condition = ColumnCondition.condition(definition, op, Terms.of(new Lists.Value(conditionValue)));
ColumnCondition.Bound bound = condition.bind(QueryOptions.DEFAULT);
return bound.appliesTo(newRow(definition, rowValue));
}
use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.
the class ColumnConditionTest method conditionApplies.
private static boolean conditionApplies(SortedSet<ByteBuffer> rowValue, Operator op, SortedSet<ByteBuffer> conditionValue) {
ColumnMetadata definition = ColumnMetadata.regularColumn("ks", "cf", "c", SetType.getInstance(Int32Type.instance, true));
ColumnCondition condition = ColumnCondition.condition(definition, op, Terms.of(new Sets.Value(conditionValue)));
ColumnCondition.Bound bound = condition.bind(QueryOptions.DEFAULT);
return bound.appliesTo(newRow(definition, rowValue));
}
use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.
the class NameSortTest method validateNameSort.
private void validateNameSort(ColumnFamilyStore cfs) throws IOException {
for (FilteredPartition partition : Util.getAll(Util.cmd(cfs).build())) {
for (Row r : partition) {
for (ColumnMetadata cd : r.columns()) {
if (r.getCell(cd) == null)
continue;
int cellVal = Integer.valueOf(cd.name.toString().substring(cd.name.toString().length() - 1));
String expected = cellVal % 2 == 0 ? "a" : "b";
assertEquals(expected, ByteBufferUtil.string(r.getCell(cd).value()));
}
}
}
}
use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.
the class PartitionRangeReadTest method testCassandra6778.
@Test
public void testCassandra6778() throws CharacterCodingException {
String cfname = CF_STANDARDINT;
Keyspace keyspace = Keyspace.open(KEYSPACE1);
ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfname);
cfs.truncateBlocking();
ByteBuffer col = ByteBufferUtil.bytes("val");
ColumnMetadata cDef = cfs.metadata().getColumn(col);
// insert two columns that represent the same integer but have different binary forms (the
// second one is padded with extra zeros)
new RowUpdateBuilder(cfs.metadata(), 0, "k1").clustering(new BigInteger(new byte[] { 1 })).add("val", "val1").build().applyUnsafe();
cfs.forceBlockingFlush();
new RowUpdateBuilder(cfs.metadata(), 1, "k1").clustering(new BigInteger(new byte[] { 0, 0, 1 })).add("val", "val2").build().applyUnsafe();
cfs.forceBlockingFlush();
// fetch by the first column name; we should get the second version of the column value
Row row = Util.getOnlyRow(Util.cmd(cfs, "k1").includeRow(new BigInteger(new byte[] { 1 })).build());
assertTrue(row.getCell(cDef).value().equals(ByteBufferUtil.bytes("val2")));
// fetch by the second column name; we should get the second version of the column value
row = Util.getOnlyRow(Util.cmd(cfs, "k1").includeRow(new BigInteger(new byte[] { 0, 0, 1 })).build());
assertTrue(row.getCell(cDef).value().equals(ByteBufferUtil.bytes("val2")));
}
use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.
the class RangeTombstoneTest method testRowWithRangeTombstonesUpdatesSecondaryIndex.
@Test
public void testRowWithRangeTombstonesUpdatesSecondaryIndex() throws Exception {
Keyspace table = Keyspace.open(KSNAME);
ColumnFamilyStore cfs = table.getColumnFamilyStore(CFNAME);
ByteBuffer key = ByteBufferUtil.bytes("k5");
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.listIndexes().stream().filter(i -> "test_index".equals(i.getIndexMetadata().name)).findFirst().orElseThrow(() -> new RuntimeException(new AssertionError("Index not found")));
index.reset();
UpdateBuilder builder = UpdateBuilder.create(cfs.metadata(), key).withTimestamp(0);
for (int i = 0; i < 10; i++) builder.newRow(i).add("val", i);
builder.applyUnsafe();
cfs.forceBlockingFlush();
new RowUpdateBuilder(cfs.metadata(), 0, key).addRangeTombstone(0, 7).build().applyUnsafe();
cfs.forceBlockingFlush();
assertEquals(10, index.rowsInserted.size());
CompactionManager.instance.performMaximal(cfs, false);
// compacted down to single sstable
assertEquals(1, cfs.getLiveSSTables().size());
assertEquals(8, index.rowsDeleted.size());
}
Aggregations