use of herddb.core.join.DataScannerJoinExecutor in project herddb by diennea.
the class DBManager method executeJoinedScansPlan.
private StatementExecutionResult executeJoinedScansPlan(List<DataScanner> scanResults, StatementEvaluationContext context, TransactionContext transactionContext, ExecutionPlan plan) throws StatementExecutionException {
try {
List<Column> composedSchema = new ArrayList<>();
for (DataScanner ds : scanResults) {
composedSchema.addAll(Arrays.asList(ds.getSchema()));
}
Column[] finalSchema = new Column[composedSchema.size()];
composedSchema.toArray(finalSchema);
String[] finalSchemaFieldNames = Column.buildFieldNamesList(finalSchema);
MaterializedRecordSet finalResultSet = recordSetFactory.createRecordSet(finalSchemaFieldNames, finalSchema);
DataScannerJoinExecutor joinExecutor;
if (plan.joinProjection != null) {
if (plan.joinFilter != null) {
TuplePredicate joinFilter = plan.joinFilter;
joinExecutor = new DataScannerJoinExecutor(finalSchemaFieldNames, finalSchema, scanResults, t -> {
if (joinFilter.matches(t, context)) {
finalResultSet.add(plan.joinProjection.map(t, context));
}
});
} else {
joinExecutor = new DataScannerJoinExecutor(finalSchemaFieldNames, finalSchema, scanResults, t -> {
finalResultSet.add(plan.joinProjection.map(t, context));
});
}
} else {
if (plan.joinFilter != null) {
TuplePredicate joinFilter = plan.joinFilter;
joinExecutor = new DataScannerJoinExecutor(finalSchemaFieldNames, finalSchema, scanResults, t -> {
if (joinFilter.matches(t, context)) {
finalResultSet.add(t);
}
});
} else {
joinExecutor = new DataScannerJoinExecutor(finalSchemaFieldNames, finalSchema, scanResults, t -> {
finalResultSet.add(t);
});
}
}
joinExecutor.executeJoin();
finalResultSet.writeFinished();
finalResultSet.sort(plan.comparator);
finalResultSet.applyLimits(plan.limits, context);
return new ScanResult(transactionContext.transactionId, new SimpleDataScanner(transactionContext.transactionId, finalResultSet));
} catch (DataScannerException err) {
throw new StatementExecutionException(err);
}
}
Aggregations