Search in sources :

Example 51 with Scan

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

the class ScalarDbUtilsTest method copyAndSetTargetToIfNot_ScanGiven_ShouldReturnDifferentInstance.

@Test
public void copyAndSetTargetToIfNot_ScanGiven_ShouldReturnDifferentInstance() {
    // Arrange
    Scan scan = new Scan(new Key("c1", "v1"));
    // Act
    Scan actual = ScalarDbUtils.copyAndSetTargetToIfNot(scan, NAMESPACE, TABLE);
    // Assert
    assertThat(actual == scan).isFalse();
    assertThat(scan.forNamespace()).isNotPresent();
    assertThat(scan.forTable()).isNotPresent();
    assertThat(actual.forNamespace()).isEqualTo(NAMESPACE);
    assertThat(actual.forTable()).isEqualTo(TABLE);
}
Also used : Scan(com.scalar.db.api.Scan) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 52 with Scan

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

the class SelectStatementHandlerTest method prepare_ScanOperationWithMultipleOrdering_ShouldPrepareProperQuery.

@Test
public void prepare_ScanOperationWithMultipleOrdering_ShouldPrepareProperQuery() {
    // Arrange
    String expected = Joiner.on(" ").skipNulls().join(new String[] { "SELECT * FROM", ANY_NAMESPACE_NAME + "." + ANY_TABLE_NAME, "WHERE", ANY_NAME_1 + "=?", "AND", ANY_NAME_2 + ">=?", "ORDER BY", ANY_NAME_2, ASC_ORDER + "," + ANY_NAME_3, DESC_ORDER.toString(), "LIMIT", ANY_LIMIT + ";" });
    configureBehavior(expected);
    scan = prepareScan();
    scan.withStart(new Key(ANY_NAME_2, ANY_TEXT_2)).withOrdering(new Scan.Ordering(ANY_NAME_2, ASC_ORDER)).withOrdering(new Scan.Ordering(ANY_NAME_3, DESC_ORDER)).withLimit(ANY_LIMIT);
    // Act
    handler.prepare(scan);
    // Assert
    verify(session).prepare(expected);
}
Also used : Scan(com.scalar.db.api.Scan) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 53 with Scan

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

the class OperationCheckerTest method whenCheckingScanOperationWithAllValidArguments_shouldNotThrowAnyException.

@Test
public void whenCheckingScanOperationWithAllValidArguments_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.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 54 with Scan

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

the class OperationCheckerTest method whenCheckingScanOperationWithInvalidClusteringKeyRange_shouldThrowIllegalArgumentException.

@Test
public void whenCheckingScanOperationWithInvalidClusteringKeyRange_shouldThrowIllegalArgumentException() {
    // Arrange
    Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
    Key startClusteringKey = new Key(CKEY1, 2, CKEY2, "val1");
    Key endClusteringKey = new Key(CKEY1, 2);
    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 55 with Scan

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

the class OperationCheckerTest method whenCheckingScanOperationWithEmptyOrdering_shouldNotThrowAnyException.

@Test
public void whenCheckingScanOperationWithEmptyOrdering_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).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)

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