Search in sources :

Example 81 with Value

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

the class StorageSingleClusteringKeyScanIntegrationTestBase method scan_WithClusteringKeyEndRangeWithMaxValue_ShouldReturnProperResult.

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

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

the class StorageSingleClusteringKeyScanIntegrationTestBase method scan_WithClusteringKeyRange_ShouldReturnProperResult.

private void scan_WithClusteringKeyRange_ShouldReturnProperResult(List<Value<?>> clusteringKeyValues, DataType clusteringKeyType, Order clusteringOrder, boolean startInclusive, boolean endInclusive, OrderingType orderingType, boolean withLimit) throws ExecutionException, IOException {
    // Arrange
    Value<?> startClusteringKeyValue;
    Value<?> endClusteringKeyValue;
    if (clusteringKeyType == DataType.BOOLEAN) {
        startClusteringKeyValue = clusteringKeyValues.get(0);
        endClusteringKeyValue = clusteringKeyValues.get(1);
    } else {
        startClusteringKeyValue = clusteringKeyValues.get(4);
        endClusteringKeyValue = clusteringKeyValues.get(14);
    }
    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 83 with Value

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

the class ResultImplTest method getValue_ProperNullValuesGivenInConstructor_ShouldReturnWhatsSet.

@Test
public void getValue_ProperNullValuesGivenInConstructor_ShouldReturnWhatsSet() {
    // Arrange
    ResultImpl result = new ResultImpl(ImmutableMap.<String, Optional<Value<?>>>builder().put(ANY_NAME_1, Optional.of(new TextValue(ANY_NAME_1, ANY_TEXT_1))).put(ANY_NAME_2, Optional.of(new TextValue(ANY_NAME_2, ANY_TEXT_2))).put(ANY_COLUMN_NAME_1, Optional.empty()).put(ANY_COLUMN_NAME_2, Optional.empty()).put(ANY_COLUMN_NAME_3, Optional.empty()).put(ANY_COLUMN_NAME_4, Optional.empty()).put(ANY_COLUMN_NAME_5, Optional.empty()).put(ANY_COLUMN_NAME_6, Optional.empty()).put(ANY_COLUMN_NAME_7, Optional.empty()).build(), TABLE_METADATA);
    // Act Assert
    assertThat(result.getValue(ANY_NAME_1)).isEqualTo(Optional.of(new TextValue(ANY_NAME_1, ANY_TEXT_1)));
    assertThat(result.getValue(ANY_NAME_2)).isEqualTo(Optional.of(new TextValue(ANY_NAME_2, ANY_TEXT_2)));
    assertThat(result.getValue(ANY_COLUMN_NAME_1)).isEqualTo(Optional.of(new BooleanValue(ANY_COLUMN_NAME_1, false)));
    assertThat(result.getValue(ANY_COLUMN_NAME_2)).isEqualTo(Optional.of(new IntValue(ANY_COLUMN_NAME_2, 0)));
    assertThat(result.getValue(ANY_COLUMN_NAME_3)).isEqualTo(Optional.of(new BigIntValue(ANY_COLUMN_NAME_3, 0L)));
    assertThat(result.getValue(ANY_COLUMN_NAME_4)).isEqualTo(Optional.of(new FloatValue(ANY_COLUMN_NAME_4, 0.0F)));
    assertThat(result.getValue(ANY_COLUMN_NAME_5)).isEqualTo(Optional.of(new DoubleValue(ANY_COLUMN_NAME_5, 0.0D)));
    assertThat(result.getValue(ANY_COLUMN_NAME_6)).isEqualTo(Optional.of(new TextValue(ANY_COLUMN_NAME_6, (String) null)));
    assertThat(result.getValue(ANY_COLUMN_NAME_7)).isEqualTo(Optional.of(new BlobValue(ANY_COLUMN_NAME_7, (byte[]) null)));
    assertThat(result.getContainedColumnNames()).isEqualTo(new HashSet<>(Arrays.asList(ANY_NAME_1, ANY_NAME_2, ANY_COLUMN_NAME_1, ANY_COLUMN_NAME_2, ANY_COLUMN_NAME_3, ANY_COLUMN_NAME_4, ANY_COLUMN_NAME_5, ANY_COLUMN_NAME_6, ANY_COLUMN_NAME_7)));
    assertThat(result.contains(ANY_NAME_1)).isTrue();
    assertThat(result.isNull(ANY_NAME_1)).isFalse();
    assertThat(result.getText(ANY_NAME_1)).isEqualTo(ANY_TEXT_1);
    assertThat(result.getAsObject(ANY_NAME_1)).isEqualTo(ANY_TEXT_1);
    assertThat(result.contains(ANY_NAME_2)).isTrue();
    assertThat(result.isNull(ANY_NAME_2)).isFalse();
    assertThat(result.getText(ANY_NAME_2)).isEqualTo(ANY_TEXT_2);
    assertThat(result.getAsObject(ANY_NAME_2)).isEqualTo(ANY_TEXT_2);
    assertThat(result.contains(ANY_COLUMN_NAME_1)).isTrue();
    assertThat(result.isNull(ANY_COLUMN_NAME_1)).isTrue();
    assertThat(result.getBoolean(ANY_COLUMN_NAME_1)).isEqualTo(false);
    assertThat(result.getAsObject(ANY_COLUMN_NAME_1)).isNull();
    assertThat(result.contains(ANY_COLUMN_NAME_2)).isTrue();
    assertThat(result.isNull(ANY_COLUMN_NAME_2)).isTrue();
    assertThat(result.getInt(ANY_COLUMN_NAME_2)).isEqualTo(0);
    assertThat(result.getAsObject(ANY_COLUMN_NAME_2)).isNull();
    assertThat(result.contains(ANY_COLUMN_NAME_3)).isTrue();
    assertThat(result.isNull(ANY_COLUMN_NAME_3)).isTrue();
    assertThat(result.getBigInt(ANY_COLUMN_NAME_3)).isEqualTo(0L);
    assertThat(result.getAsObject(ANY_COLUMN_NAME_3)).isNull();
    assertThat(result.contains(ANY_COLUMN_NAME_4)).isTrue();
    assertThat(result.isNull(ANY_COLUMN_NAME_4)).isTrue();
    assertThat(result.getFloat(ANY_COLUMN_NAME_4)).isEqualTo(0.0F);
    assertThat(result.getAsObject(ANY_COLUMN_NAME_4)).isNull();
    assertThat(result.contains(ANY_COLUMN_NAME_5)).isTrue();
    assertThat(result.isNull(ANY_COLUMN_NAME_5)).isTrue();
    assertThat(result.getDouble(ANY_COLUMN_NAME_5)).isEqualTo(0.0D);
    assertThat(result.getAsObject(ANY_COLUMN_NAME_5)).isNull();
    assertThat(result.contains(ANY_COLUMN_NAME_6)).isTrue();
    assertThat(result.isNull(ANY_COLUMN_NAME_6)).isTrue();
    assertThat(result.getText(ANY_COLUMN_NAME_6)).isNull();
    assertThat(result.getAsObject(ANY_COLUMN_NAME_6)).isNull();
    assertThat(result.contains(ANY_COLUMN_NAME_7)).isTrue();
    assertThat(result.isNull(ANY_COLUMN_NAME_7)).isTrue();
    assertThat(result.getBlob(ANY_COLUMN_NAME_7)).isNull();
    assertThat(result.getBlobAsByteBuffer(ANY_COLUMN_NAME_7)).isNull();
    assertThat(result.getBlobAsBytes(ANY_COLUMN_NAME_7)).isNull();
    assertThat(result.getAsObject(ANY_COLUMN_NAME_7)).isNull();
}
Also used : DoubleValue(com.scalar.db.io.DoubleValue) 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) FloatValue(com.scalar.db.io.FloatValue) IntValue(com.scalar.db.io.IntValue) BigIntValue(com.scalar.db.io.BigIntValue) BigIntValue(com.scalar.db.io.BigIntValue) BlobValue(com.scalar.db.io.BlobValue) Test(org.junit.Test)

