Search in sources :

Example 76 with DataAccessor

use of herddb.utils.DataAccessor in project herddb by diennea.

the class ServerSideConnectionPeer method handleFetchScannerData.

private void handleFetchScannerData(Pdu message, Channel channel) {
    long scannerId = PduCodec.FetchScannerData.readScannerId(message);
    int fetchSize = PduCodec.FetchScannerData.readFetchSize(message);
    if (fetchSize <= 0) {
        fetchSize = 10;
    }
    ServerSideScannerPeer scanner = scanners.get(scannerId);
    if (scanner != null) {
        try {
            DataScanner dataScanner = scanner.getScanner();
            List<DataAccessor> records = dataScanner.consume(fetchSize);
            String[] columns = dataScanner.getFieldNames();
            TuplesList tuplesList = new TuplesList(columns, records);
            boolean last = false;
            if (dataScanner.isFinished()) {
                LOGGER.log(Level.FINEST, "unregistering scanner {0}, resultset is finished", scannerId);
                scanners.remove(scannerId);
                last = true;
            }
            // LOGGER.log(Level.SEVERE, "sending " + converted.size() + " records to scanner " + scannerId);
            try {
                ByteBuf result = PduCodec.ResultSetChunk.write(message.messageId, tuplesList, last, dataScanner.getTransactionId());
                channel.sendReplyMessage(message.messageId, result);
            } catch (HerdDBInternalException err) {
                // do not leak an unserializable scanner
                scanners.remove(scannerId);
                scanner.close();
                throw err;
            }
            if (last) {
                dataScanner.close();
            }
        } catch (DataScannerException | StatementExecutionException err) {
            ByteBuf error = composeErrorResponse(message.messageId, err);
            channel.sendReplyMessage(message.messageId, error);
        }
    } else {
        ByteBuf error = PduCodec.ErrorResponse.write(message.messageId, "no such scanner " + scannerId);
        channel.sendReplyMessage(message.messageId, error);
    }
}
Also used : HerdDBInternalException(herddb.core.HerdDBInternalException) DataAccessor(herddb.utils.DataAccessor) RawString(herddb.utils.RawString) ByteBuf(io.netty.buffer.ByteBuf) StatementExecutionException(herddb.model.StatementExecutionException) DataScanner(herddb.model.DataScanner) TuplesList(herddb.utils.TuplesList) DataScannerException(herddb.model.DataScannerException)

Example 77 with DataAccessor

use of herddb.utils.DataAccessor in project herddb by diennea.

the class JoinOp method resultProjection.

private Function2<DataAccessor, DataAccessor, DataAccessor> resultProjection(String[] fieldNamesFromLeft, String[] fieldNamesFromRight) {
    DataAccessor nullsOnLeft = DataAccessor.ALL_NULLS(fieldNamesFromLeft);
    DataAccessor nullsOnRight = DataAccessor.ALL_NULLS(fieldNamesFromRight);
    return (DataAccessor a, DataAccessor b) -> new ConcatenatedDataAccessor(fieldNames, a != null ? a : nullsOnLeft, b != null ? b : nullsOnRight);
}
Also used : DataAccessor(herddb.utils.DataAccessor)

Example 78 with DataAccessor

use of herddb.utils.DataAccessor in project herddb by diennea.

the class NestedLoopJoinOp method resultProjection.

private Function2<DataAccessor, DataAccessor, DataAccessor> resultProjection(String[] fieldNamesFromLeft, String[] fieldNamesFromRight) {
    final DataAccessor nullsOnLeft = DataAccessor.ALL_NULLS(fieldNamesFromLeft);
    final DataAccessor nullsOnRight = DataAccessor.ALL_NULLS(fieldNamesFromRight);
    return (DataAccessor a, DataAccessor b) -> new ConcatenatedDataAccessor(fieldNames, a != null ? a : nullsOnLeft, b != null ? b : nullsOnRight);
}
Also used : DataAccessor(herddb.utils.DataAccessor)

Example 79 with DataAccessor

use of herddb.utils.DataAccessor in project herddb by diennea.

the class NestedLoopJoinOp method execute.

@Override
public StatementExecutionResult execute(TableSpaceManager tableSpaceManager, TransactionContext transactionContext, StatementEvaluationContext context, boolean lockRequired, boolean forWrite) throws StatementExecutionException {
    ScanResult resLeft = (ScanResult) left.execute(tableSpaceManager, transactionContext, context, lockRequired, forWrite);
    DataScanner leftScanner = resLeft.dataScanner;
    transactionContext = new TransactionContext(resLeft.transactionId);
    ScanResult resRight = (ScanResult) right.execute(tableSpaceManager, transactionContext, context, lockRequired, forWrite);
    DataScanner rightScanner = resRight.dataScanner;
    final JoinType linq4jJoinType = CalciteEnumUtils.toLinq4jJoinType(joinRelType);
    if (!linq4jJoinType.generatesNullsOnLeft() && !rightScanner.isRewindSupported()) {
        try {
            MaterializedRecordSet recordSet = tableSpaceManager.getDbmanager().getRecordSetFactory().createRecordSet(rightScanner.getFieldNames(), rightScanner.getSchema());
            rightScanner.forEach(d -> {
                recordSet.add(d);
            });
            recordSet.writeFinished();
            SimpleDataScanner materialized = new SimpleDataScanner(rightScanner.getTransaction(), recordSet);
            rightScanner.close();
            rightScanner = materialized;
        } catch (DataScannerException err) {
            throw new StatementExecutionException(err);
        }
    }
    final long resTransactionId = resRight.transactionId;
    final String[] fieldNamesFromLeft = leftScanner.getFieldNames();
    final String[] fieldNamesFromRight = rightScanner.getFieldNames();
    final Function2<DataAccessor, DataAccessor, DataAccessor> resultProjection = resultProjection(fieldNamesFromLeft, fieldNamesFromRight);
    Enumerable<DataAccessor> result = EnumerableDefaults.nestedLoopJoin(leftScanner.createNonRewindableEnumerable(), rightScanner.createRewindOnCloseEnumerable(), predicate(resultProjection, context), resultProjection, linq4jJoinType);
    EnumerableDataScanner joinedScanner = new EnumerableDataScanner(rightScanner.getTransaction(), fieldNames, columns, result, leftScanner, rightScanner);
    return new ScanResult(resTransactionId, joinedScanner);
}
Also used : ScanResult(herddb.model.ScanResult) MaterializedRecordSet(herddb.core.MaterializedRecordSet) DataAccessor(herddb.utils.DataAccessor) JoinType(org.apache.calcite.linq4j.JoinType) StatementExecutionException(herddb.model.StatementExecutionException) SimpleDataScanner(herddb.core.SimpleDataScanner) DataScanner(herddb.model.DataScanner) TransactionContext(herddb.model.TransactionContext) SimpleDataScanner(herddb.core.SimpleDataScanner) DataScannerException(herddb.model.DataScannerException)

