Search in sources :

Example 1 with SingletonUnfilteredPartitionIterator

use of org.apache.cassandra.db.partitions.SingletonUnfilteredPartitionIterator in project cassandra by apache.

the class RowFilterTest method testCQLFilterClose.

@Test
public void testCQLFilterClose() {
    // CASSANDRA-15126
    TableMetadata metadata = TableMetadata.builder("testks", "testcf").addPartitionKeyColumn("pk", Int32Type.instance).addStaticColumn("s", Int32Type.instance).addRegularColumn("r", Int32Type.instance).build();
    ColumnMetadata s = metadata.getColumn(new ColumnIdentifier("s", true));
    ColumnMetadata r = metadata.getColumn(new ColumnIdentifier("r", true));
    ByteBuffer one = Int32Type.instance.decompose(1);
    RowFilter filter = RowFilter.NONE.withNewExpressions(new ArrayList<>());
    filter.add(s, Operator.NEQ, one);
    AtomicBoolean closed = new AtomicBoolean();
    UnfilteredPartitionIterator iter = filter.filter(new SingletonUnfilteredPartitionIterator(new UnfilteredRowIterator() {

        public DeletionTime partitionLevelDeletion() {
            return null;
        }

        public EncodingStats stats() {
            return null;
        }

        public TableMetadata metadata() {
            return metadata;
        }

        public boolean isReverseOrder() {
            return false;
        }

        public RegularAndStaticColumns columns() {
            return null;
        }

        public DecoratedKey partitionKey() {
            return null;
        }

        public boolean hasNext() {
            return false;
        }

        public Unfiltered next() {
            return null;
        }

        public Row staticRow() {
            return BTreeRow.create(Clustering.STATIC_CLUSTERING, LivenessInfo.EMPTY, Row.Deletion.LIVE, BTree.singleton(new BufferCell(s, 1, Cell.NO_TTL, Cell.NO_DELETION_TIME, one, null)));
        }

        public void close() {
            closed.set(true);
        }
    }), 1);
    Assert.assertFalse(iter.hasNext());
    Assert.assertTrue(closed.get());
    filter = RowFilter.NONE.withNewExpressions(new ArrayList<>());
    filter.add(r, Operator.NEQ, one);
    closed.set(false);
    iter = filter.filter(new SingletonUnfilteredPartitionIterator(new UnfilteredRowIterator() {

        boolean hasNext = true;

        public DeletionTime partitionLevelDeletion() {
            return null;
        }

        public EncodingStats stats() {
            return null;
        }

        public TableMetadata metadata() {
            return metadata;
        }

        public boolean isReverseOrder() {
            return false;
        }

        public RegularAndStaticColumns columns() {
            return null;
        }

        public DecoratedKey partitionKey() {
            return null;
        }

        public Row staticRow() {
            return Rows.EMPTY_STATIC_ROW;
        }

        public boolean hasNext() {
            boolean r = hasNext;
            hasNext = false;
            return r;
        }

        public Unfiltered next() {
            return BTreeRow.create(Clustering.EMPTY, LivenessInfo.EMPTY, Row.Deletion.LIVE, BTree.singleton(new BufferCell(r, 1, Cell.NO_TTL, Cell.NO_DELETION_TIME, one, null)));
        }

        public void close() {
            closed.set(true);
        }
    }), 1);
    Assert.assertFalse(iter.hasNext());
    Assert.assertTrue(closed.get());
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) DeletionTime(org.apache.cassandra.db.DeletionTime) DecoratedKey(org.apache.cassandra.db.DecoratedKey) ArrayList(java.util.ArrayList) UnfilteredPartitionIterator(org.apache.cassandra.db.partitions.UnfilteredPartitionIterator) SingletonUnfilteredPartitionIterator(org.apache.cassandra.db.partitions.SingletonUnfilteredPartitionIterator) BufferCell(org.apache.cassandra.db.rows.BufferCell) ByteBuffer(java.nio.ByteBuffer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EncodingStats(org.apache.cassandra.db.rows.EncodingStats) ColumnIdentifier(org.apache.cassandra.cql3.ColumnIdentifier) BTreeRow(org.apache.cassandra.db.rows.BTreeRow) Row(org.apache.cassandra.db.rows.Row) SingletonUnfilteredPartitionIterator(org.apache.cassandra.db.partitions.SingletonUnfilteredPartitionIterator) Unfiltered(org.apache.cassandra.db.rows.Unfiltered) RegularAndStaticColumns(org.apache.cassandra.db.RegularAndStaticColumns) Test(org.junit.Test)

Example 2 with SingletonUnfilteredPartitionIterator

use of org.apache.cassandra.db.partitions.SingletonUnfilteredPartitionIterator in project cassandra by apache.

the class SSTableAndMemTableDigestMatchTest method getDigest.

private String getDigest(ColumnFilter filter, Clustering<?>... clusterings) {
    ColumnFamilyStore cfs = getCurrentColumnFamilyStore();
    NavigableSet<Clustering<?>> clusteringSet = Sets.newTreeSet(new ClusteringComparator());
    for (Clustering<?> clustering : clusterings) clusteringSet.add(clustering);
    BufferDecoratedKey key = new BufferDecoratedKey(DatabaseDescriptor.getPartitioner().getToken(Int32Type.instance.decompose(1)), Int32Type.instance.decompose(1));
    SinglePartitionReadCommand cmd = SinglePartitionReadCommand.create(cfs.metadata(), (int) (System.currentTimeMillis() / 1000), key, filter, new ClusteringIndexNamesFilter(clusteringSet, false)).copyAsDigestQuery();
    cmd.setDigestVersion(MessagingService.current_version);
    ReadResponse resp;
    try (ReadExecutionController ctrl = ReadExecutionController.forCommand(cmd, false);
        UnfilteredRowIterator iterator = cmd.queryMemtableAndDisk(cfs, ctrl)) {
        resp = ReadResponse.createDataResponse(new SingletonUnfilteredPartitionIterator(iterator), cmd, ctrl.getRepairedDataInfo());
        logger.info("Response is: {}", resp.toDebugString(cmd, key));
        ByteBuffer digest = resp.digest(cmd);
        return ByteBufferUtil.bytesToHex(digest);
    }
}
Also used : UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) ClusteringIndexNamesFilter(org.apache.cassandra.db.filter.ClusteringIndexNamesFilter) ByteBuffer(java.nio.ByteBuffer) SingletonUnfilteredPartitionIterator(org.apache.cassandra.db.partitions.SingletonUnfilteredPartitionIterator)

