use of com.scalar.db.api.Scan in project scalardb by scalar-labs.
the class SelectStatementHandlerTest method handle_ScanOperationWithMultipleReversedOrderingsAndLimit_ShouldCallQueryItemsWithProperQuery.
@Test
public void handle_ScanOperationWithMultipleReversedOrderingsAndLimit_ShouldCallQueryItemsWithProperQuery() {
// Arrange
when(metadata.getClusteringKeyNames()).thenReturn(new LinkedHashSet<>(Arrays.asList(ANY_NAME_2, ANY_NAME_3)));
when(metadata.getClusteringOrder(ANY_NAME_3)).thenReturn(Order.DESC);
when(container.queryItems(anyString(), any(CosmosQueryRequestOptions.class), eq(Record.class))).thenReturn(responseIterable);
Record expected = new Record();
when(responseIterable.iterator()).thenReturn(Collections.singletonList(expected).iterator());
Scan scan = prepareScan().withStart(new Key(ANY_NAME_2, ANY_TEXT_2)).withOrdering(new Scan.Ordering(ANY_NAME_2, Order.DESC)).withOrdering(new Scan.Ordering(ANY_NAME_3, Order.ASC)).withLimit(ANY_LIMIT);
String query = "select * from Record r where (r.concatenatedPartitionKey = '" + ANY_TEXT_1 + "' and r.clusteringKey[\"" + ANY_NAME_2 + "\"] >= '" + ANY_TEXT_2 + "') order by r.concatenatedPartitionKey desc, r.clusteringKey[\"" + ANY_NAME_2 + "\"] desc, r.clusteringKey[\"" + ANY_NAME_3 + "\"] asc offset 0 limit " + ANY_LIMIT;
// Act Assert
assertThatCode(() -> handler.handle(scan)).doesNotThrowAnyException();
// Assert
verify(container).queryItems(eq(query), any(CosmosQueryRequestOptions.class), eq(Record.class));
}
use of com.scalar.db.api.Scan in project scalardb by scalar-labs.
the class SelectStatementHandlerTest method handle_ScanOperationWithIndexGiven_ShouldCallQueryItems.
@Test
public void handle_ScanOperationWithIndexGiven_ShouldCallQueryItems() {
// Arrange
when(container.queryItems(anyString(), any(CosmosQueryRequestOptions.class), eq(Record.class))).thenReturn(responseIterable);
Record expected = new Record();
when(responseIterable.iterator()).thenReturn(Collections.singletonList(expected).iterator());
Key indexKey = new Key(ANY_NAME_3, ANY_TEXT_3);
Scan scan = new Scan(indexKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME);
String query = "select * from Record r where r.values[\"" + ANY_NAME_3 + "\"]" + " = '" + ANY_TEXT_3 + "'";
// Act Assert
assertThatCode(() -> handler.handle(scan)).doesNotThrowAnyException();
// Assert
verify(container).queryItems(eq(query), any(CosmosQueryRequestOptions.class), eq(Record.class));
}
use of com.scalar.db.api.Scan in project scalardb by scalar-labs.
the class SelectStatementHandlerTest method handle_ScanOperationWithMultipleClusteringKeys_ShouldCallQueryItemsWithProperQuery.
@Test
public void handle_ScanOperationWithMultipleClusteringKeys_ShouldCallQueryItemsWithProperQuery() {
// Arrange
when(metadata.getClusteringKeyNames()).thenReturn(new LinkedHashSet<>(Arrays.asList(ANY_NAME_2, ANY_NAME_3)));
when(metadata.getClusteringOrder(ANY_NAME_3)).thenReturn(Order.DESC);
when(container.queryItems(anyString(), any(CosmosQueryRequestOptions.class), eq(Record.class))).thenReturn(responseIterable);
Record expected = new Record();
when(responseIterable.iterator()).thenReturn(Collections.singletonList(expected).iterator());
Scan scan = prepareScan().withStart(new Key(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_3)).withEnd(new Key(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_4));
String query = "select * from Record r where (r.concatenatedPartitionKey = '" + ANY_TEXT_1 + "' and r.clusteringKey[\"" + ANY_NAME_2 + "\"] = '" + ANY_TEXT_2 + "' and r.clusteringKey[\"" + ANY_NAME_3 + "\"] >= '" + ANY_TEXT_3 + "' and r.clusteringKey[\"" + ANY_NAME_2 + "\"] = '" + ANY_TEXT_2 + "' and r.clusteringKey[\"" + ANY_NAME_3 + "\"] <= '" + ANY_TEXT_4 + "') order by r.concatenatedPartitionKey asc, r.clusteringKey[\"" + ANY_NAME_2 + "\"] asc, r.clusteringKey[\"" + ANY_NAME_3 + "\"] desc";
// Act Assert
assertThatCode(() -> handler.handle(scan)).doesNotThrowAnyException();
// Assert
verify(container).queryItems(eq(query), any(CosmosQueryRequestOptions.class), eq(Record.class));
}
use of com.scalar.db.api.Scan in project scalardb by scalar-labs.
the class SelectStatementHandlerTest method handle_ScanOperationWithMultipleOrderingsAndLimit_ShouldCallQueryItemsWithProperQuery.
@Test
public void handle_ScanOperationWithMultipleOrderingsAndLimit_ShouldCallQueryItemsWithProperQuery() {
// Arrange
when(metadata.getClusteringKeyNames()).thenReturn(new LinkedHashSet<>(Arrays.asList(ANY_NAME_2, ANY_NAME_3)));
when(metadata.getClusteringOrder(ANY_NAME_3)).thenReturn(Order.DESC);
when(container.queryItems(anyString(), any(CosmosQueryRequestOptions.class), eq(Record.class))).thenReturn(responseIterable);
Record expected = new Record();
when(responseIterable.iterator()).thenReturn(Collections.singletonList(expected).iterator());
Scan scan = prepareScan().withStart(new Key(ANY_NAME_2, ANY_TEXT_2)).withOrdering(new Scan.Ordering(ANY_NAME_2, Order.ASC)).withOrdering(new Scan.Ordering(ANY_NAME_3, Order.DESC)).withLimit(ANY_LIMIT);
String query = "select * from Record r where (r.concatenatedPartitionKey = '" + ANY_TEXT_1 + "' and r.clusteringKey[\"" + ANY_NAME_2 + "\"] >= '" + ANY_TEXT_2 + "') order by r.concatenatedPartitionKey asc, r.clusteringKey[\"" + ANY_NAME_2 + "\"] asc, r.clusteringKey[\"" + ANY_NAME_3 + "\"] desc offset 0 limit " + ANY_LIMIT;
// Act Assert
assertThatCode(() -> handler.handle(scan)).doesNotThrowAnyException();
// Assert
verify(container).queryItems(eq(query), any(CosmosQueryRequestOptions.class), eq(Record.class));
}
use of com.scalar.db.api.Scan in project scalardb by scalar-labs.
the class MultiStorageIntegrationTest method whenScanDataFromTable1_DataShouldBeScannedFromStorage1.
@Test
public void whenScanDataFromTable1_DataShouldBeScannedFromStorage1() throws ExecutionException, IOException {
// Arrange
String namespace = NAMESPACE1;
String table = TABLE1;
Key partitionKey = new Key(COL_NAME1, 1);
Key clusteringKey1 = new Key(COL_NAME4, 0);
Key clusteringKey2 = new Key(COL_NAME4, 1);
Key clusteringKey3 = new Key(COL_NAME4, 2);
storage1.mutate(Arrays.asList(new Put(partitionKey, clusteringKey1).withValue(COL_NAME3, 2).forNamespace(namespace).forTable(table), new Put(partitionKey, clusteringKey2).withValue(COL_NAME3, 1).forNamespace(namespace).forTable(table), new Put(partitionKey, clusteringKey3).withValue(COL_NAME3, 0).forNamespace(namespace).forTable(table)));
// Act
List<Result> results = scanAll(new Scan(partitionKey).forNamespace(namespace).forTable(table));
// Assert
assertThat(results.size()).isEqualTo(3);
assertThat(getCol1Value(results.get(0))).isEqualTo(1);
assertThat(getCol3Value(results.get(0))).isEqualTo(2);
assertThat(getCol4Value(results.get(0))).isEqualTo(0);
assertThat(getCol1Value(results.get(1))).isEqualTo(1);
assertThat(getCol3Value(results.get(1))).isEqualTo(1);
assertThat(getCol4Value(results.get(1))).isEqualTo(1);
assertThat(getCol1Value(results.get(2))).isEqualTo(1);
assertThat(getCol3Value(results.get(2))).isEqualTo(0);
assertThat(getCol4Value(results.get(2))).isEqualTo(2);
}
Aggregations