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());
}
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);
}
}
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);
}
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);
}
Aggregations