Files
memgraph/src/query/interpret/awesome_memgraph_functions.cpp
Mislav Bradac fe36835519 Add db_accessor to ExpressionEvaluator
Summary: Add db_accessor to ExpressionEvaluator

Reviewers: florijan, teon.banek

Reviewed By: teon.banek

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D310
2017-04-24 14:38:38 +02:00

37 lines
936 B
C++

#include "query/interpret/awesome_memgraph_functions.hpp"
#include <cmath>
#include <cstdlib>
#include "query/exceptions.hpp"
namespace query {
namespace {
TypedValue Abs(const std::vector<TypedValue> &args, GraphDbAccessor &) {
if (args.size() != 1U) {
throw QueryRuntimeException("ABS requires one argument");
}
switch (args[0].type()) {
case TypedValue::Type::Null:
return TypedValue::Null;
case TypedValue::Type::Int:
return static_cast<int64_t>(
std::abs(static_cast<long long>(args[0].Value<int64_t>())));
case TypedValue::Type::Double:
return std::abs(args[0].Value<double>());
default:
throw QueryRuntimeException("ABS called with incompatible type");
}
}
}
std::function<TypedValue(const std::vector<TypedValue> &, GraphDbAccessor &)>
NameToFunction(const std::string &function_name) {
if (function_name == "ABS") {
return Abs;
}
return nullptr;
}
}