Example 80 with DataAccessor

use of herddb.utils.DataAccessor in project herddb by diennea.

the class SemiJoinOp method execute.

@Override
public StatementExecutionResult execute(TableSpaceManager tableSpaceManager, TransactionContext transactionContext, StatementEvaluationContext context, boolean lockRequired, boolean forWrite) throws StatementExecutionException {
    ScanResult resLeft = (ScanResult) left.execute(tableSpaceManager, transactionContext, context, lockRequired, forWrite);
    transactionContext = new TransactionContext(resLeft.transactionId);
    ScanResult resRight = (ScanResult) right.execute(tableSpaceManager, transactionContext, context, lockRequired, forWrite);
    DataScanner leftScanner = resLeft.dataScanner;
    DataScanner rightScanner = resRight.dataScanner;
    if (!leftScanner.isRewindSupported()) {
        try {
            MaterializedRecordSet recordSet = tableSpaceManager.getDbmanager().getRecordSetFactory().createRecordSet(leftScanner.getFieldNames(), leftScanner.getSchema());
            leftScanner.forEach(d -> {
                recordSet.add(d);
            });
            recordSet.writeFinished();
            SimpleDataScanner materialized = new SimpleDataScanner(leftScanner.getTransaction(), recordSet);
            leftScanner.close();
            leftScanner = materialized;
        } catch (DataScannerException err) {
            throw new StatementExecutionException(err);
        }
    }
    if (!rightScanner.isRewindSupported()) {
        try {
            MaterializedRecordSet recordSet = tableSpaceManager.getDbmanager().getRecordSetFactory().createRecordSet(rightScanner.getFieldNames(), rightScanner.getSchema());
            rightScanner.forEach(d -> {
                recordSet.add(d);
            });
            recordSet.writeFinished();
            SimpleDataScanner materialized = new SimpleDataScanner(rightScanner.getTransaction(), recordSet);
            rightScanner.close();
            rightScanner = materialized;
        } catch (DataScannerException err) {
            throw new StatementExecutionException(err);
        }
    }
    final long resTransactionId = resRight.transactionId;
    Enumerable<DataAccessor> result = EnumerableDefaults.semiJoin(leftScanner.createRewindOnCloseEnumerable(), rightScanner.createRewindOnCloseEnumerable(), JoinKey.keyExtractor(leftKeys), JoinKey.keyExtractor(rightKeys));
    EnumerableDataScanner joinedScanner = new EnumerableDataScanner(rightScanner.getTransaction(), fieldNames, columns, result, leftScanner, rightScanner);
    return new ScanResult(resTransactionId, joinedScanner);
}
Also used : ScanResult(herddb.model.ScanResult) SimpleDataScanner(herddb.core.SimpleDataScanner) DataScanner(herddb.model.DataScanner) MaterializedRecordSet(herddb.core.MaterializedRecordSet) TransactionContext(herddb.model.TransactionContext) DataAccessor(herddb.utils.DataAccessor) SimpleDataScanner(herddb.core.SimpleDataScanner) StatementExecutionException(herddb.model.StatementExecutionException) DataScannerException(herddb.model.DataScannerException)

Aggregations

DataAccessor (herddb.utils.DataAccessor)164 DataScanner (herddb.model.DataScanner)118 Test (org.junit.Test)110 MemoryCommitLogManager (herddb.mem.MemoryCommitLogManager)83 MemoryDataStorageManager (herddb.mem.MemoryDataStorageManager)82 MemoryMetadataStorageManager (herddb.mem.MemoryMetadataStorageManager)82 CreateTableSpaceStatement (herddb.model.commands.CreateTableSpaceStatement)76 RawString (herddb.utils.RawString)70 DBManager (herddb.core.DBManager)52 TransactionContext (herddb.model.TransactionContext)44 StatementExecutionException (herddb.model.StatementExecutionException)38 Table (herddb.model.Table)34 List (java.util.List)31 DataScannerException (herddb.model.DataScannerException)28 DMLStatementExecutionResult (herddb.model.DMLStatementExecutionResult)27 RuntimeProjectedDataAccessor (herddb.model.planner.ProjectOp.ZeroCopyProjection.RuntimeProjectedDataAccessor)27 Column (herddb.model.Column)22 ScanResult (herddb.model.ScanResult)22 ScanStatement (herddb.model.commands.ScanStatement)22 Bytes (herddb.utils.Bytes)22