Search in sources :

Example 16 with Order

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

the class KeyBytesEncoderTest method encode_DoubleKeysGiven_ShouldEncodeProperlyWithPreservingSortOrder.

@Test
public void encode_DoubleKeysGiven_ShouldEncodeProperlyWithPreservingSortOrder() {
    RANDOM.setSeed(seed);
    runTest(() -> {
        for (DataType col1Type : KEY_TYPES) {
            // the BLOB type is supported only for the last key
            if (col1Type == DataType.BLOB) {
                continue;
            }
            for (DataType col2Type : KEY_TYPES) {
                for (Order col1Order : ORDERS) {
                    for (Order col2Order : ORDERS) {
                        encode_DoubleKeysGiven_ShouldEncodeProperlyWithPreservingSortOrder(col1Type, col2Type, col1Order, col2Order);
                    }
                }
            }
        }
    });
}
Also used : Order(com.scalar.db.api.Scan.Ordering.Order) DataType(com.scalar.db.io.DataType) Test(org.junit.jupiter.api.Test)

Example 17 with Order

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

the class KeyBytesEncoderTest method encode_TripleKeysGiven_ShouldEncodeProperlyWithPreservingSortOrder.

@Test
public void encode_TripleKeysGiven_ShouldEncodeProperlyWithPreservingSortOrder() {
    RANDOM.setSeed(seed);
    runTest(() -> {
        for (DataType col1Type : KEY_TYPES) {
            // the BLOB type is supported only for the last key
            if (col1Type == DataType.BLOB) {
                continue;
            }
            for (DataType col2Type : KEY_TYPES) {
                // the BLOB type is supported only for the last key
                if (col2Type == DataType.BLOB) {
                    continue;
                }
                for (DataType col3Type : KEY_TYPES) {
                    for (Order col1Order : ORDERS) {
                        for (Order col2Order : ORDERS) {
                            for (Order col3Order : ORDERS) {
                                encode_TripleKeysGiven_ShouldEncodeProperlyWithPreservingSortOrder(col1Type, col2Type, col3Type, col1Order, col2Order, col3Order);
                            }
                        }
                    }
                }
            }
        }
    });
}
Also used : Order(com.scalar.db.api.Scan.Ordering.Order) DataType(com.scalar.db.io.DataType) Test(org.junit.jupiter.api.Test)

Example 18 with Order

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

the class KeyBytesEncoderTest method encode_DoubleKeysGiven_ShouldEncodeProperlyWithPreservingSortOrder.

private void encode_DoubleKeysGiven_ShouldEncodeProperlyWithPreservingSortOrder(DataType col1Type, DataType col2Type, Order col1Order, Order col2Order) {
    // 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)));
    target.add(new Key(getMaxValue(COL1, col1Type), getMaxValue(COL2, col2Type)));
    for (int i = 0; i < KEY_ELEMENT_COUNT - 2; i++) {
        target.add(new Key(getRandomValue(COL1, col1Type, col1Order), getRandomValue(COL2, col2Type, col2Order)));
    }
    Map<String, Order> keyOrders = new HashMap<>();
    keyOrders.put(COL1, col1Order);
    keyOrders.put(COL2, col2Order);
    // 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 19 with Order

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

the class DistributedStorageMultipleClusteringKeyScanIntegrationTestBase method dropTables.

private void dropTables() throws java.util.concurrent.ExecutionException, InterruptedException {
    List<Callable<Void>> testCallables = new ArrayList<>();
    for (DataType firstClusteringKeyType : clusteringKeyTypes.keySet()) {
        Callable<Void> testCallable = () -> {
            for (DataType secondClusteringKeyType : clusteringKeyTypes.get(firstClusteringKeyType)) {
                for (Order firstClusteringOrder : Order.values()) {
                    for (Order secondClusteringOrder : Order.values()) {
                        admin.dropTable(getNamespaceName(firstClusteringKeyType), getTableName(firstClusteringKeyType, firstClusteringOrder, secondClusteringKeyType, secondClusteringOrder));
                    }
                }
            }
            admin.dropNamespace(getNamespaceName(firstClusteringKeyType));
            return null;
        };
        testCallables.add(testCallable);
    }
    // We firstly execute the callables without the last one. And then we execute the last one. This
    // is because the last table deletion deletes the metadata table, and this process can't be
    // handled in multiple threads/processes at the same time.
    executeInParallel(testCallables.subList(0, testCallables.size() - 1));
    executeInParallel(testCallables.subList(testCallables.size() - 1, testCallables.size()));
}
Also used : Order(com.scalar.db.api.Scan.Ordering.Order) ArrayList(java.util.ArrayList) DataType(com.scalar.db.io.DataType) Callable(java.util.concurrent.Callable)

Example 20 with Order

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

the class DistributedStorageSingleClusteringKeyScanIntegrationTestBase method scan_WithoutClusteringKeyRange_ShouldReturnProperResult.

@Test
public void scan_WithoutClusteringKeyRange_ShouldReturnProperResult() throws ExecutionException, IOException {
    for (DataType clusteringKeyType : clusteringKeyTypes) {
        for (Order clusteringOrder : Order.values()) {
            truncateTable(clusteringKeyType, clusteringOrder);
            List<Value<?>> clusteringKeyValues = prepareRecords(clusteringKeyType, clusteringOrder);
            for (OrderingType orderingType : OrderingType.values()) {
                for (boolean withLimit : Arrays.asList(false, true)) {
                    scan_WithoutClusteringKeyRange_ShouldReturnProperResult(clusteringKeyValues, clusteringKeyType, clusteringOrder, 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)

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