mirror of https://gitee.com/bigwinds/arangodb
use special functions for lookups
This commit is contained in:
parent
1554619c35
commit
3fde96b422
|
@ -24,6 +24,7 @@
|
|||
#include "AttributeAccessor.h"
|
||||
#include "Aql/AqlItemBlock.h"
|
||||
#include "Aql/Variable.h"
|
||||
#include "Basics/StaticStrings.h"
|
||||
#include "Basics/VelocyPackHelper.h"
|
||||
#include "Utils/AqlTransaction.h"
|
||||
|
||||
|
@ -33,9 +34,23 @@ using namespace arangodb::aql;
|
|||
AttributeAccessor::AttributeAccessor(
|
||||
std::vector<std::string> const& attributeParts, Variable const* variable)
|
||||
: _attributeParts(attributeParts),
|
||||
_variable(variable) {
|
||||
_variable(variable),
|
||||
_type(EXTRACT_MULTI) {
|
||||
|
||||
TRI_ASSERT(_variable != nullptr);
|
||||
|
||||
// determine accessor type
|
||||
if (_attributeParts.size() == 1) {
|
||||
if (attributeParts[0] == StaticStrings::KeyString) {
|
||||
_type = EXTRACT_KEY;
|
||||
} else if (attributeParts[0] == StaticStrings::FromString) {
|
||||
_type = EXTRACT_FROM;
|
||||
} else if (attributeParts[0] == StaticStrings::ToString) {
|
||||
_type = EXTRACT_TO;
|
||||
} else {
|
||||
_type = EXTRACT_SINGLE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// @brief replace the variable in the accessor
|
||||
|
@ -58,12 +73,19 @@ AqlValue AttributeAccessor::get(arangodb::AqlTransaction* trx,
|
|||
for (auto it = vars.begin(); it != vars.end(); ++it, ++i) {
|
||||
if ((*it)->id == _variable->id) {
|
||||
// get the AQL value
|
||||
if (_attributeParts.size() == 1) {
|
||||
// use optimized version for single attribute (e.g. variable.attr)
|
||||
return argv->getValueReference(startPos, regs[i]).get(trx, _attributeParts[0], mustDestroy, true);
|
||||
} else {
|
||||
// use general version for multiple attributes (e.g. variable.attr.subattr)
|
||||
return argv->getValueReference(startPos, regs[i]).get(trx, _attributeParts, mustDestroy, true);
|
||||
switch (_type) {
|
||||
case EXTRACT_KEY:
|
||||
return argv->getValueReference(startPos, regs[i]).getKeyAttribute(trx, mustDestroy, true);
|
||||
case EXTRACT_FROM:
|
||||
return argv->getValueReference(startPos, regs[i]).getFromAttribute(trx, mustDestroy, true);
|
||||
case EXTRACT_TO:
|
||||
return argv->getValueReference(startPos, regs[i]).getToAttribute(trx, mustDestroy, true);
|
||||
case EXTRACT_SINGLE:
|
||||
// use optimized version for single attribute (e.g. variable.attr)
|
||||
return argv->getValueReference(startPos, regs[i]).get(trx, _attributeParts[0], mustDestroy, true);
|
||||
case EXTRACT_MULTI:
|
||||
// use general version for multiple attributes (e.g. variable.attr.subattr)
|
||||
return argv->getValueReference(startPos, regs[i]).get(trx, _attributeParts, mustDestroy, true);
|
||||
}
|
||||
}
|
||||
// fall-through intentional
|
||||
|
|
|
@ -50,6 +50,13 @@ class AttributeAccessor {
|
|||
void replaceVariable(std::unordered_map<VariableId, Variable const*> const& replacements);
|
||||
|
||||
private:
|
||||
enum AccessorType {
|
||||
EXTRACT_KEY,
|
||||
EXTRACT_FROM,
|
||||
EXTRACT_TO,
|
||||
EXTRACT_SINGLE,
|
||||
EXTRACT_MULTI
|
||||
};
|
||||
|
||||
/// @brief the attribute names vector (e.g. [ "a", "b", "c" ] for a.b.c)
|
||||
std::vector<std::string> const _attributeParts;
|
||||
|
@ -57,6 +64,8 @@ class AttributeAccessor {
|
|||
/// @brief the accessed variable
|
||||
Variable const* _variable;
|
||||
|
||||
/// @brief type of the accessor
|
||||
AccessorType _type;
|
||||
};
|
||||
|
||||
} // namespace arangodb::aql
|
||||
|
|
Loading…
Reference in New Issue