Search in sources :

Example 61 with Value

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

the class OperationCheckerTest method whenCheckingPutOperationWithClusteringKeyWithEmptyBlobValue_shouldThrowIllegalArgumentException.

@Test
public void whenCheckingPutOperationWithClusteringKeyWithEmptyBlobValue_shouldThrowIllegalArgumentException() throws ExecutionException {
    // Arrange
    when(metadataManager.getTableMetadata(any())).thenReturn(TableMetadata.newBuilder().addColumn(PKEY1, DataType.BLOB).addColumn(CKEY1, DataType.BLOB).addColumn(COL1, DataType.INT).addPartitionKey(PKEY1).addClusteringKey(CKEY1).build());
    operationChecker = new OperationChecker(metadataManager);
    Key partitionKey = new Key(PKEY1, new byte[] { 1, 1, 1 });
    Key clusteringKey = new Key(CKEY1, new byte[0]);
    List<Value<?>> values = Collections.singletonList(new IntValue(COL1, 1));
    Put put = new Put(partitionKey, clusteringKey).withValues(values).forNamespace(NAMESPACE).forTable(TABLE_NAME);
    // Act Assert
    assertThatThrownBy(() -> operationChecker.check(put)).isInstanceOf(IllegalArgumentException.class);
}
Also used : 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 62 with Value

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

the class ResultInterpreterTest method interpret_ShouldReturnWhatsSetWithNullValues.