Example 84 with Value

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

the class ResultImplTest method getClusteringKey_NotRequiredValuesGiven_ShouldReturnClusteringKey.

@Test
public void getClusteringKey_NotRequiredValuesGiven_ShouldReturnClusteringKey() {
    // Arrange
    ResultImpl result1 = new ResultImpl(ImmutableMap.<String, Optional<Value<?>>>builder().put(ANY_NAME_1, Optional.of(new TextValue(ANY_NAME_1, ANY_TEXT_1))).build(), TABLE_METADATA);
    ResultImpl result2 = new ResultImpl(ImmutableMap.<String, Optional<Value<?>>>builder().put(ANY_NAME_1, Optional.of(new TextValue(ANY_NAME_1, ANY_TEXT_1))).put(ANY_NAME_2, Optional.empty()).build(), TABLE_METADATA);
    // Act
    Optional<Key> key1 = result1.getClusteringKey();
    Optional<Key> key2 = result2.getClusteringKey();
    // Assert
    assertThat(key1).isNotPresent();
    assertThat(key2).isNotPresent();
}
Also used : Optional(java.util.Optional) 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) Key(com.scalar.db.io.Key) Test(org.junit.Test)

Example 85 with Value

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

the class ResultImplTest method getValue_ProperValuesWithNullTextValueAndNullBlobValueGivenInConstructor_ShouldReturnWhatsSet.

