Search in sources :

Example 66 with Key

use of com.scalar.db.io.Key in project scalardb by scalar-labs.

the class DistributedStorageIntegrationTestBase method scan_ScanLargeDataWithOrdering_ShouldRetrieveExpectedValues.

@Test
public void scan_ScanLargeDataWithOrdering_ShouldRetrieveExpectedValues() throws ExecutionException, IOException {
    // Arrange
    Key partitionKey = new Key(COL_NAME1, 1);
    for (int i = 0; i < 345; i++) {
        Key clusteringKey = new Key(COL_NAME4, i);
        storage.put(new Put(partitionKey, clusteringKey).withBlobValue(COL_NAME6, new byte[5000]));
    }
    Scan scan = new Scan(partitionKey).withOrdering(new Ordering(COL_NAME4, Order.ASC));
    // Act
    List<Result> results = new ArrayList<>();
    try (Scanner scanner = storage.scan(scan)) {
        Iterator<Result> iterator = scanner.iterator();
        for (int i = 0; i < 234; i++) {
            results.add(iterator.next());
        }
    }
    // Assert
    assertThat(results.size()).isEqualTo(234);
    for (int i = 0; i < 234; i++) {
        assertThat(results.get(i).getPartitionKey().isPresent()).isTrue();
        assertThat(results.get(i).getClusteringKey().isPresent()).isTrue();
        assertThat(results.get(i).getPartitionKey().get().get().get(0).getAsInt()).isEqualTo(1);
        assertThat(results.get(i).getClusteringKey().get().get().get(0).getAsInt()).isEqualTo(i);
    }
}
Also used : Ordering(com.scalar.db.api.Scan.Ordering) ArrayList(java.util.ArrayList) Key(com.scalar.db.io.Key) ExpectedResult(com.scalar.db.util.TestUtils.ExpectedResult) Test(org.junit.jupiter.api.Test)

Example 67 with Key

use of com.scalar.db.io.Key in project scalardb by scalar-labs.

the class DistributedStorageSecondaryIndexIntegrationTestBase method scan_WithMinSecondaryIndexValue_ShouldReturnProperResult.

@Test
public void scan_WithMinSecondaryIndexValue_ShouldReturnProperResult() throws ExecutionException, IOException {
    for (DataType secondaryIndexType : secondaryIndexTypes) {
        truncateTable(secondaryIndexType);
        // Arrange
        Value<?> secondaryIndexValue = getMinValue(INDEX_COL_NAME, secondaryIndexType);
        prepareRecords(secondaryIndexType, secondaryIndexValue);
        Scan scan = new Scan(new Key(secondaryIndexValue)).forNamespace(namespace).forTable(getTableName(secondaryIndexType));
        // Act
        List<Result> results = scanAll(scan);
        // Assert
        assertResults(results, secondaryIndexValue);
    }
}
Also used : DataType(com.scalar.db.io.DataType) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 68 with Key

use of com.scalar.db.io.Key in project scalardb by scalar-labs.

the class DistributedStorageWithReservedKeywordIntegrationTestBase method delete_WithReservedKeywordAndDeleteWithPartitionKeyAndClusteringKeyGiven_ShouldDeleteSingleRecordProperly.

@Test
public void delete_WithReservedKeywordAndDeleteWithPartitionKeyAndClusteringKeyGiven_ShouldDeleteSingleRecordProperly() throws IOException, ExecutionException {
    // Arrange
    populateRecords();
    int pKey = 0;
    int cKey = 0;
    Key partitionKey = new Key(columnName1, pKey);
    // Act
    Delete delete = prepareDelete(pKey, cKey);
    assertThatCode(() -> storage.delete(delete)).doesNotThrowAnyException();
    // Assert
    List<Result> results = scanAll(new Scan(partitionKey));
    assertThat(results.size()).isEqualTo(2);
    assertThat(results.get(0).getValue(columnName1).isPresent()).isTrue();
    assertThat(results.get(0).getValue(columnName1).get().getAsInt()).isEqualTo(0);
    assertThat(results.get(0).getValue(columnName4).isPresent()).isTrue();
    assertThat(results.get(0).getValue(columnName4).get().getAsInt()).isEqualTo(cKey + 1);
    assertThat(results.get(1).getValue(columnName1).isPresent()).isTrue();
    assertThat(results.get(1).getValue(columnName1).get().getAsInt()).isEqualTo(0);
    assertThat(results.get(1).getValue(columnName4).isPresent()).isTrue();
    assertThat(results.get(1).getValue(columnName4).get().getAsInt()).isEqualTo(cKey + 2);
}
Also used : Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 69 with Key

