Search in sources :

Example 21 with BooleanValue

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

the class OperationCheckerTest method whenCheckingPutOperationWithoutAnyClusteringKey_shouldThrowIllegalArgumentException.

@Test
public void whenCheckingPutOperationWithoutAnyClusteringKey_shouldThrowIllegalArgumentException() {
    // Arrange
    Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
    Key clusteringKey = null;
    List<Value<?>> values = Arrays.asList(new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true));
    MutationCondition condition = new PutIfNotExists();
    Put put = new Put(partitionKey, clusteringKey).withValues(values).withCondition(condition).forNamespace(NAMESPACE).forTable(TABLE_NAME);
    // Act Assert
    assertThatThrownBy(() -> operationChecker.check(put)).isInstanceOf(IllegalArgumentException.class);
}
Also used : PutIfNotExists(com.scalar.db.api.PutIfNotExists) DoubleValue(com.scalar.db.io.DoubleValue) MutationCondition(com.scalar.db.api.MutationCondition) 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) BooleanValue(com.scalar.db.io.BooleanValue) IntValue(com.scalar.db.io.IntValue) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put) Test(org.junit.jupiter.api.Test)

Example 22 with BooleanValue

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

the class OperationCheckerTest method whenCheckingPutOperationWithInvalidPutIfConditionWithIsNotNull_shouldThrowIllegalArgumentException.

@Test
public void whenCheckingPutOperationWithInvalidPutIfConditionWithIsNotNull_shouldThrowIllegalArgumentException() {
    // Arrange
    Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
    Key clusteringKey = new Key(CKEY1, 2, CKEY2, "val1");
    List<Value<?>> values = Arrays.asList(new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true));
    MutationCondition condition = ConditionBuilder.putIf(ConditionBuilder.buildConditionalExpression(IntColumn.of(COL1, 1), Operator.IS_NOT_NULL)).build();
    Put put = new Put(partitionKey, clusteringKey).withValues(values).withCondition(condition).forNamespace(NAMESPACE).forTable(TABLE_NAME);
    // Act Assert
    assertThatThrownBy(() -> operationChecker.check(put)).isInstanceOf(IllegalArgumentException.class);
}
Also used : DoubleValue(com.scalar.db.io.DoubleValue) MutationCondition(com.scalar.db.api.MutationCondition) 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) BooleanValue(com.scalar.db.io.BooleanValue) IntValue(com.scalar.db.io.IntValue) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put) Test(org.junit.jupiter.api.Test)

Example 23 with BooleanValue

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

the class PutTest method withXXXValue_ProperValuesGiven_ShouldReturnWhatsSet.

