Search in sources :

Example 96 with Scan

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

the class SelectStatementHandlerTest method handle_ScanOperationWithMultipleReversedOrderingsAndLimit_ShouldCallQueryItemsWithProperQuery.

@Test
public void handle_ScanOperationWithMultipleReversedOrderingsAndLimit_ShouldCallQueryItemsWithProperQuery() {
    // Arrange
    when(metadata.getClusteringKeyNames()).thenReturn(new LinkedHashSet<>(Arrays.asList(ANY_NAME_2, ANY_NAME_3)));
    when(metadata.getClusteringOrder(ANY_NAME_3)).thenReturn(Order.DESC);
    when(container.queryItems(anyString(), any(CosmosQueryRequestOptions.class), eq(Record.class))).thenReturn(responseIterable);
    Record expected = new Record();
    when(responseIterable.iterator()).thenReturn(Collections.singletonList(expected).iterator());
    Scan scan = prepareScan().withStart(new Key(ANY_NAME_2, ANY_TEXT_2)).withOrdering(new Scan.Ordering(ANY_NAME_2, Order.DESC)).withOrdering(new Scan.Ordering(ANY_NAME_3, Order.ASC)).withLimit(ANY_LIMIT);
    String query = "select * from Record r where (r.concatenatedPartitionKey = '" + ANY_TEXT_1 + "' and r.clusteringKey[\"" + ANY_NAME_2 + "\"] >= '" + ANY_TEXT_2 + "') order by r.concatenatedPartitionKey desc, r.clusteringKey[\"" + ANY_NAME_2 + "\"] desc, r.clusteringKey[\"" + ANY_NAME_3 + "\"] asc offset 0 limit " + ANY_LIMIT;
    // Act Assert
    assertThatCode(() -> handler.handle(scan)).doesNotThrowAnyException();
    // Assert
    verify(container).queryItems(eq(query), any(CosmosQueryRequestOptions.class), eq(Record.class));
}
Also used : CosmosQueryRequestOptions(com.azure.cosmos.models.CosmosQueryRequestOptions) Scan(com.scalar.db.api.Scan) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PartitionKey(com.azure.cosmos.models.PartitionKey) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 97 with Scan

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

the class SelectStatementHandlerTest method handle_ScanOperationWithIndexGiven_ShouldCallQueryItems.

@Test
public void handle_ScanOperationWithIndexGiven_ShouldCallQueryItems() {
    // Arrange
    when(container.queryItems(anyString(), any(CosmosQueryRequestOptions.class), eq(Record.class))).thenReturn(responseIterable);
    Record expected = new Record();
    when(responseIterable.iterator()).thenReturn(Collections.singletonList(expected).iterator());
    Key indexKey = new Key(ANY_NAME_3, ANY_TEXT_3);
    Scan scan = new Scan(indexKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME);
    String query = "select * from Record r where r.values[\"" + ANY_NAME_3 + "\"]" + " = '" + ANY_TEXT_3 + "'";
    // Act Assert
    assertThatCode(() -> handler.handle(scan)).doesNotThrowAnyException();
    // Assert
    verify(container).queryItems(eq(query), any(CosmosQueryRequestOptions.class), eq(Record.class));
}
Also used : CosmosQueryRequestOptions(com.azure.cosmos.models.CosmosQueryRequestOptions) Scan(com.scalar.db.api.Scan) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PartitionKey(com.azure.cosmos.models.PartitionKey) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 98 with Scan

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

the class SelectStatementHandlerTest method handle_ScanOperationWithMultipleClusteringKeys_ShouldCallQueryItemsWithProperQuery.

@Test
public void handle_ScanOperationWithMultipleClusteringKeys_ShouldCallQueryItemsWithProperQuery() {
    // Arrange
    when(metadata.getClusteringKeyNames()).thenReturn(new LinkedHashSet<>(Arrays.asList(ANY_NAME_2, ANY_NAME_3)));
    when(metadata.getClusteringOrder(ANY_NAME_3)).thenReturn(Order.DESC);
    when(container.queryItems(anyString(), any(CosmosQueryRequestOptions.class), eq(Record.class))).thenReturn(responseIterable);
    Record expected = new Record();
    when(responseIterable.iterator()).thenReturn(Collections.singletonList(expected).iterator());
    Scan scan = prepareScan().withStart(new Key(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_3)).withEnd(new Key(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_4));
    String query = "select * from Record r where (r.concatenatedPartitionKey = '" + ANY_TEXT_1 + "' and r.clusteringKey[\"" + ANY_NAME_2 + "\"] = '" + ANY_TEXT_2 + "' and r.clusteringKey[\"" + ANY_NAME_3 + "\"] >= '" + ANY_TEXT_3 + "' and r.clusteringKey[\"" + ANY_NAME_2 + "\"] = '" + ANY_TEXT_2 + "' and r.clusteringKey[\"" + ANY_NAME_3 + "\"] <= '" + ANY_TEXT_4 + "') order by r.concatenatedPartitionKey asc, r.clusteringKey[\"" + ANY_NAME_2 + "\"] asc, r.clusteringKey[\"" + ANY_NAME_3 + "\"] desc";
    // Act Assert
    assertThatCode(() -> handler.handle(scan)).doesNotThrowAnyException();
    // Assert
    verify(container).queryItems(eq(query), any(CosmosQueryRequestOptions.class), eq(Record.class));
}
Also used : CosmosQueryRequestOptions(com.azure.cosmos.models.CosmosQueryRequestOptions) Scan(com.scalar.db.api.Scan) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PartitionKey(com.azure.cosmos.models.PartitionKey) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 99 with Scan

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

