Search in sources :

Example 26 with ScanAll

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

the class Cosmos method scan.

@Override
public Scanner scan(Scan scan) throws ExecutionException {
    scan = copyAndSetTargetToIfNot(scan);
    if (scan instanceof ScanAll) {
        operationChecker.check((ScanAll) scan);
    } else {
        operationChecker.check(scan);
    }
    List<Record> records = selectStatementHandler.handle(scan);
    TableMetadata metadata = metadataManager.getTableMetadata(scan);
    return new ScannerImpl(records, new ResultInterpreter(scan.getProjections(), metadata));
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) ScanAll(com.scalar.db.api.ScanAll)

Example 27 with ScanAll

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

the class SelectStatementHandler method prepare.

@Override
@Nonnull
protected PreparedStatement prepare(Operation operation) {
    checkArgument(operation, Get.class, Scan.class, ScanAll.class);
    Select select;
    if (operation instanceof Get) {
        select = prepare((Get) operation);
    } else if (operation instanceof ScanAll) {
        select = prepare((ScanAll) operation);
    } else {
        select = prepare((Scan) operation);
    }
    return prepare(select.getQueryString());
}
Also used : Get(com.scalar.db.api.Get) Select(com.datastax.driver.core.querybuilder.Select) ScanAll(com.scalar.db.api.ScanAll) Nonnull(javax.annotation.Nonnull)

Example 28 with ScanAll

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

the class JdbcService method scan.

public List<Result> scan(Scan scan, Connection connection) throws SQLException, ExecutionException {
    if (scan instanceof ScanAll) {
        operationChecker.check((ScanAll) scan);
    } else {
        operationChecker.check(scan);
    }
    TableMetadata tableMetadata = tableMetadataManager.getTableMetadata(scan);
    SelectQuery selectQuery = scan instanceof ScanAll ? buildSelectQueryForScanAll((ScanAll) scan, tableMetadata) : buildSelectQueryForScan(scan, tableMetadata);
    try (PreparedStatement preparedStatement = connection.prepareStatement(selectQuery.sql())) {
        selectQuery.bind(preparedStatement);
        try (ResultSet resultSet = preparedStatement.executeQuery()) {
            List<Result> ret = new ArrayList<>();
            ResultInterpreter resultInterpreter = new ResultInterpreter(scan.getProjections(), tableMetadata);
            while (resultSet.next()) {
                ret.add(resultInterpreter.interpret(resultSet));
            }
            return ret;
        }
    }
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) SelectQuery(com.scalar.db.storage.jdbc.query.SelectQuery) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) ScanAll(com.scalar.db.api.ScanAll) PreparedStatement(java.sql.PreparedStatement) Result(com.scalar.db.api.Result)

Example 29 with ScanAll

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

the class ScalarDbUtils method copyAndSetTargetToIfNot.

public static Scan copyAndSetTargetToIfNot(Scan scan, Optional<String> namespace, Optional<String> tableName) {
    Scan ret;
    if (scan instanceof ScanAll) {
        // copy
        ret = new ScanAll((ScanAll) scan);
    } else {
        // copy
        ret = new Scan(scan);
    }
    setTargetToIfNot(ret, namespace, tableName);
    return ret;
}
Also used : Scan(com.scalar.db.api.Scan) ScanAll(com.scalar.db.api.ScanAll)

Example 30 with ScanAll

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

the class JdbcService method getScanner.

@SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE")
public Scanner getScanner(Scan scan, Connection connection) throws SQLException, ExecutionException {
    if (scan instanceof ScanAll) {
        operationChecker.check((ScanAll) scan);
    } else {
        operationChecker.check(scan);
    }
    TableMetadata tableMetadata = tableMetadataManager.getTableMetadata(scan);
    SelectQuery selectQuery = scan instanceof ScanAll ? buildSelectQueryForScanAll((ScanAll) scan, tableMetadata) : buildSelectQueryForScan(scan, tableMetadata);
    PreparedStatement preparedStatement = connection.prepareStatement(selectQuery.sql());
    selectQuery.bind(preparedStatement);
    ResultSet resultSet = preparedStatement.executeQuery();
    return new ScannerImpl(new ResultInterpreter(scan.getProjections(), tableMetadata), connection, preparedStatement, resultSet);
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) SelectQuery(com.scalar.db.storage.jdbc.query.SelectQuery) ResultSet(java.sql.ResultSet) ScanAll(com.scalar.db.api.ScanAll) PreparedStatement(java.sql.PreparedStatement) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

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