@Test
public void withXXXValue_ProperValuesGiven_ShouldReturnWhatsSet() {
    // Arrange
    Put put = preparePut();
    // Act
    put.withBooleanValue("val1", true).withIntValue("val2", 5678).withBigIntValue("val3", 1234L).withFloatValue("val4", 4.56f).withDoubleValue("val5", 1.23).withTextValue("val6", "string_value").withBlobValue("val7", "blob_value".getBytes(StandardCharsets.UTF_8)).withBlobValue("val8", ByteBuffer.wrap("blob_value2".getBytes(StandardCharsets.UTF_8))).withBooleanValue("val9", null).withIntValue("val10", null).withBigIntValue("val11", null).withFloatValue("val12", null).withDoubleValue("val13", null).withTextValue("val14", null).withBlobValue("val15", (ByteBuffer) null).withBlobValue("val16", (byte[]) null);
    // Assert
    Map<String, Value<?>> values = put.getValues();
    assertThat(values.size()).isEqualTo(16);
    assertThat(values.get("val1")).isEqualTo(new BooleanValue("val1", true));
    assertThat(values.get("val2")).isEqualTo(new IntValue("val2", 5678));
    assertThat(values.get("val3")).isEqualTo(new BigIntValue("val3", 1234L));
    assertThat(values.get("val4")).isEqualTo(new FloatValue("val4", 4.56f));
    assertThat(values.get("val5")).isEqualTo(new DoubleValue("val5", 1.23));
    assertThat(values.get("val6")).isEqualTo(new TextValue("val6", "string_value"));
    assertThat(values.get("val7")).isEqualTo(new BlobValue("val7", "blob_value".getBytes(StandardCharsets.UTF_8)));
    assertThat(values.get("val8")).isEqualTo(new BlobValue("val8", "blob_value2".getBytes(StandardCharsets.UTF_8)));
    assertThat(values).containsKey("val9");
    assertThat(values.get("val9")).isNull();
    assertThat(values).containsKey("val10");
    assertThat(values.get("val10")).isNull();
    assertThat(values).containsKey("val11");
    assertThat(values.get("val11")).isNull();
    assertThat(values).containsKey("val12");
    assertThat(values.get("val12")).isNull();
    assertThat(values).containsKey("val13");
    assertThat(values.get("val13")).isNull();
    assertThat(values).containsKey("val14");
    assertThat(values.get("val14")).isNull();
    assertThat(values).containsKey("val15");
    assertThat(values.get("val15")).isNull();
    assertThat(values).containsKey("val16");
    assertThat(values.get("val16")).isNull();
    Map<String, Column<?>> columns = put.getColumns();
    assertThat(columns.size()).isEqualTo(16);
    assertThat(columns.get("val1")).isEqualTo(BooleanColumn.of("val1", true));
    assertThat(columns.get("val2")).isEqualTo(IntColumn.of("val2", 5678));
    assertThat(columns.get("val3")).isEqualTo(BigIntColumn.of("val3", 1234L));
    assertThat(columns.get("val4")).isEqualTo(FloatColumn.of("val4", 4.56f));
    assertThat(columns.get("val5")).isEqualTo(DoubleColumn.of("val5", 1.23));
    assertThat(columns.get("val6")).isEqualTo(TextColumn.of("val6", "string_value"));
    assertThat(columns.get("val7")).isEqualTo(BlobColumn.of("val7", "blob_value".getBytes(StandardCharsets.UTF_8)));
    assertThat(columns.get("val8")).isEqualTo(BlobColumn.of("val8", "blob_value2".getBytes(StandardCharsets.UTF_8)));
    assertThat(columns.get("val9")).isEqualTo(BooleanColumn.ofNull("val9"));
    assertThat(columns.get("val10")).isEqualTo(IntColumn.ofNull("val10"));
    assertThat(columns.get("val11")).isEqualTo(BigIntColumn.ofNull("val11"));
    assertThat(columns.get("val12")).isEqualTo(FloatColumn.ofNull("val12"));
    assertThat(columns.get("val13")).isEqualTo(DoubleColumn.ofNull("val13"));
    assertThat(columns.get("val14")).isEqualTo(TextColumn.ofNull("val14"));
    assertThat(columns.get("val15")).isEqualTo(BlobColumn.ofNull("val15"));
    assertThat(columns.get("val16")).isEqualTo(BlobColumn.ofNull("val16"));
    assertThat(put.getContainedColumnNames()).isEqualTo(ImmutableSet.of("val1", "val2", "val3", "val4", "val5", "val6", "val7", "val8", "val9", "val10", "val11", "val12", "val13", "val14", "val15", "val16"));
    assertThat(put.containsColumn("val1")).isTrue();
    assertThat(put.isNullValue("val1")).isFalse();
    assertThat(put.getBooleanValue("val1")).isTrue();
    assertThat(put.getValueAsObject("val1")).isEqualTo(true);
    assertThat(put.containsColumn("val2")).isTrue();
    assertThat(put.isNullValue("val2")).isFalse();
    assertThat(put.getIntValue("val2")).isEqualTo(5678);
    assertThat(put.getValueAsObject("val2")).isEqualTo(5678);
    assertThat(put.containsColumn("val3")).isTrue();
    assertThat(put.isNullValue("val3")).isFalse();
    assertThat(put.getBigIntValue("val3")).isEqualTo(1234L);
    assertThat(put.getValueAsObject("val3")).isEqualTo(1234L);
    assertThat(put.containsColumn("val4")).isTrue();
    assertThat(put.isNullValue("val4")).isFalse();
    assertThat(put.getFloatValue("val4")).isEqualTo(4.56f);
    assertThat(put.getValueAsObject("val4")).isEqualTo(4.56f);
    assertThat(put.containsColumn("val5")).isTrue();
    assertThat(put.isNullValue("val5")).isFalse();
    assertThat(put.getDoubleValue("val5")).isEqualTo(1.23);
    assertThat(put.getValueAsObject("val5")).isEqualTo(1.23);
    assertThat(put.containsColumn("val6")).isTrue();
    assertThat(put.isNullValue("val6")).isFalse();
    assertThat(put.getTextValue("val6")).isEqualTo("string_value");
    assertThat(put.getValueAsObject("val6")).isEqualTo("string_value");
    assertThat(put.containsColumn("val7")).isTrue();
    assertThat(put.isNullValue("val7")).isFalse();
    assertThat(put.getBlobValue("val7")).isEqualTo(ByteBuffer.wrap("blob_value".getBytes(StandardCharsets.UTF_8)));
    assertThat(put.getBlobValueAsByteBuffer("val7")).isEqualTo(ByteBuffer.wrap("blob_value".getBytes(StandardCharsets.UTF_8)));
    assertThat(put.getBlobValueAsBytes("val7")).isEqualTo("blob_value".getBytes(StandardCharsets.UTF_8));
    assertThat(put.getValueAsObject("val7")).isEqualTo(ByteBuffer.wrap("blob_value".getBytes(StandardCharsets.UTF_8)));
    assertThat(put.containsColumn("val8")).isTrue();
    assertThat(put.isNullValue("val8")).isFalse();
    assertThat(put.getBlobValue("val8")).isEqualTo(ByteBuffer.wrap("blob_value2".getBytes(StandardCharsets.UTF_8)));
    assertThat(put.getBlobValueAsByteBuffer("val8")).isEqualTo(ByteBuffer.wrap("blob_value2".getBytes(StandardCharsets.UTF_8)));
    assertThat(put.getBlobValueAsBytes("val8")).isEqualTo("blob_value2".getBytes(StandardCharsets.UTF_8));
    assertThat(put.getValueAsObject("val8")).isEqualTo(ByteBuffer.wrap("blob_value2".getBytes(StandardCharsets.UTF_8)));
    assertThat(put.containsColumn("val9")).isTrue();
    assertThat(put.isNullValue("val9")).isTrue();
    assertThat(put.getBooleanValue("val9")).isFalse();
    assertThat(put.getValueAsObject("val9")).isNull();
    assertThat(put.containsColumn("val10")).isTrue();
    assertThat(put.isNullValue("val10")).isTrue();
    assertThat(put.getIntValue("val10")).isEqualTo(0);
    assertThat(put.getValueAsObject("val10")).isNull();
    assertThat(put.containsColumn("val11")).isTrue();
    assertThat(put.isNullValue("val11")).isTrue();
    assertThat(put.getBigIntValue("val11")).isEqualTo(0L);
    assertThat(put.getValueAsObject("val11")).isNull();
    assertThat(put.containsColumn("val12")).isTrue();
    assertThat(put.isNullValue("val12")).isTrue();
    assertThat(put.getFloatValue("val12")).isEqualTo(0.0F);
    assertThat(put.getValueAsObject("val12")).isNull();
    assertThat(put.containsColumn("val13")).isTrue();
    assertThat(put.isNullValue("val13")).isTrue();
    assertThat(put.getDoubleValue("val13")).isEqualTo(0.0);
    assertThat(put.getValueAsObject("val13")).isNull();
    assertThat(put.containsColumn("val14")).isTrue();
    assertThat(put.isNullValue("val14")).isTrue();
    assertThat(put.getTextValue("val14")).isNull();
    assertThat(put.getValueAsObject("val14")).isNull();
    assertThat(put.containsColumn("val15")).isTrue();
    assertThat(put.isNullValue("val15")).isTrue();
    assertThat(put.getBlobValue("val15")).isNull();
    assertThat(put.getValueAsObject("val15")).isNull();
    assertThat(put.containsColumn("val16")).isTrue();
    assertThat(put.isNullValue("val16")).isTrue();
    assertThat(put.getBlobValue("val16")).isNull();
    assertThat(put.getValueAsObject("val16")).isNull();
}
Also used : ByteBuffer(java.nio.ByteBuffer) BlobValue(com.scalar.db.io.BlobValue) DoubleValue(com.scalar.db.io.DoubleValue) IntColumn(com.scalar.db.io.IntColumn) BooleanColumn(com.scalar.db.io.BooleanColumn) TextColumn(com.scalar.db.io.TextColumn) DoubleColumn(com.scalar.db.io.DoubleColumn) BigIntColumn(com.scalar.db.io.BigIntColumn) FloatColumn(com.scalar.db.io.FloatColumn) Column(com.scalar.db.io.Column) BlobColumn(com.scalar.db.io.BlobColumn) 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) FloatValue(com.scalar.db.io.FloatValue) BigIntValue(com.scalar.db.io.BigIntValue) 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) Test(org.junit.jupiter.api.Test)

