Search in sources :

Example 46 with ColumnIdentifier

use of org.apache.cassandra.cql3.ColumnIdentifier in project cassandra by apache.

the class QueryPagerTest method queryAndVerifyCells.

private void queryAndVerifyCells(TableMetadata table, boolean reversed, String key) {
    ClusteringIndexFilter rowfilter = new ClusteringIndexSliceFilter(Slices.ALL, reversed);
    ReadCommand command = SinglePartitionReadCommand.create(table, nowInSec, Util.dk(key), ColumnFilter.all(table), rowfilter);
    QueryPager pager = command.getPager(null, ProtocolVersion.CURRENT);
    ColumnMetadata staticColumn = table.staticColumns().getSimple(0);
    assertEquals(staticColumn.name.toCQLString(), "st");
    for (int i = 0; i < 5; i++) {
        try (ReadExecutionController controller = pager.executionController();
            PartitionIterator partitions = pager.fetchPageInternal(1, controller)) {
            try (RowIterator partition = partitions.next()) {
                assertCell(partition.staticRow(), staticColumn, 4);
                Row row = partition.next();
                int cellIndex = !reversed ? i : 4 - i;
                assertEquals(row.clustering().bufferAt(0), ByteBufferUtil.bytes(cellIndex));
                assertCell(row, table.getColumn(new ColumnIdentifier("v1", false)), cellIndex);
                assertCell(row, table.getColumn(new ColumnIdentifier("v2", false)), cellIndex);
                // the partition/page should contain just a single regular row
                assertFalse(partition.hasNext());
            }
        }
    }
    // After processing the 5 rows there should be no more rows to return
    try (ReadExecutionController controller = pager.executionController();
        PartitionIterator partitions = pager.fetchPageInternal(1, controller)) {
        assertFalse(partitions.hasNext());
    }
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) QueryPager(org.apache.cassandra.service.pager.QueryPager) PartitionIterator(org.apache.cassandra.db.partitions.PartitionIterator) RowIterator(org.apache.cassandra.db.rows.RowIterator) ColumnIdentifier(org.apache.cassandra.cql3.ColumnIdentifier) Row(org.apache.cassandra.db.rows.Row)

Example 47 with ColumnIdentifier

use of org.apache.cassandra.cql3.ColumnIdentifier in project stargate-core by tuplejump.

the class RowIndexSupport method loadOldRow.

private void loadOldRow(DecoratedKey dk, ByteBuffer pkBuf, List<Field> fields) {
    CellName clusteringKey = tableMapper.makeClusteringKey(pkBuf);
    Composite start = tableMapper.start(clusteringKey);
    Composite end = tableMapper.end(start);
    ColumnSlice columnSlice = new ColumnSlice(start, end);
    SliceQueryFilter sliceQueryFilter = new SliceQueryFilter(columnSlice, false, Integer.MAX_VALUE);
    QueryFilter queryFilter = new QueryFilter(dk, tableMapper.table.name, sliceQueryFilter, new Date().getTime());
    ColumnFamily columnFamily = tableMapper.table.getColumnFamily(queryFilter);
    Map<CellName, ColumnFamily> fullSlice = tableMapper.getRows(columnFamily);
    ColumnFamily oldDocument = fullSlice.get(clusteringKey);
    for (Cell cell : oldDocument) {
        CellName cellName = cell.name();
        ColumnIdentifier cql3ColName = cellName.cql3ColumnName(tableMapper.cfMetaData);
        String actualColName = cql3ColName.toString();
        ColumnDefinition columnDefinition = tableMapper.cfMetaData.getColumnDefinition(cql3ColName);
        if (options.shouldIndex(actualColName)) {
            addFields(cell, actualColName, columnDefinition, fields);
        }
    }
}
Also used : SliceQueryFilter(org.apache.cassandra.db.filter.SliceQueryFilter) QueryFilter(org.apache.cassandra.db.filter.QueryFilter) Composite(org.apache.cassandra.db.composites.Composite) ColumnSlice(org.apache.cassandra.db.filter.ColumnSlice) SliceQueryFilter(org.apache.cassandra.db.filter.SliceQueryFilter) ColumnIdentifier(org.apache.cassandra.cql3.ColumnIdentifier) CellName(org.apache.cassandra.db.composites.CellName) ColumnDefinition(org.apache.cassandra.config.ColumnDefinition)

Aggregations

ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)43 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)26 Test (org.junit.Test)15 TableMetadata (org.apache.cassandra.schema.TableMetadata)14 Row (org.apache.cassandra.db.rows.Row)10 ByteBuffer (java.nio.ByteBuffer)9 IndexTarget (org.apache.cassandra.cql3.statements.schema.IndexTarget)8 java.util (java.util)4 ArrayList (java.util.ArrayList)4 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)4 PartitionIterator (org.apache.cassandra.db.partitions.PartitionIterator)4 PartitionUpdate (org.apache.cassandra.db.partitions.PartitionUpdate)4 RowIterator (org.apache.cassandra.db.rows.RowIterator)4 ClientState (org.apache.cassandra.service.ClientState)4 Iterables (com.google.common.collect.Iterables)3 StatementRestrictions (org.apache.cassandra.cql3.restrictions.StatementRestrictions)3 UnfilteredRowIterator (org.apache.cassandra.db.rows.UnfilteredRowIterator)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 Iterables.transform (com.google.common.collect.Iterables.transform)2 Lists (com.google.common.collect.Lists)2