Search in sources :

Example 11 with Value

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

the class StorageSingleClusteringKeyScanIntegrationTestBase method scan_WithClusteringKeyStartRangeWithMinValue_ShouldReturnProperResult.

@Test
public void scan_WithClusteringKeyStartRangeWithMinValue_ShouldReturnProperResult() throws ExecutionException, IOException {
    for (DataType clusteringKeyType : clusteringKeyTypes) {
        for (Order clusteringOrder : Order.values()) {
            truncateTable(clusteringKeyType, clusteringOrder);
            List<Value<?>> clusteringKeyValues = prepareRecords(clusteringKeyType, clusteringOrder);
            for (boolean startInclusive : Arrays.asList(true, false)) {
                for (OrderingType orderingType : OrderingType.values()) {
                    for (boolean withLimit : Arrays.asList(false, true)) {
                        scan_WithClusteringKeyStartRangeWithMinValue_ShouldReturnProperResult(clusteringKeyValues, clusteringKeyType, clusteringOrder, startInclusive, 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 12 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(values, 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) BigIntValue(com.scalar.db.io.BigIntValue) FloatValue(com.scalar.db.io.FloatValue) BlobValue(com.scalar.db.io.BlobValue) BooleanValue(com.scalar.db.io.BooleanValue) BlobValue(com.scalar.db.io.BlobValue) Test(org.junit.Test)

Example 13 with Value

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

the class ResultImplTest method getValues_TryToModifyReturned_ShouldThrowException.

@Test
public void getValues_TryToModifyReturned_ShouldThrowException() {
    // Arrange
    ResultImpl result = new ResultImpl(values, TABLE_METADATA);
    Map<String, Value<?>> values = result.getValues();
    // Act Assert
    assertThatThrownBy(() -> values.put("new", new TextValue(ANY_NAME_1, ANY_TEXT_1))).isInstanceOf(UnsupportedOperationException.class);
}
Also used : TextValue(com.scalar.db.io.TextValue) IntValue(com.scalar.db.io.IntValue) DoubleValue(com.scalar.db.io.DoubleValue) TextValue(com.scalar.db.io.TextValue) Value(com.scalar.db.io.Value) BigIntValue(com.scalar.db.io.BigIntValue) FloatValue(com.scalar.db.io.FloatValue) BlobValue(com.scalar.db.io.BlobValue) BooleanValue(com.scalar.db.io.BooleanValue) Test(org.junit.Test)

Example 14 with Value

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

the class DistributedStorageMultipleClusteringKeyScanIntegrationTestBase method prepareRecords.

private List<ClusteringKey> prepareRecords(DataType firstClusteringKeyType, Order firstClusteringOrder, DataType secondClusteringKeyType, Order secondClusteringOrder) throws ExecutionException {
    RANDOM.setSeed(seed);
    List<ClusteringKey> ret = new ArrayList<>();
    List<Put> puts = new ArrayList<>();
    if (firstClusteringKeyType == DataType.BOOLEAN) {
        TestUtils.booleanValues(FIRST_CLUSTERING_KEY).forEach(firstClusteringKeyValue -> prepareRecords(firstClusteringKeyType, firstClusteringOrder, firstClusteringKeyValue, secondClusteringKeyType, secondClusteringOrder, puts, ret));
    } else {
        Set<Value<?>> valueSet = new HashSet<>();
        // Add min and max first clustering key values
        Arrays.asList(getMinValue(FIRST_CLUSTERING_KEY, firstClusteringKeyType), getMaxValue(FIRST_CLUSTERING_KEY, firstClusteringKeyType)).forEach(firstClusteringKeyValue -> {
            valueSet.add(firstClusteringKeyValue);
            prepareRecords(firstClusteringKeyType, firstClusteringOrder, firstClusteringKeyValue, secondClusteringKeyType, secondClusteringOrder, puts, ret);
        });
        IntStream.range(0, FIRST_CLUSTERING_KEY_NUM - 2).forEach(i -> {
            Value<?> firstClusteringKeyValue;
            while (true) {
                firstClusteringKeyValue = getFirstClusteringKeyValue(firstClusteringKeyType);
                // reject duplication
                if (!valueSet.contains(firstClusteringKeyValue)) {
                    valueSet.add(firstClusteringKeyValue);
                    break;
                }
            }
            prepareRecords(firstClusteringKeyType, firstClusteringOrder, firstClusteringKeyValue, secondClusteringKeyType, secondClusteringOrder, puts, ret);
        });
    }
    try {
        List<Put> buffer = new ArrayList<>();
        for (Put put : puts) {
            buffer.add(put);
            if (buffer.size() == 20) {
                storage.mutate(buffer);
                buffer.clear();
            }
        }
        if (!buffer.isEmpty()) {
            storage.mutate(buffer);
        }
    } catch (ExecutionException e) {
        throw new ExecutionException("put data to database failed", e);
    }
    ret.sort(getClusteringKeyComparator(firstClusteringOrder, secondClusteringOrder));
    return ret;
}
Also used : ArrayList(java.util.ArrayList) Value(com.scalar.db.io.Value) ExecutionException(com.scalar.db.exception.storage.ExecutionException) HashSet(java.util.HashSet)

Example 15 with Value

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

the class DistributedStorageMultiplePartitionKeyIntegrationTestBase 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) 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