Search in sources :

Example 1 with DataScannerJoinExecutor

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);
    }
}
Also used : ExecutionPlan(herddb.model.ExecutionPlan) SQLStatementEvaluationContext(herddb.sql.SQLStatementEvaluationContext) Arrays(java.util.Arrays) FileMetadataStorageManager(herddb.file.FileMetadataStorageManager) JMXUtils(herddb.jmx.JMXUtils) ClientConfiguration(herddb.client.ClientConfiguration) MetadataStorageManager(herddb.metadata.MetadataStorageManager) Channel(herddb.network.Channel) ServerConfiguration(herddb.server.ServerConfiguration) Map(java.util.Map) DDLStatementExecutionResult(herddb.model.DDLStatementExecutionResult) ConnectionsInfoProvider(herddb.core.stats.ConnectionsInfoProvider) DMLStatementExecutionResult(herddb.model.DMLStatementExecutionResult) ThreadFactory(java.util.concurrent.ThreadFactory) Path(java.nio.file.Path) DataStorageManagerException(herddb.storage.DataStorageManagerException) DropTableSpaceStatement(herddb.model.commands.DropTableSpaceStatement) ScanResult(herddb.model.ScanResult) DataAccessor(herddb.utils.DataAccessor) LogNotAvailableException(herddb.log.LogNotAvailableException) DataScannerJoinExecutor(herddb.core.join.DataScannerJoinExecutor) InsertStatement(herddb.model.commands.InsertStatement) DataScanner(herddb.model.DataScanner) DDLException(herddb.model.DDLException) StatementExecutionException(herddb.model.StatementExecutionException) Collection(java.util.Collection) AbstractSQLPlanner(herddb.sql.AbstractSQLPlanner) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) BlockingQueue(java.util.concurrent.BlockingQueue) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) ScanStatement(herddb.model.commands.ScanStatement) List(java.util.List) Message(herddb.network.Message) NotLeaderException(herddb.model.NotLeaderException) GetStatement(herddb.model.commands.GetStatement) NodeMetadata(herddb.model.NodeMetadata) DefaultJVMHalt(herddb.utils.DefaultJVMHalt) DDLStatement(herddb.model.DDLStatement) TableSpace(herddb.model.TableSpace) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) Statement(herddb.model.Statement) AlterTableSpaceStatement(herddb.model.commands.AlterTableSpaceStatement) CalcitePlanner(herddb.sql.CalcitePlanner) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) MetadataStorageManagerException(herddb.metadata.MetadataStorageManagerException) DataScannerException(herddb.model.DataScannerException) MetadataChangeListener(herddb.metadata.MetadataChangeListener) GetResult(herddb.model.GetResult) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) TableSpaceReplicaState(herddb.model.TableSpaceReplicaState) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) HashSet(java.util.HashSet) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) TableSpaceDoesNotExistException(herddb.model.TableSpaceDoesNotExistException) SQLPlanner(herddb.sql.SQLPlanner) TransactionContext(herddb.model.TransactionContext) CommitLogManager(herddb.log.CommitLogManager) ManagementFactory(java.lang.management.ManagementFactory) ExecutorService(java.util.concurrent.ExecutorService) ReentrantLock(java.util.concurrent.locks.ReentrantLock) StatementExecutionResult(herddb.model.StatementExecutionResult) DMLStatement(herddb.model.DMLStatement) LimitedDataScanner(herddb.model.LimitedDataScanner) DataStorageManager(herddb.storage.DataStorageManager) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) DBManagerStatsMXBean(herddb.jmx.DBManagerStatsMXBean) Condition(java.util.concurrent.locks.Condition) Lock(java.util.concurrent.locks.Lock) CommitLog(herddb.log.CommitLog) TuplePredicate(herddb.model.TuplePredicate) Column(herddb.model.Column) StatementEvaluationContext(herddb.model.StatementEvaluationContext) Collections(java.util.Collections) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) ServerHostData(herddb.network.ServerHostData) TuplePredicate(herddb.model.TuplePredicate) ScanResult(herddb.model.ScanResult) ArrayList(java.util.ArrayList) DataScannerJoinExecutor(herddb.core.join.DataScannerJoinExecutor) StatementExecutionException(herddb.model.StatementExecutionException) DataScanner(herddb.model.DataScanner) LimitedDataScanner(herddb.model.LimitedDataScanner) Column(herddb.model.Column) DataScannerException(herddb.model.DataScannerException)

Aggregations

SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 ClientConfiguration (herddb.client.ClientConfiguration)1 DataScannerJoinExecutor (herddb.core.join.DataScannerJoinExecutor)1 ConnectionsInfoProvider (herddb.core.stats.ConnectionsInfoProvider)1 FileMetadataStorageManager (herddb.file.FileMetadataStorageManager)1 DBManagerStatsMXBean (herddb.jmx.DBManagerStatsMXBean)1 JMXUtils (herddb.jmx.JMXUtils)1 CommitLog (herddb.log.CommitLog)1 CommitLogManager (herddb.log.CommitLogManager)1 LogNotAvailableException (herddb.log.LogNotAvailableException)1 MemoryMetadataStorageManager (herddb.mem.MemoryMetadataStorageManager)1 MetadataChangeListener (herddb.metadata.MetadataChangeListener)1 MetadataStorageManager (herddb.metadata.MetadataStorageManager)1 MetadataStorageManagerException (herddb.metadata.MetadataStorageManagerException)1 Column (herddb.model.Column)1 DDLException (herddb.model.DDLException)1 DDLStatement (herddb.model.DDLStatement)1 DDLStatementExecutionResult (herddb.model.DDLStatementExecutionResult)1 DMLStatement (herddb.model.DMLStatement)1 DMLStatementExecutionResult (herddb.model.DMLStatementExecutionResult)1