Example 24 with BooleanValue

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

the class ConditionalExpressionTest method constructor_ProperArgsGiven_ShouldConstructProperly.

@Test
public void constructor_ProperArgsGiven_ShouldConstructProperly() {
    // Arrange
    // Act
    ConditionalExpression expression1 = new ConditionalExpression("col1", new TextValue("aaa"), Operator.EQ);
    ConditionalExpression expression2 = new ConditionalExpression("col2", true, Operator.EQ);
    ConditionalExpression expression3 = new ConditionalExpression("col3", 123, Operator.NE);
    ConditionalExpression expression4 = new ConditionalExpression("col4", 456L, Operator.GT);
    ConditionalExpression expression5 = new ConditionalExpression("col5", 1.23F, Operator.GTE);
    ConditionalExpression expression6 = new ConditionalExpression("col6", 4.56D, Operator.LT);
    ConditionalExpression expression7 = new ConditionalExpression("col7", "text", Operator.LTE);
    ConditionalExpression expression8 = new ConditionalExpression("col8", "blob".getBytes(StandardCharsets.UTF_8), Operator.EQ);
    ConditionalExpression expression9 = new ConditionalExpression("col9", ByteBuffer.wrap("blob2".getBytes(StandardCharsets.UTF_8)), Operator.NE);
    // Assert
    assertThat(expression1.getName()).isEqualTo("col1");
    assertThat(expression1.getValue()).isEqualTo(new TextValue("aaa"));
    assertThat(expression1.getTextValue()).isEqualTo("aaa");
    assertThat(expression1.getValueAsObject()).isEqualTo("aaa");
    assertThat(expression1.getOperator()).isEqualTo(Operator.EQ);
    assertThat(expression2.getName()).isEqualTo("col2");
    assertThat(expression2.getValue()).isEqualTo(new BooleanValue(true));
    assertThat(expression2.getBooleanValue()).isTrue();
    assertThat(expression2.getValueAsObject()).isEqualTo(true);
    assertThat(expression2.getOperator()).isEqualTo(Operator.EQ);
    assertThat(expression3.getName()).isEqualTo("col3");
    assertThat(expression3.getValue()).isEqualTo(new IntValue(123));
    assertThat(expression3.getIntValue()).isEqualTo(123);
    assertThat(expression3.getValueAsObject()).isEqualTo(123);
    assertThat(expression3.getOperator()).isEqualTo(Operator.NE);
    assertThat(expression4.getName()).isEqualTo("col4");
    assertThat(expression4.getValue()).isEqualTo(new BigIntValue(456L));
    assertThat(expression4.getBigIntValue()).isEqualTo(456L);
    assertThat(expression4.getValueAsObject()).isEqualTo(456L);
    assertThat(expression4.getOperator()).isEqualTo(Operator.GT);
    assertThat(expression5.getName()).isEqualTo("col5");
    assertThat(expression5.getValue()).isEqualTo(new FloatValue(1.23F));
    assertThat(expression5.getFloatValue()).isEqualTo(1.23F);
    assertThat(expression5.getValueAsObject()).isEqualTo(1.23F);
    assertThat(expression5.getOperator()).isEqualTo(Operator.GTE);
    assertThat(expression6.getName()).isEqualTo("col6");
    assertThat(expression6.getValue()).isEqualTo(new DoubleValue(4.56D));
    assertThat(expression6.getDoubleValue()).isEqualTo(4.56D);
    assertThat(expression6.getValueAsObject()).isEqualTo(4.56D);
    assertThat(expression6.getOperator()).isEqualTo(Operator.LT);
    assertThat(expression7.getName()).isEqualTo("col7");
    assertThat(expression7.getValue()).isEqualTo(new TextValue("text"));
    assertThat(expression7.getTextValue()).isEqualTo("text");
    assertThat(expression7.getValueAsObject()).isEqualTo("text");
    assertThat(expression7.getOperator()).isEqualTo(Operator.LTE);
    assertThat(expression8.getName()).isEqualTo("col8");
    assertThat(expression8.getValue()).isEqualTo(new BlobValue("blob".getBytes(StandardCharsets.UTF_8)));
    assertThat(expression8.getBlobValue()).isEqualTo(ByteBuffer.wrap("blob".getBytes(StandardCharsets.UTF_8)));
    assertThat(expression8.getBlobValueAsByteBuffer()).isEqualTo(ByteBuffer.wrap("blob".getBytes(StandardCharsets.UTF_8)));
    assertThat(expression8.getBlobValueAsBytes()).isEqualTo("blob".getBytes(StandardCharsets.UTF_8));
    assertThat(expression8.getValueAsObject()).isEqualTo(ByteBuffer.wrap("blob".getBytes(StandardCharsets.UTF_8)));
    assertThat(expression8.getOperator()).isEqualTo(Operator.EQ);
    assertThat(expression9.getName()).isEqualTo("col9");
    assertThat(expression9.getValue()).isEqualTo(new BlobValue("blob2".getBytes(StandardCharsets.UTF_8)));
    assertThat(expression9.getBlobValue()).isEqualTo(ByteBuffer.wrap("blob2".getBytes(StandardCharsets.UTF_8)));
    assertThat(expression9.getBlobValueAsByteBuffer()).isEqualTo(ByteBuffer.wrap("blob2".getBytes(StandardCharsets.UTF_8)));
    assertThat(expression9.getBlobValueAsBytes()).isEqualTo("blob2".getBytes(StandardCharsets.UTF_8));
    assertThat(expression9.getValueAsObject()).isEqualTo(ByteBuffer.wrap("blob2".getBytes(StandardCharsets.UTF_8)));
    assertThat(expression9.getOperator()).isEqualTo(Operator.NE);
}
Also used : DoubleValue(com.scalar.db.io.DoubleValue) TextValue(com.scalar.db.io.TextValue) 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.jupiter.api.Test)

