Search in sources :

Example 1 with Result

use of com.scalar.db.api.Result in project scalardb by scalar-labs.

the class AbstractResult method equals.

@Override
public boolean equals(Object o) {
    if (o == this) {
        return true;
    }
    if (!(o instanceof Result)) {
        return false;
    }
    Result other = (Result) o;
    if (!getContainedColumnNames().equals(other.getContainedColumnNames())) {
        return false;
    }
    for (String containedColumnName : getContainedColumnNames()) {
        Object value = getAsObject(containedColumnName);
        Object otherValue = other.getAsObject(containedColumnName);
        if (value == null && otherValue == null) {
            continue;
        }
        if (value == null || otherValue == null) {
            return false;
        }
        if (!value.equals(otherValue)) {
            return false;
        }
    }
    return true;
}
Also used : Result(com.scalar.db.api.Result)

Example 2 with Result

use of com.scalar.db.api.Result in project scalardb by scalar-labs.

the class StorageMultipleClusteringKeyScanIntegrationTestBase method scan_WithSecondClusteringKeyRangeWithSameValues_ShouldReturnProperResult.

private void scan_WithSecondClusteringKeyRangeWithSameValues_ShouldReturnProperResult(List<ClusteringKey> clusteringKeys, DataType firstClusteringKeyType, Order firstClusteringOrder, DataType secondClusteringKeyType, Order secondClusteringOrder, boolean startInclusive, boolean endInclusive, OrderingType orderingType, boolean withLimit) throws ExecutionException, IOException {
    // Arrange
    if (firstClusteringKeyType == DataType.BOOLEAN) {
        Value<?> firstClusteringKeyValue = clusteringKeys.get(0).first;
        clusteringKeys = clusteringKeys.stream().filter(c -> c.first.equals(firstClusteringKeyValue)).collect(Collectors.toList());
    } else {
        Value<?> firstClusteringKeyValue = clusteringKeys.get(getFirstClusteringKeyIndex(2, secondClusteringKeyType)).first;
        clusteringKeys = clusteringKeys.stream().filter(c -> c.first.equals(firstClusteringKeyValue)).collect(Collectors.toList());
    }
    ClusteringKey startAndEndClusteringKey;
    if (secondClusteringKeyType == DataType.BOOLEAN) {
        startAndEndClusteringKey = new ClusteringKey(clusteringKeys.get(0).first, clusteringKeys.get(0).second);
    } else {
        startAndEndClusteringKey = new ClusteringKey(clusteringKeys.get(9).first, clusteringKeys.get(9).second);
    }
    List<ClusteringKey> expected = getExpected(clusteringKeys, startAndEndClusteringKey, startInclusive, startAndEndClusteringKey, endInclusive, orderingType);
    int limit = getLimit(withLimit, expected);
    if (limit > 0) {
        expected = expected.subList(0, limit);
    }
    Scan scan = getScan(firstClusteringKeyType, firstClusteringOrder, secondClusteringKeyType, secondClusteringOrder, startAndEndClusteringKey, startInclusive, startAndEndClusteringKey, endInclusive, orderingType, limit);
    // Act
    List<Result> actual = scanAll(scan);
    // Assert
    assertScanResult(actual, expected, description(firstClusteringKeyType, firstClusteringOrder, secondClusteringKeyType, secondClusteringOrder, startInclusive, endInclusive, orderingType, withLimit));
}
Also used : Scan(com.scalar.db.api.Scan) Result(com.scalar.db.api.Result)

Example 3 with Result

use of com.scalar.db.api.Result in project scalardb by scalar-labs.

the class StorageMultipleClusteringKeyScanIntegrationTestBase method scan_WithFirstClusteringKeyEndRange_ShouldReturnProperResult.

private void scan_WithFirstClusteringKeyEndRange_ShouldReturnProperResult(List<ClusteringKey> clusteringKeys, DataType firstClusteringKeyType, Order firstClusteringOrder, boolean endInclusive, OrderingType orderingType, boolean withLimit) throws ExecutionException, IOException {
    // Arrange
    ClusteringKey endClusteringKey;
    if (firstClusteringKeyType == DataType.BOOLEAN) {
        endClusteringKey = new ClusteringKey(clusteringKeys.get(getFirstClusteringKeyIndex(1, DataType.INT)).first);
    } else {
        endClusteringKey = new ClusteringKey(clusteringKeys.get(getFirstClusteringKeyIndex(3, DataType.INT)).first);
    }
    List<ClusteringKey> expected = getExpected(clusteringKeys, null, null, endClusteringKey, endInclusive, orderingType);
    int limit = getLimit(withLimit, expected);
    if (limit > 0) {
        expected = expected.subList(0, limit);
    }
    Scan scan = getScan(firstClusteringKeyType, firstClusteringOrder, DataType.INT, Order.ASC, null, null, endClusteringKey, endInclusive, orderingType, limit);
    // Act
    List<Result> actual = scanAll(scan);
    // Assert
    assertScanResult(actual, expected, description(firstClusteringKeyType, firstClusteringOrder, null, null, null, endInclusive, orderingType, withLimit));
}
Also used : Scan(com.scalar.db.api.Scan) Result(com.scalar.db.api.Result)

