Search in sources :

Example 1 with LimitedDataScanner

use of herddb.model.LimitedDataScanner in project herddb by diennea.

the class LimitOp method execute.

@Override
public StatementExecutionResult execute(TableSpaceManager tableSpaceManager, TransactionContext transactionContext, StatementEvaluationContext context, boolean lockRequired, boolean forWrite) throws StatementExecutionException {
    try {
        // TODO merge projection + scan + sort + limit
        StatementExecutionResult input = this.input.execute(tableSpaceManager, transactionContext, context, lockRequired, forWrite);
        ScanResult downstreamScanResult = (ScanResult) input;
        final DataScanner inputScanner = downstreamScanResult.dataScanner;
        int offset = computeOffset(context);
        int maxrows = computeMaxRows(context);
        if (maxrows <= 0 && offset == 0) {
            return downstreamScanResult;
        } else {
            LimitedDataScanner limited = new LimitedDataScanner(inputScanner, maxrows, offset, context);
            return new ScanResult(downstreamScanResult.transactionId, limited);
        }
    } catch (DataScannerException ex) {
        throw new StatementExecutionException(ex);
    }
}
Also used : ScanResult(herddb.model.ScanResult) SimpleDataScanner(herddb.core.SimpleDataScanner) DataScanner(herddb.model.DataScanner) LimitedDataScanner(herddb.model.LimitedDataScanner) StatementExecutionResult(herddb.model.StatementExecutionResult) LimitedDataScanner(herddb.model.LimitedDataScanner) StatementExecutionException(herddb.model.StatementExecutionException) DataScannerException(herddb.model.DataScannerException)

Example 2 with LimitedDataScanner

use of herddb.model.LimitedDataScanner in project herddb by diennea.

the class DBManager method executeDataScannerPlan.

private StatementExecutionResult executeDataScannerPlan(ExecutionPlan plan, DataScanner result, StatementEvaluationContext context, TransactionContext transactionContext) throws StatementExecutionException {
    ScanResult scanResult;
    if (plan.mainAggregator != null) {
        scanResult = new ScanResult(transactionContext.transactionId, plan.mainAggregator.aggregate(result, context));
    } else {
        scanResult = new ScanResult(transactionContext.transactionId, result);
    }
    if (plan.comparator != null) {
        // SORT is to be applied before limits
        MaterializedRecordSet sortedSet = recordSetFactory.createRecordSet(scanResult.dataScanner.getFieldNames(), scanResult.dataScanner.getSchema());
        try {
            scanResult.dataScanner.forEach(sortedSet::add);
            sortedSet.writeFinished();
            sortedSet.sort(plan.comparator);
            scanResult.dataScanner.close();
            scanResult = new ScanResult(transactionContext.transactionId, new SimpleDataScanner(transactionContext.transactionId, sortedSet));
        } catch (DataScannerException err) {
            throw new StatementExecutionException(err);
        }
    }
    if (plan.limits != null) {
        try {
            return new ScanResult(transactionContext.transactionId, new LimitedDataScanner(scanResult.dataScanner, plan.limits, context));
        } catch (DataScannerException limitError) {
            throw new StatementExecutionException(limitError);
        }
    } else {
        return scanResult;
    }
}
Also used : ScanResult(herddb.model.ScanResult) LimitedDataScanner(herddb.model.LimitedDataScanner) StatementExecutionException(herddb.model.StatementExecutionException) DataScannerException(herddb.model.DataScannerException)

Aggregations

DataScannerException (herddb.model.DataScannerException)2 LimitedDataScanner (herddb.model.LimitedDataScanner)2 ScanResult (herddb.model.ScanResult)2 StatementExecutionException (herddb.model.StatementExecutionException)2 SimpleDataScanner (herddb.core.SimpleDataScanner)1 DataScanner (herddb.model.DataScanner)1 StatementExecutionResult (herddb.model.StatementExecutionResult)1