Search in sources :

Example 6 with ColumnMetadata

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));
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata)

Example 7 with ColumnMetadata

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));
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata)

Example 8 with ColumnMetadata

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()));
            }
        }
    }
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) Row(org.apache.cassandra.db.rows.Row)

Example 9 with ColumnMetadata

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")));
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) BigInteger(java.math.BigInteger) Row(org.apache.cassandra.db.rows.Row) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 10 with ColumnMetadata

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());
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) StubIndex(org.apache.cassandra.index.StubIndex) java.util(java.util) CompactionManager(org.apache.cassandra.db.compaction.CompactionManager) ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) BeforeClass(org.junit.BeforeClass) ByteBuffer(java.nio.ByteBuffer) Iterators(com.google.common.collect.Iterators) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) org.apache.cassandra.db.rows(org.apache.cassandra.db.rows) Int32Type(org.apache.cassandra.db.marshal.Int32Type) UTF8Type(org.apache.cassandra.db.marshal.UTF8Type) Future(java.util.concurrent.Future) MigrationManager(org.apache.cassandra.schema.MigrationManager) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) IndexTarget(org.apache.cassandra.cql3.statements.IndexTarget) ColumnFilter(org.apache.cassandra.db.filter.ColumnFilter) UpdateBuilder(org.apache.cassandra.UpdateBuilder) org.apache.cassandra.db.partitions(org.apache.cassandra.db.partitions) SchemaLoader.standardCFMD(org.apache.cassandra.SchemaLoader.standardCFMD) FBUtilities(org.apache.cassandra.utils.FBUtilities) IndexMetadata(org.apache.cassandra.schema.IndexMetadata) ImmutableMap(com.google.common.collect.ImmutableMap) Util(org.apache.cassandra.Util) ByteBufferUtil(org.apache.cassandra.utils.ByteBufferUtil) KeyspaceParams(org.apache.cassandra.schema.KeyspaceParams) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ExecutionException(java.util.concurrent.ExecutionException) SchemaLoader(org.apache.cassandra.SchemaLoader) Assert.assertFalse(org.junit.Assert.assertFalse) TableMetadata(org.apache.cassandra.schema.TableMetadata) StatsMetadata(org.apache.cassandra.io.sstable.metadata.StatsMetadata) StubIndex(org.apache.cassandra.index.StubIndex) Assert.assertEquals(org.junit.Assert.assertEquals) ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) IndexTarget(org.apache.cassandra.cql3.statements.IndexTarget) UpdateBuilder(org.apache.cassandra.UpdateBuilder) ByteBuffer(java.nio.ByteBuffer) IndexMetadata(org.apache.cassandra.schema.IndexMetadata) Test(org.junit.Test)

Aggregations

ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)123 Test (org.junit.Test)35 ByteBuffer (java.nio.ByteBuffer)23 Row (org.apache.cassandra.db.rows.Row)17 TableMetadata (org.apache.cassandra.schema.TableMetadata)16 ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)15 AbstractType (org.apache.cassandra.db.marshal.AbstractType)8 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)5 java.util (java.util)4 IndexTarget (org.apache.cassandra.cql3.statements.IndexTarget)4 CollectionType (org.apache.cassandra.db.marshal.CollectionType)4 IndexMetadata (org.apache.cassandra.schema.IndexMetadata)4 IOException (java.io.IOException)3 Collectors (java.util.stream.Collectors)3 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)3 ColumnFilter (org.apache.cassandra.db.filter.ColumnFilter)3 ImmutableBTreePartition (org.apache.cassandra.db.partitions.ImmutableBTreePartition)3 Cell (org.apache.cassandra.db.rows.Cell)3 RowIterator (org.apache.cassandra.db.rows.RowIterator)3 InvalidRequestException (org.apache.cassandra.exceptions.InvalidRequestException)3