Search in sources :

Example 71 with Value

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

the class ResultImplTest method getValues_ProperValuesGivenInConstructor_ShouldReturnWhatsSet.

@Test
public void getValues_ProperValuesGivenInConstructor_ShouldReturnWhatsSet() {
    // Arrange
    ResultImpl result = new ResultImpl(columns, TABLE_METADATA);
    // Act
    Map<String, Value<?>> actual = result.getValues();
    // Assert
    assertThat(actual.get(ANY_NAME_1)).isEqualTo(new TextValue(ANY_NAME_1, ANY_TEXT_1));
    assertThat(actual.get(ANY_NAME_2)).isEqualTo(new TextValue(ANY_NAME_2, ANY_TEXT_2));
    assertThat(actual.get(ANY_COLUMN_NAME_1)).isEqualTo(new BooleanValue(ANY_COLUMN_NAME_1, true));
    assertThat(actual.get(ANY_COLUMN_NAME_7)).isEqualTo(new BlobValue(ANY_COLUMN_NAME_7, "bytes".getBytes(StandardCharsets.UTF_8)));
}
Also used : TextValue(com.scalar.db.io.TextValue) BooleanValue(com.scalar.db.io.BooleanValue) IntValue(com.scalar.db.io.IntValue) DoubleValue(com.scalar.db.io.DoubleValue) TextValue(com.scalar.db.io.TextValue) Value(com.scalar.db.io.Value) FloatValue(com.scalar.db.io.FloatValue) BigIntValue(com.scalar.db.io.BigIntValue) BlobValue(com.scalar.db.io.BlobValue) BooleanValue(com.scalar.db.io.BooleanValue) BlobValue(com.scalar.db.io.BlobValue) Test(org.junit.jupiter.api.Test)

Example 72 with Value

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

the class StorageSingleClusteringKeyScanIntegrationTestBase method scan_WithClusteringKeyEndRange_ShouldReturnProperResult.

@Test
public void scan_WithClusteringKeyEndRange_ShouldReturnProperResult() throws ExecutionException, IOException {
    for (DataType clusteringKeyType : clusteringKeyTypes) {
        for (Order clusteringOrder : Order.values()) {
            truncateTable(clusteringKeyType, clusteringOrder);
            List<Value<?>> clusteringKeyValues = prepareRecords(clusteringKeyType, clusteringOrder);
            for (boolean endInclusive : Arrays.asList(true, false)) {
                for (OrderingType orderingType : OrderingType.values()) {
                    for (boolean withLimit : Arrays.asList(false, true)) {
                        scan_WithClusteringKeyEndRange_ShouldReturnProperResult(clusteringKeyValues, clusteringKeyType, clusteringOrder, endInclusive, orderingType, withLimit);
                    }
                }
            }
        }
    }
}
Also used : Order(com.scalar.db.api.Scan.Ordering.Order) Value(com.scalar.db.io.Value) DataType(com.scalar.db.io.DataType) Test(org.junit.Test)

Example 73 with Value

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

the class StorageSinglePartitionKeyIntegrationTestBase method getAndDelete_ShouldBehaveCorrectly.

@Test
public void getAndDelete_ShouldBehaveCorrectly() throws ExecutionException {
    for (DataType partitionKeyType : partitionKeyTypes) {
        truncateTable(partitionKeyType);
        List<Value<?>> partitionKeyValues = prepareRecords(partitionKeyType);
        String description = description(partitionKeyType);
        // for get
        for (Value<?> partitionKeyValue : partitionKeyValues) {
            // Arrange
            Get get = prepareGet(partitionKeyType, partitionKeyValue);
            // Act
            Optional<Result> result = storage.get(get);
            // Assert
            Assertions.assertThat(result).describedAs(description).isPresent();
            Assertions.assertThat(result.get().getValue(PARTITION_KEY).isPresent()).describedAs(description).isTrue();
            Assertions.assertThat(result.get().getValue(PARTITION_KEY).get()).describedAs(description).isEqualTo(partitionKeyValue);
            Assertions.assertThat(result.get().getValue(COL_NAME).isPresent()).describedAs(description).isTrue();
            Assertions.assertThat(result.get().getValue(COL_NAME).get().getAsInt()).describedAs(description).isEqualTo(1);
        }
        // for delete
        for (Value<?> partitionKeyValue : partitionKeyValues) {
            // Arrange
            Delete delete = prepareDelete(partitionKeyType, partitionKeyValue);
            // Act
            storage.delete(delete);
            // Assert
            Optional<Result> result = storage.get(prepareGet(partitionKeyType, partitionKeyValue));
            Assertions.assertThat(result).describedAs(description).isNotPresent();
        }
    }
}
Also used : Delete(com.scalar.db.api.Delete) Get(com.scalar.db.api.Get) Value(com.scalar.db.io.Value) DataType(com.scalar.db.io.DataType) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 74 with Value

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

the class StorageSinglePartitionKeyIntegrationTestBase method prepareRecords.