Example 25 with BooleanValue

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

the class DistributedStorageWithReservedKeywordIntegrationTestBase method put_WithReservedKeywordAndSinglePutGiven_ShouldStoreProperly.

@Test
public void put_WithReservedKeywordAndSinglePutGiven_ShouldStoreProperly() throws ExecutionException {
    // Arrange
    int pKey = 0;
    int cKey = 0;
    List<Put> puts = preparePuts();
    Key partitionKey = new Key(columnName1, pKey);
    Key clusteringKey = new Key(columnName4, cKey);
    Get get = new Get(partitionKey, clusteringKey);
    // Act
    storage.put(puts.get(pKey * 2 + cKey));
    // Assert
    Optional<Result> actual = storage.get(get);
    assertThat(actual.isPresent()).isTrue();
    assertThat(actual.get().getValue(columnName1)).isEqualTo(Optional.of(new IntValue(columnName1, pKey)));
    assertThat(actual.get().getValue(columnName2)).isEqualTo(Optional.of(new TextValue(columnName2, Integer.toString(pKey + cKey))));
    assertThat(actual.get().getValue(columnName3)).isEqualTo(Optional.of(new IntValue(columnName3, pKey + cKey)));
    assertThat(actual.get().getValue(columnName4)).isEqualTo(Optional.of(new IntValue(columnName4, cKey)));
    assertThat(actual.get().getValue(columnName5)).isEqualTo(Optional.of(new BooleanValue(columnName5, cKey % 2 == 0)));
}
Also used : TextValue(com.scalar.db.io.TextValue) BooleanValue(com.scalar.db.io.BooleanValue) IntValue(com.scalar.db.io.IntValue) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Aggregations

BooleanValue (com.scalar.db.io.BooleanValue)48 IntValue (com.scalar.db.io.IntValue)47 TextValue (com.scalar.db.io.TextValue)47 DoubleValue (com.scalar.db.io.DoubleValue)37 Key (com.scalar.db.io.Key)36 Test (org.junit.jupiter.api.Test)31 Put (com.scalar.db.api.Put)27 Value (com.scalar.db.io.Value)22 BigIntValue (com.scalar.db.io.BigIntValue)21 BlobValue (com.scalar.db.io.BlobValue)21 FloatValue (com.scalar.db.io.FloatValue)21 Test (org.junit.Test)16 MutationCondition (com.scalar.db.api.MutationCondition)12 Result (com.scalar.db.api.Result)11 Get (com.scalar.db.api.Get)10 PutIfNotExists (com.scalar.db.api.PutIfNotExists)4 ExpectedResult (com.scalar.db.util.TestUtils.ExpectedResult)4 PutIfExists (com.scalar.db.api.PutIfExists)3 BigIntColumn (com.scalar.db.io.BigIntColumn)2 BlobColumn (com.scalar.db.io.BlobColumn)2