Skip to content

Commit

Permalink
Add in a test
Browse files Browse the repository at this point in the history
  • Loading branch information
EricBorczuk committed Mar 30, 2022
1 parent caef986 commit 013012f
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import io.stargate.db.schema.TableName;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.stream.Stream;

public abstract class AbstractRowDecorator implements RowDecorator {

Expand Down Expand Up @@ -55,6 +54,4 @@ public <T extends Comparable<T>> ComparableKey<T> decoratePartitionKey(Row row)
//noinspection unchecked
return (ComparableKey<T>) decoratePrimaryKey(pkValues);
}

public abstract Stream<Byte> getComparableBytes();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import io.stargate.db.datastore.ResultSet;
import io.stargate.db.datastore.Row;
import java.util.stream.Stream;

/**
* A table-specific interface for extracting key column values from a {@link ResultSet} {@link Row}
Expand All @@ -29,4 +30,6 @@ public interface RowDecorator {
* same order that queries iterate / paginate over the Cassandra data ring.
*/
<T extends Comparable<T>> ComparableKey<T> decoratePartitionKey(Row row);

Stream<Byte> getComparableBytes(Object... rawKeyValues);
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected ComparableKey<?> decoratePrimaryKey(Object... pkValues) {
}

@Override
public Stream<Byte> getComparableBytes() {
public Stream<Byte> getComparableBytes(Object... rawKeyValues) {
// TODO replace this with the relevant row's byte-comparable value when
// https://github.com/apache/cassandra/pull/1294 is ready
return Stream.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected ComparableKey<?> decoratePrimaryKey(Object... pkValues) {
}

@Override
public Stream<Byte> getComparableBytes() {
public Stream<Byte> getComparableBytes(Object... rawKeyValues) {
// TODO replace this with the relevant row's byte-comparable value when
// https://github.com/apache/cassandra/pull/1294 is ready
return Stream.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,10 @@ protected ComparableKey<?> decoratePrimaryKey(Object... rawKeyValues) {
}

@Override
public Stream<Byte> getComparableBytes() {
ByteSource src = decoratePrimaryKey().asComparableBytes();
Spliterator<Byte>
spliterator = Spliterators
.spliteratorUnknownSize(new ByteSourceIterable(src), 0);
public Stream<Byte> getComparableBytes(Object... rawKeyValues) {
ByteSource src = decoratePrimaryKey(rawKeyValues).asComparableBytes();
Spliterator<Byte> spliterator = Spliterators
.spliteratorUnknownSize(new ByteSourceIterable(src), 0);
return StreamSupport.stream(spliterator, false);
}
}
25 changes: 25 additions & 0 deletions persistence-test/src/main/java/io/stargate/it/PersistenceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1964,6 +1964,31 @@ public void testRowDecorator() throws ExecutionException, InterruptedException {
assertGt(last, first, dec1, dec2);
}

@Test
public void testRowDecoratorComparableBytes() throws ExecutionException, InterruptedException {
setupCustomPagingData();

// Obtain partition keys in "ring" order
AbstractBound<?> selectAll =
dataStore
.queryBuilder()
.select()
.column("pk")
.column("val")
.from(keyspace, table)
.build()
.bind();

ResultSet rs1 = dataStore.execute(selectAll).get();
RowDecorator dec1 = rs1.makeRowDecorator();
Stream<Byte> src = dec1.getComparableBytes();
if (backend.isDse()) {
assertThat(src.collect(Collectors.toList()).size()).isGreaterThan(0);
} else {
assertThat(src.collect(Collectors.toList()).size()).isEqualTo(0);
}
}

private boolean isCassandra4() {
return !backend.isDse()
&& Version.parse(backend.clusterVersion()).nextStable().compareTo(Version.V4_0_0) >= 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.stargate.db.schema.Column;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* A test implementation of {@link RowDecorator} that assumes partition keys to be {@link String}
Expand All @@ -43,4 +44,11 @@ public <T extends Comparable<T>> ComparableKey<T> decoratePartitionKey(Row row)
//noinspection unchecked
return (ComparableKey<T>) new ComparableKey<>(String.class, decorated);
}

@Override
public Stream<Byte> getComparableBytes(Object... rawKeyValues) {
// TODO replace this with the relevant row's byte-comparable value when
// https://github.com/apache/cassandra/pull/1294 is ready
return Stream.empty();
}
}

0 comments on commit 013012f

Please sign in to comment.