Handle zero increment in counters
Reviewers: teon.banek Reviewed By: teon.banek Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2208
This commit is contained in:
parent
e7f897984f
commit
d5106c7233
@ -702,7 +702,12 @@ TypedValue Counter(TypedValue *args, int64_t nargs,
|
|||||||
"Third argument of 'counter' must be an integer.");
|
"Third argument of 'counter' must be an integer.");
|
||||||
|
|
||||||
int64_t step = 1;
|
int64_t step = 1;
|
||||||
if (nargs == 3) step = args[2].ValueInt();
|
if (nargs == 3) {
|
||||||
|
step = args[2].ValueInt();
|
||||||
|
if (step == 0)
|
||||||
|
throw QueryRuntimeException(
|
||||||
|
"Third argument of 'counter' must not be zero.");
|
||||||
|
}
|
||||||
|
|
||||||
auto [it, inserted] =
|
auto [it, inserted] =
|
||||||
context.counters.emplace(args[0].ValueString(), args[1].ValueInt());
|
context.counters.emplace(args[0].ValueString(), args[1].ValueInt());
|
||||||
|
@ -1494,6 +1494,8 @@ TEST_F(FunctionTest, Counter) {
|
|||||||
EXPECT_EQ(EvaluateFunction("COUNTER", "c5", 0, -5).ValueInt(), 0);
|
EXPECT_EQ(EvaluateFunction("COUNTER", "c5", 0, -5).ValueInt(), 0);
|
||||||
EXPECT_EQ(EvaluateFunction("COUNTER", "c5", 0, -5).ValueInt(), -5);
|
EXPECT_EQ(EvaluateFunction("COUNTER", "c5", 0, -5).ValueInt(), -5);
|
||||||
EXPECT_EQ(EvaluateFunction("COUNTER", "c5", 0, -5).ValueInt(), -10);
|
EXPECT_EQ(EvaluateFunction("COUNTER", "c5", 0, -5).ValueInt(), -10);
|
||||||
|
|
||||||
|
EXPECT_THROW(EvaluateFunction("COUNTER", "c6", 0, 0), QueryRuntimeException);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FunctionTest, Id) {
|
TEST_F(FunctionTest, Id) {
|
||||||
|
Loading…
Reference in New Issue
Block a user