mirror of https://gitee.com/bigwinds/arangodb
actually getting out what was put into kv-store
This commit is contained in:
parent
a2956fde7b
commit
ac52b47708
|
@ -67,11 +67,9 @@ Node& Node::operator= (Slice const& slice) { // Assign value (become leaf)
|
||||||
}
|
}
|
||||||
|
|
||||||
Node& Node::operator= (Node const& node) { // Assign node
|
Node& Node::operator= (Node const& node) { // Assign node
|
||||||
|
|
||||||
_value.reset();
|
|
||||||
_value.append((char const*)node._value.data(),node._value.byteSize());
|
|
||||||
_name = node._name;
|
_name = node._name;
|
||||||
_type = node._type;
|
_type = node._type;
|
||||||
|
_value = node._value;
|
||||||
_children = node._children;
|
_children = node._children;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -157,6 +155,23 @@ bool Node::apply (arangodb::velocypack::Slice const& slice) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Node::toBuilder (Builder& builder) const {
|
||||||
|
try {
|
||||||
|
if (type()==NODE) {
|
||||||
|
VPackObjectBuilder guard(&builder);
|
||||||
|
for (auto const& child : _children) {
|
||||||
|
std::cout << _name << " : " <<std::endl;
|
||||||
|
builder.add(VPackValue(_name));
|
||||||
|
child.second->toBuilder(builder);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
builder.add(Slice(_value.data()));
|
||||||
|
}
|
||||||
|
} catch (std::exception const& e) {
|
||||||
|
LOG(FATAL) << e.what();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Store::Store () : Node("root") {}
|
Store::Store () : Node("root") {}
|
||||||
Store::~Store () {}
|
Store::~Store () {}
|
||||||
|
|
||||||
|
@ -211,8 +226,9 @@ query_t Store::read (query_t const& queries) const { // list of list of paths
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Store::read (arangodb::velocypack::Slice const& query,
|
bool Store::read (arangodb::velocypack::Slice const& query, Builder& ret) const {
|
||||||
Builder& ret) const {
|
|
||||||
|
// Collect all paths
|
||||||
std::list<std::string> query_strs;
|
std::list<std::string> query_strs;
|
||||||
if (query.type() == VPackValueType::Array) {
|
if (query.type() == VPackValueType::Array) {
|
||||||
for (auto const& sub_query : VPackArrayIterator(query))
|
for (auto const& sub_query : VPackArrayIterator(query))
|
||||||
|
@ -224,7 +240,7 @@ bool Store::read (arangodb::velocypack::Slice const& query,
|
||||||
}
|
}
|
||||||
query_strs.sort(); // sort paths
|
query_strs.sort(); // sort paths
|
||||||
|
|
||||||
// remove "double" entries
|
// Remove double ranges (inclusion / identity)
|
||||||
for (auto i = query_strs.begin(), j = i; i != query_strs.end(); ++i) {
|
for (auto i = query_strs.begin(), j = i; i != query_strs.end(); ++i) {
|
||||||
if (i!=j && i->compare(0,j->size(),*j)==0) {
|
if (i!=j && i->compare(0,j->size(),*j)==0) {
|
||||||
*i="";
|
*i="";
|
||||||
|
@ -235,32 +251,17 @@ bool Store::read (arangodb::velocypack::Slice const& query,
|
||||||
auto cut = std::remove_if(query_strs.begin(), query_strs.end(), Empty());
|
auto cut = std::remove_if(query_strs.begin(), query_strs.end(), Empty());
|
||||||
query_strs.erase (cut,query_strs.end());
|
query_strs.erase (cut,query_strs.end());
|
||||||
|
|
||||||
|
// Create response tree
|
||||||
Node node("root");
|
Node node("root");
|
||||||
for (auto i = query_strs.begin(); i != query_strs.end(); ++i) {
|
for (auto i = query_strs.begin(); i != query_strs.end(); ++i) {
|
||||||
node(*i) = (*this)(*i);
|
node(*i) = (*this)(*i);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << node << std::endl;
|
// Assemble builder from node
|
||||||
|
node.toBuilder(ret);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
{
|
|
||||||
Node* par = n._parent;
|
|
||||||
while (par != 0) {
|
|
||||||
par = par->_parent;
|
|
||||||
os << " ";
|
|
||||||
}
|
|
||||||
os << n._name << " : ";
|
|
||||||
if (n.type() == NODE) {
|
|
||||||
os << std::endl;
|
|
||||||
for (auto const& i : n._children)
|
|
||||||
os << *(i.second);
|
|
||||||
} else {
|
|
||||||
os << n._value.toString() << std::endl;
|
|
||||||
}
|
|
||||||
return os;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -100,13 +100,15 @@ public:
|
||||||
for (auto const& i : n._children)
|
for (auto const& i : n._children)
|
||||||
os << *(i.second);
|
os << *(i.second);
|
||||||
} else {
|
} else {
|
||||||
os << n._value.toString() << std::endl;
|
os << Slice(n._value.data()).toJson() << std::endl;
|
||||||
}
|
}
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool apply (arangodb::velocypack::Slice const&);
|
virtual bool apply (arangodb::velocypack::Slice const&);
|
||||||
|
|
||||||
|
void toBuilder (Builder&) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Node const* _parent;
|
Node const* _parent;
|
||||||
Children _children;
|
Children _children;
|
||||||
|
|
Loading…
Reference in New Issue