Search in sources :

Example 51 with ScanAll

use of com.scalar.db.api.ScanAll in project scalardb by scalar-labs.

the class Cassandra method scan.

@Override
@Nonnull
public Scanner scan(Scan scan) throws ExecutionException {
    scan = copyAndSetTargetToIfNot(scan);
    if (scan instanceof ScanAll) {
        operationChecker.check((ScanAll) scan);
    } else {
        operationChecker.check(scan);
    }
    ResultSet results = handlers.select().handle(scan);
    return new ScannerImpl(results, new ResultInterpreter(scan.getProjections(), metadataManager.getTableMetadata(scan)));
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) ScanAll(com.scalar.db.api.ScanAll) Nonnull(javax.annotation.Nonnull)

Example 52 with ScanAll

use of com.scalar.db.api.ScanAll in project scalardb by scalar-labs.

the class SelectStatementHandler method executeQuery.

private List<Record> executeQuery(Scan scan, TableMetadata tableMetadata) throws CosmosException {
    CosmosOperation cosmosOperation = new CosmosOperation(scan, tableMetadata);
    String query;
    CosmosQueryRequestOptions options;
    if (scan instanceof ScanAll) {
        query = makeQueryWithProjections(scan, tableMetadata).getSQL(ParamType.INLINED);
        options = new CosmosQueryRequestOptions();
    } else if (ScalarDbUtils.isSecondaryIndexSpecified(scan, tableMetadata)) {
        query = makeQueryWithIndex(scan, tableMetadata);
        options = new CosmosQueryRequestOptions();
    } else {
        query = makeQueryWithCondition(tableMetadata, cosmosOperation, scan);
        options = new CosmosQueryRequestOptions().setPartitionKey(cosmosOperation.getCosmosPartitionKey());
    }
    if (scan.getLimit() > 0) {
        // Add limit as a string
        // because JOOQ doesn't support OFFSET LIMIT clause which Cosmos DB requires
        query += " offset 0 limit " + scan.getLimit();
    }
    CosmosPagedIterable<Record> iterable = getContainer(scan).queryItems(query, options, Record.class);
    return Lists.newArrayList(iterable);
}
Also used : CosmosQueryRequestOptions(com.azure.cosmos.models.CosmosQueryRequestOptions) ScanAll(com.scalar.db.api.ScanAll)

Aggregations

ScanAll (com.scalar.db.api.ScanAll)52 Test (org.junit.jupiter.api.Test)43 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 Result (com.scalar.db.api.Result)9 CosmosQueryRequestOptions (com.azure.cosmos.models.CosmosQueryRequestOptions)8 Put (com.scalar.db.api.Put)4 HashMap (java.util.HashMap)4 Scan (com.scalar.db.api.Scan)3 TableMetadata (com.scalar.db.api.TableMetadata)3 Key (com.scalar.db.io.Key)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)3 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)3 ScanRequest (software.amazon.awssdk.services.dynamodb.model.ScanRequest)3 SelectQuery (com.scalar.db.storage.jdbc.query.SelectQuery)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 List (java.util.List)2 Nonnull (javax.annotation.Nonnull)2 ResultSet (com.datastax.driver.core.ResultSet)1 Select (com.datastax.driver.core.querybuilder.Select)1