@Test
public void interpret_ShouldReturnWhatsSetWithNullValues() {
    // Arrange
    when(row.getString(ANY_NAME_1)).thenReturn(ANY_TEXT_1);
    when(row.getString(ANY_NAME_2)).thenReturn(ANY_TEXT_2);
    when(row.isNull(ANY_COLUMN_NAME_1)).thenReturn(true);
    when(row.getBool(ANY_COLUMN_NAME_1)).thenReturn(false);
    when(row.isNull(ANY_COLUMN_NAME_2)).thenReturn(true);
    when(row.getInt(ANY_COLUMN_NAME_2)).thenReturn(0);
    when(row.isNull(ANY_COLUMN_NAME_3)).thenReturn(true);
    when(row.getLong(ANY_COLUMN_NAME_3)).thenReturn(0L);
    when(row.isNull(ANY_COLUMN_NAME_4)).thenReturn(true);
    when(row.getFloat(ANY_COLUMN_NAME_4)).thenReturn(0.0F);
    when(row.isNull(ANY_COLUMN_NAME_5)).thenReturn(true);
    when(row.getDouble(ANY_COLUMN_NAME_5)).thenReturn(0.0D);
    when(row.isNull(ANY_COLUMN_NAME_6)).thenReturn(true);
    when(row.getString(ANY_COLUMN_NAME_6)).thenReturn(null);
    when(row.isNull(ANY_COLUMN_NAME_7)).thenReturn(true);
    when(row.getBytes(ANY_COLUMN_NAME_7)).thenReturn(null);
    List<String> projections = Collections.emptyList();
    ResultInterpreter spy = spy(new ResultInterpreter(projections, TABLE_METADATA));
    // Act
    Result result = spy.interpret(row);
    // Assert
    assertThat(result.getValue(ANY_NAME_1).isPresent()).isTrue();
    assertThat(result.getValue(ANY_NAME_1).get().getAsString().isPresent()).isTrue();
    assertThat(result.getValue(ANY_NAME_1).get().getAsString().get()).isEqualTo(ANY_TEXT_1);
    assertThat(result.getValue(ANY_NAME_2).isPresent()).isTrue();
    assertThat(result.getValue(ANY_NAME_2).get().getAsString().isPresent()).isTrue();
    assertThat(result.getValue(ANY_NAME_2).get().getAsString().get()).isEqualTo(ANY_TEXT_2);
    assertThat(result.getValue(ANY_COLUMN_NAME_1).isPresent()).isTrue();
    assertThat(result.getValue(ANY_COLUMN_NAME_1).get().getAsBoolean()).isFalse();
    assertThat(result.getValue(ANY_COLUMN_NAME_2).isPresent()).isTrue();
    assertThat(result.getValue(ANY_COLUMN_NAME_2).get().getAsInt()).isEqualTo(0);
    assertThat(result.getValue(ANY_COLUMN_NAME_3).isPresent()).isTrue();
    assertThat(result.getValue(ANY_COLUMN_NAME_3).get().getAsLong()).isEqualTo(0L);
    assertThat(result.getValue(ANY_COLUMN_NAME_4).isPresent()).isTrue();
    assertThat(result.getValue(ANY_COLUMN_NAME_4).get().getAsFloat()).isEqualTo(0.0F);
    assertThat(result.getValue(ANY_COLUMN_NAME_5).isPresent()).isTrue();
    assertThat(result.getValue(ANY_COLUMN_NAME_5).get().getAsDouble()).isEqualTo(0.0D);
    assertThat(result.getValue(ANY_COLUMN_NAME_6).isPresent()).isTrue();
    assertThat(result.getValue(ANY_COLUMN_NAME_6).get().getAsString()).isNotPresent();
    assertThat(result.getValue(ANY_COLUMN_NAME_7).isPresent()).isTrue();
    assertThat(result.getValue(ANY_COLUMN_NAME_7).get().getAsBytes()).isNotPresent();
    Map<String, Value<?>> values = result.getValues();
    assertThat(values.containsKey(ANY_NAME_1)).isTrue();
    assertThat(values.get(ANY_NAME_1).getAsString().isPresent()).isTrue();
    assertThat(values.get(ANY_NAME_1).getAsString().get()).isEqualTo(ANY_TEXT_1);
    assertThat(values.containsKey(ANY_NAME_2)).isTrue();
    assertThat(values.get(ANY_NAME_2).getAsString().isPresent()).isTrue();
    assertThat(values.get(ANY_NAME_2).getAsString().get()).isEqualTo(ANY_TEXT_2);
    assertThat(values.containsKey(ANY_COLUMN_NAME_1)).isTrue();
    assertThat(values.get(ANY_COLUMN_NAME_1).getAsBoolean()).isFalse();
    assertThat(values.containsKey(ANY_COLUMN_NAME_2)).isTrue();
    assertThat(values.get(ANY_COLUMN_NAME_2).getAsInt()).isEqualTo(0);
    assertThat(values.containsKey(ANY_COLUMN_NAME_3)).isTrue();
    assertThat(values.get(ANY_COLUMN_NAME_3).getAsLong()).isEqualTo(0L);
    assertThat(values.containsKey(ANY_COLUMN_NAME_4)).isTrue();
    assertThat(values.get(ANY_COLUMN_NAME_4).getAsFloat()).isEqualTo(0.0F);
    assertThat(values.containsKey(ANY_COLUMN_NAME_5)).isTrue();
    assertThat(values.get(ANY_COLUMN_NAME_5).getAsDouble()).isEqualTo(0.0D);
    assertThat(values.containsKey(ANY_COLUMN_NAME_6)).isTrue();
    assertThat(values.get(ANY_COLUMN_NAME_6).getAsString()).isNotPresent();
    assertThat(values.containsKey(ANY_COLUMN_NAME_7)).isTrue();
    assertThat(values.get(ANY_COLUMN_NAME_7).getAsBytes()).isNotPresent();
    assertThat(result.isNull(ANY_NAME_1)).isFalse();
    assertThat(result.getText(ANY_NAME_1)).isEqualTo(ANY_TEXT_1);
    assertThat(result.isNull(ANY_NAME_2)).isFalse();
    assertThat(result.getText(ANY_NAME_2)).isEqualTo(ANY_TEXT_2);
    assertThat(result.isNull(ANY_COLUMN_NAME_1)).isTrue();
    assertThat(result.getBoolean(ANY_COLUMN_NAME_1)).isFalse();
    assertThat(result.isNull(ANY_COLUMN_NAME_2)).isTrue();
    assertThat(result.getInt(ANY_COLUMN_NAME_2)).isEqualTo(0);
    assertThat(result.isNull(ANY_COLUMN_NAME_3)).isTrue();
    assertThat(result.getBigInt(ANY_COLUMN_NAME_3)).isEqualTo(0L);
    assertThat(result.isNull(ANY_COLUMN_NAME_4)).isTrue();
    assertThat(result.getFloat(ANY_COLUMN_NAME_4)).isEqualTo(0.0F);
    assertThat(result.isNull(ANY_COLUMN_NAME_5)).isTrue();
    assertThat(result.getDouble(ANY_COLUMN_NAME_5)).isEqualTo(0.0D);
    assertThat(result.isNull(ANY_COLUMN_NAME_6)).isTrue();
    assertThat(result.getText(ANY_COLUMN_NAME_6)).isNull();
    assertThat(result.isNull(ANY_COLUMN_NAME_7)).isTrue();
    assertThat(result.getBlob(ANY_COLUMN_NAME_7)).isNull();
    assertThat(result.getBlobAsBytes(ANY_COLUMN_NAME_7)).isNull();
}
Also used : Value(com.scalar.db.io.Value) BigIntValue(com.scalar.db.io.BigIntValue) Result(com.scalar.db.api.Result) Test(org.junit.jupiter.api.Test)

Example 63 with Value

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

the class OperationCheckerTest method whenCheckingPutOperationWithAllValidArguments_shouldNotThrowAnyException.

@Test
public void whenCheckingPutOperationWithAllValidArguments_shouldNotThrowAnyException() {
    // 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 = new PutIfNotExists();
    Put put = new Put(partitionKey, clusteringKey).withValues(values).withCondition(condition).forNamespace(NAMESPACE).forTable(TABLE_NAME);
    // Act Assert
    assertThatCode(() -> operationChecker.check(put)).doesNotThrowAnyException();
}
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 64 with Value

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

the class OperationCheckerTest method whenCheckingPutOperationWithInvalidPutIfConditionWithIsNull_shouldThrowIllegalArgumentException.

@Test
public void whenCheckingPutOperationWithInvalidPutIfConditionWithIsNull_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_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 65 with Value

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

the class OperationCheckerTest method whenCheckingPutOperationWithDeleteIfCondition_shouldThrowIllegalArgumentException.

@Test
public void whenCheckingPutOperationWithDeleteIfCondition_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 = new DeleteIf();
    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) DeleteIf(com.scalar.db.api.DeleteIf) Put(com.scalar.db.api.Put) Test(org.junit.jupiter.api.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