Search in sources :

Example 1 with Value

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

the class StorageMultipleClusteringKeyScanIntegrationTestBase 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) Put(com.scalar.db.api.Put) HashSet(java.util.HashSet)

Example 2 with Value

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

the class StorageSingleClusteringKeyScanIntegrationTestBase method scan_WithClusteringKeyEndRange_ShouldReturnProperResult.

private void scan_WithClusteringKeyEndRange_ShouldReturnProperResult(List<Value<?>> clusteringKeyValues, DataType clusteringKeyType, Order clusteringOrder, boolean endInclusive, OrderingType orderingType, boolean withLimit) throws ExecutionException, IOException {
    // Arrange
    Value<?> endClusteringKeyValue;
    if (clusteringKeyType == DataType.BOOLEAN) {
        endClusteringKeyValue = clusteringKeyValues.get(1);
    } else {
        endClusteringKeyValue = clusteringKeyValues.get(14);
    }
    List<Value<?>> expected = getExpected(clusteringKeyValues, null, null, endClusteringKeyValue, endInclusive, orderingType);
    int limit = getLimit(withLimit, expected);
    if (limit > 0) {
        expected = expected.subList(0, limit);
    }
    Scan scan = getScan(clusteringKeyType, clusteringOrder, null, null, endClusteringKeyValue, endInclusive, orderingType, limit);
    // Act
    List<Result> actual = scanAll(scan);
    // Assert
    assertScanResult(actual, expected, description(clusteringKeyType, clusteringOrder, null, endInclusive, orderingType, withLimit));
}
Also used : Value(com.scalar.db.io.Value) Scan(com.scalar.db.api.Scan) Result(com.scalar.db.api.Result)

Example 3 with Value

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

the class StorageSingleClusteringKeyScanIntegrationTestBase method scan_WithClusteringKeyRangeWithMinAndMaxValue_ShouldReturnProperResult.

private void scan_WithClusteringKeyRangeWithMinAndMaxValue_ShouldReturnProperResult(List<Value<?>> clusteringKeyValues, DataType clusteringKeyType, Order clusteringOrder, boolean startInclusive, boolean endInclusive, OrderingType orderingType, boolean withLimit) throws ExecutionException, IOException {
    // Arrange
    Value<?> startClusteringKeyValue = getMinValue(CLUSTERING_KEY, clusteringKeyType);
    Value<?> endClusteringKeyValue = getMaxValue(CLUSTERING_KEY, clusteringKeyType);
    List<Value<?>> expected = getExpected(clusteringKeyValues, startClusteringKeyValue, startInclusive, endClusteringKeyValue, endInclusive, orderingType);
    int limit = getLimit(withLimit, expected);
    if (limit > 0) {
        expected = expected.subList(0, limit);
    }
    Scan scan = getScan(clusteringKeyType, clusteringOrder, startClusteringKeyValue, startInclusive, endClusteringKeyValue, endInclusive, orderingType, limit);
    // Act
    List<Result> actual = scanAll(scan);
    // Assert
    assertScanResult(actual, expected, description(clusteringKeyType, clusteringOrder, startInclusive, endInclusive, orderingType, withLimit));
}
Also used : Value(com.scalar.db.io.Value) Scan(com.scalar.db.api.Scan) Result(com.scalar.db.api.Result)

Example 4 with Value

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

the class StorageSingleClusteringKeyScanIntegrationTestBase method scan_WithClusteringKeyRange_ShouldReturnProperResult.

@Test
public void scan_WithClusteringKeyRange_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 (boolean endInclusive : Arrays.asList(true, false)) {
                    for (OrderingType orderingType : OrderingType.values()) {
                        for (boolean withLimit : Arrays.asList(false, true)) {
                            scan_WithClusteringKeyRange_ShouldReturnProperResult(clusteringKeyValues, clusteringKeyType, clusteringOrder, startInclusive, 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 5 with Value

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

the class StorageSingleClusteringKeyScanIntegrationTestBase method scan_WithClusteringKeyRangeWithSameValues_ShouldReturnProperResult.

private void scan_WithClusteringKeyRangeWithSameValues_ShouldReturnProperResult(List<Value<?>> clusteringKeyValues, DataType clusteringKeyType, Order clusteringOrder, boolean startInclusive, boolean endInclusive, OrderingType orderingType, boolean withLimit) throws ExecutionException, IOException {
    // Arrange
    Value<?> startAndEndClusteringKeyValue;
    if (clusteringKeyType == DataType.BOOLEAN) {
        startAndEndClusteringKeyValue = clusteringKeyValues.get(0);
    } else {
        startAndEndClusteringKeyValue = clusteringKeyValues.get(9);
    }
    List<Value<?>> expected = getExpected(clusteringKeyValues, startAndEndClusteringKeyValue, startInclusive, startAndEndClusteringKeyValue, endInclusive, orderingType);
    int limit = getLimit(withLimit, expected);
    if (limit > 0) {
        expected = expected.subList(0, limit);
    }
    Scan scan = getScan(clusteringKeyType, clusteringOrder, startAndEndClusteringKeyValue, startInclusive, startAndEndClusteringKeyValue, endInclusive, orderingType, limit);
    // Act
    List<Result> actual = scanAll(scan);
    // Assert
    assertScanResult(actual, expected, description(clusteringKeyType, clusteringOrder, startInclusive, endInclusive, orderingType, withLimit));
}
Also used : Value(com.scalar.db.io.Value) Scan(com.scalar.db.api.Scan) Result(com.scalar.db.api.Result)

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