Search in sources :

Example 56 with Scan

use of com.scalar.db.api.Scan in project scalardb by scalar-labs.

the class OperationCheckerTest method whenCheckingScanOperationWithReverseOrderings_shouldNotThrowAnyException.

@Test
public void whenCheckingScanOperationWithReverseOrderings_shouldNotThrowAnyException() {
    // Arrange
    Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
    Key startClusteringKey = new Key(CKEY1, 2, CKEY2, "val1");
    Key endClusteringKey = new Key(CKEY1, 2, CKEY2, "val9");
    List<String> projections = Arrays.asList(COL1, COL2, COL3);
    int limit = 10;
    Scan scan = new Scan(partitionKey).withStart(startClusteringKey).withEnd(endClusteringKey).withProjections(projections).withLimit(limit).withOrdering(new Scan.Ordering(CKEY1, Scan.Ordering.Order.DESC)).withOrdering(new Scan.Ordering(CKEY2, Scan.Ordering.Order.ASC)).forNamespace(NAMESPACE).forTable(TABLE_NAME);
    // Act Assert
    assertThatCode(() -> operationChecker.check(scan)).doesNotThrowAnyException();
}
Also used : Scan(com.scalar.db.api.Scan) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 57 with Scan

use of com.scalar.db.api.Scan in project scalardb by scalar-labs.

the class OperationCheckerTest method whenCheckingScanOperationWithInvalidPartitionKey_shouldThrowIllegalArgumentException.

@Test
public void whenCheckingScanOperationWithInvalidPartitionKey_shouldThrowIllegalArgumentException() {
    // Arrange
    Key partitionKey = new Key(PKEY1, 1, "p3", "val1");
    Key startClusteringKey = new Key(CKEY1, 2, CKEY2, "val1");
    Key endClusteringKey = new Key(CKEY1, 2, CKEY2, "val9");
    List<String> projections = Arrays.asList(COL1, COL2, COL3);
    int limit = 10;
    Scan scan = new Scan(partitionKey).withStart(startClusteringKey).withEnd(endClusteringKey).withProjections(projections).withLimit(limit).withOrdering(new Scan.Ordering(CKEY1, Scan.Ordering.Order.ASC)).withOrdering(new Scan.Ordering(CKEY2, Scan.Ordering.Order.DESC)).forNamespace(NAMESPACE).forTable(TABLE_NAME);
    // Act Assert
    assertThatThrownBy(() -> operationChecker.check(scan)).isInstanceOf(IllegalArgumentException.class);
}
Also used : Scan(com.scalar.db.api.Scan) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 58 with Scan

use of com.scalar.db.api.Scan in project scalardb by scalar-labs.

the class OperationCheckerTest method whenCheckingScanOperationWithInvalidOrderings_shouldThrowIllegalArgumentException.

@Test
public void whenCheckingScanOperationWithInvalidOrderings_shouldThrowIllegalArgumentException() {
    // Arrange
    Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
    Key startClusteringKey = new Key(CKEY1, 2, CKEY2, "val1");
    Key endClusteringKey = new Key(CKEY1, 2, CKEY2, "val9");
    List<String> projections = Arrays.asList(COL1, COL2, COL3);
    int limit = -10;
    Scan scan = new Scan(partitionKey).withStart(startClusteringKey).withEnd(endClusteringKey).withProjections(projections).withLimit(limit).withOrdering(new Scan.Ordering(CKEY1, Scan.Ordering.Order.DESC)).withOrdering(new Scan.Ordering(CKEY2, Scan.Ordering.Order.DESC)).forNamespace(NAMESPACE).forTable(TABLE_NAME);
    // Act Assert
    assertThatThrownBy(() -> operationChecker.check(scan)).isInstanceOf(IllegalArgumentException.class);
}
Also used : Scan(com.scalar.db.api.Scan) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 59 with Scan

use of com.scalar.db.api.Scan in project scalardb by scalar-labs.

the class OperationCheckerTest method whenCheckingScanOperationWithPartialClusteringKey_shouldNotThrowAnyException.

@Test
public void whenCheckingScanOperationWithPartialClusteringKey_shouldNotThrowAnyException() {
    // Arrange
    Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
    Key startClusteringKey = new Key(CKEY1, 1);
    Key endClusteringKey = new Key(CKEY1, 9);
    List<String> projections = Arrays.asList(COL1, COL2, COL3);
    int limit = 10;
    Scan scan = new Scan(partitionKey).withStart(startClusteringKey).withEnd(endClusteringKey).withProjections(projections).withLimit(limit).withOrdering(new Scan.Ordering(CKEY1, Scan.Ordering.Order.ASC)).withOrdering(new Scan.Ordering(CKEY2, Scan.Ordering.Order.DESC)).forNamespace(NAMESPACE).forTable(TABLE_NAME);
    // Act Assert
    assertThatCode(() -> operationChecker.check(scan)).doesNotThrowAnyException();
}
Also used : Scan(com.scalar.db.api.Scan) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 60 with Scan

use of com.scalar.db.api.Scan in project scalardb by scalar-labs.

the class OperationCheckerTest method whenCheckingScanOperationWithIndexedColumnAsPartitionKeyWithOrderings_shouldThrowIllegalArgumentException.

@Test
public void whenCheckingScanOperationWithIndexedColumnAsPartitionKeyWithOrderings_shouldThrowIllegalArgumentException() {
    // Arrange
    Key partitionKey = new Key(COL1, 1);
    Key startClusteringKey = null;
    Key endClusteringKey = null;
    List<String> projections = Arrays.asList(COL1, COL2, COL3);
    int limit = 10;
    Scan scan = new Scan(partitionKey).withStart(startClusteringKey).withStart(endClusteringKey).withProjections(projections).withLimit(limit).withOrdering(new Scan.Ordering(CKEY1, Scan.Ordering.Order.ASC)).forNamespace(NAMESPACE).forTable(TABLE_NAME);
    // Act Assert
    assertThatThrownBy(() -> operationChecker.check(scan)).isInstanceOf(IllegalArgumentException.class);
}
Also used : Scan(com.scalar.db.api.Scan) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

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