Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

Commit

Permalink
Fix the exists eval for null properties (#582)
Browse files Browse the repository at this point in the history
Co-authored-by: Yee <2520865+yixinglu@users.noreply.github.com>
  • Loading branch information
Shylock-Hg and yixinglu committed Jul 12, 2021
1 parent 8537a34 commit 9dfac8a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/common/datatypes/Edge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/common/datatypes/Edge.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions src/common/datatypes/Vertex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 << ")";
Expand Down
2 changes: 2 additions & 0 deletions src/common/datatypes/Vertex.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};


Expand Down
11 changes: 8 additions & 3 deletions src/common/expression/PredicateExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 9dfac8a

Please sign in to comment.