Example 4 with Result

use of com.scalar.db.api.Result in project scalardb by scalar-labs.

the class StorageMultipleClusteringKeyScanIntegrationTestBase method scan_WithFirstClusteringKeyRangeWithSameValues_ShouldReturnProperResult.

private void scan_WithFirstClusteringKeyRangeWithSameValues_ShouldReturnProperResult(List<ClusteringKey> clusteringKeys, DataType firstClusteringKeyType, Order firstClusteringOrder, boolean startInclusive, boolean endInclusive, OrderingType orderingType, boolean withLimit) throws ExecutionException, IOException {
    // Arrange
    ClusteringKey startAndEndClusteringKey;
    if (firstClusteringKeyType == DataType.BOOLEAN) {
        startAndEndClusteringKey = new ClusteringKey(clusteringKeys.get(getFirstClusteringKeyIndex(0, DataType.INT)).first);
    } else {
        startAndEndClusteringKey = new ClusteringKey(clusteringKeys.get(getFirstClusteringKeyIndex(2, DataType.INT)).first);
    }
    List<ClusteringKey> expected = getExpected(clusteringKeys, startAndEndClusteringKey, startInclusive, startAndEndClusteringKey, endInclusive, orderingType);
    int limit = getLimit(withLimit, expected);
    if (limit > 0) {
        expected = expected.subList(0, limit);
    }
    Scan scan = getScan(firstClusteringKeyType, firstClusteringOrder, DataType.INT, Order.ASC, startAndEndClusteringKey, startInclusive, startAndEndClusteringKey, endInclusive, orderingType, limit);
    // Act
    List<Result> actual = scanAll(scan);
    // Assert
    assertScanResult(actual, expected, description(firstClusteringKeyType, firstClusteringOrder, null, null, startInclusive, endInclusive, orderingType, withLimit));
}
Also used : Scan(com.scalar.db.api.Scan) Result(com.scalar.db.api.Result)

Example 5 with Result

use of com.scalar.db.api.Result in project scalardb by scalar-labs.

the class StorageMultipleClusteringKeyScanIntegrationTestBase method scan_WithSecondClusteringKeyStartRangeWithMinValue_ShouldReturnProperResult.

private void scan_WithSecondClusteringKeyStartRangeWithMinValue_ShouldReturnProperResult(List<ClusteringKey> clusteringKeys, DataType firstClusteringKeyType, Order firstClusteringOrder, DataType secondClusteringKeyType, Order secondClusteringOrder, boolean startInclusive, OrderingType orderingType, boolean withLimit) throws ExecutionException, IOException {
    // Arrange
    Value<?> firstClusteringKeyValue = getMinValue(FIRST_CLUSTERING_KEY, firstClusteringKeyType);
    clusteringKeys = clusteringKeys.stream().filter(c -> c.first.equals(firstClusteringKeyValue)).collect(Collectors.toList());
    ClusteringKey startClusteringKey = new ClusteringKey(firstClusteringKeyValue, getMinValue(SECOND_CLUSTERING_KEY, secondClusteringKeyType));
    List<ClusteringKey> expected = getExpected(clusteringKeys, startClusteringKey, startInclusive, null, null, orderingType);
    int limit = getLimit(withLimit, expected);
    if (limit > 0) {
        expected = expected.subList(0, limit);
    }
    Scan scan = getScan(firstClusteringKeyType, firstClusteringOrder, secondClusteringKeyType, secondClusteringOrder, startClusteringKey, startInclusive, null, null, orderingType, limit);
    // Act
    List<Result> actual = scanAll(scan);
    // Assert
    assertScanResult(actual, expected, description(firstClusteringKeyType, firstClusteringOrder, secondClusteringKeyType, secondClusteringOrder, startInclusive, null, orderingType, withLimit));
}
Also used : Scan(com.scalar.db.api.Scan) Result(com.scalar.db.api.Result)

Aggregations

Result (com.scalar.db.api.Result)324 Test (org.junit.Test)158 Get (com.scalar.db.api.Get)132 Scan (com.scalar.db.api.Scan)106 Put (com.scalar.db.api.Put)101 Key (com.scalar.db.io.Key)85 Test (org.junit.jupiter.api.Test)83 GrpcTransaction (com.scalar.db.transaction.rpc.GrpcTransaction)39 IntValue (com.scalar.db.io.IntValue)36 GrpcTwoPhaseCommitTransaction (com.scalar.db.transaction.rpc.GrpcTwoPhaseCommitTransaction)32 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)29 Delete (com.scalar.db.api.Delete)28 TextValue (com.scalar.db.io.TextValue)24 Value (com.scalar.db.io.Value)19 BigIntValue (com.scalar.db.io.BigIntValue)16 Scanner (com.scalar.db.api.Scanner)15 ArrayList (java.util.ArrayList)14 BooleanValue (com.scalar.db.io.BooleanValue)11 ConditionalExpression (com.scalar.db.api.ConditionalExpression)10 ScanAll (com.scalar.db.api.ScanAll)9