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);
}
}
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;
}
}
Aggregations