private List<Value<?>> prepareRecords(DataType partitionKeyType) throws ExecutionException {
    RANDOM.setSeed(seed);
    List<Value<?>> ret = new ArrayList<>();
    List<Put> puts = new ArrayList<>();
    if (partitionKeyType == DataType.BOOLEAN) {
        TestUtils.booleanValues(PARTITION_KEY).forEach(partitionKeyValue -> {
            ret.add(partitionKeyValue);
            puts.add(preparePut(partitionKeyType, partitionKeyValue));
        });
    } else {
        Set<Value<?>> valueSet = new HashSet<>();
        // Add min and max partition key values
        Arrays.asList(getMinValue(PARTITION_KEY, partitionKeyType), getMaxValue(PARTITION_KEY, partitionKeyType)).forEach(partitionKeyValue -> {
            valueSet.add(partitionKeyValue);
            ret.add(partitionKeyValue);
            puts.add(preparePut(partitionKeyType, partitionKeyValue));
        });
        IntStream.range(0, PARTITION_KEY_NUM - 2).forEach(i -> {
            Value<?> partitionKeyValue;
            while (true) {
                partitionKeyValue = getRandomValue(RANDOM, PARTITION_KEY, partitionKeyType);
                // reject duplication
                if (!valueSet.contains(partitionKeyValue)) {
                    valueSet.add(partitionKeyValue);
                    break;
                }
            }
            ret.add(partitionKeyValue);
            puts.add(preparePut(partitionKeyType, partitionKeyValue));
        });
    }
    try {
        for (Put put : puts) {
            storage.put(put);
        }
    } catch (ExecutionException e) {
        throw new ExecutionException("put data to database failed", e);
    }
    return ret;
}
Also used : Value(com.scalar.db.io.Value) ArrayList(java.util.ArrayList) ExecutionException(com.scalar.db.exception.storage.ExecutionException) Put(com.scalar.db.api.Put) HashSet(java.util.HashSet)

Example 75 with Value

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

the class StorageMultiplePartitionKeyIntegrationTestBase method prepareRecords.

private List<PartitionKey> prepareRecords(DataType firstPartitionKeyType, DataType secondPartitionKeyType) throws ExecutionException {
    RANDOM.setSeed(seed);
    List<Put> puts = new ArrayList<>();
    List<PartitionKey> ret = new ArrayList<>();
    if (firstPartitionKeyType == DataType.BOOLEAN) {
        TestUtils.booleanValues(FIRST_PARTITION_KEY).forEach(firstPartitionKeyValue -> prepareRecords(firstPartitionKeyType, firstPartitionKeyValue, secondPartitionKeyType, puts, ret));
    } else {
        Set<Value<?>> valueSet = new HashSet<>();
        // Add min and max partition key values
        Arrays.asList(getMinValue(FIRST_PARTITION_KEY, firstPartitionKeyType), getMaxValue(FIRST_PARTITION_KEY, firstPartitionKeyType)).forEach(firstPartitionKeyValue -> {
            valueSet.add(firstPartitionKeyValue);
            prepareRecords(firstPartitionKeyType, firstPartitionKeyValue, secondPartitionKeyType, puts, ret);
        });
        IntStream.range(0, FIRST_PARTITION_KEY_NUM - 2).forEach(i -> {
            Value<?> firstPartitionKeyValue;
            while (true) {
                firstPartitionKeyValue = getRandomValue(RANDOM, FIRST_PARTITION_KEY, firstPartitionKeyType);
                // reject duplication
                if (!valueSet.contains(firstPartitionKeyValue)) {
                    valueSet.add(firstPartitionKeyValue);
                    break;
                }
            }
            prepareRecords(firstPartitionKeyType, firstPartitionKeyValue, secondPartitionKeyType, puts, ret);
        });
    }
    try {
        for (Put put : puts) {
            storage.put(put);
        }
    } catch (ExecutionException e) {
        throw new ExecutionException("put data to database failed", e);
    }
    return ret;
}
Also used : ArrayList(java.util.ArrayList) Value(com.scalar.db.io.Value) ExecutionException(com.scalar.db.exception.storage.ExecutionException) Put(com.scalar.db.api.Put) HashSet(java.util.HashSet)

Aggregations

Value (com.scalar.db.io.Value)85 Test (org.junit.jupiter.api.Test)50 TextValue (com.scalar.db.io.TextValue)36 IntValue (com.scalar.db.io.IntValue)34 Put (com.scalar.db.api.Put)31 BooleanValue (com.scalar.db.io.BooleanValue)30 DoubleValue (com.scalar.db.io.DoubleValue)30 Key (com.scalar.db.io.Key)30 Result (com.scalar.db.api.Result)19 BigIntValue (com.scalar.db.io.BigIntValue)18 DataType (com.scalar.db.io.DataType)18 Order (com.scalar.db.api.Scan.Ordering.Order)16 Test (org.junit.Test)14 MutationCondition (com.scalar.db.api.MutationCondition)12 ArrayList (java.util.ArrayList)12 BlobValue (com.scalar.db.io.BlobValue)10 FloatValue (com.scalar.db.io.FloatValue)10 Scan (com.scalar.db.api.Scan)8 ExecutionException (com.scalar.db.exception.storage.ExecutionException)8 HashSet (java.util.HashSet)8