Search in sources :

Example 21 with Order

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

the class DistributedStorageSingleClusteringKeyScanIntegrationTestBase method scan_WithClusteringKeyRangeWithSameValues_ShouldReturnProperResult.

@Test
public void scan_WithClusteringKeyRangeWithSameValues_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_WithClusteringKeyRangeWithSameValues_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.jupiter.api.Test)

Example 22 with Order

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

the class DistributedStorageSingleClusteringKeyScanIntegrationTestBase method scan_WithClusteringKeyRangeWithMinAndMaxValue_ShouldReturnProperResult.

@Test
public void scan_WithClusteringKeyRangeWithMinAndMaxValue_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_WithClusteringKeyRangeWithMinAndMaxValue_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.jupiter.api.Test)

Example 23 with Order

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

the class KeyBytesEncoderTest method encode_SingleKeysGiven_ShouldEncodeProperlyWithPreservingSortOrder.

private void encode_SingleKeysGiven_ShouldEncodeProperlyWithPreservingSortOrder(DataType col1Type, Order col1Order) {
    // Arrange
    // Add min and max values and random values
    List<Key> target = new ArrayList<>(KEY_ELEMENT_COUNT);
    target.add(new Key(getMinValue(COL1, col1Type)));
    target.add(new Key(getMaxValue(COL1, col1Type)));
    for (int i = 0; i < KEY_ELEMENT_COUNT - 2; i++) {
        target.add(new Key(getRandomValue(COL1, col1Type, col1Order)));
    }
    Map<String, Order> keyOrders = new HashMap<>();
    keyOrders.put(COL1, col1Order);
    // Act
    List<Key> actual = sortWithKeyBytesEncoder(target, keyOrders);
    List<Key> expected = target.stream().sorted(getComparator(keyOrders)).collect(Collectors.toList());
    // Assert
    assertThat(actual).isEqualTo(expected);
}
Also used : Order(com.scalar.db.api.Scan.Ordering.Order) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Key(com.scalar.db.io.Key)

Example 24 with Order

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

the class KeyBytesEncoderTest method encode_TripleKeysGiven_ShouldEncodeProperlyWithPreservingSortOrder.

private void encode_TripleKeysGiven_ShouldEncodeProperlyWithPreservingSortOrder(DataType col1Type, DataType col2Type, DataType col3Type, Order col1Order, Order col2Order, Order col3Order) {
    // Arrange
    // Add min and max values and random values
    List<Key> target = new ArrayList<>(KEY_ELEMENT_COUNT);
    target.add(new Key(getMinValue(COL1, col1Type), getMinValue(COL2, col2Type), getMinValue(COL3, col3Type)));
    target.add(new Key(getMaxValue(COL1, col1Type), getMaxValue(COL2, col2Type), getMaxValue(COL3, col3Type)));
    for (int i = 0; i < KEY_ELEMENT_COUNT - 2; i++) {
        target.add(new Key(getRandomValue(COL1, col1Type, col1Order), getRandomValue(COL2, col2Type, col2Order), getRandomValue(COL3, col3Type, col3Order)));
    }
    Map<String, Order> keyOrders = new HashMap<>();
    keyOrders.put(COL1, col1Order);
    keyOrders.put(COL2, col2Order);
    keyOrders.put(COL3, col3Order);
    // Act
    List<Key> actual = sortWithKeyBytesEncoder(target, keyOrders);
    List<Key> expected = target.stream().sorted(getComparator(keyOrders)).collect(Collectors.toList());
    // Assert
    assertThat(actual).isEqualTo(expected);
}
Also used : Order(com.scalar.db.api.Scan.Ordering.Order) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Key(com.scalar.db.io.Key)

Example 25 with Order

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

the class KeyBytesEncoderTest method sortWithKeyBytesEncoder.

private static List<Key> sortWithKeyBytesEncoder(List<Key> target, Map<String, Order> keyOrders) {
    List<Element> list = new ArrayList<>();
    for (Key key : target) {
        ByteBuffer byteBuffer = new KeyBytesEncoder().encode(key, keyOrders);
        list.add(new Element(byteBuffer, key));
    }
    return list.stream().sorted().map(e -> e.key).collect(Collectors.toList());
}
Also used : IntStream(java.util.stream.IntStream) IntValue(com.scalar.db.io.IntValue) Arrays(java.util.Arrays) DoubleValue(com.scalar.db.io.DoubleValue) TextValue(com.scalar.db.io.TextValue) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Value(com.scalar.db.io.Value) OptionalDouble(java.util.OptionalDouble) HashMap(java.util.HashMap) Random(java.util.Random) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) OptionalLong(java.util.OptionalLong) FloatValue(com.scalar.db.io.FloatValue) 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) UnsignedBytes(com.google.common.primitives.UnsignedBytes) Key(com.scalar.db.io.Key) BigIntValue(com.scalar.db.io.BigIntValue) ComparisonChain(com.google.common.collect.ComparisonChain) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) List(java.util.List) Ordering(com.google.common.collect.Ordering) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) Comparator(java.util.Comparator) BlobValue(com.scalar.db.io.BlobValue) BooleanValue(com.scalar.db.io.BooleanValue) ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer) Key(com.scalar.db.io.Key)

Aggregations

Order (com.scalar.db.api.Scan.Ordering.Order)33 DataType (com.scalar.db.io.DataType)30 Value (com.scalar.db.io.Value)17 ArrayList (java.util.ArrayList)12 Test (org.junit.jupiter.api.Test)12 Callable (java.util.concurrent.Callable)8 Test (org.junit.Test)8 Key (com.scalar.db.io.Key)4 HashMap (java.util.HashMap)4 ComparisonChain (com.google.common.collect.ComparisonChain)1 ImmutableList (com.google.common.collect.ImmutableList)1 Ordering (com.google.common.collect.Ordering)1 UnsignedBytes (com.google.common.primitives.UnsignedBytes)1 BigIntValue (com.scalar.db.io.BigIntValue)1 BlobValue (com.scalar.db.io.BlobValue)1 BooleanValue (com.scalar.db.io.BooleanValue)1 DoubleValue (com.scalar.db.io.DoubleValue)1 FloatValue (com.scalar.db.io.FloatValue)1 IntValue (com.scalar.db.io.IntValue)1 TextValue (com.scalar.db.io.TextValue)1