the class SelectStatementHandlerTest method handle_ScanOperationWithMultipleOrderingsAndLimit_ShouldCallQueryItemsWithProperQuery.

@Test
public void handle_ScanOperationWithMultipleOrderingsAndLimit_ShouldCallQueryItemsWithProperQuery() {
    // Arrange
    when(metadata.getClusteringKeyNames()).thenReturn(new LinkedHashSet<>(Arrays.asList(ANY_NAME_2, ANY_NAME_3)));
    when(metadata.getClusteringOrder(ANY_NAME_3)).thenReturn(Order.DESC);
    when(container.queryItems(anyString(), any(CosmosQueryRequestOptions.class), eq(Record.class))).thenReturn(responseIterable);
    Record expected = new Record();
    when(responseIterable.iterator()).thenReturn(Collections.singletonList(expected).iterator());
    Scan scan = prepareScan().withStart(new Key(ANY_NAME_2, ANY_TEXT_2)).withOrdering(new Scan.Ordering(ANY_NAME_2, Order.ASC)).withOrdering(new Scan.Ordering(ANY_NAME_3, Order.DESC)).withLimit(ANY_LIMIT);
    String query = "select * from Record r where (r.concatenatedPartitionKey = '" + ANY_TEXT_1 + "' and r.clusteringKey[\"" + ANY_NAME_2 + "\"] >= '" + ANY_TEXT_2 + "') order by r.concatenatedPartitionKey asc, r.clusteringKey[\"" + ANY_NAME_2 + "\"] asc, r.clusteringKey[\"" + ANY_NAME_3 + "\"] desc offset 0 limit " + ANY_LIMIT;
    // Act Assert
    assertThatCode(() -> handler.handle(scan)).doesNotThrowAnyException();
    // Assert
    verify(container).queryItems(eq(query), any(CosmosQueryRequestOptions.class), eq(Record.class));
}
Also used : CosmosQueryRequestOptions(com.azure.cosmos.models.CosmosQueryRequestOptions) Scan(com.scalar.db.api.Scan) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PartitionKey(com.azure.cosmos.models.PartitionKey) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 100 with Scan

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

the class MultiStorageIntegrationTest method whenScanDataFromTable1_DataShouldBeScannedFromStorage1.

@Test
public void whenScanDataFromTable1_DataShouldBeScannedFromStorage1() throws ExecutionException, IOException {
    // Arrange
    String namespace = NAMESPACE1;
    String table = TABLE1;
    Key partitionKey = new Key(COL_NAME1, 1);
    Key clusteringKey1 = new Key(COL_NAME4, 0);
    Key clusteringKey2 = new Key(COL_NAME4, 1);
    Key clusteringKey3 = new Key(COL_NAME4, 2);
    storage1.mutate(Arrays.asList(new Put(partitionKey, clusteringKey1).withValue(COL_NAME3, 2).forNamespace(namespace).forTable(table), new Put(partitionKey, clusteringKey2).withValue(COL_NAME3, 1).forNamespace(namespace).forTable(table), new Put(partitionKey, clusteringKey3).withValue(COL_NAME3, 0).forNamespace(namespace).forTable(table)));
    // Act
    List<Result> results = scanAll(new Scan(partitionKey).forNamespace(namespace).forTable(table));
    // Assert
    assertThat(results.size()).isEqualTo(3);
    assertThat(getCol1Value(results.get(0))).isEqualTo(1);
    assertThat(getCol3Value(results.get(0))).isEqualTo(2);
    assertThat(getCol4Value(results.get(0))).isEqualTo(0);
    assertThat(getCol1Value(results.get(1))).isEqualTo(1);
    assertThat(getCol3Value(results.get(1))).isEqualTo(1);
    assertThat(getCol4Value(results.get(1))).isEqualTo(1);
    assertThat(getCol1Value(results.get(2))).isEqualTo(1);
    assertThat(getCol3Value(results.get(2))).isEqualTo(0);
    assertThat(getCol4Value(results.get(2))).isEqualTo(2);
}
Also used : Scan(com.scalar.db.api.Scan) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put) Result(com.scalar.db.api.Result) 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