use of com.scalar.db.io.Value in project scalardb by scalar-labs.
the class StorageMultipleClusteringKeyScanIntegrationTestBase method prepareRecords.
private List<ClusteringKey> prepareRecords(DataType firstClusteringKeyType, Order firstClusteringOrder, DataType secondClusteringKeyType, Order secondClusteringOrder) throws ExecutionException {
RANDOM.setSeed(seed);
List<ClusteringKey> ret = new ArrayList<>();
List<Put> puts = new ArrayList<>();
if (firstClusteringKeyType == DataType.BOOLEAN) {
TestUtils.booleanValues(FIRST_CLUSTERING_KEY).forEach(firstClusteringKeyValue -> prepareRecords(firstClusteringKeyType, firstClusteringOrder, firstClusteringKeyValue, secondClusteringKeyType, secondClusteringOrder, puts, ret));
} else {
Set<Value<?>> valueSet = new HashSet<>();
// Add min and max first clustering key values
Arrays.asList(getMinValue(FIRST_CLUSTERING_KEY, firstClusteringKeyType), getMaxValue(FIRST_CLUSTERING_KEY, firstClusteringKeyType)).forEach(firstClusteringKeyValue -> {
valueSet.add(firstClusteringKeyValue);
prepareRecords(firstClusteringKeyType, firstClusteringOrder, firstClusteringKeyValue, secondClusteringKeyType, secondClusteringOrder, puts, ret);
});
IntStream.range(0, FIRST_CLUSTERING_KEY_NUM - 2).forEach(i -> {
Value<?> firstClusteringKeyValue;
while (true) {
firstClusteringKeyValue = getFirstClusteringKeyValue(firstClusteringKeyType);
// reject duplication
if (!valueSet.contains(firstClusteringKeyValue)) {
valueSet.add(firstClusteringKeyValue);
break;
}
}
prepareRecords(firstClusteringKeyType, firstClusteringOrder, firstClusteringKeyValue, secondClusteringKeyType, secondClusteringOrder, puts, ret);
});
}
try {
List<Put> buffer = new ArrayList<>();
for (Put put : puts) {
buffer.add(put);
if (buffer.size() == 20) {
storage.mutate(buffer);
buffer.clear();
}
}
if (!buffer.isEmpty()) {
storage.mutate(buffer);
}
} catch (ExecutionException e) {
throw new ExecutionException("put data to database failed", e);
}
ret.sort(getClusteringKeyComparator(firstClusteringOrder, secondClusteringOrder));
return ret;
}
use of com.scalar.db.io.Value in project scalardb by scalar-labs.
the class StorageSingleClusteringKeyScanIntegrationTestBase method scan_WithClusteringKeyEndRange_ShouldReturnProperResult.
private void scan_WithClusteringKeyEndRange_ShouldReturnProperResult(List<Value<?>> clusteringKeyValues, DataType clusteringKeyType, Order clusteringOrder, boolean endInclusive, OrderingType orderingType, boolean withLimit) throws ExecutionException, IOException {
// Arrange
Value<?> endClusteringKeyValue;
if (clusteringKeyType == DataType.BOOLEAN) {
endClusteringKeyValue = clusteringKeyValues.get(1);
} else {
endClusteringKeyValue = clusteringKeyValues.get(14);
}
List<Value<?>> expected = getExpected(clusteringKeyValues, null, null, endClusteringKeyValue, endInclusive, orderingType);
int limit = getLimit(withLimit, expected);
if (limit > 0) {
expected = expected.subList(0, limit);
}
Scan scan = getScan(clusteringKeyType, clusteringOrder, null, null, endClusteringKeyValue, endInclusive, orderingType, limit);
// Act
List<Result> actual = scanAll(scan);
// Assert
assertScanResult(actual, expected, description(clusteringKeyType, clusteringOrder, null, endInclusive, orderingType, withLimit));
}
use of com.scalar.db.io.Value in project scalardb by scalar-labs.
the class StorageSingleClusteringKeyScanIntegrationTestBase method scan_WithClusteringKeyRangeWithMinAndMaxValue_ShouldReturnProperResult.
private void scan_WithClusteringKeyRangeWithMinAndMaxValue_ShouldReturnProperResult(List<Value<?>> clusteringKeyValues, DataType clusteringKeyType, Order clusteringOrder, boolean startInclusive, boolean endInclusive, OrderingType orderingType, boolean withLimit) throws ExecutionException, IOException {
// Arrange
Value<?> startClusteringKeyValue = getMinValue(CLUSTERING_KEY, clusteringKeyType);
Value<?> endClusteringKeyValue = getMaxValue(CLUSTERING_KEY, clusteringKeyType);
List<Value<?>> expected = getExpected(clusteringKeyValues, startClusteringKeyValue, startInclusive, endClusteringKeyValue, endInclusive, orderingType);
int limit = getLimit(withLimit, expected);
if (limit > 0) {
expected = expected.subList(0, limit);
}
Scan scan = getScan(clusteringKeyType, clusteringOrder, startClusteringKeyValue, startInclusive, endClusteringKeyValue, endInclusive, orderingType, limit);
// Act
List<Result> actual = scanAll(scan);
// Assert
assertScanResult(actual, expected, description(clusteringKeyType, clusteringOrder, startInclusive, endInclusive, orderingType, withLimit));
}
use of com.scalar.db.io.Value in project scalardb by scalar-labs.
the class StorageSingleClusteringKeyScanIntegrationTestBase method scan_WithClusteringKeyRange_ShouldReturnProperResult.
@Test
public void scan_WithClusteringKeyRange_ShouldReturnProperResult() throws ExecutionException, IOException {
for (DataType clusteringKeyType : clusteringKeyTypes) {
for (Order clusteringOrder : Order.values()) {
truncateTable(clusteringKeyType, clusteringOrder);
List<Value<?>> clusteringKeyValues = prepareRecords(clusteringKeyType, clusteringOrder);
for (boolean startInclusive : Arrays.asList(true, false)) {
for (boolean endInclusive : Arrays.asList(true, false)) {
for (OrderingType orderingType : OrderingType.values()) {
for (boolean withLimit : Arrays.asList(false, true)) {
scan_WithClusteringKeyRange_ShouldReturnProperResult(clusteringKeyValues, clusteringKeyType, clusteringOrder, startInclusive, endInclusive, orderingType, withLimit);
}
}
}
}
}
}
}
use of com.scalar.db.io.Value in project scalardb by scalar-labs.
the class StorageSingleClusteringKeyScanIntegrationTestBase method scan_WithClusteringKeyRangeWithSameValues_ShouldReturnProperResult.
private void scan_WithClusteringKeyRangeWithSameValues_ShouldReturnProperResult(List<Value<?>> clusteringKeyValues, DataType clusteringKeyType, Order clusteringOrder, boolean startInclusive, boolean endInclusive, OrderingType orderingType, boolean withLimit) throws ExecutionException, IOException {
// Arrange
Value<?> startAndEndClusteringKeyValue;
if (clusteringKeyType == DataType.BOOLEAN) {
startAndEndClusteringKeyValue = clusteringKeyValues.get(0);
} else {
startAndEndClusteringKeyValue = clusteringKeyValues.get(9);
}
List<Value<?>> expected = getExpected(clusteringKeyValues, startAndEndClusteringKeyValue, startInclusive, startAndEndClusteringKeyValue, endInclusive, orderingType);
int limit = getLimit(withLimit, expected);
if (limit > 0) {
expected = expected.subList(0, limit);
}
Scan scan = getScan(clusteringKeyType, clusteringOrder, startAndEndClusteringKeyValue, startInclusive, startAndEndClusteringKeyValue, endInclusive, orderingType, limit);
// Act
List<Result> actual = scanAll(scan);
// Assert
assertScanResult(actual, expected, description(clusteringKeyType, clusteringOrder, startInclusive, endInclusive, orderingType, withLimit));
}
Aggregations