use of com.scalar.db.io.Key in project scalardb by scalar-labs.

the class DistributedStorageWithReservedKeywordIntegrationTestBase method scan_WithReservedKeywordAndScanGivenForIndexedColumn_ShouldScan.

@Test
public void scan_WithReservedKeywordAndScanGivenForIndexedColumn_ShouldScan() throws ExecutionException, IOException {
    // Arrange
    populateRecords();
    int c3 = 3;
    Scan scan = new Scan(new Key(columnName3, c3));
    // Act
    List<Result> actual = scanAll(scan);
    // Assert
    // (1,2), (2,1), (3,0)
    assertThat(actual.size()).isEqualTo(3);
    List<List<Integer>> expectedValues = new ArrayList<>(Arrays.asList(Arrays.asList(1, 2), Arrays.asList(2, 1), Arrays.asList(3, 0)));
    for (Result result : actual) {
        assertThat(result.getValue(columnName1).isPresent()).isTrue();
        assertThat(result.getValue(columnName4).isPresent()).isTrue();
        int col1Val = result.getValue(columnName1).get().getAsInt();
        int col4Val = result.getValue(columnName4).get().getAsInt();
        List<Integer> col1AndCol4 = Arrays.asList(col1Val, col4Val);
        assertThat(expectedValues).contains(col1AndCol4);
        expectedValues.remove(col1AndCol4);
    }
    assertThat(expectedValues).isEmpty();
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 70 with Key

use of com.scalar.db.io.Key in project scalardb by scalar-labs.

the class DistributedStorageWithReservedKeywordIntegrationTestBase method prepareDeletes.

private List<Delete> prepareDeletes() {
    List<Delete> deletes = new ArrayList<>();
    IntStream.range(0, 5).forEach(i -> IntStream.range(0, 3).forEach(j -> {
        Key partitionKey = new Key(columnName1, i);
        Key clusteringKey = new Key(columnName4, j);
        Delete delete = new Delete(partitionKey, clusteringKey);
        deletes.add(delete);
    }));
    return deletes;
}
Also used : IntStream(java.util.stream.IntStream) BeforeEach(org.junit.jupiter.api.BeforeEach) IntValue(com.scalar.db.io.IntValue) Arrays(java.util.Arrays) TextValue(com.scalar.db.io.TextValue) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ExecutionException(com.scalar.db.exception.storage.ExecutionException) StorageFactory(com.scalar.db.service.StorageFactory) TestUtils(com.scalar.db.util.TestUtils) ArrayList(java.util.ArrayList) AfterAll(org.junit.jupiter.api.AfterAll) TestInstance(org.junit.jupiter.api.TestInstance) ImmutableList(com.google.common.collect.ImmutableList) BeforeAll(org.junit.jupiter.api.BeforeAll) Order(com.scalar.db.api.Scan.Ordering.Order) Map(java.util.Map) DataType(com.scalar.db.io.DataType) Key(com.scalar.db.io.Key) Properties(java.util.Properties) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test) List(java.util.List) Ordering(com.scalar.db.api.Scan.Ordering) Optional(java.util.Optional) BooleanValue(com.scalar.db.io.BooleanValue) Collections(java.util.Collections) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) ArrayList(java.util.ArrayList) Key(com.scalar.db.io.Key)

Aggregations

Key (com.scalar.db.io.Key)603 Test (org.junit.jupiter.api.Test)391 Put (com.scalar.db.api.Put)211 Scan (com.scalar.db.api.Scan)145 Get (com.scalar.db.api.Get)134 Delete (com.scalar.db.api.Delete)118 Result (com.scalar.db.api.Result)94 Test (org.junit.Test)90 TextValue (com.scalar.db.io.TextValue)88 IntValue (com.scalar.db.io.IntValue)81 BooleanValue (com.scalar.db.io.BooleanValue)51 HashMap (java.util.HashMap)42 ExpectedResult (com.scalar.db.util.TestUtils.ExpectedResult)40 ArrayList (java.util.ArrayList)39 Value (com.scalar.db.io.Value)38 DoubleValue (com.scalar.db.io.DoubleValue)35 AttributeValue (software.amazon.awssdk.services.dynamodb.model.AttributeValue)31 QueryRequest (software.amazon.awssdk.services.dynamodb.model.QueryRequest)29 KeyBytesEncoder (com.scalar.db.storage.dynamo.bytes.KeyBytesEncoder)27 ByteBuffer (java.nio.ByteBuffer)27