Search in sources :

Example 1 with Scan

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));
}
Also used : Scan(com.scalar.db.api.Scan) Result(com.scalar.db.api.Result)

Example 2 with Scan

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));
}
Also used : Scan(com.scalar.db.api.Scan) Result(com.scalar.db.api.Result)

Example 3 with Scan

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));
}
Also used : Scan(com.scalar.db.api.Scan) Result(com.scalar.db.api.Result)

Example 4 with Scan

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));
}
Also used : Scan(com.scalar.db.api.Scan) Result(com.scalar.db.api.Result)

Example 5 with Scan

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;
}
Also used : Ordering(com.scalar.db.api.Scan.Ordering) Scan(com.scalar.db.api.Scan) Key(com.scalar.db.io.Key)

Aggregations

Scan (com.scalar.db.api.Scan)241 Key (com.scalar.db.io.Key)137 Test (org.junit.jupiter.api.Test)125 Result (com.scalar.db.api.Result)105 Test (org.junit.Test)72 Put (com.scalar.db.api.Put)37 HashMap (java.util.HashMap)32 QueryRequest (software.amazon.awssdk.services.dynamodb.model.QueryRequest)32 AttributeValue (software.amazon.awssdk.services.dynamodb.model.AttributeValue)31 ByteBuffer (java.nio.ByteBuffer)27 KeyBytesEncoder (com.scalar.db.storage.dynamo.bytes.KeyBytesEncoder)26 Scanner (com.scalar.db.api.Scanner)17 CosmosQueryRequestOptions (com.azure.cosmos.models.CosmosQueryRequestOptions)14 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)13 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)13 PartitionKey (com.azure.cosmos.models.PartitionKey)11 ArrayList (java.util.ArrayList)11 Delete (com.scalar.db.api.Delete)9 Value (com.scalar.db.io.Value)8 ConditionalExpression (com.scalar.db.api.ConditionalExpression)7