use of com.scalar.db.io.TextValue in project scalardb by scalar-labs.
the class StorageWithReservedKeywordIntegrationTestBase method get_GetWithReservedKeywordAndProjectionsGiven_ShouldRetrieveSpecifiedValues.
@Test
public void get_GetWithReservedKeywordAndProjectionsGiven_ShouldRetrieveSpecifiedValues() throws ExecutionException {
// Arrange
populateRecords();
int pKey = 0;
int cKey = 0;
// Act
Get get = prepareGet(pKey, cKey);
get.withProjection(columnName1).withProjection(columnName2).withProjection(columnName3);
Optional<Result> actual = storage.get(get);
// Assert
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).isPresent()).isTrue();
assertThat(actual.get().getValue(columnName5).isPresent()).isFalse();
}
use of com.scalar.db.io.TextValue in project scalardb by scalar-labs.
the class StorageWithReservedKeywordIntegrationTestBase method put_WithReservedKeywordAndMultiplePutWithDifferentConditionsGiven_ShouldStoreProperly.
@Test
public void put_WithReservedKeywordAndMultiplePutWithDifferentConditionsGiven_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(columnName2, 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(columnName1, 0)));
assertThat(results.size()).isEqualTo(2);
assertThat(results.get(0).getValue(columnName1).isPresent()).isTrue();
assertThat(results.get(0).getValue(columnName1).get().getAsInt()).isEqualTo(0);
assertThat(results.get(0).getValue(columnName4).isPresent()).isTrue();
assertThat(results.get(0).getValue(columnName4).get().getAsInt()).isEqualTo(0);
assertThat(results.get(1).getValue(columnName1).isPresent()).isTrue();
assertThat(results.get(1).getValue(columnName1).get().getAsInt()).isEqualTo(0);
assertThat(results.get(1).getValue(columnName4).isPresent()).isTrue();
assertThat(results.get(1).getValue(columnName4).get().getAsInt()).isEqualTo(1);
}
use of com.scalar.db.io.TextValue in project scalardb by scalar-labs.
the class StorageWithReservedKeywordIntegrationTestBase method delete_WithReservedKeywordAndDeleteWithIfGivenWhenSuchRecordExists_ShouldDeleteProperly.
@Test
public void delete_WithReservedKeywordAndDeleteWithIfGivenWhenSuchRecordExists_ShouldDeleteProperly() throws ExecutionException {
// Arrange
populateRecords();
int pKey = 0;
int cKey = 0;
Key partitionKey = new Key(columnName1, pKey);
Key clusteringKey = new Key(columnName4, cKey);
// Act
Delete delete = prepareDelete(pKey, cKey);
delete.withCondition(new DeleteIf(new ConditionalExpression(columnName2, new TextValue(Integer.toString(pKey)), ConditionalExpression.Operator.EQ)));
assertThatCode(() -> storage.delete(delete)).doesNotThrowAnyException();
// Assert
Optional<Result> actual = storage.get(new Get(partitionKey, clusteringKey));
assertThat(actual.isPresent()).isFalse();
}
use of com.scalar.db.io.TextValue in project scalardb by scalar-labs.
the class PutTest method getNullableValues_TryToModifyReturned_ShouldThrowException.
@Test
public void getNullableValues_TryToModifyReturned_ShouldThrowException() {
// Arrange
Put put = preparePut();
TextValue value1 = new TextValue(ANY_NAME_1, ANY_TEXT_1);
TextValue value2 = new TextValue(ANY_NAME_2, ANY_TEXT_2);
put.withValue(value1).withValue(value2);
// Act Assert
Map<String, Optional<Value<?>>> values = put.getNullableValues();
assertThatThrownBy(() -> values.put(ANY_NAME_3, Optional.of(new TextValue(ANY_NAME_3, ANY_TEXT_3)))).isInstanceOf(UnsupportedOperationException.class);
}
use of com.scalar.db.io.TextValue in project scalardb by scalar-labs.
the class ConditionExpressionTest 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.getColumnName()).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.getColumnName()).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.getColumnName()).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.getColumnName()).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.getColumnName()).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.getColumnName()).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.getColumnName()).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.getColumnName()).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.getColumnName()).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);
}
Aggregations