diff --git a/src/common/datatypes/Edge.cpp b/src/common/datatypes/Edge.cpp index 657b8294f..af01fb4f0 100644 --- a/src/common/datatypes/Edge.cpp +++ b/src/common/datatypes/Edge.cpp @@ -40,6 +40,15 @@ bool Edge::contains(const Value& key) const { return props.find(key.getStr()) != props.end(); } +const Value& Edge::value(const std::string &key) const { + auto find = props.find(key); + if (find != props.end()) { + return find->second; + } else { + return Value::kNullValue; + } +} + bool Edge::operator<(const Edge& rhs) const { if (src != rhs.src) { return src < rhs.src; diff --git a/src/common/datatypes/Edge.h b/src/common/datatypes/Edge.h index 90546ba6d..288b3f2d0 100644 --- a/src/common/datatypes/Edge.h +++ b/src/common/datatypes/Edge.h @@ -71,6 +71,8 @@ struct Edge { bool operator<(const Edge& rhs) const; bool contains(const Value &key) const; + + const Value& value(const std::string &key) const; }; inline std::ostream &operator<<(std::ostream& os, const Edge& v) { diff --git a/src/common/datatypes/Vertex.cpp b/src/common/datatypes/Vertex.cpp index 87d0695f4..388c23b49 100644 --- a/src/common/datatypes/Vertex.cpp +++ b/src/common/datatypes/Vertex.cpp @@ -38,6 +38,16 @@ bool Vertex::contains(const Value &key) const { return false; } +const Value& Vertex::value(const std::string &key) const { + for (const auto& tag : tags) { + auto find = tag.props.find(key); + if (find != tag.props.end()) { + return find->second; + } + } + return Value::kNullValue; +} + std::string Vertex::toString() const { std::stringstream os; os << "(" << vid << ")"; diff --git a/src/common/datatypes/Vertex.h b/src/common/datatypes/Vertex.h index 808e0173b..664619c5a 100644 --- a/src/common/datatypes/Vertex.h +++ b/src/common/datatypes/Vertex.h @@ -99,6 +99,8 @@ struct Vertex { bool operator<(const Vertex& rhs) const; bool contains(const Value &key) const; + + const Value& value(const std::string &key) const; }; diff --git a/src/common/expression/PredicateExpression.cpp b/src/common/expression/PredicateExpression.cpp index ab684d16b..62d070746 100644 --- a/src/common/expression/PredicateExpression.cpp +++ b/src/common/expression/PredicateExpression.cpp @@ -24,17 +24,22 @@ const Value& PredicateExpression::evalExists(ExpressionContext& ctx) { auto& container = attributeExpr->left()->eval(ctx); auto& key = attributeExpr->right()->eval(ctx); + if (!key.isStr()) { + result_ = Value::kNullBadType; + return result_; + } + switch (container.type()) { case Value::Type::VERTEX: { - result_ = container.getVertex().contains(key); + result_ = !container.getVertex().value(key.getStr()).isNull(); break; } case Value::Type::EDGE: { - result_ = container.getEdge().contains(key); + result_ = !container.getEdge().value(key.getStr()).isNull(); break; } case Value::Type::MAP: { - result_ = container.getMap().contains(key); + result_ = !container.getMap().at(key.getStr()).isNull(); break; } case Value::Type::NULLVALUE: {