use of com.scalar.db.io.BooleanValue in project scalardb by scalar-labs.
the class StorageColumnValueIntegrationTestBase method put_WithRandomValues_ShouldPutCorrectly.
@Test
public void put_WithRandomValues_ShouldPutCorrectly() throws ExecutionException {
RANDOM.setSeed(seed);
for (int i = 0; i < ATTEMPT_COUNT; i++) {
// Arrange
IntValue partitionKeyValue = (IntValue) getRandomValue(RANDOM, PARTITION_KEY, DataType.INT);
BooleanValue col1Value = (BooleanValue) getRandomValue(RANDOM, COL_NAME1, DataType.BOOLEAN);
IntValue col2Value = (IntValue) getRandomValue(RANDOM, COL_NAME2, DataType.INT);
BigIntValue col3Value = (BigIntValue) getRandomValue(RANDOM, COL_NAME3, DataType.BIGINT);
FloatValue col4Value = (FloatValue) getRandomValue(RANDOM, COL_NAME4, DataType.FLOAT);
DoubleValue col5Value = (DoubleValue) getRandomValue(RANDOM, COL_NAME5, DataType.DOUBLE);
TextValue col6Value = (TextValue) getRandomValue(RANDOM, COL_NAME6, DataType.TEXT);
BlobValue col7Value = (BlobValue) getRandomValue(RANDOM, COL_NAME7, DataType.BLOB);
Put put = new Put(new Key(partitionKeyValue)).withValue(col1Value).withValue(col2Value).withValue(col3Value).withValue(col4Value).withValue(col5Value).withValue(col6Value).withValue(col7Value).forNamespace(namespace).forTable(TABLE);
// Act
storage.put(put);
// Assert
Optional<Result> actual = storage.get(new Get(new Key(partitionKeyValue)).forNamespace(namespace).forTable(TABLE));
assertThat(actual).isPresent();
assertThat(actual.get().getValue(PARTITION_KEY).isPresent()).isTrue();
assertThat(actual.get().getValue(PARTITION_KEY).get()).isEqualTo(partitionKeyValue);
assertThat(actual.get().getValue(COL_NAME1).isPresent()).isTrue();
assertThat(actual.get().getValue(COL_NAME1).get()).isEqualTo(col1Value);
assertThat(actual.get().getValue(COL_NAME2).isPresent()).isTrue();
assertThat(actual.get().getValue(COL_NAME2).get()).isEqualTo(col2Value);
assertThat(actual.get().getValue(COL_NAME3).isPresent()).isTrue();
assertThat(actual.get().getValue(COL_NAME3).get()).isEqualTo(col3Value);
assertThat(actual.get().getValue(COL_NAME4).isPresent()).isTrue();
assertThat(actual.get().getValue(COL_NAME4).get()).isEqualTo(col4Value);
assertThat(actual.get().getValue(COL_NAME5).isPresent()).isTrue();
assertThat(actual.get().getValue(COL_NAME5).get()).isEqualTo(col5Value);
assertThat(actual.get().getValue(COL_NAME6).isPresent()).isTrue();
assertThat(actual.get().getValue(COL_NAME6).get()).isEqualTo(col6Value);
assertThat(actual.get().getValue(COL_NAME7).isPresent()).isTrue();
assertThat(actual.get().getValue(COL_NAME7).get()).isEqualTo(col7Value);
assertThat(actual.get().getContainedColumnNames()).isEqualTo(new HashSet<>(Arrays.asList(PARTITION_KEY, COL_NAME1, COL_NAME2, COL_NAME3, COL_NAME4, COL_NAME5, COL_NAME6, COL_NAME7)));
assertThat(actual.get().contains(PARTITION_KEY)).isTrue();
assertThat(actual.get().isNull(PARTITION_KEY)).isFalse();
assertThat(actual.get().getInt(PARTITION_KEY)).isEqualTo(partitionKeyValue.get());
assertThat(actual.get().getAsObject(PARTITION_KEY)).isEqualTo(partitionKeyValue.get());
assertThat(actual.get().contains(COL_NAME1)).isTrue();
assertThat(actual.get().isNull(COL_NAME1)).isFalse();
assertThat(actual.get().getBoolean(COL_NAME1)).isEqualTo(col1Value.get());
assertThat(actual.get().getAsObject(COL_NAME1)).isEqualTo(col1Value.get());
assertThat(actual.get().contains(COL_NAME2)).isTrue();
assertThat(actual.get().isNull(COL_NAME2)).isFalse();
assertThat(actual.get().getInt(COL_NAME2)).isEqualTo(col2Value.get());
assertThat(actual.get().getAsObject(COL_NAME2)).isEqualTo(col2Value.get());
assertThat(actual.get().contains(COL_NAME3)).isTrue();
assertThat(actual.get().isNull(COL_NAME3)).isFalse();
assertThat(actual.get().getBigInt(COL_NAME3)).isEqualTo(col3Value.get());
assertThat(actual.get().getAsObject(COL_NAME3)).isEqualTo(col3Value.get());
assertThat(actual.get().contains(COL_NAME4)).isTrue();
assertThat(actual.get().isNull(COL_NAME4)).isFalse();
assertThat(actual.get().getFloat(COL_NAME4)).isEqualTo(col4Value.get());
assertThat(actual.get().getAsObject(COL_NAME4)).isEqualTo(col4Value.get());
assertThat(actual.get().contains(COL_NAME5)).isTrue();
assertThat(actual.get().isNull(COL_NAME5)).isFalse();
assertThat(actual.get().getDouble(COL_NAME5)).isEqualTo(col5Value.get());
assertThat(actual.get().getAsObject(COL_NAME5)).isEqualTo(col5Value.get());
assertThat(actual.get().contains(COL_NAME6)).isTrue();
assertThat(actual.get().isNull(COL_NAME6)).isFalse();
assertThat(actual.get().getText(COL_NAME6)).isEqualTo(col6Value.get().get());
assertThat(actual.get().getAsObject(COL_NAME6)).isEqualTo(col6Value.get().get());
assertThat(actual.get().contains(COL_NAME7)).isTrue();
assertThat(actual.get().isNull(COL_NAME7)).isFalse();
assertThat(actual.get().getBlob(COL_NAME7)).isEqualTo(ByteBuffer.wrap(col7Value.get().get()));
assertThat(actual.get().getBlobAsByteBuffer(COL_NAME7)).isEqualTo(ByteBuffer.wrap(col7Value.get().get()));
assertThat(actual.get().getBlobAsBytes(COL_NAME7)).isEqualTo(col7Value.get().get());
assertThat(actual.get().getAsObject(COL_NAME7)).isEqualTo(ByteBuffer.wrap(col7Value.get().get()));
}
}
use of com.scalar.db.io.BooleanValue in project scalardb by scalar-labs.
the class ResultImplTest method getValues_ProperValuesGivenInConstructor_ShouldReturnWhatsSet.
@Test
public void getValues_ProperValuesGivenInConstructor_ShouldReturnWhatsSet() {
// Arrange
ResultImpl result = new ResultImpl(values, 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)));
}
use of com.scalar.db.io.BooleanValue in project scalardb by scalar-labs.
the class StorageWithReservedKeywordIntegrationTestBase 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)));
}
use of com.scalar.db.io.BooleanValue in project scalardb by scalar-labs.
the class ResultInterpreter method getValue.
@Nullable
private Value<?> getValue(String name, ResultSet resultSet) throws SQLException {
Value<?> ret;
DataType dataType = metadata.getColumnDataType(name);
switch(dataType) {
case BOOLEAN:
ret = new BooleanValue(name, resultSet.getBoolean(name));
break;
case INT:
ret = new IntValue(name, resultSet.getInt(name));
break;
case BIGINT:
ret = new BigIntValue(name, resultSet.getLong(name));
break;
case FLOAT:
// To handle Float.MAX_VALUE in MySQL, we need to get the value as double, then cast it to
// float
ret = new FloatValue(name, (float) resultSet.getDouble(name));
break;
case DOUBLE:
ret = new DoubleValue(name, resultSet.getDouble(name));
break;
case TEXT:
ret = new TextValue(name, resultSet.getString(name));
break;
case BLOB:
ret = new BlobValue(name, resultSet.getBytes(name));
break;
default:
throw new AssertionError();
}
if (resultSet.wasNull()) {
return null;
}
return ret;
}
use of com.scalar.db.io.BooleanValue in project scalardb by scalar-labs.
the class DistributedStorageColumnValueIntegrationTestBase method put_WithRandomValues_ShouldPutCorrectly.
@Test
public void put_WithRandomValues_ShouldPutCorrectly() throws ExecutionException {
RANDOM.setSeed(seed);
for (int i = 0; i < ATTEMPT_COUNT; i++) {
// Arrange
IntValue partitionKeyValue = (IntValue) getRandomValue(RANDOM, PARTITION_KEY, DataType.INT);
BooleanValue col1Value = (BooleanValue) getRandomValue(RANDOM, COL_NAME1, DataType.BOOLEAN);
IntValue col2Value = (IntValue) getRandomValue(RANDOM, COL_NAME2, DataType.INT);
BigIntValue col3Value = (BigIntValue) getRandomValue(RANDOM, COL_NAME3, DataType.BIGINT);
FloatValue col4Value = (FloatValue) getRandomValue(RANDOM, COL_NAME4, DataType.FLOAT);
DoubleValue col5Value = (DoubleValue) getRandomValue(RANDOM, COL_NAME5, DataType.DOUBLE);
TextValue col6Value = (TextValue) getRandomValue(RANDOM, COL_NAME6, DataType.TEXT);
BlobValue col7Value = (BlobValue) getRandomValue(RANDOM, COL_NAME7, DataType.BLOB);
Put put = new Put(new Key(partitionKeyValue)).withValue(col1Value).withValue(col2Value).withValue(col3Value).withValue(col4Value).withValue(col5Value).withValue(col6Value).withValue(col7Value).forNamespace(namespace).forTable(TABLE);
// Act
storage.put(put);
// Assert
Optional<Result> actual = storage.get(new Get(new Key(partitionKeyValue)).forNamespace(namespace).forTable(TABLE));
assertThat(actual).isPresent();
assertThat(actual.get().getValue(PARTITION_KEY).isPresent()).isTrue();
assertThat(actual.get().getValue(PARTITION_KEY).get()).isEqualTo(partitionKeyValue);
assertThat(actual.get().getValue(COL_NAME1).isPresent()).isTrue();
assertThat(actual.get().getValue(COL_NAME1).get()).isEqualTo(col1Value);
assertThat(actual.get().getValue(COL_NAME2).isPresent()).isTrue();
assertThat(actual.get().getValue(COL_NAME2).get()).isEqualTo(col2Value);
assertThat(actual.get().getValue(COL_NAME3).isPresent()).isTrue();
assertThat(actual.get().getValue(COL_NAME3).get()).isEqualTo(col3Value);
assertThat(actual.get().getValue(COL_NAME4).isPresent()).isTrue();
assertThat(actual.get().getValue(COL_NAME4).get()).isEqualTo(col4Value);
assertThat(actual.get().getValue(COL_NAME5).isPresent()).isTrue();
assertThat(actual.get().getValue(COL_NAME5).get()).isEqualTo(col5Value);
assertThat(actual.get().getValue(COL_NAME6).isPresent()).isTrue();
assertThat(actual.get().getValue(COL_NAME6).get()).isEqualTo(col6Value);
assertThat(actual.get().getValue(COL_NAME7).isPresent()).isTrue();
assertThat(actual.get().getValue(COL_NAME7).get()).isEqualTo(col7Value);
assertThat(actual.get().getContainedColumnNames()).isEqualTo(new HashSet<>(Arrays.asList(PARTITION_KEY, COL_NAME1, COL_NAME2, COL_NAME3, COL_NAME4, COL_NAME5, COL_NAME6, COL_NAME7)));
assertThat(actual.get().contains(PARTITION_KEY)).isTrue();
assertThat(actual.get().isNull(PARTITION_KEY)).isFalse();
assertThat(actual.get().getInt(PARTITION_KEY)).isEqualTo(partitionKeyValue.get());
assertThat(actual.get().getAsObject(PARTITION_KEY)).isEqualTo(partitionKeyValue.get());
assertThat(actual.get().contains(COL_NAME1)).isTrue();
assertThat(actual.get().isNull(COL_NAME1)).isFalse();
assertThat(actual.get().getBoolean(COL_NAME1)).isEqualTo(col1Value.get());
assertThat(actual.get().getAsObject(COL_NAME1)).isEqualTo(col1Value.get());
assertThat(actual.get().contains(COL_NAME2)).isTrue();
assertThat(actual.get().isNull(COL_NAME2)).isFalse();
assertThat(actual.get().getInt(COL_NAME2)).isEqualTo(col2Value.get());
assertThat(actual.get().getAsObject(COL_NAME2)).isEqualTo(col2Value.get());
assertThat(actual.get().contains(COL_NAME3)).isTrue();
assertThat(actual.get().isNull(COL_NAME3)).isFalse();
assertThat(actual.get().getBigInt(COL_NAME3)).isEqualTo(col3Value.get());
assertThat(actual.get().getAsObject(COL_NAME3)).isEqualTo(col3Value.get());
assertThat(actual.get().contains(COL_NAME4)).isTrue();
assertThat(actual.get().isNull(COL_NAME4)).isFalse();
assertThat(actual.get().getFloat(COL_NAME4)).isEqualTo(col4Value.get());
assertThat(actual.get().getAsObject(COL_NAME4)).isEqualTo(col4Value.get());
assertThat(actual.get().contains(COL_NAME5)).isTrue();
assertThat(actual.get().isNull(COL_NAME5)).isFalse();
assertThat(actual.get().getDouble(COL_NAME5)).isEqualTo(col5Value.get());
assertThat(actual.get().getAsObject(COL_NAME5)).isEqualTo(col5Value.get());
assertThat(actual.get().contains(COL_NAME6)).isTrue();
assertThat(actual.get().isNull(COL_NAME6)).isFalse();
assertThat(actual.get().getText(COL_NAME6)).isEqualTo(col6Value.get().get());
assertThat(actual.get().getAsObject(COL_NAME6)).isEqualTo(col6Value.get().get());
assertThat(actual.get().contains(COL_NAME7)).isTrue();
assertThat(actual.get().isNull(COL_NAME7)).isFalse();
assertThat(actual.get().getBlob(COL_NAME7)).isEqualTo(ByteBuffer.wrap(col7Value.get().get()));
assertThat(actual.get().getBlobAsByteBuffer(COL_NAME7)).isEqualTo(ByteBuffer.wrap(col7Value.get().get()));
assertThat(actual.get().getBlobAsBytes(COL_NAME7)).isEqualTo(col7Value.get().get());
assertThat(actual.get().getAsObject(COL_NAME7)).isEqualTo(ByteBuffer.wrap(col7Value.get().get()));
}
}
Aggregations