use of com.scalar.db.api.Scan in project scalardb by scalar-labs.
the class StorageMultipleClusteringKeyScanIntegrationTestBase method scan_WithSecondClusteringKeyRangeWithSameValues_ShouldReturnProperResult.
private void scan_WithSecondClusteringKeyRangeWithSameValues_ShouldReturnProperResult(List<ClusteringKey> clusteringKeys, DataType firstClusteringKeyType, Order firstClusteringOrder, DataType secondClusteringKeyType, Order secondClusteringOrder, boolean startInclusive, boolean endInclusive, OrderingType orderingType, boolean withLimit) throws ExecutionException, IOException {
// Arrange
if (firstClusteringKeyType == DataType.BOOLEAN) {
Value<?> firstClusteringKeyValue = clusteringKeys.get(0).first;
clusteringKeys = clusteringKeys.stream().filter(c -> c.first.equals(firstClusteringKeyValue)).collect(Collectors.toList());
} else {
Value<?> firstClusteringKeyValue = clusteringKeys.get(getFirstClusteringKeyIndex(2, secondClusteringKeyType)).first;
clusteringKeys = clusteringKeys.stream().filter(c -> c.first.equals(firstClusteringKeyValue)).collect(Collectors.toList());
}
ClusteringKey startAndEndClusteringKey;
if (secondClusteringKeyType == DataType.BOOLEAN) {
startAndEndClusteringKey = new ClusteringKey(clusteringKeys.get(0).first, clusteringKeys.get(0).second);
} else {
startAndEndClusteringKey = new ClusteringKey(clusteringKeys.get(9).first, clusteringKeys.get(9).second);
}
List<ClusteringKey> expected = getExpected(clusteringKeys, startAndEndClusteringKey, startInclusive, startAndEndClusteringKey, endInclusive, orderingType);
int limit = getLimit(withLimit, expected);
if (limit > 0) {
expected = expected.subList(0, limit);
}
Scan scan = getScan(firstClusteringKeyType, firstClusteringOrder, secondClusteringKeyType, secondClusteringOrder, startAndEndClusteringKey, startInclusive, startAndEndClusteringKey, endInclusive, orderingType, limit);
// Act
List<Result> actual = scanAll(scan);
// Assert
assertScanResult(actual, expected, description(firstClusteringKeyType, firstClusteringOrder, secondClusteringKeyType, secondClusteringOrder, startInclusive, endInclusive, orderingType, withLimit));
}
use of com.scalar.db.api.Scan in project scalardb by scalar-labs.
the class StorageMultipleClusteringKeyScanIntegrationTestBase method scan_WithFirstClusteringKeyEndRange_ShouldReturnProperResult.
private void scan_WithFirstClusteringKeyEndRange_ShouldReturnProperResult(List<ClusteringKey> clusteringKeys, DataType firstClusteringKeyType, Order firstClusteringOrder, boolean endInclusive, OrderingType orderingType, boolean withLimit) throws ExecutionException, IOException {
// Arrange
ClusteringKey endClusteringKey;
if (firstClusteringKeyType == DataType.BOOLEAN) {
endClusteringKey = new ClusteringKey(clusteringKeys.get(getFirstClusteringKeyIndex(1, DataType.INT)).first);
} else {
endClusteringKey = new ClusteringKey(clusteringKeys.get(getFirstClusteringKeyIndex(3, DataType.INT)).first);
}
List<ClusteringKey> expected = getExpected(clusteringKeys, null, null, endClusteringKey, endInclusive, orderingType);
int limit = getLimit(withLimit, expected);
if (limit > 0) {
expected = expected.subList(0, limit);
}
Scan scan = getScan(firstClusteringKeyType, firstClusteringOrder, DataType.INT, Order.ASC, null, null, endClusteringKey, endInclusive, orderingType, limit);
// Act
List<Result> actual = scanAll(scan);
// Assert
assertScanResult(actual, expected, description(firstClusteringKeyType, firstClusteringOrder, null, null, null, endInclusive, orderingType, withLimit));
}
use of com.scalar.db.api.Scan in project scalardb by scalar-labs.
the class StorageMultipleClusteringKeyScanIntegrationTestBase method scan_WithFirstClusteringKeyRangeWithSameValues_ShouldReturnProperResult.
private void scan_WithFirstClusteringKeyRangeWithSameValues_ShouldReturnProperResult(List<ClusteringKey> clusteringKeys, DataType firstClusteringKeyType, Order firstClusteringOrder, boolean startInclusive, boolean endInclusive, OrderingType orderingType, boolean withLimit) throws ExecutionException, IOException {
// Arrange
ClusteringKey startAndEndClusteringKey;
if (firstClusteringKeyType == DataType.BOOLEAN) {
startAndEndClusteringKey = new ClusteringKey(clusteringKeys.get(getFirstClusteringKeyIndex(0, DataType.INT)).first);
} else {
startAndEndClusteringKey = new ClusteringKey(clusteringKeys.get(getFirstClusteringKeyIndex(2, DataType.INT)).first);
}
List<ClusteringKey> expected = getExpected(clusteringKeys, startAndEndClusteringKey, startInclusive, startAndEndClusteringKey, endInclusive, orderingType);
int limit = getLimit(withLimit, expected);
if (limit > 0) {
expected = expected.subList(0, limit);
}
Scan scan = getScan(firstClusteringKeyType, firstClusteringOrder, DataType.INT, Order.ASC, startAndEndClusteringKey, startInclusive, startAndEndClusteringKey, endInclusive, orderingType, limit);
// Act
List<Result> actual = scanAll(scan);
// Assert
assertScanResult(actual, expected, description(firstClusteringKeyType, firstClusteringOrder, null, null, startInclusive, endInclusive, orderingType, withLimit));
}
use of com.scalar.db.api.Scan in project scalardb by scalar-labs.
the class StorageMultipleClusteringKeyScanIntegrationTestBase method scan_WithSecondClusteringKeyStartRangeWithMinValue_ShouldReturnProperResult.
private void scan_WithSecondClusteringKeyStartRangeWithMinValue_ShouldReturnProperResult(List<ClusteringKey> clusteringKeys, DataType firstClusteringKeyType, Order firstClusteringOrder, DataType secondClusteringKeyType, Order secondClusteringOrder, boolean startInclusive, OrderingType orderingType, boolean withLimit) throws ExecutionException, IOException {
// Arrange
Value<?> firstClusteringKeyValue = getMinValue(FIRST_CLUSTERING_KEY, firstClusteringKeyType);
clusteringKeys = clusteringKeys.stream().filter(c -> c.first.equals(firstClusteringKeyValue)).collect(Collectors.toList());
ClusteringKey startClusteringKey = new ClusteringKey(firstClusteringKeyValue, getMinValue(SECOND_CLUSTERING_KEY, secondClusteringKeyType));
List<ClusteringKey> expected = getExpected(clusteringKeys, startClusteringKey, startInclusive, null, null, orderingType);
int limit = getLimit(withLimit, expected);
if (limit > 0) {
expected = expected.subList(0, limit);
}
Scan scan = getScan(firstClusteringKeyType, firstClusteringOrder, secondClusteringKeyType, secondClusteringOrder, startClusteringKey, startInclusive, null, null, orderingType, limit);
// Act
List<Result> actual = scanAll(scan);
// Assert
assertScanResult(actual, expected, description(firstClusteringKeyType, firstClusteringOrder, secondClusteringKeyType, secondClusteringOrder, startInclusive, null, orderingType, withLimit));
}
use of com.scalar.db.api.Scan in project scalardb by scalar-labs.
the class StorageMultipleClusteringKeyScanIntegrationTestBase method getScan.
private Scan getScan(DataType firstClusteringKeyType, Order firstClusteringOrder, DataType secondClusteringKeyType, Order secondClusteringOrder, @Nullable ClusteringKey startClusteringKey, @Nullable Boolean startInclusive, @Nullable ClusteringKey endClusteringKey, @Nullable Boolean endInclusive, OrderingType orderingType, int limit) {
Scan scan = new Scan(getPartitionKey()).forNamespace(getNamespaceName(firstClusteringKeyType)).forTable(getTableName(firstClusteringKeyType, firstClusteringOrder, secondClusteringKeyType, secondClusteringOrder));
if (startClusteringKey != null && startInclusive != null) {
Key key;
if (startClusteringKey.second != null) {
key = new Key(startClusteringKey.first, startClusteringKey.second);
} else {
key = new Key(startClusteringKey.first);
}
scan.withStart(key, startInclusive);
}
if (endClusteringKey != null && endInclusive != null) {
Key key;
if (endClusteringKey.second != null) {
key = new Key(endClusteringKey.first, endClusteringKey.second);
} else {
key = new Key(endClusteringKey.first);
}
scan.withEnd(key, endInclusive);
}
switch(orderingType) {
case BOTH_SPECIFIED:
scan.withOrdering(new Ordering(FIRST_CLUSTERING_KEY, firstClusteringOrder)).withOrdering(new Ordering(SECOND_CLUSTERING_KEY, secondClusteringOrder));
break;
case ONLY_FIRST_SPECIFIED:
scan.withOrdering(new Ordering(FIRST_CLUSTERING_KEY, firstClusteringOrder));
break;
case BOTH_SPECIFIED_AND_REVERSED:
scan.withOrdering(new Ordering(FIRST_CLUSTERING_KEY, TestUtils.reverseOrder(firstClusteringOrder))).withOrdering(new Ordering(SECOND_CLUSTERING_KEY, TestUtils.reverseOrder(secondClusteringOrder)));
break;
case ONLY_FIRST_SPECIFIED_AND_REVERSED:
scan.withOrdering(new Ordering(FIRST_CLUSTERING_KEY, TestUtils.reverseOrder(firstClusteringOrder)));
break;
case NOTHING:
break;
default:
throw new AssertionError();
}
if (limit > 0) {
scan.withLimit(limit);
}
return scan;
}
Aggregations