| 527 | } |
| 528 | |
| 529 | void NodeBatchInsert::executeInternal(ExecutionContext* context) { |
| 530 | const auto clientContext = context->clientContext; |
| 531 | std::optional<ProducerToken> token; |
| 532 | auto nodeLocalState = localState->ptrCast<NodeBatchInsertLocalState>(); |
| 533 | const auto nodeSharedState = |
| 534 | dynamic_cast_checked<NodeBatchInsertSharedState*>(sharedState.get()); |
| 535 | if (nodeLocalState->localIndexBuilder) { |
| 536 | token = nodeLocalState->localIndexBuilder->getProducerToken(); |
| 537 | } |
| 538 | auto transaction = Transaction::Get(*clientContext); |
| 539 | while (children[0]->getNextTuple(context)) { |
| 540 | const auto originalSelVector = nodeLocalState->columnState->getSelVectorShared(); |
| 541 | // Evaluate expressions if needed. |
| 542 | const auto numTuples = nodeLocalState->columnState->getSelVector().getSelSize(); |
| 543 | evaluateExpressions(numTuples); |
| 544 | copyToNodeGroup(transaction, MemoryManager::Get(*clientContext)), |
| 545 | nodeLocalState->columnState->setSelVector(originalSelVector); |
| 546 | } |
| 547 | if (nodeLocalState->chunkedGroup->getNumRows() > 0) { |
| 548 | appendIncompleteNodeGroup(transaction, std::move(nodeLocalState->chunkedGroup), |
| 549 | nodeLocalState->localIndexBuilder, MemoryManager::Get(*context->clientContext)); |
| 550 | } |
| 551 | if (nodeLocalState->localIndexBuilder) { |
| 552 | DASSERT(token); |
| 553 | token->quit(); |
| 554 | |
| 555 | DASSERT(nodeLocalState->errorHandler.has_value()); |
| 556 | nodeLocalState->localIndexBuilder->finishedProducing(nodeLocalState->errorHandler.value()); |
| 557 | nodeLocalState->errorHandler->flushStoredErrors(); |
| 558 | } |
| 559 | const auto nodeInfo = info->ptrCast<NodeBatchInsertInfo>(); |
| 560 | if (nodeInfo->skipDuplicatePK) { |
| 561 | std::lock_guard lck{nodeSharedState->duplicatePKSkipResult->mtx}; |
| 562 | nodeSharedState->duplicatePKSkipResult->skippedCount += |
| 563 | nodeLocalState->duplicatePKSkipResult.skippedCount; |
| 564 | nodeSharedState->duplicatePKSkipResult->pks.insert( |
| 565 | nodeSharedState->duplicatePKSkipResult->pks.end(), |
| 566 | std::make_move_iterator(nodeLocalState->duplicatePKSkipResult.pks.begin()), |
| 567 | std::make_move_iterator(nodeLocalState->duplicatePKSkipResult.pks.end())); |
| 568 | nodeLocalState->duplicatePKSkipResult.pks.clear(); |
| 569 | } |
| 570 | sharedState->table->cast<NodeTable>().mergeStats(nodeInfo->insertColumnIDs, |
| 571 | nodeLocalState->stats); |
| 572 | } |
| 573 | |
| 574 | void NodeBatchInsert::evaluateExpressions(uint64_t numTuples) const { |
| 575 | const auto nodeInfo = info->ptrCast<NodeBatchInsertInfo>(); |
nothing calls this directly
no test coverage detected