use of com.scalar.db.api.Scan.Ordering in project scalardb by scalar-labs.
the class DistributedStorageMultipleClusteringKeyScanIntegrationTestBase 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;
}
use of com.scalar.db.api.Scan.Ordering in project scalardb by scalar-labs.
the class StorageWithReservedKeywordIntegrationTestBase method scan_WithReservedKeywordAndClusteringKeyRange_ShouldReturnProperResult.
@Test
public void scan_WithReservedKeywordAndClusteringKeyRange_ShouldReturnProperResult() throws ExecutionException, IOException {
// Arrange
populateRecords();
Scan scan = new Scan(new Key(columnName1, 1)).withStart(new Key(columnName4, 1), false).withEnd(new Key(columnName4, 3), false).withOrdering(new Ordering(columnName4, Order.DESC)).forNamespace(namespace).forTable(tableName);
List<Integer> expected = ImmutableList.of(2);
// Act
List<Result> actual = scanAll(scan);
// Assert
assertThat(actual.size()).isEqualTo(1);
assertThat(actual.get(0).getValue(columnName4).isPresent()).isTrue();
assertThat(actual.get(0).getValue(columnName4).get().getAsInt()).isEqualTo(expected.get(0));
}
use of com.scalar.db.api.Scan.Ordering in project scalardb by scalar-labs.
the class SelectStatementHandler method executeQuery.
private List<Map<String, AttributeValue>> executeQuery(Scan scan, TableMetadata tableMetadata) {
DynamoOperation dynamoOperation = new DynamoOperation(scan, tableMetadata);
QueryRequest.Builder builder = QueryRequest.builder().tableName(dynamoOperation.getTableName());
if (!setConditions(builder, scan, tableMetadata)) {
// if setConditions() fails, return empty list
return new ArrayList<>();
}
if (!scan.getOrderings().isEmpty()) {
Ordering ordering = scan.getOrderings().get(0);
if (ordering.getOrder() != tableMetadata.getClusteringOrder(ordering.getColumnName())) {
// reverse scan
builder.scanIndexForward(false);
}
}
if (scan.getLimit() > 0) {
builder.limit(scan.getLimit());
}
if (!scan.getProjections().isEmpty()) {
projectionExpression(builder, scan);
}
if (scan.getConsistency() != Consistency.EVENTUAL) {
builder.consistentRead(true);
}
QueryResponse queryResponse = client.query(builder.build());
return new ArrayList<>(queryResponse.items());
}
Aggregations