Fix Cypher ID
function Null
handling
Reviewers: buda Reviewed By: buda Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2815
This commit is contained in:
parent
c12a87e9ca
commit
d2ff465f8e
@ -886,12 +886,15 @@ TypedValue Counter(const TypedValue *args, int64_t nargs,
|
||||
|
||||
TypedValue Id(const TypedValue *args, int64_t nargs,
|
||||
const FunctionContext &ctx) {
|
||||
FType<Or<Vertex, Edge>>("id", args, nargs);
|
||||
FType<Or<Null, Vertex, Edge>>("id", args, nargs);
|
||||
const auto &arg = args[0];
|
||||
if (arg.IsVertex())
|
||||
if (arg.IsNull()) {
|
||||
return TypedValue(ctx.memory);
|
||||
} else if (arg.IsVertex()) {
|
||||
return TypedValue(arg.ValueVertex().CypherId(), ctx.memory);
|
||||
else
|
||||
} else {
|
||||
return TypedValue(arg.ValueEdge().CypherId(), ctx.memory);
|
||||
}
|
||||
}
|
||||
|
||||
TypedValue ToString(const TypedValue *args, int64_t nargs,
|
||||
|
@ -1746,6 +1746,7 @@ TEST_F(FunctionTest, Id) {
|
||||
ASSERT_TRUE(ea.HasValue());
|
||||
auto vb = dba.InsertVertex();
|
||||
dba.AdvanceCommand();
|
||||
EXPECT_TRUE(EvaluateFunction("ID", TypedValue()).IsNull());
|
||||
EXPECT_EQ(EvaluateFunction("ID", va).ValueInt(), 0);
|
||||
EXPECT_EQ(EvaluateFunction("ID", *ea).ValueInt(), 0);
|
||||
EXPECT_EQ(EvaluateFunction("ID", vb).ValueInt(), 1);
|
||||
|
Loading…
Reference in New Issue
Block a user