Search in sources :

Example 66 with TextValue

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

the class PutTest method withValue_ProperValuesGiven_ShouldReturnWhatsSet.

@Test
public void withValue_ProperValuesGiven_ShouldReturnWhatsSet() {
    // Arrange
    Put put = preparePut();
    // Act
    put.withValue("val1", true).withValue("val2", 5678).withValue("val3", 1234L).withValue("val4", 4.56f).withValue("val5", 1.23).withValue("val6", "string_value").withValue("val7", "blob_value".getBytes(StandardCharsets.UTF_8)).withValue("val8", ByteBuffer.wrap("blob_value2".getBytes(StandardCharsets.UTF_8)));
    // Assert
    Map<String, Value<?>> values = put.getValues();
    assertThat(values.size()).isEqualTo(8);
    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)));
    Map<String, Column<?>> columns = put.getColumns();
    assertThat(columns.size()).isEqualTo(8);
    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(put.getContainedColumnNames()).isEqualTo(ImmutableSet.of("val1", "val2", "val3", "val4", "val5", "val6", "val7", "val8"));
    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)));
}
Also used : 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 67 with TextValue

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

the class ResultImplTest method getPartitionKey_RequiredValuesGiven_ShouldReturnPartitionKey.

@Test
public void getPartitionKey_RequiredValuesGiven_ShouldReturnPartitionKey() {
    // Arrange
    ResultImpl result = new ResultImpl(columns, TABLE_METADATA);
    // Act
    Optional<Key> key = result.getPartitionKey();
    // Assert
    assertThat(key.isPresent()).isTrue();
    assertThat(key.get().get().size()).isEqualTo(1);
    assertThat(key.get().get().get(0)).isEqualTo(new TextValue(ANY_NAME_1, ANY_TEXT_1));
}
Also used : TextValue(com.scalar.db.io.TextValue) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 68 with TextValue

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

the class ResultImplTest method getValues_TryToModifyReturned_ShouldThrowException.

@Test
public void getValues_TryToModifyReturned_ShouldThrowException() {
    // Arrange
    ResultImpl result = new ResultImpl(columns, TABLE_METADATA);
    Map<String, Value<?>> values = result.getValues();
    // Act Assert
    assertThatThrownBy(() -> values.put("new", new TextValue(ANY_NAME_1, ANY_TEXT_1))).isInstanceOf(UnsupportedOperationException.class);
}
Also used : 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) FloatValue(com.scalar.db.io.FloatValue) BigIntValue(com.scalar.db.io.BigIntValue) BlobValue(com.scalar.db.io.BlobValue) BooleanValue(com.scalar.db.io.BooleanValue) Test(org.junit.jupiter.api.Test)

Example 69 with TextValue

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

the class ResultImplTest method getValues_ProperValuesGivenInConstructor_ShouldReturnWhatsSet.

@Test
public void getValues_ProperValuesGivenInConstructor_ShouldReturnWhatsSet() {
    // Arrange
    ResultImpl result = new ResultImpl(columns, TABLE_METADATA);
    // Act
    Map<String, Value<?>> actual = result.getValues();
    // Assert
    assertThat(actual.get(ANY_NAME_1)).isEqualTo(new TextValue(ANY_NAME_1, ANY_TEXT_1));
    assertThat(actual.get(ANY_NAME_2)).isEqualTo(new TextValue(ANY_NAME_2, ANY_TEXT_2));
    assertThat(actual.get(ANY_COLUMN_NAME_1)).isEqualTo(new BooleanValue(ANY_COLUMN_NAME_1, true));
    assertThat(actual.get(ANY_COLUMN_NAME_7)).isEqualTo(new BlobValue(ANY_COLUMN_NAME_7, "bytes".getBytes(StandardCharsets.UTF_8)));
}
Also used : 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) BlobValue(com.scalar.db.io.BlobValue) Test(org.junit.jupiter.api.Test)

Example 70 with TextValue

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

the class StorageIntegrationTestBase method put_MultiplePutWithDifferentConditionsGiven_ShouldStoreProperly.

@Test
public void put_MultiplePutWithDifferentConditionsGiven_ShouldStoreProperly() throws IOException, ExecutionException {
    // Arrange
    List<Put> puts = preparePuts();
    storage.put(puts.get(1));
    puts.get(0).withCondition(new PutIfNotExists());
    puts.get(1).withCondition(new PutIf(new ConditionalExpression(COL_NAME2, new TextValue("1"), ConditionalExpression.Operator.EQ)));
    // Act
    assertThatCode(() -> storage.put(Arrays.asList(puts.get(0), puts.get(1)))).doesNotThrowAnyException();
    // Assert
    List<Result> results = scanAll(new Scan(new Key(COL_NAME1, 0)));
    assertThat(results.size()).isEqualTo(2);
    assertThat(results.get(0).getValue(COL_NAME1).isPresent()).isTrue();
    assertThat(results.get(0).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0);
    assertThat(results.get(0).getValue(COL_NAME4).isPresent()).isTrue();
    assertThat(results.get(0).getValue(COL_NAME4).get().getAsInt()).isEqualTo(0);
    assertThat(results.get(1).getValue(COL_NAME1).isPresent()).isTrue();
    assertThat(results.get(1).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0);
    assertThat(results.get(1).getValue(COL_NAME4).isPresent()).isTrue();
    assertThat(results.get(1).getValue(COL_NAME4).get().getAsInt()).isEqualTo(1);
}
Also used : PutIfNotExists(com.scalar.db.api.PutIfNotExists) PutIf(com.scalar.db.api.PutIf) TextValue(com.scalar.db.io.TextValue) ConditionalExpression(com.scalar.db.api.ConditionalExpression) Scan(com.scalar.db.api.Scan) Put(com.scalar.db.api.Put) Key(com.scalar.db.io.Key) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Aggregations

TextValue (com.scalar.db.io.TextValue)89 Key (com.scalar.db.io.Key)60 IntValue (com.scalar.db.io.IntValue)51 Test (org.junit.jupiter.api.Test)47 Test (org.junit.Test)38 BooleanValue (com.scalar.db.io.BooleanValue)36 Put (com.scalar.db.api.Put)27 BigIntValue (com.scalar.db.io.BigIntValue)27 DoubleValue (com.scalar.db.io.DoubleValue)26 BlobValue (com.scalar.db.io.BlobValue)25 FloatValue (com.scalar.db.io.FloatValue)24 Result (com.scalar.db.api.Result)23 ConditionalExpression (com.scalar.db.api.ConditionalExpression)21 Get (com.scalar.db.api.Get)17 Value (com.scalar.db.io.Value)15 DeleteIf (com.scalar.db.api.DeleteIf)11 Delete (com.scalar.db.api.Delete)8 ExpectedResult (com.scalar.db.util.TestUtils.ExpectedResult)8 PutIf (com.scalar.db.api.PutIf)6 PreparedStatement (java.sql.PreparedStatement)6