1
0
Fork 0

Changes necessary for AQL INSERT for smart edge collections.

This commit is contained in:
Max Neunhoeffer 2016-10-09 23:53:26 +02:00
parent c9763a68ee
commit 476856954f
3 changed files with 48 additions and 24 deletions

View File

@ -432,12 +432,16 @@ AqlItemBlock* InsertBlock::work(std::vector<AqlItemBlock*>& blocks) {
// value is no object
errorCode = TRI_ERROR_ARANGO_DOCUMENT_TYPE_INVALID;
} else {
OperationResult opRes = _trx->insert(_collection->name, a.slice(), options);
errorCode = opRes.code;
if (!_collection->getCollection()->skipForAqlWrite(a.slice())) {
OperationResult opRes = _trx->insert(_collection->name, a.slice(), options);
errorCode = opRes.code;
if (producesOutput && errorCode == TRI_ERROR_NO_ERROR) {
// return $NEW
result->setValue(dstRow, _outRegNew, AqlValue(opRes.slice().get("new")));
if (producesOutput && errorCode == TRI_ERROR_NO_ERROR) {
// return $NEW
result->setValue(dstRow, _outRegNew, AqlValue(opRes.slice().get("new")));
}
} else {
errorCode = TRI_ERROR_NO_ERROR;
}
}
@ -454,32 +458,40 @@ AqlItemBlock* InsertBlock::work(std::vector<AqlItemBlock*>& blocks) {
// only copy 1st row of registers inherited from previous frame(s)
inheritRegisters(res, result.get(), i, dstRow);
// TODO This may be optimized with externals
babyBuilder.add(a.slice());
if (!_collection->getCollection()->skipForAqlWrite(a.slice())) {
babyBuilder.add(a.slice());
}
++dstRow;
}
babyBuilder.close();
VPackSlice toSend = babyBuilder.slice();
OperationResult opRes =
_trx->insert(_collection->name, toSend, options);
OperationResult opRes;
if (toSend.length() > 0) {
opRes = _trx->insert(_collection->name, toSend, options);
if (producesOutput) {
// Reset dstRow
dstRow -= n;
VPackSlice resultList = opRes.slice();
TRI_ASSERT(resultList.isArray());
for (auto const& elm: VPackArrayIterator(resultList)) {
bool wasError = arangodb::basics::VelocyPackHelper::getBooleanValue(
elm, "error", false);
if (!wasError) {
// return $NEW
result->setValue(dstRow, _outRegNew, AqlValue(elm.get("new")));
if (producesOutput) {
// Reset dstRow
dstRow -= n;
VPackSlice resultList = opRes.slice();
TRI_ASSERT(resultList.isArray());
auto iter = VPackArrayIterator(resultList);
for (size_t i = 0; i < n; ++i) {
TRI_ASSERT(iter.valid());
auto elm = iter.value();
bool wasError = arangodb::basics::VelocyPackHelper::getBooleanValue(
elm, "error", false);
if (!wasError) {
// return $NEW
result->setValue(dstRow, _outRegNew, AqlValue(elm.get("new")));
}
++iter;
++dstRow;
}
++dstRow;
}
}
handleBabyResult(opRes.countErrorCodes, static_cast<size_t>(toSend.length()),
ep->_options.ignoreErrors);
handleBabyResult(opRes.countErrorCodes, static_cast<size_t>(toSend.length()),
ep->_options.ignoreErrors);
}
}
// now free it already
(*it) = nullptr;

View File

@ -3402,3 +3402,11 @@ void LogicalCollection::newObjectForRemove(
builder.add(StaticStrings::RevString, VPackValue(rev));
builder.close();
}
/// @brief a method to skip certain documents in AQL write operations,
/// this is only used in the enterprise edition for smart graphs
#ifndef USE_ENTERPRISE
bool LogicalCollection::skipForAqlWrite(arangodb::velocypack::Slice document) const {
return false;
}
#endif

View File

@ -236,6 +236,10 @@ class LogicalCollection {
std::shared_ptr<ShardMap> shardIds() const;
void setShardMap(std::shared_ptr<ShardMap>& map);
/// @brief a method to skip certain documents in AQL write operations,
/// this is only used in the enterprise edition for smart graphs
virtual bool skipForAqlWrite(arangodb::velocypack::Slice document) const;
// SECTION: Modification Functions
int rename(std::string const&);
virtual void drop();
@ -474,7 +478,7 @@ class LogicalCollection {
void increaseInternalVersion();
void toVelocyPackInObject(VPackBuilder& result) const;
void toVelocyPackInObject(arangodb::velocypack::Builder& result) const;
protected:
// SECTION: Private variables