@Test
public void getValue_ProperValuesWithNullTextValueAndNullBlobValueGivenInConstructor_ShouldReturnWhatsSet() {
    // Arrange
    ResultImpl result = new ResultImpl(ImmutableMap.<String, Optional<Value<?>>>builder().put(ANY_NAME_1, Optional.of(new TextValue(ANY_NAME_1, ANY_TEXT_1))).put(ANY_NAME_2, Optional.of(new TextValue(ANY_NAME_2, ANY_TEXT_2))).put(ANY_COLUMN_NAME_1, Optional.of(new BooleanValue(ANY_COLUMN_NAME_1, true))).put(ANY_COLUMN_NAME_2, Optional.of(new IntValue(ANY_COLUMN_NAME_2, Integer.MAX_VALUE))).put(ANY_COLUMN_NAME_3, Optional.of(new BigIntValue(ANY_COLUMN_NAME_3, BigIntValue.MAX_VALUE))).put(ANY_COLUMN_NAME_4, Optional.of(new FloatValue(ANY_COLUMN_NAME_4, Float.MAX_VALUE))).put(ANY_COLUMN_NAME_5, Optional.of(new DoubleValue(ANY_COLUMN_NAME_5, Double.MAX_VALUE))).put(ANY_COLUMN_NAME_6, Optional.of(new TextValue(ANY_COLUMN_NAME_6, (String) null))).put(ANY_COLUMN_NAME_7, Optional.of(new BlobValue(ANY_COLUMN_NAME_7, (byte[]) null))).build(), TABLE_METADATA);
    // Act Assert
    assertThat(result.getValue(ANY_NAME_1)).isEqualTo(Optional.of(new TextValue(ANY_NAME_1, ANY_TEXT_1)));
    assertThat(result.getValue(ANY_NAME_2)).isEqualTo(Optional.of(new TextValue(ANY_NAME_2, ANY_TEXT_2)));
    assertThat(result.getValue(ANY_COLUMN_NAME_1)).isEqualTo(Optional.of(new BooleanValue(ANY_COLUMN_NAME_1, true)));
    assertThat(result.getValue(ANY_COLUMN_NAME_2)).isEqualTo(Optional.of(new IntValue(ANY_COLUMN_NAME_2, Integer.MAX_VALUE)));
    assertThat(result.getValue(ANY_COLUMN_NAME_3)).isEqualTo(Optional.of(new BigIntValue(ANY_COLUMN_NAME_3, BigIntValue.MAX_VALUE)));
    assertThat(result.getValue(ANY_COLUMN_NAME_4)).isEqualTo(Optional.of(new FloatValue(ANY_COLUMN_NAME_4, Float.MAX_VALUE)));
    assertThat(result.getValue(ANY_COLUMN_NAME_5)).isEqualTo(Optional.of(new DoubleValue(ANY_COLUMN_NAME_5, Double.MAX_VALUE)));
    assertThat(result.getValue(ANY_COLUMN_NAME_6)).isEqualTo(Optional.of(new TextValue(ANY_COLUMN_NAME_6, (String) null)));
    assertThat(result.getValue(ANY_COLUMN_NAME_7)).isEqualTo(Optional.of(new BlobValue(ANY_COLUMN_NAME_7, (byte[]) null)));
    assertThat(result.getContainedColumnNames()).isEqualTo(new HashSet<>(Arrays.asList(ANY_NAME_1, ANY_NAME_2, ANY_COLUMN_NAME_1, ANY_COLUMN_NAME_2, ANY_COLUMN_NAME_3, ANY_COLUMN_NAME_4, ANY_COLUMN_NAME_5, ANY_COLUMN_NAME_6, ANY_COLUMN_NAME_7)));
    assertThat(result.contains(ANY_NAME_1)).isTrue();
    assertThat(result.isNull(ANY_NAME_1)).isFalse();
    assertThat(result.getText(ANY_NAME_1)).isEqualTo(ANY_TEXT_1);
    assertThat(result.getAsObject(ANY_NAME_1)).isEqualTo(ANY_TEXT_1);
    assertThat(result.contains(ANY_NAME_2)).isTrue();
    assertThat(result.isNull(ANY_NAME_2)).isFalse();
    assertThat(result.getText(ANY_NAME_2)).isEqualTo(ANY_TEXT_2);
    assertThat(result.getAsObject(ANY_NAME_2)).isEqualTo(ANY_TEXT_2);
    assertThat(result.contains(ANY_COLUMN_NAME_1)).isTrue();
    assertThat(result.isNull(ANY_COLUMN_NAME_1)).isFalse();
    assertThat(result.getBoolean(ANY_COLUMN_NAME_1)).isEqualTo(true);
    assertThat(result.getAsObject(ANY_COLUMN_NAME_1)).isEqualTo(true);
    assertThat(result.contains(ANY_COLUMN_NAME_2)).isTrue();
    assertThat(result.isNull(ANY_COLUMN_NAME_2)).isFalse();
    assertThat(result.getInt(ANY_COLUMN_NAME_2)).isEqualTo(Integer.MAX_VALUE);
    assertThat(result.getAsObject(ANY_COLUMN_NAME_2)).isEqualTo(Integer.MAX_VALUE);
    assertThat(result.contains(ANY_COLUMN_NAME_3)).isTrue();
    assertThat(result.isNull(ANY_COLUMN_NAME_3)).isFalse();
    assertThat(result.getBigInt(ANY_COLUMN_NAME_3)).isEqualTo(BigIntValue.MAX_VALUE);
    assertThat(result.getAsObject(ANY_COLUMN_NAME_3)).isEqualTo(BigIntValue.MAX_VALUE);
    assertThat(result.contains(ANY_COLUMN_NAME_4)).isTrue();
    assertThat(result.isNull(ANY_COLUMN_NAME_4)).isFalse();
    assertThat(result.getFloat(ANY_COLUMN_NAME_4)).isEqualTo(Float.MAX_VALUE);
    assertThat(result.getAsObject(ANY_COLUMN_NAME_4)).isEqualTo(Float.MAX_VALUE);
    assertThat(result.contains(ANY_COLUMN_NAME_5)).isTrue();
    assertThat(result.isNull(ANY_COLUMN_NAME_5)).isFalse();
    assertThat(result.getDouble(ANY_COLUMN_NAME_5)).isEqualTo(Double.MAX_VALUE);
    assertThat(result.getAsObject(ANY_COLUMN_NAME_5)).isEqualTo(Double.MAX_VALUE);
    assertThat(result.contains(ANY_COLUMN_NAME_6)).isTrue();
    assertThat(result.isNull(ANY_COLUMN_NAME_6)).isTrue();
    assertThat(result.getText(ANY_COLUMN_NAME_6)).isNull();
    assertThat(result.getAsObject(ANY_COLUMN_NAME_6)).isNull();
    assertThat(result.contains(ANY_COLUMN_NAME_7)).isTrue();
    assertThat(result.isNull(ANY_COLUMN_NAME_7)).isTrue();
    assertThat(result.getBlob(ANY_COLUMN_NAME_7)).isNull();
    assertThat(result.getBlobAsByteBuffer(ANY_COLUMN_NAME_7)).isNull();
    assertThat(result.getBlobAsBytes(ANY_COLUMN_NAME_7)).isNull();
    assertThat(result.getAsObject(ANY_COLUMN_NAME_7)).isNull();
}
Also used : DoubleValue(com.scalar.db.io.DoubleValue) 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) FloatValue(com.scalar.db.io.FloatValue) IntValue(com.scalar.db.io.IntValue) BigIntValue(com.scalar.db.io.BigIntValue) BigIntValue(com.scalar.db.io.BigIntValue) BlobValue(com.scalar.db.io.BlobValue) Test(org.junit.Test)

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