Example 3 with SingletonUnfilteredPartitionIterator

use of org.apache.cassandra.db.partitions.SingletonUnfilteredPartitionIterator in project cassandra by apache.

the class AbstractVirtualTable method select.

@Override
@SuppressWarnings("resource")
public final UnfilteredPartitionIterator select(DecoratedKey partitionKey, ClusteringIndexFilter clusteringIndexFilter, ColumnFilter columnFilter) {
    Partition partition = data(partitionKey).getPartition(partitionKey);
    if (null == partition)
        return EmptyIterators.unfilteredPartition(metadata);
    long now = currentTimeMillis();
    UnfilteredRowIterator rowIterator = partition.toRowIterator(metadata(), clusteringIndexFilter, columnFilter, now);
    return new SingletonUnfilteredPartitionIterator(rowIterator);
}
Also used : UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) SingletonUnfilteredPartitionIterator(org.apache.cassandra.db.partitions.SingletonUnfilteredPartitionIterator)

Example 4 with SingletonUnfilteredPartitionIterator

use of org.apache.cassandra.db.partitions.SingletonUnfilteredPartitionIterator in project cassandra by apache.

the class AbstractReadResponseTest method iter.

public UnfilteredPartitionIterator iter(DecoratedKey key, Unfiltered... unfiltereds) {
    SortedSet<Unfiltered> s = new TreeSet<>(cfm.comparator);
    Collections.addAll(s, unfiltereds);
    final Iterator<Unfiltered> iterator = s.iterator();
    UnfilteredRowIterator rowIter = new AbstractUnfilteredRowIterator(cfm, key, DeletionTime.LIVE, cfm.regularAndStaticColumns(), Rows.EMPTY_STATIC_ROW, false, EncodingStats.NO_STATS) {

        protected Unfiltered computeNext() {
            return iterator.hasNext() ? iterator.next() : endOfData();
        }
    };
    return new SingletonUnfilteredPartitionIterator(rowIter);
}
Also used : AbstractUnfilteredRowIterator(org.apache.cassandra.db.rows.AbstractUnfilteredRowIterator) UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) TreeSet(java.util.TreeSet) AbstractUnfilteredRowIterator(org.apache.cassandra.db.rows.AbstractUnfilteredRowIterator) SingletonUnfilteredPartitionIterator(org.apache.cassandra.db.partitions.SingletonUnfilteredPartitionIterator) Unfiltered(org.apache.cassandra.db.rows.Unfiltered)

Aggregations

SingletonUnfilteredPartitionIterator (org.apache.cassandra.db.partitions.SingletonUnfilteredPartitionIterator)4 UnfilteredRowIterator (org.apache.cassandra.db.rows.UnfilteredRowIterator)4 ByteBuffer (java.nio.ByteBuffer)2 Unfiltered (org.apache.cassandra.db.rows.Unfiltered)2 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)1 DecoratedKey (org.apache.cassandra.db.DecoratedKey)1 DeletionTime (org.apache.cassandra.db.DeletionTime)1 RegularAndStaticColumns (org.apache.cassandra.db.RegularAndStaticColumns)1 ClusteringIndexNamesFilter (org.apache.cassandra.db.filter.ClusteringIndexNamesFilter)1 UnfilteredPartitionIterator (org.apache.cassandra.db.partitions.UnfilteredPartitionIterator)1 AbstractUnfilteredRowIterator (org.apache.cassandra.db.rows.AbstractUnfilteredRowIterator)1 BTreeRow (org.apache.cassandra.db.rows.BTreeRow)1 BufferCell (org.apache.cassandra.db.rows.BufferCell)1 EncodingStats (org.apache.cassandra.db.rows.EncodingStats)1 Row (org.apache.cassandra.db.rows.Row)1 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)1 TableMetadata (org.apache.cassandra.schema.TableMetadata)1