Remove TypedValue::Null

Summary:
The global variable may hide the fact that it uses the default
utils::NewDeleteResource() for allocations.

Reviewers: mtomic, llugovic, mferencevic

Reviewed By: mtomic

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D2121
This commit is contained in:
Teon Banek 2019-06-04 16:11:31 +02:00
parent df90184b50
commit 6d3e3ac4aa
19 changed files with 193 additions and 199 deletions

View File

@ -13,7 +13,7 @@ namespace glue {
query::TypedValue ToTypedValue(const Value &value) {
switch (value.type()) {
case Value::Type::Null:
return query::TypedValue::Null;
return query::TypedValue();
case Value::Type::Bool:
return query::TypedValue(value.ValueBool());
case Value::Type::Int:

View File

@ -83,7 +83,7 @@ void Load(query::TypedValue *value, slk::Reader *reader,
slk::Load(&type, reader);
switch (type) {
case static_cast<uint8_t>(0):
*value = query::TypedValue::Null;
*value = query::TypedValue();
return;
case static_cast<uint8_t>(1): {
bool v;

View File

@ -1474,7 +1474,7 @@ antlrcpp::Any CypherMainVisitor::visitLiteral(
int token_position = ctx->getStart()->getTokenIndex();
if (ctx->CYPHERNULL()) {
return static_cast<Expression *>(
storage_->Create<PrimitiveLiteral>(TypedValue::Null, token_position));
storage_->Create<PrimitiveLiteral>(TypedValue(), token_position));
} else if (context_.is_query_cached) {
// Instead of generating PrimitiveLiteral, we generate a
// ParameterLookup, so that the AST can be cached. This allows for
@ -1714,7 +1714,7 @@ antlrcpp::Any CypherMainVisitor::visitCaseExpression(
Expression *else_expression =
ctx->else_expression
? ctx->else_expression->accept(this).as<Expression *>()
: storage_->Create<PrimitiveLiteral>(TypedValue::Null);
: storage_->Create<PrimitiveLiteral>(TypedValue());
for (auto *alternative : alternatives) {
Expression *condition =
test_expression

View File

@ -41,7 +41,7 @@ TypedValue EndNode(TypedValue *args, int64_t nargs, const EvaluationContext &,
}
switch (args[0].type()) {
case TypedValue::Type::Null:
return TypedValue::Null;
return TypedValue();
case TypedValue::Type::Edge:
return args[0].Value<EdgeAccessor>().to();
default:
@ -56,10 +56,10 @@ TypedValue Head(TypedValue *args, int64_t nargs, const EvaluationContext &,
}
switch (args[0].type()) {
case TypedValue::Type::Null:
return TypedValue::Null;
return TypedValue();
case TypedValue::Type::List: {
const auto &list = args[0].ValueList();
if (list.empty()) return TypedValue::Null;
if (list.empty()) return TypedValue();
return list[0];
}
default:
@ -74,10 +74,10 @@ TypedValue Last(TypedValue *args, int64_t nargs, const EvaluationContext &,
}
switch (args[0].type()) {
case TypedValue::Type::Null:
return TypedValue::Null;
return TypedValue();
case TypedValue::Type::List: {
const auto &list = args[0].ValueList();
if (list.empty()) return TypedValue::Null;
if (list.empty()) return TypedValue();
return list.back();
}
default:
@ -100,7 +100,7 @@ TypedValue Properties(TypedValue *args, int64_t nargs,
};
switch (args[0].type()) {
case TypedValue::Type::Null:
return TypedValue::Null;
return TypedValue();
case TypedValue::Type::Vertex:
return get_properties(args[0].Value<VertexAccessor>());
case TypedValue::Type::Edge:
@ -118,7 +118,7 @@ TypedValue Size(TypedValue *args, int64_t nargs, const EvaluationContext &,
}
switch (args[0].type()) {
case TypedValue::Type::Null:
return TypedValue::Null;
return TypedValue();
case TypedValue::Type::List:
return static_cast<int64_t>(
args[0].ValueList().size());
@ -144,7 +144,7 @@ TypedValue StartNode(TypedValue *args, int64_t nargs, const EvaluationContext &,
}
switch (args[0].type()) {
case TypedValue::Type::Null:
return TypedValue::Null;
return TypedValue();
case TypedValue::Type::Edge:
return args[0].Value<EdgeAccessor>().from();
default:
@ -159,7 +159,7 @@ TypedValue Degree(TypedValue *args, int64_t nargs, const EvaluationContext &,
}
switch (args[0].type()) {
case TypedValue::Type::Null:
return TypedValue::Null;
return TypedValue();
case TypedValue::Type::Vertex: {
auto &vertex = args[0].Value<VertexAccessor>();
return static_cast<int64_t>(vertex.out_degree() + vertex.in_degree());
@ -177,7 +177,7 @@ TypedValue InDegree(TypedValue *args, int64_t nargs, const EvaluationContext &,
switch (args[0].type()) {
case TypedValue::Type::Null:
return TypedValue::Null;
return TypedValue();
case TypedValue::Type::Vertex: {
auto &vertex = args[0].Value<VertexAccessor>();
return static_cast<int64_t>(vertex.in_degree());
@ -195,7 +195,7 @@ TypedValue OutDegree(TypedValue *args, int64_t nargs, const EvaluationContext &,
switch (args[0].type()) {
case TypedValue::Type::Null:
return TypedValue::Null;
return TypedValue();
case TypedValue::Type::Vertex: {
auto &vertex = args[0].Value<VertexAccessor>();
return static_cast<int64_t>(vertex.out_degree());
@ -212,7 +212,7 @@ TypedValue ToBoolean(TypedValue *args, int64_t nargs, const EvaluationContext &,
}
switch (args[0].type()) {
case TypedValue::Type::Null:
return TypedValue::Null;
return TypedValue();
case TypedValue::Type::Bool:
return args[0].Value<bool>();
case TypedValue::Type::Int:
@ -223,7 +223,7 @@ TypedValue ToBoolean(TypedValue *args, int64_t nargs, const EvaluationContext &,
if (s == "FALSE") return false;
// I think this is just stupid and that exception should be thrown, but
// neo4j does it this way...
return TypedValue::Null;
return TypedValue();
}
default:
throw QueryRuntimeException(
@ -238,7 +238,7 @@ TypedValue ToFloat(TypedValue *args, int64_t nargs, const EvaluationContext &,
}
switch (args[0].type()) {
case TypedValue::Type::Null:
return TypedValue::Null;
return TypedValue();
case TypedValue::Type::Int:
return static_cast<double>(args[0].Value<int64_t>());
case TypedValue::Type::Double:
@ -247,7 +247,7 @@ TypedValue ToFloat(TypedValue *args, int64_t nargs, const EvaluationContext &,
try {
return utils::ParseDouble(utils::Trim(args[0].ValueString()));
} catch (const utils::BasicException &) {
return TypedValue::Null;
return TypedValue();
}
default:
throw QueryRuntimeException(
@ -262,7 +262,7 @@ TypedValue ToInteger(TypedValue *args, int64_t nargs, const EvaluationContext &,
}
switch (args[0].type()) {
case TypedValue::Type::Null:
return TypedValue::Null;
return TypedValue();
case TypedValue::Type::Bool:
return args[0].ValueBool() ? 1L : 0L;
case TypedValue::Type::Int:
@ -276,7 +276,7 @@ TypedValue ToInteger(TypedValue *args, int64_t nargs, const EvaluationContext &,
return static_cast<int64_t>(
utils::ParseDouble(utils::Trim(args[0].ValueString())));
} catch (const utils::BasicException &) {
return TypedValue::Null;
return TypedValue();
}
default:
throw QueryRuntimeException(
@ -291,7 +291,7 @@ TypedValue Type(TypedValue *args, int64_t nargs, const EvaluationContext &,
}
switch (args[0].type()) {
case TypedValue::Type::Null:
return TypedValue::Null;
return TypedValue();
case TypedValue::Type::Edge:
return dba->EdgeTypeName(args[0].Value<EdgeAccessor>().EdgeType());
default:
@ -313,7 +313,7 @@ TypedValue Keys(TypedValue *args, int64_t nargs, const EvaluationContext &,
};
switch (args[0].type()) {
case TypedValue::Type::Null:
return TypedValue::Null;
return TypedValue();
case TypedValue::Type::Vertex:
return get_keys(args[0].Value<VertexAccessor>());
case TypedValue::Type::Edge:
@ -330,7 +330,7 @@ TypedValue Labels(TypedValue *args, int64_t nargs, const EvaluationContext &,
}
switch (args[0].type()) {
case TypedValue::Type::Null:
return TypedValue::Null;
return TypedValue();
case TypedValue::Type::Vertex: {
std::vector<TypedValue> labels;
for (const auto &label : args[0].Value<VertexAccessor>().labels()) {
@ -348,7 +348,7 @@ TypedValue Nodes(TypedValue *args, int64_t nargs, const EvaluationContext &,
if (nargs != 1) {
throw QueryRuntimeException("'nodes' requires exactly one argument.");
}
if (args[0].IsNull()) return TypedValue::Null;
if (args[0].IsNull()) return TypedValue();
if (!args[0].IsPath()) {
throw QueryRuntimeException("'nodes' argument should be a path.");
}
@ -363,7 +363,7 @@ TypedValue Relationships(TypedValue *args, int64_t nargs,
throw QueryRuntimeException(
"'relationships' requires exactly one argument.");
}
if (args[0].IsNull()) return TypedValue::Null;
if (args[0].IsNull()) return TypedValue();
if (!args[0].IsPath()) {
throw QueryRuntimeException("'relationships' argument must be a path.");
}
@ -385,7 +385,7 @@ TypedValue Range(TypedValue *args, int64_t nargs, const EvaluationContext &,
}
};
for (int64_t i = 0; i < nargs; ++i) check_type(args[i]);
if (has_null) return TypedValue::Null;
if (has_null) return TypedValue();
auto lbound = args[0].Value<int64_t>();
auto rbound = args[1].Value<int64_t>();
int64_t step = nargs == 3 ? args[2].Value<int64_t>() : 1;
@ -412,7 +412,7 @@ TypedValue Tail(TypedValue *args, int64_t nargs, const EvaluationContext &,
}
switch (args[0].type()) {
case TypedValue::Type::Null:
return TypedValue::Null;
return TypedValue();
case TypedValue::Type::List: {
auto list = args[0].ValueList();
if (list.empty()) return list;
@ -435,7 +435,7 @@ TypedValue UniformSample(TypedValue *args, int64_t nargs,
switch (args[0].type()) {
case TypedValue::Type::Null:
if (args[1].IsNull() || (args[1].IsInt() && args[1].ValueInt() >= 0)) {
return TypedValue::Null;
return TypedValue();
}
throw QueryRuntimeException(
"Second argument of 'uniformSample' must be a non-negative integer.");
@ -443,7 +443,7 @@ TypedValue UniformSample(TypedValue *args, int64_t nargs,
if (args[1].IsInt() && args[1].ValueInt() >= 0) {
auto &population = args[0].ValueList();
auto population_size = population.size();
if (population_size == 0) return TypedValue::Null;
if (population_size == 0) return TypedValue();
auto desired_length = args[1].ValueInt();
std::uniform_int_distribution<uint64_t> rand_dist{0,
population_size - 1};
@ -469,7 +469,7 @@ TypedValue Abs(TypedValue *args, int64_t nargs, const EvaluationContext &,
}
switch (args[0].type()) {
case TypedValue::Type::Null:
return TypedValue::Null;
return TypedValue();
case TypedValue::Type::Int:
return static_cast<int64_t>(
std::abs(static_cast<long long>(args[0].Value<int64_t>())));
@ -489,7 +489,7 @@ TypedValue Abs(TypedValue *args, int64_t nargs, const EvaluationContext &,
} \
switch (args[0].type()) { \
case TypedValue::Type::Null: \
return TypedValue::Null; \
return TypedValue(); \
case TypedValue::Type::Int: \
return lowercased_name(args[0].Value<int64_t>()); \
case TypedValue::Type::Double: \
@ -523,8 +523,8 @@ TypedValue Atan2(TypedValue *args, int64_t nargs, const EvaluationContext &,
if (nargs != 2) {
throw QueryRuntimeException("'atan2' requires two arguments.");
}
if (args[0].type() == TypedValue::Type::Null) return TypedValue::Null;
if (args[1].type() == TypedValue::Type::Null) return TypedValue::Null;
if (args[0].type() == TypedValue::Type::Null) return TypedValue();
if (args[1].type() == TypedValue::Type::Null) return TypedValue();
auto to_double = [](const TypedValue &t) -> double {
switch (t.type()) {
case TypedValue::Type::Int:
@ -548,7 +548,7 @@ TypedValue Sign(TypedValue *args, int64_t nargs, const EvaluationContext &,
auto sign = [](auto x) { return (0 < x) - (x < 0); };
switch (args[0].type()) {
case TypedValue::Type::Null:
return TypedValue::Null;
return TypedValue();
case TypedValue::Type::Int:
return sign(args[0].Value<int64_t>());
case TypedValue::Type::Double:
@ -604,7 +604,7 @@ TypedValue StringMatchOperator(TypedValue *args, int64_t nargs,
};
check_arg(args[0]);
check_arg(args[1]);
if (has_null) return TypedValue::Null;
if (has_null) return TypedValue();
const auto &s1 = args[0].ValueString();
const auto &s2 = args[1].ValueString();
return Predicate(s1, s2);
@ -731,7 +731,7 @@ TypedValue ToString(TypedValue *args, int64_t nargs, const EvaluationContext &,
auto &arg = args[0];
switch (arg.type()) {
case TypedValue::Type::Null:
return TypedValue::Null;
return TypedValue();
case TypedValue::Type::String:
return arg;
case TypedValue::Type::Int:
@ -762,7 +762,7 @@ TypedValue Left(TypedValue *args, int64_t nargs, const EvaluationContext &,
switch (args[0].type()) {
case TypedValue::Type::Null:
if (args[1].IsNull() || (args[1].IsInt() && args[1].ValueInt() >= 0)) {
return TypedValue::Null;
return TypedValue();
}
throw QueryRuntimeException(
"Second argument of 'left' must be a non-negative integer.");
@ -788,7 +788,7 @@ TypedValue Right(TypedValue *args, int64_t nargs, const EvaluationContext &,
switch (args[0].type()) {
case TypedValue::Type::Null:
if (args[1].IsNull() || (args[1].IsInt() && args[1].ValueInt() >= 0)) {
return TypedValue::Null;
return TypedValue();
}
throw QueryRuntimeException(
"Second argument of 'right' must be a non-negative integer.");
@ -893,7 +893,7 @@ TypedValue Replace(TypedValue *args, int64_t nargs, const EvaluationContext &,
"Third argument of 'replace' should be a string.");
}
if (args[0].IsNull() || args[1].IsNull() || args[2].IsNull()) {
return TypedValue::Null;
return TypedValue();
}
return utils::Replace(args[0].ValueString(), args[1].ValueString(),
args[2].ValueString());
@ -913,7 +913,7 @@ TypedValue Split(TypedValue *args, int64_t nargs, const EvaluationContext &,
"Second argument of 'split' should be a string.");
}
if (args[0].IsNull() || args[1].IsNull()) {
return TypedValue::Null;
return TypedValue();
}
std::vector<TypedValue> result;
for (const auto &str :
@ -941,7 +941,7 @@ TypedValue Substring(TypedValue *args, int64_t nargs, const EvaluationContext &,
"Third argument of 'substring' should be a non-negative integer.");
}
if (args[0].IsNull()) {
return TypedValue::Null;
return TypedValue();
}
const auto &str = args[0].ValueString();
auto start = args[1].ValueInt();

View File

@ -124,7 +124,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
auto literal = in_list.expression1_->Accept(*this);
auto _list = in_list.expression2_->Accept(*this);
if (_list.IsNull()) {
return TypedValue::Null;
return TypedValue();
}
// Exceptions have higher priority than returning nulls when list expression
// is not null.
@ -138,7 +138,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
// is one special case that we must test explicitly: if list is empty then
// result is false since no comparison will be performed.
if (list.size() == 0U) return false;
if (literal.IsNull()) return TypedValue::Null;
if (literal.IsNull()) return TypedValue();
auto has_null = false;
for (const auto &element : list) {
@ -150,7 +150,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
}
}
if (has_null) {
return TypedValue::Null;
return TypedValue();
}
return false;
}
@ -164,7 +164,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
"Expected a list, a map, a node or an edge to index with '[]', got "
"{}.",
lhs.type());
if (lhs.IsNull() || index.IsNull()) return TypedValue::Null;
if (lhs.IsNull() || index.IsNull()) return TypedValue();
if (lhs.IsList()) {
if (!index.IsInt())
throw QueryRuntimeException(
@ -175,7 +175,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
index_int += static_cast<int64_t>(list.size());
}
if (index_int >= static_cast<int64_t>(list.size()) || index_int < 0)
return TypedValue::Null;
return TypedValue();
return list[index_int];
}
@ -185,7 +185,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
index.type());
const auto &map = lhs.ValueMap();
auto found = map.find(index.ValueString());
if (found == map.end()) return TypedValue::Null;
if (found == map.end()) return TypedValue();
return found->second;
}
@ -206,7 +206,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
}
// lhs is Null
return TypedValue::Null;
return TypedValue();
}
TypedValue Visit(ListSlicingOperator &op) override {
@ -240,7 +240,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
}
if (is_null) {
return TypedValue::Null;
return TypedValue();
}
const auto &list = _list.ValueList();
auto normalise_bound = [&](int64_t bound) {
@ -268,7 +268,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
auto expression_result = property_lookup.expression_->Accept(*this);
switch (expression_result.type()) {
case TypedValue::Type::Null:
return TypedValue::Null;
return TypedValue();
case TypedValue::Type::Vertex:
return expression_result.Value<VertexAccessor>().PropsAt(
GetProperty(property_lookup.property_));
@ -278,7 +278,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
case TypedValue::Type::Map: {
const auto &map = expression_result.ValueMap();
auto found = map.find(property_lookup.property_.name.c_str());
if (found == map.end()) return TypedValue::Null;
if (found == map.end()) return TypedValue();
return found->second;
}
default:
@ -291,7 +291,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
auto expression_result = labels_test.expression_->Accept(*this);
switch (expression_result.type()) {
case TypedValue::Type::Null:
return TypedValue::Null;
return TypedValue();
case TypedValue::Type::Vertex: {
auto vertex = expression_result.Value<VertexAccessor>();
for (const auto label : labels_test.labels_) {
@ -349,7 +349,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
}
}
return TypedValue::Null;
return TypedValue();
}
TypedValue Visit(Function &function) override {
@ -375,7 +375,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
TypedValue Visit(Reduce &reduce) override {
auto list_value = reduce.list_->Accept(*this);
if (list_value.IsNull()) {
return TypedValue::Null;
return TypedValue();
}
if (list_value.type() != TypedValue::Type::List) {
throw QueryRuntimeException("REDUCE expected a list, got {}.",
@ -396,7 +396,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
TypedValue Visit(Extract &extract) override {
auto list_value = extract.list_->Accept(*this);
if (list_value.IsNull()) {
return TypedValue::Null;
return TypedValue();
}
if (list_value.type() != TypedValue::Type::List) {
throw QueryRuntimeException("EXTRACT expected a list, got {}.",
@ -408,7 +408,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
result.reserve(list.size());
for (const auto &element : list) {
if (element.IsNull()) {
result.push_back(TypedValue::Null);
result.emplace_back(TypedValue());
} else {
frame_->at(element_symbol) = element;
result.emplace_back(extract.expression_->Accept(*this));
@ -420,7 +420,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
TypedValue Visit(All &all) override {
auto list_value = all.list_expression_->Accept(*this);
if (list_value.IsNull()) {
return TypedValue::Null;
return TypedValue();
}
if (list_value.type() != TypedValue::Type::List) {
throw QueryRuntimeException("ALL expected a list, got {}.",
@ -446,7 +446,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
TypedValue Visit(Single &single) override {
auto list_value = single.list_expression_->Accept(*this);
if (list_value.IsNull()) {
return TypedValue::Null;
return TypedValue();
}
if (list_value.type() != TypedValue::Type::List) {
throw QueryRuntimeException("SINGLE expected a list, got {}.",
@ -484,7 +484,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
auto target_string_value = regex_match.string_expr_->Accept(*this);
auto regex_value = regex_match.regex_->Accept(*this);
if (target_string_value.IsNull() || regex_value.IsNull()) {
return TypedValue::Null;
return TypedValue();
}
if (regex_value.type() != TypedValue::Type::String) {
throw QueryRuntimeException(
@ -495,7 +495,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
// Instead of error, we return Null which makes it compatible in case we
// use indexed lookup which filters out any non-string properties.
// Assuming a property lookup is the target_string_value.
return TypedValue::Null;
return TypedValue();
}
const auto &target_string = target_string_value.ValueString();
try {

View File

@ -115,7 +115,7 @@ struct Callback {
TypedValue EvaluateOptionalExpression(Expression *expression,
ExpressionEvaluator *eval) {
return expression ? expression->Accept(*eval) : TypedValue::Null;
return expression ? expression->Accept(*eval) : TypedValue();
}
Callback HandleAuthQuery(AuthQuery *auth_query, auth::Auth *auth,

View File

@ -1637,7 +1637,7 @@ class ConstructNamedPathCursor : public Cursor {
// In an OPTIONAL MATCH everything could be Null.
if (start_vertex.IsNull()) {
frame[self_.path_symbol_] = TypedValue::Null;
frame[self_.path_symbol_] = TypedValue();
return true;
}
@ -1657,7 +1657,7 @@ class ConstructNamedPathCursor : public Cursor {
// list (variable expand or BFS).
switch (expansion.type()) {
case TypedValue::Type::Null:
frame[self_.path_symbol_] = TypedValue::Null;
frame[self_.path_symbol_] = TypedValue();
return true;
case TypedValue::Type::Vertex:
if (!last_was_edge_list) path.Expand(expansion.ValueVertex());
@ -2390,7 +2390,7 @@ TypedValue DefaultAggregationOpValue(const Aggregate::Element &element) {
case Aggregation::Op::MIN:
case Aggregation::Op::MAX:
case Aggregation::Op::AVG:
return TypedValue::Null;
return TypedValue();
case Aggregation::Op::COLLECT_LIST:
return TypedValue(std::vector<TypedValue>());
case Aggregation::Op::COLLECT_MAP:
@ -2423,7 +2423,7 @@ class AggregateCursor : public Cursor {
frame[elem.output_sym] = DefaultAggregationOpValue(elem);
// place null as remember values on the frame
for (const Symbol &remember_sym : self_.remember_)
frame[remember_sym] = TypedValue::Null;
frame[remember_sym] = TypedValue();
return true;
}
}
@ -3090,7 +3090,7 @@ bool Optional::OptionalCursor::Pull(Frame &frame, ExecutionContext &context) {
// optional symbols to Null, ensure next time the
// input gets pulled and return true
for (const Symbol &sym : self_.optional_symbols_)
frame[sym] = TypedValue::Null;
frame[sym] = TypedValue();
pull_input_ = true;
return true;
}

View File

@ -3,6 +3,7 @@
#include <optional>
#include "query/typed_value.hpp"
#include "storage/common/types/property_value.hpp"
#include "storage/common/types/types.hpp"
#include "utils/bound.hpp"
@ -85,8 +86,8 @@ class VertexCountCache {
size_t operator()(const BoundsKey &key) const {
const auto &maybe_lower = key.first;
const auto &maybe_upper = key.second;
query::TypedValue lower(query::TypedValue::Null);
query::TypedValue upper(query::TypedValue::Null);
query::TypedValue lower;
query::TypedValue upper;
if (maybe_lower) lower = maybe_lower->value();
if (maybe_upper) upper = maybe_upper->value();
query::TypedValue::Hash hash;
@ -101,8 +102,8 @@ class VertexCountCache {
if (maybe_bound_a && maybe_bound_b &&
maybe_bound_a->type() != maybe_bound_b->type())
return false;
query::TypedValue bound_a(query::TypedValue::Null);
query::TypedValue bound_b(query::TypedValue::Null);
query::TypedValue bound_a;
query::TypedValue bound_b;
if (maybe_bound_a) bound_a = maybe_bound_a->value();
if (maybe_bound_b) bound_b = maybe_bound_b->value();
return query::TypedValue::BoolEqual{}(bound_a, bound_b);

View File

@ -185,7 +185,7 @@ TypedValue::TypedValue(TypedValue &&other, utils::MemoryResource *memory)
new (&path_v) Path(std::move(other.path_v), memory_);
break;
}
other = TypedValue::Null;
other.DestroyValue();
}
TypedValue::operator PropertyValue() const {
@ -508,13 +508,11 @@ TypedValue &TypedValue::operator=(TypedValue &&other) noexcept(false) {
new (&path_v) Path(std::move(other.path_v), memory_);
break;
}
other = TypedValue::Null;
other.DestroyValue();
}
return *this;
}
const TypedValue TypedValue::Null = TypedValue();
void TypedValue::DestroyValue() {
switch (type_) {
// destructor for primitive types does nothing

View File

@ -94,11 +94,6 @@ class TypedValue {
explicit TypedValue(utils::MemoryResource *memory)
: memory_(memory), type_(Type::Null) {}
// single static reference to Null, used whenever Null should be returned
// TODO: Remove this as it may be needed to construct TypedValue with a
// different MemoryResource.
static const TypedValue Null;
/**
* Construct a copy of other.
* utils::MemoryResource is obtained by calling

View File

@ -381,7 +381,7 @@ TEST_P(CypherMainVisitorTest, NullLiteral) {
auto *single_query = query->single_query_;
auto *return_clause = dynamic_cast<Return *>(single_query->clauses_[0]);
ast_generator.CheckLiteral(
return_clause->body_.named_expressions[0]->expression_, TypedValue::Null,
return_clause->body_.named_expressions[0]->expression_, TypedValue(),
1);
}
@ -638,7 +638,7 @@ TEST_P(CypherMainVisitorTest, CaseGenericForm) {
auto *condition2 = dynamic_cast<GreaterOperator *>(if_operator2->condition_);
ASSERT_TRUE(condition2);
ast_generator.CheckLiteral(if_operator2->then_expression_, 2);
ast_generator.CheckLiteral(if_operator2->else_expression_, TypedValue::Null);
ast_generator.CheckLiteral(if_operator2->else_expression_, TypedValue());
}
TEST_P(CypherMainVisitorTest, CaseGenericFormElse) {
@ -672,7 +672,7 @@ TEST_P(CypherMainVisitorTest, CaseSimpleForm) {
ast_generator.CheckLiteral(condition->expression1_, 5);
ast_generator.CheckLiteral(condition->expression2_, 10);
ast_generator.CheckLiteral(if_operator->then_expression_, 1);
ast_generator.CheckLiteral(if_operator->else_expression_, TypedValue::Null);
ast_generator.CheckLiteral(if_operator->else_expression_, TypedValue());
}
TEST_P(CypherMainVisitorTest, IsNull) {
@ -2082,7 +2082,7 @@ TEST_P(CypherMainVisitorTest, CreateUser) {
AuthQuery::Action::CREATE_USER, "user", "", "", "", {});
check_auth_query(&ast_generator, "CREATE USER user IDENTIFIED BY null",
AuthQuery::Action::CREATE_USER, "user", "", "",
TypedValue::Null, {});
TypedValue(), {});
ASSERT_THROW(
ast_generator.ParseQuery("CRATE USER user IDENTIFIED BY password"),
SyntaxException);
@ -2099,7 +2099,7 @@ TEST_P(CypherMainVisitorTest, SetPassword) {
SyntaxException);
check_auth_query(&ast_generator, "SET PASSWORD FOR user TO null",
AuthQuery::Action::SET_PASSWORD, "user", "", "",
TypedValue::Null, {});
TypedValue(), {});
check_auth_query(&ast_generator, "SET PASSWORD FOR user TO 'password'",
AuthQuery::Action::SET_PASSWORD, "user", "", "", "password",
{});

View File

@ -226,13 +226,13 @@ class Database {
};
// Returns an operator that yields vertices given by their address. We will also
// include query::TypedValue::Null to account for the optional match case.
// include query::TypedValue() to account for the optional match case.
std::unique_ptr<query::plan::LogicalOperator> YieldVertices(
database::GraphDbAccessor *dba, std::vector<VertexAddress> vertices,
query::Symbol symbol,
std::shared_ptr<query::plan::LogicalOperator> input_op) {
std::vector<std::vector<query::TypedValue>> frames;
frames.push_back(std::vector<query::TypedValue>{query::TypedValue::Null});
frames.push_back(std::vector<query::TypedValue>{query::TypedValue()});
for (const auto &vertex : vertices) {
frames.push_back(
std::vector<query::TypedValue>{VertexAccessor(vertex, *dba)});
@ -349,7 +349,7 @@ void BfsTest(Database *db, int lower_bound, int upper_bound,
input_op = std::make_shared<Yield>(
nullptr, std::vector<query::Symbol>{blocked_sym},
std::vector<std::vector<query::TypedValue>>{
{query::TypedValue::Null}});
{query::TypedValue()}});
filter_expr = nullptr;
break;
case FilterLambdaType::USE_FRAME:

View File

@ -450,7 +450,7 @@ TEST_P(CypherMainVisitorTest, NullLiteral) {
auto *single_query = query->single_query_;
auto *return_clause = dynamic_cast<Return *>(single_query->clauses_[0]);
ast_generator.CheckLiteral(
return_clause->body_.named_expressions[0]->expression_, TypedValue::Null,
return_clause->body_.named_expressions[0]->expression_, TypedValue(),
1);
}
@ -707,7 +707,7 @@ TEST_P(CypherMainVisitorTest, CaseGenericForm) {
auto *condition2 = dynamic_cast<GreaterOperator *>(if_operator2->condition_);
ASSERT_TRUE(condition2);
ast_generator.CheckLiteral(if_operator2->then_expression_, 2);
ast_generator.CheckLiteral(if_operator2->else_expression_, TypedValue::Null);
ast_generator.CheckLiteral(if_operator2->else_expression_, TypedValue());
}
TEST_P(CypherMainVisitorTest, CaseGenericFormElse) {
@ -741,7 +741,7 @@ TEST_P(CypherMainVisitorTest, CaseSimpleForm) {
ast_generator.CheckLiteral(condition->expression1_, 5);
ast_generator.CheckLiteral(condition->expression2_, 10);
ast_generator.CheckLiteral(if_operator->then_expression_, 1);
ast_generator.CheckLiteral(if_operator->else_expression_, TypedValue::Null);
ast_generator.CheckLiteral(if_operator->else_expression_, TypedValue());
}
TEST_P(CypherMainVisitorTest, IsNull) {
@ -2186,7 +2186,7 @@ TEST_P(CypherMainVisitorTest, CreateUser) {
AuthQuery::Action::CREATE_USER, "user", "", "", "", {});
check_auth_query(&ast_generator, "CREATE USER user IDENTIFIED BY null",
AuthQuery::Action::CREATE_USER, "user", "", "",
TypedValue::Null, {});
TypedValue(), {});
ASSERT_THROW(
ast_generator.ParseQuery("CRATE USER user IDENTIFIED BY password"),
SyntaxException);
@ -2203,7 +2203,7 @@ TEST_P(CypherMainVisitorTest, SetPassword) {
SyntaxException);
check_auth_query(&ast_generator, "SET PASSWORD FOR user TO null",
AuthQuery::Action::SET_PASSWORD, "user", "", "",
TypedValue::Null, {});
TypedValue(), {});
check_auth_query(&ast_generator, "SET PASSWORD FOR user TO 'password'",
AuthQuery::Action::SET_PASSWORD, "user", "", "", "password",
{});

View File

@ -648,7 +648,7 @@ TEST_F(ExpressionEvaluatorTest, LabelsTest) {
EXPECT_EQ(value.ValueBool(), false);
}
{
frame[node_symbol] = TypedValue::Null;
frame[node_symbol] = TypedValue();
auto *op = storage.Create<LabelsTest>(
identifier, std::vector<LabelIx>{storage.GetLabelIx("DOG"),
storage.GetLabelIx("BAD_DOG"),
@ -822,33 +822,33 @@ TEST_F(ExpressionEvaluatorTest, Coalesce) {
// coalesce(null, null)
EXPECT_TRUE(
Eval(COALESCE(LITERAL(TypedValue::Null), LITERAL(TypedValue::Null)))
Eval(COALESCE(LITERAL(TypedValue()), LITERAL(TypedValue())))
.IsNull());
// coalesce(null, 2, 3)
EXPECT_EQ(Eval(COALESCE(LITERAL(TypedValue::Null), LITERAL(2), LITERAL(3)))
EXPECT_EQ(Eval(COALESCE(LITERAL(TypedValue()), LITERAL(2), LITERAL(3)))
.ValueInt(),
2);
// coalesce(null, 2, assert(false), 3)
EXPECT_EQ(Eval(COALESCE(LITERAL(TypedValue::Null), LITERAL(2),
EXPECT_EQ(Eval(COALESCE(LITERAL(TypedValue()), LITERAL(2),
FN("ASSERT", LITERAL(false)), LITERAL(3)))
.ValueInt(),
2);
// (null, assert(false))
EXPECT_THROW(
Eval(COALESCE(LITERAL(TypedValue::Null), FN("ASSERT", LITERAL(false)))),
Eval(COALESCE(LITERAL(TypedValue()), FN("ASSERT", LITERAL(false)))),
QueryRuntimeException);
// coalesce([null, null])
EXPECT_FALSE(Eval(COALESCE(LITERAL(TypedValue(std::vector<TypedValue>{
TypedValue::Null, TypedValue::Null}))))
TypedValue(), TypedValue()}))))
.IsNull());
}
TEST_F(ExpressionEvaluatorTest, RegexMatchInvalidArguments) {
EXPECT_TRUE(Eval(storage.Create<RegexMatch>(LITERAL(TypedValue::Null),
EXPECT_TRUE(Eval(storage.Create<RegexMatch>(LITERAL(TypedValue()),
LITERAL("regex")))
.IsNull());
EXPECT_TRUE(
@ -857,7 +857,7 @@ TEST_F(ExpressionEvaluatorTest, RegexMatchInvalidArguments) {
LITERAL("regex")))
.IsNull());
EXPECT_TRUE(Eval(storage.Create<RegexMatch>(LITERAL("string"),
LITERAL(TypedValue::Null)))
LITERAL(TypedValue())))
.IsNull());
EXPECT_THROW(Eval(storage.Create<RegexMatch>(LITERAL("string"), LITERAL(42))),
QueryRuntimeException);
@ -927,7 +927,7 @@ TEST_F(ExpressionEvaluatorPropertyLookup, Edge) {
}
TEST_F(ExpressionEvaluatorPropertyLookup, Null) {
frame[symbol] = TypedValue::Null;
frame[symbol] = TypedValue();
EXPECT_TRUE(Value(prop_age).IsNull());
}
@ -972,7 +972,7 @@ class FunctionTest : public ExpressionEvaluatorTest {
TEST_F(FunctionTest, EndNode) {
ASSERT_THROW(EvaluateFunction("ENDNODE", {}), QueryRuntimeException);
ASSERT_TRUE(EvaluateFunction("ENDNODE", {TypedValue::Null}).IsNull());
ASSERT_TRUE(EvaluateFunction("ENDNODE", {TypedValue()}).IsNull());
auto v1 = dba.InsertVertex();
v1.add_label(dba.Label("label1"));
auto v2 = dba.InsertVertex();
@ -986,7 +986,7 @@ TEST_F(FunctionTest, EndNode) {
TEST_F(FunctionTest, Head) {
ASSERT_THROW(EvaluateFunction("HEAD", {}), QueryRuntimeException);
ASSERT_TRUE(EvaluateFunction("HEAD", {TypedValue::Null}).IsNull());
ASSERT_TRUE(EvaluateFunction("HEAD", {TypedValue()}).IsNull());
std::vector<TypedValue> arguments;
arguments.push_back(std::vector<TypedValue>{3, 4, 5});
ASSERT_EQ(EvaluateFunction("HEAD", arguments).ValueInt(), 3);
@ -997,7 +997,7 @@ TEST_F(FunctionTest, Head) {
TEST_F(FunctionTest, Properties) {
ASSERT_THROW(EvaluateFunction("PROPERTIES", {}), QueryRuntimeException);
ASSERT_TRUE(EvaluateFunction("PROPERTIES", {TypedValue::Null}).IsNull());
ASSERT_TRUE(EvaluateFunction("PROPERTIES", {TypedValue()}).IsNull());
auto v1 = dba.InsertVertex();
v1.PropsSet(dba.Property("height"), 5);
v1.PropsSet(dba.Property("age"), 10);
@ -1025,7 +1025,7 @@ TEST_F(FunctionTest, Properties) {
TEST_F(FunctionTest, Last) {
ASSERT_THROW(EvaluateFunction("LAST", {}), QueryRuntimeException);
ASSERT_TRUE(EvaluateFunction("LAST", {TypedValue::Null}).IsNull());
ASSERT_TRUE(EvaluateFunction("LAST", {TypedValue()}).IsNull());
std::vector<TypedValue> arguments;
arguments.push_back(std::vector<TypedValue>{3, 4, 5});
ASSERT_EQ(EvaluateFunction("LAST", arguments).ValueInt(), 5);
@ -1036,7 +1036,7 @@ TEST_F(FunctionTest, Last) {
TEST_F(FunctionTest, Size) {
ASSERT_THROW(EvaluateFunction("SIZE", {}), QueryRuntimeException);
ASSERT_TRUE(EvaluateFunction("SIZE", {TypedValue::Null}).IsNull());
ASSERT_TRUE(EvaluateFunction("SIZE", {TypedValue()}).IsNull());
std::vector<TypedValue> arguments;
arguments.push_back(std::vector<TypedValue>{3, 4, 5});
ASSERT_EQ(EvaluateFunction("SIZE", arguments).ValueInt(), 3);
@ -1058,7 +1058,7 @@ TEST_F(FunctionTest, Size) {
TEST_F(FunctionTest, StartNode) {
ASSERT_THROW(EvaluateFunction("STARTNODE", {}), QueryRuntimeException);
ASSERT_TRUE(EvaluateFunction("STARTNODE", {TypedValue::Null}).IsNull());
ASSERT_TRUE(EvaluateFunction("STARTNODE", {TypedValue()}).IsNull());
auto v1 = dba.InsertVertex();
v1.add_label(dba.Label("label1"));
auto v2 = dba.InsertVertex();
@ -1072,7 +1072,7 @@ TEST_F(FunctionTest, StartNode) {
TEST_F(FunctionTest, Degree) {
ASSERT_THROW(EvaluateFunction("DEGREE", {}), QueryRuntimeException);
ASSERT_TRUE(EvaluateFunction("DEGREE", {TypedValue::Null}).IsNull());
ASSERT_TRUE(EvaluateFunction("DEGREE", {TypedValue()}).IsNull());
auto v1 = dba.InsertVertex();
auto v2 = dba.InsertVertex();
auto v3 = dba.InsertVertex();
@ -1087,7 +1087,7 @@ TEST_F(FunctionTest, Degree) {
TEST_F(FunctionTest, InDegree) {
ASSERT_THROW(EvaluateFunction("INDEGREE", {}), QueryRuntimeException);
ASSERT_TRUE(EvaluateFunction("INDEGREE", {TypedValue::Null}).IsNull());
ASSERT_TRUE(EvaluateFunction("INDEGREE", {TypedValue()}).IsNull());
auto v1 = dba.InsertVertex();
auto v2 = dba.InsertVertex();
auto v3 = dba.InsertVertex();
@ -1102,7 +1102,7 @@ TEST_F(FunctionTest, InDegree) {
TEST_F(FunctionTest, OutDegree) {
ASSERT_THROW(EvaluateFunction("OUTDEGREE", {}), QueryRuntimeException);
ASSERT_TRUE(EvaluateFunction("OUTDEGREE", {TypedValue::Null}).IsNull());
ASSERT_TRUE(EvaluateFunction("OUTDEGREE", {TypedValue()}).IsNull());
auto v1 = dba.InsertVertex();
auto v2 = dba.InsertVertex();
auto v3 = dba.InsertVertex();
@ -1117,7 +1117,7 @@ TEST_F(FunctionTest, OutDegree) {
TEST_F(FunctionTest, ToBoolean) {
ASSERT_THROW(EvaluateFunction("TOBOOLEAN", {}), QueryRuntimeException);
ASSERT_TRUE(EvaluateFunction("TOBOOLEAN", {TypedValue::Null}).IsNull());
ASSERT_TRUE(EvaluateFunction("TOBOOLEAN", {TypedValue()}).IsNull());
ASSERT_EQ(EvaluateFunction("TOBOOLEAN", {123}).ValueBool(), true);
ASSERT_EQ(EvaluateFunction("TOBOOLEAN", {-213}).ValueBool(), true);
ASSERT_EQ(EvaluateFunction("TOBOOLEAN", {0}).ValueBool(), false);
@ -1130,7 +1130,7 @@ TEST_F(FunctionTest, ToBoolean) {
TEST_F(FunctionTest, ToFloat) {
ASSERT_THROW(EvaluateFunction("TOFLOAT", {}), QueryRuntimeException);
ASSERT_TRUE(EvaluateFunction("TOFLOAT", {TypedValue::Null}).IsNull());
ASSERT_TRUE(EvaluateFunction("TOFLOAT", {TypedValue()}).IsNull());
ASSERT_EQ(EvaluateFunction("TOFLOAT", {" -3.5 \n\t"}).ValueDouble(), -3.5);
ASSERT_EQ(EvaluateFunction("TOFLOAT", {"\n\t0.5e-1"}).ValueDouble(), 0.05);
ASSERT_TRUE(EvaluateFunction("TOFLOAT", {"\n\t3.4e-3X "}).IsNull());
@ -1141,7 +1141,7 @@ TEST_F(FunctionTest, ToFloat) {
TEST_F(FunctionTest, ToInteger) {
ASSERT_THROW(EvaluateFunction("TOINTEGER", {}), QueryRuntimeException);
ASSERT_TRUE(EvaluateFunction("TOINTEGER", {TypedValue::Null}).IsNull());
ASSERT_TRUE(EvaluateFunction("TOINTEGER", {TypedValue()}).IsNull());
ASSERT_EQ(EvaluateFunction("TOINTEGER", {false}).ValueInt(), 0);
ASSERT_EQ(EvaluateFunction("TOINTEGER", {true}).ValueInt(), 1);
ASSERT_EQ(EvaluateFunction("TOINTEGER", {"\n\t3"}).ValueInt(), 3);
@ -1153,7 +1153,7 @@ TEST_F(FunctionTest, ToInteger) {
TEST_F(FunctionTest, Type) {
ASSERT_THROW(EvaluateFunction("TYPE", {}), QueryRuntimeException);
ASSERT_TRUE(EvaluateFunction("TYPE", {TypedValue::Null}).IsNull());
ASSERT_TRUE(EvaluateFunction("TYPE", {TypedValue()}).IsNull());
auto v1 = dba.InsertVertex();
v1.add_label(dba.Label("label1"));
auto v2 = dba.InsertVertex();
@ -1165,7 +1165,7 @@ TEST_F(FunctionTest, Type) {
TEST_F(FunctionTest, Labels) {
ASSERT_THROW(EvaluateFunction("LABELS", {}), QueryRuntimeException);
ASSERT_TRUE(EvaluateFunction("LABELS", {TypedValue::Null}).IsNull());
ASSERT_TRUE(EvaluateFunction("LABELS", {TypedValue()}).IsNull());
auto v = dba.InsertVertex();
v.add_label(dba.Label("label1"));
v.add_label(dba.Label("label2"));
@ -1182,8 +1182,8 @@ TEST_F(FunctionTest, Labels) {
TEST_F(FunctionTest, NodesRelationships) {
EXPECT_THROW(EvaluateFunction("NODES", {}), QueryRuntimeException);
EXPECT_THROW(EvaluateFunction("RELATIONSHIPS", {}), QueryRuntimeException);
EXPECT_TRUE(EvaluateFunction("NODES", {TypedValue::Null}).IsNull());
EXPECT_TRUE(EvaluateFunction("RELATIONSHIPS", {TypedValue::Null}).IsNull());
EXPECT_TRUE(EvaluateFunction("NODES", {TypedValue()}).IsNull());
EXPECT_TRUE(EvaluateFunction("RELATIONSHIPS", {TypedValue()}).IsNull());
{
auto v1 = dba.InsertVertex();
@ -1214,8 +1214,8 @@ TEST_F(FunctionTest, NodesRelationships) {
TEST_F(FunctionTest, Range) {
EXPECT_THROW(EvaluateFunction("RANGE", {}), QueryRuntimeException);
EXPECT_TRUE(EvaluateFunction("RANGE", {1, 2, TypedValue::Null}).IsNull());
EXPECT_THROW(EvaluateFunction("RANGE", {1, TypedValue::Null, 1.3}),
EXPECT_TRUE(EvaluateFunction("RANGE", {1, 2, TypedValue()}).IsNull());
EXPECT_THROW(EvaluateFunction("RANGE", {1, TypedValue(), 1.3}),
QueryRuntimeException);
EXPECT_THROW(EvaluateFunction("RANGE", {1, 2, 0}), QueryRuntimeException);
EXPECT_THAT(ToList<int64_t>(EvaluateFunction("RANGE", {1, 3})),
@ -1240,7 +1240,7 @@ TEST_F(FunctionTest, Range) {
TEST_F(FunctionTest, Keys) {
ASSERT_THROW(EvaluateFunction("KEYS", {}), QueryRuntimeException);
ASSERT_TRUE(EvaluateFunction("KEYS", {TypedValue::Null}).IsNull());
ASSERT_TRUE(EvaluateFunction("KEYS", {TypedValue()}).IsNull());
auto v1 = dba.InsertVertex();
v1.PropsSet(dba.Property("height"), 5);
v1.PropsSet(dba.Property("age"), 10);
@ -1265,7 +1265,7 @@ TEST_F(FunctionTest, Keys) {
TEST_F(FunctionTest, Tail) {
ASSERT_THROW(EvaluateFunction("TAIL", {}), QueryRuntimeException);
ASSERT_TRUE(EvaluateFunction("TAIL", {TypedValue::Null}).IsNull());
ASSERT_TRUE(EvaluateFunction("TAIL", {TypedValue()}).IsNull());
std::vector<TypedValue> arguments;
arguments.push_back(std::vector<TypedValue>{});
ASSERT_EQ(EvaluateFunction("TAIL", arguments).ValueList().size(), 0U);
@ -1281,12 +1281,12 @@ TEST_F(FunctionTest, Tail) {
TEST_F(FunctionTest, UniformSample) {
ASSERT_THROW(EvaluateFunction("UNIFORMSAMPLE", {}), QueryRuntimeException);
ASSERT_TRUE(
EvaluateFunction("UNIFORMSAMPLE", {TypedValue::Null, TypedValue::Null})
EvaluateFunction("UNIFORMSAMPLE", {TypedValue(), TypedValue()})
.IsNull());
ASSERT_TRUE(
EvaluateFunction("UNIFORMSAMPLE", {TypedValue::Null, 1}).IsNull());
EvaluateFunction("UNIFORMSAMPLE", {TypedValue(), 1}).IsNull());
ASSERT_THROW(EvaluateFunction("UNIFORMSAMPLE",
{std::vector<TypedValue>{}, TypedValue::Null}),
{std::vector<TypedValue>{}, TypedValue()}),
QueryRuntimeException);
ASSERT_TRUE(EvaluateFunction("UNIFORMSAMPLE", {std::vector<TypedValue>{}, 1})
.IsNull());
@ -1317,7 +1317,7 @@ TEST_F(FunctionTest, UniformSample) {
TEST_F(FunctionTest, Abs) {
ASSERT_THROW(EvaluateFunction("ABS", {}), QueryRuntimeException);
ASSERT_TRUE(EvaluateFunction("ABS", {TypedValue::Null}).IsNull());
ASSERT_TRUE(EvaluateFunction("ABS", {TypedValue()}).IsNull());
ASSERT_EQ(EvaluateFunction("ABS", {-2}).ValueInt(), 2);
ASSERT_EQ(EvaluateFunction("ABS", {-2.5}).ValueDouble(), 2.5);
ASSERT_THROW(EvaluateFunction("ABS", {true}), QueryRuntimeException);
@ -1328,7 +1328,7 @@ TEST_F(FunctionTest, Abs) {
// correctnes..
TEST_F(FunctionTest, Log) {
ASSERT_THROW(EvaluateFunction("LOG", {}), QueryRuntimeException);
ASSERT_TRUE(EvaluateFunction("LOG", {TypedValue::Null}).IsNull());
ASSERT_TRUE(EvaluateFunction("LOG", {TypedValue()}).IsNull());
ASSERT_DOUBLE_EQ(EvaluateFunction("LOG", {2}).ValueDouble(), log(2));
ASSERT_DOUBLE_EQ(EvaluateFunction("LOG", {1.5}).ValueDouble(), log(1.5));
// Not portable, but should work on most platforms.
@ -1341,7 +1341,7 @@ TEST_F(FunctionTest, Log) {
// neo4j's round.
TEST_F(FunctionTest, Round) {
ASSERT_THROW(EvaluateFunction("ROUND", {}), QueryRuntimeException);
ASSERT_TRUE(EvaluateFunction("ROUND", {TypedValue::Null}).IsNull());
ASSERT_TRUE(EvaluateFunction("ROUND", {TypedValue()}).IsNull());
ASSERT_EQ(EvaluateFunction("ROUND", {-2}).ValueDouble(), -2);
ASSERT_EQ(EvaluateFunction("ROUND", {-2.4}).ValueDouble(), -2);
ASSERT_EQ(EvaluateFunction("ROUND", {-2.5}).ValueDouble(), -3);
@ -1365,8 +1365,8 @@ TEST_F(FunctionTest, WrappedMathFunctions) {
TEST_F(FunctionTest, Atan2) {
ASSERT_THROW(EvaluateFunction("ATAN2", {}), QueryRuntimeException);
ASSERT_TRUE(EvaluateFunction("ATAN2", {TypedValue::Null, 1}).IsNull());
ASSERT_TRUE(EvaluateFunction("ATAN2", {1, TypedValue::Null}).IsNull());
ASSERT_TRUE(EvaluateFunction("ATAN2", {TypedValue(), 1}).IsNull());
ASSERT_TRUE(EvaluateFunction("ATAN2", {1, TypedValue()}).IsNull());
ASSERT_DOUBLE_EQ(EvaluateFunction("ATAN2", {2, -1.0}).ValueDouble(),
atan2(2, -1));
ASSERT_THROW(EvaluateFunction("ATAN2", {3.0, true}), QueryRuntimeException);
@ -1374,7 +1374,7 @@ TEST_F(FunctionTest, Atan2) {
TEST_F(FunctionTest, Sign) {
ASSERT_THROW(EvaluateFunction("SIGN", {}), QueryRuntimeException);
ASSERT_TRUE(EvaluateFunction("SIGN", {TypedValue::Null}).IsNull());
ASSERT_TRUE(EvaluateFunction("SIGN", {TypedValue()}).IsNull());
ASSERT_EQ(EvaluateFunction("SIGN", {-2}).ValueInt(), -1);
ASSERT_EQ(EvaluateFunction("SIGN", {-0.2}).ValueInt(), -1);
ASSERT_EQ(EvaluateFunction("SIGN", {0.0}).ValueInt(), 0);
@ -1400,8 +1400,8 @@ TEST_F(FunctionTest, Rand) {
TEST_F(FunctionTest, StartsWith) {
EXPECT_THROW(EvaluateFunction(kStartsWith, {}), QueryRuntimeException);
EXPECT_TRUE(EvaluateFunction(kStartsWith, {"a", TypedValue::Null}).IsNull());
EXPECT_THROW(EvaluateFunction(kStartsWith, {TypedValue::Null, 1.3}),
EXPECT_TRUE(EvaluateFunction(kStartsWith, {"a", TypedValue()}).IsNull());
EXPECT_THROW(EvaluateFunction(kStartsWith, {TypedValue(), 1.3}),
QueryRuntimeException);
EXPECT_TRUE(EvaluateFunction(kStartsWith, {"abc", "abc"}).ValueBool());
EXPECT_TRUE(EvaluateFunction(kStartsWith, {"abcdef", "abc"}).ValueBool());
@ -1411,8 +1411,8 @@ TEST_F(FunctionTest, StartsWith) {
TEST_F(FunctionTest, EndsWith) {
EXPECT_THROW(EvaluateFunction(kEndsWith, {}), QueryRuntimeException);
EXPECT_TRUE(EvaluateFunction(kEndsWith, {"a", TypedValue::Null}).IsNull());
EXPECT_THROW(EvaluateFunction(kEndsWith, {TypedValue::Null, 1.3}),
EXPECT_TRUE(EvaluateFunction(kEndsWith, {"a", TypedValue()}).IsNull());
EXPECT_THROW(EvaluateFunction(kEndsWith, {TypedValue(), 1.3}),
QueryRuntimeException);
EXPECT_TRUE(EvaluateFunction(kEndsWith, {"abc", "abc"}).ValueBool());
EXPECT_TRUE(EvaluateFunction(kEndsWith, {"abcdef", "def"}).ValueBool());
@ -1422,8 +1422,8 @@ TEST_F(FunctionTest, EndsWith) {
TEST_F(FunctionTest, Contains) {
EXPECT_THROW(EvaluateFunction(kContains, {}), QueryRuntimeException);
EXPECT_TRUE(EvaluateFunction(kContains, {"a", TypedValue::Null}).IsNull());
EXPECT_THROW(EvaluateFunction(kContains, {TypedValue::Null, 1.3}),
EXPECT_TRUE(EvaluateFunction(kContains, {"a", TypedValue()}).IsNull());
EXPECT_THROW(EvaluateFunction(kContains, {TypedValue(), 1.3}),
QueryRuntimeException);
EXPECT_TRUE(EvaluateFunction(kContains, {"abc", "abc"}).ValueBool());
EXPECT_TRUE(EvaluateFunction(kContains, {"abcde", "bcd"}).ValueBool());
@ -1509,7 +1509,7 @@ TEST_F(FunctionTest, WorkerIdSingleNode) {
*/
TEST_F(FunctionTest, ToStringNull) {
EXPECT_TRUE(EvaluateFunction("TOSTRING", {TypedValue::Null}).IsNull());
EXPECT_TRUE(EvaluateFunction("TOSTRING", {TypedValue()}).IsNull());
}
TEST_F(FunctionTest, ToStringString) {
@ -1558,9 +1558,9 @@ TEST_F(FunctionTest, Left) {
EXPECT_THROW(EvaluateFunction("LEFT", {}), QueryRuntimeException);
EXPECT_TRUE(
EvaluateFunction("LEFT", {TypedValue::Null, TypedValue::Null}).IsNull());
EXPECT_TRUE(EvaluateFunction("LEFT", {TypedValue::Null, 10}).IsNull());
EXPECT_THROW(EvaluateFunction("LEFT", {TypedValue::Null, -10}),
EvaluateFunction("LEFT", {TypedValue(), TypedValue()}).IsNull());
EXPECT_TRUE(EvaluateFunction("LEFT", {TypedValue(), 10}).IsNull());
EXPECT_THROW(EvaluateFunction("LEFT", {TypedValue(), -10}),
QueryRuntimeException);
EXPECT_EQ(EvaluateFunction("LEFT", {"memgraph", 0}).ValueString(), "");
@ -1579,9 +1579,9 @@ TEST_F(FunctionTest, Right) {
EXPECT_THROW(EvaluateFunction("RIGHT", {}), QueryRuntimeException);
EXPECT_TRUE(
EvaluateFunction("RIGHT", {TypedValue::Null, TypedValue::Null}).IsNull());
EXPECT_TRUE(EvaluateFunction("RIGHT", {TypedValue::Null, 10}).IsNull());
EXPECT_THROW(EvaluateFunction("RIGHT", {TypedValue::Null, -10}),
EvaluateFunction("RIGHT", {TypedValue(), TypedValue()}).IsNull());
EXPECT_TRUE(EvaluateFunction("RIGHT", {TypedValue(), 10}).IsNull());
EXPECT_THROW(EvaluateFunction("RIGHT", {TypedValue(), -10}),
QueryRuntimeException);
EXPECT_EQ(EvaluateFunction("RIGHT", {"memgraph", 0}).ValueString(), "");
@ -1597,9 +1597,9 @@ TEST_F(FunctionTest, Right) {
}
TEST_F(FunctionTest, Trimming) {
EXPECT_TRUE(EvaluateFunction("LTRIM", {TypedValue::Null}).IsNull());
EXPECT_TRUE(EvaluateFunction("RTRIM", {TypedValue::Null}).IsNull());
EXPECT_TRUE(EvaluateFunction("TRIM", {TypedValue::Null}).IsNull());
EXPECT_TRUE(EvaluateFunction("LTRIM", {TypedValue()}).IsNull());
EXPECT_TRUE(EvaluateFunction("RTRIM", {TypedValue()}).IsNull());
EXPECT_TRUE(EvaluateFunction("TRIM", {TypedValue()}).IsNull());
EXPECT_EQ(EvaluateFunction("LTRIM", {" abc "}).ValueString(), "abc ");
EXPECT_EQ(EvaluateFunction("RTRIM", {" abc "}).ValueString(), " abc");
@ -1611,7 +1611,7 @@ TEST_F(FunctionTest, Trimming) {
}
TEST_F(FunctionTest, Reverse) {
EXPECT_TRUE(EvaluateFunction("REVERSE", {TypedValue::Null}).IsNull());
EXPECT_TRUE(EvaluateFunction("REVERSE", {TypedValue()}).IsNull());
EXPECT_EQ(EvaluateFunction("REVERSE", {"abc"}).ValueString(), "cba");
EXPECT_THROW(EvaluateFunction("REVERSE", {"x", "y"}), QueryRuntimeException);
}
@ -1619,11 +1619,11 @@ TEST_F(FunctionTest, Reverse) {
TEST_F(FunctionTest, Replace) {
EXPECT_THROW(EvaluateFunction("REPLACE", {}), QueryRuntimeException);
EXPECT_TRUE(
EvaluateFunction("REPLACE", {TypedValue::Null, "l", "w"}).IsNull());
EvaluateFunction("REPLACE", {TypedValue(), "l", "w"}).IsNull());
EXPECT_TRUE(
EvaluateFunction("REPLACE", {"hello", TypedValue::Null, "w"}).IsNull());
EvaluateFunction("REPLACE", {"hello", TypedValue(), "w"}).IsNull());
EXPECT_TRUE(
EvaluateFunction("REPLACE", {"hello", "l", TypedValue::Null}).IsNull());
EvaluateFunction("REPLACE", {"hello", "l", TypedValue()}).IsNull());
EXPECT_EQ(EvaluateFunction("REPLACE", {"hello", "l", "w"}).ValueString(),
"hewwo");
@ -1643,10 +1643,10 @@ TEST_F(FunctionTest, Split) {
QueryRuntimeException);
EXPECT_TRUE(
EvaluateFunction("SPLIT", {TypedValue::Null, TypedValue::Null}).IsNull());
EvaluateFunction("SPLIT", {TypedValue(), TypedValue()}).IsNull());
EXPECT_TRUE(
EvaluateFunction("SPLIT", {"one,two", TypedValue::Null}).IsNull());
EXPECT_TRUE(EvaluateFunction("SPLIT", {TypedValue::Null, ","}).IsNull());
EvaluateFunction("SPLIT", {"one,two", TypedValue()}).IsNull());
EXPECT_TRUE(EvaluateFunction("SPLIT", {TypedValue(), ","}).IsNull());
auto result = EvaluateFunction("SPLIT", {"one,two", ","});
EXPECT_TRUE(result.IsList());
@ -1658,16 +1658,16 @@ TEST_F(FunctionTest, Substring) {
EXPECT_THROW(EvaluateFunction("SUBSTRING", {}), QueryRuntimeException);
EXPECT_TRUE(
EvaluateFunction("SUBSTRING", {TypedValue::Null, 0, 10}).IsNull());
EvaluateFunction("SUBSTRING", {TypedValue(), 0, 10}).IsNull());
EXPECT_THROW(
EvaluateFunction("SUBSTRING", {TypedValue::Null, TypedValue::Null}),
EvaluateFunction("SUBSTRING", {TypedValue(), TypedValue()}),
QueryRuntimeException);
EXPECT_THROW(EvaluateFunction("SUBSTRING", {TypedValue::Null, -10}),
EXPECT_THROW(EvaluateFunction("SUBSTRING", {TypedValue(), -10}),
QueryRuntimeException);
EXPECT_THROW(
EvaluateFunction("SUBSTRING", {TypedValue::Null, 0, TypedValue::Null}),
EvaluateFunction("SUBSTRING", {TypedValue(), 0, TypedValue()}),
QueryRuntimeException);
EXPECT_THROW(EvaluateFunction("SUBSTRING", {TypedValue::Null, 0, -10}),
EXPECT_THROW(EvaluateFunction("SUBSTRING", {TypedValue(), 0, -10}),
QueryRuntimeException);
EXPECT_EQ(EvaluateFunction("SUBSTRING", {"hello", 2}).ValueString(), "llo");
@ -1683,13 +1683,13 @@ TEST_F(FunctionTest, Substring) {
TEST_F(FunctionTest, ToLower) {
EXPECT_THROW(EvaluateFunction("TOLOWER", {}), QueryRuntimeException);
EXPECT_TRUE(EvaluateFunction("TOLOWER", {TypedValue::Null}).IsNull());
EXPECT_TRUE(EvaluateFunction("TOLOWER", {TypedValue()}).IsNull());
EXPECT_EQ(EvaluateFunction("TOLOWER", {"Ab__C"}).ValueString(), "ab__c");
}
TEST_F(FunctionTest, ToUpper) {
EXPECT_THROW(EvaluateFunction("TOUPPER", {}), QueryRuntimeException);
EXPECT_TRUE(EvaluateFunction("TOUPPER", {TypedValue::Null}).IsNull());
EXPECT_TRUE(EvaluateFunction("TOUPPER", {TypedValue()}).IsNull());
EXPECT_EQ(EvaluateFunction("TOUPPER", {"Ab__C"}).ValueString(), "AB__C");
}

View File

@ -411,7 +411,7 @@ TEST(QueryPlan, DeleteNull) {
auto once = std::make_shared<Once>();
auto delete_op = std::make_shared<plan::Delete>(
once, std::vector<Expression *>{LITERAL(TypedValue::Null)}, false);
once, std::vector<Expression *>{LITERAL(TypedValue())}, false);
auto context = MakeContext(storage, symbol_table, &dba);
EXPECT_EQ(1, PullAll(*delete_op, &context));
}
@ -861,7 +861,7 @@ TEST(QueryPlan, SetPropertyOnNull) {
AstStorage storage;
SymbolTable symbol_table;
auto prop = PROPERTY_PAIR("property");
auto null = LITERAL(TypedValue::Null);
auto null = LITERAL(TypedValue());
auto literal = LITERAL(42);
auto n_prop = PROPERTY_LOOKUP(null, prop);
auto once = std::make_shared<Once>();
@ -912,7 +912,7 @@ TEST(QueryPlan, RemovePropertyOnNull) {
AstStorage storage;
SymbolTable symbol_table;
auto prop = PROPERTY_PAIR("property");
auto null = LITERAL(TypedValue::Null);
auto null = LITERAL(TypedValue());
auto n_prop = PROPERTY_LOOKUP(null, prop);
auto once = std::make_shared<Once>();
auto remove_op =

View File

@ -1545,8 +1545,8 @@ TEST(QueryPlan, Distinct) {
check_distinct({1, 1, 2, 3, 3, 3}, {1, 2, 3}, true);
check_distinct({3, 2, 3, 5, 3, 5, 2, 1, 2}, {3, 2, 5, 1}, true);
check_distinct(
{3, "two", TypedValue::Null, 3, true, false, "TWO", TypedValue::Null},
{3, "two", TypedValue::Null, true, false, "TWO"}, false);
{3, "two", TypedValue(), 3, true, false, "TWO", TypedValue()},
{3, "two", TypedValue(), true, false, "TWO"}, false);
}
TEST(QueryPlan, ScanAllByLabel) {
@ -1786,7 +1786,7 @@ TEST(QueryPlan, ScanAllByLabelPropertyEqualNull) {
SymbolTable symbol_table;
auto scan_all =
MakeScanAllByLabelPropertyValue(storage, symbol_table, "n", label, prop,
"prop", LITERAL(TypedValue::Null));
"prop", LITERAL(TypedValue()));
// RETURN n
auto output = NEXPR("n", IDENT("n")->MapTo(scan_all.sym_))
->MapTo(symbol_table.CreateSymbol("n", true));
@ -1820,8 +1820,8 @@ TEST(QueryPlan, ScanAllByLabelPropertyRangeNull) {
SymbolTable symbol_table;
auto scan_all = MakeScanAllByLabelPropertyRange(
storage, symbol_table, "n", label, prop, "prop",
Bound{LITERAL(TypedValue::Null), Bound::Type::INCLUSIVE},
Bound{LITERAL(TypedValue::Null), Bound::Type::EXCLUSIVE});
Bound{LITERAL(TypedValue()), Bound::Type::INCLUSIVE},
Bound{LITERAL(TypedValue()), Bound::Type::EXCLUSIVE});
// RETURN n
auto output = NEXPR("n", IDENT("n")->MapTo(scan_all.sym_))
->MapTo(symbol_table.CreateSymbol("n", true));

View File

@ -33,7 +33,7 @@ TEST_F(ExpressionPrettyPrinterTest, Literals) {
EXPECT_EQ(ToString(LITERAL("hello")), "\"hello\"");
// null
EXPECT_EQ(ToString(LITERAL(TypedValue::Null)), "null");
EXPECT_EQ(ToString(LITERAL(TypedValue())), "null");
// true
EXPECT_EQ(ToString(LITERAL(true)), "true");
@ -88,12 +88,12 @@ TEST_F(ExpressionPrettyPrinterTest, UnaryOperators) {
EXPECT_EQ(ToString(UMINUS(LITERAL(1))), "(- 1)");
// null IS NULL
EXPECT_EQ(ToString(IS_NULL(LITERAL(TypedValue::Null))), "(IsNull null)");
EXPECT_EQ(ToString(IS_NULL(LITERAL(TypedValue()))), "(IsNull null)");
}
TEST_F(ExpressionPrettyPrinterTest, BinaryOperators) {
// and(null, 5)
EXPECT_EQ(ToString(AND(LITERAL(TypedValue::Null), LITERAL(5))),
EXPECT_EQ(ToString(AND(LITERAL(TypedValue()), LITERAL(5))),
"(And null 5)");
// or(5, {hello: "there"}["hello"])
@ -105,7 +105,7 @@ TEST_F(ExpressionPrettyPrinterTest, BinaryOperators) {
"(Or 5 (PropertyLookup {\"hello\": \"there\"} \"hello\"))");
// and(coalesce(null, 1), {hello: "there"})
EXPECT_EQ(ToString(AND(COALESCE(LITERAL(TypedValue::Null), LITERAL(1)),
EXPECT_EQ(ToString(AND(COALESCE(LITERAL(TypedValue()), LITERAL(1)),
MAP(std::make_pair(storage.GetPropertyIx("hello"),
LITERAL("there"))))),
"(And (Coalesce [null, 1]) {\"hello\": \"there\"})");
@ -117,27 +117,27 @@ TEST_F(ExpressionPrettyPrinterTest, Coalesce) {
// coalesce(null, null)
EXPECT_EQ(
ToString(COALESCE(LITERAL(TypedValue::Null), LITERAL(TypedValue::Null))),
ToString(COALESCE(LITERAL(TypedValue()), LITERAL(TypedValue()))),
"(Coalesce [null, null])");
// coalesce(null, 2, 3)
EXPECT_EQ(
ToString(COALESCE(LITERAL(TypedValue::Null), LITERAL(2), LITERAL(3))),
ToString(COALESCE(LITERAL(TypedValue()), LITERAL(2), LITERAL(3))),
"(Coalesce [null, 2, 3])");
// coalesce(null, 2, assert(false), 3)
EXPECT_EQ(ToString(COALESCE(LITERAL(TypedValue::Null), LITERAL(2),
EXPECT_EQ(ToString(COALESCE(LITERAL(TypedValue()), LITERAL(2),
FN("ASSERT", LITERAL(false)), LITERAL(3))),
"(Coalesce [null, 2, (Function \"ASSERT\" [false]), 3])");
// coalesce(null, assert(false))
EXPECT_EQ(ToString(COALESCE(LITERAL(TypedValue::Null),
EXPECT_EQ(ToString(COALESCE(LITERAL(TypedValue()),
FN("ASSERT", LITERAL(false)))),
"(Coalesce [null, (Function \"ASSERT\" [false])])");
// coalesce([null, null])
EXPECT_EQ(ToString(COALESCE(LITERAL(TypedValue(
std::vector<TypedValue>{TypedValue::Null, TypedValue::Null})))),
std::vector<TypedValue>{TypedValue(), TypedValue()})))),
"(Coalesce [[null, null]])");
}

View File

@ -156,7 +156,7 @@ TEST(TestVariableStartPlanner, MatchOptionalMatchReturn) {
// We expect to produce 2 rows:
// * (v1), (v3)
// * (v2), null
AssertRows(results, {{v1, v3}, {v2, TypedValue::Null}});
AssertRows(results, {{v1, v3}, {v2, TypedValue()}});
});
}
@ -183,7 +183,7 @@ TEST(TestVariableStartPlanner, MatchOptionalMatchMergeReturn) {
// start, we generate 2 * 2 * 2 plans.
CheckPlansProduce(8, query, storage, &dba, [&](const auto &results) {
// We expect to produce a single row: (v1), (v2), null, (v1), (v2)
AssertRows(results, {{v1, v2, TypedValue::Null, v1, v2}});
AssertRows(results, {{v1, v2, TypedValue(), v1, v2}});
});
}

View File

@ -22,19 +22,19 @@ class AllTypesFixture : public testing::Test {
database::GraphDbAccessor dba_{db_.Access()};
void SetUp() override {
values_.emplace_back(TypedValue::Null);
values_.emplace_back(TypedValue());
values_.emplace_back(true);
values_.emplace_back(42);
values_.emplace_back(3.14);
values_.emplace_back("something");
values_.emplace_back(
std::vector<TypedValue>{true, "something", 42, 0.5, TypedValue::Null});
std::vector<TypedValue>{true, "something", 42, 0.5, TypedValue()});
values_.emplace_back(
std::map<std::string, TypedValue>{{"a", true},
{"b", "something"},
{"c", 42},
{"d", 0.5},
{"e", TypedValue::Null}});
{"e", TypedValue()}});
auto vertex = dba_.InsertVertex();
values_.emplace_back(vertex);
values_.emplace_back(
@ -62,7 +62,7 @@ void EXPECT_PROP_NE(const TypedValue &a, const TypedValue &b) {
}
TEST(TypedValue, CreationTypes) {
EXPECT_TRUE(TypedValue::Null.type() == TypedValue::Type::Null);
EXPECT_TRUE(TypedValue().type() == TypedValue::Type::Null);
EXPECT_TRUE(TypedValue(true).type() == TypedValue::Type::Bool);
EXPECT_TRUE(TypedValue(false).type() == TypedValue::Type::Bool);
@ -136,8 +136,8 @@ TEST(TypedValue, BoolEquals) {
EXPECT_TRUE(eq(TypedValue(1), TypedValue(1)));
EXPECT_FALSE(eq(TypedValue(1), TypedValue(2)));
EXPECT_FALSE(eq(TypedValue(1), TypedValue("asd")));
EXPECT_FALSE(eq(TypedValue(1), TypedValue::Null));
EXPECT_TRUE(eq(TypedValue::Null, TypedValue::Null));
EXPECT_FALSE(eq(TypedValue(1), TypedValue()));
EXPECT_TRUE(eq(TypedValue(), TypedValue()));
}
TEST(TypedValue, Hash) {
@ -146,7 +146,7 @@ TEST(TypedValue, Hash) {
EXPECT_EQ(hash(TypedValue(1)), hash(TypedValue(1)));
EXPECT_EQ(hash(TypedValue(1)), hash(TypedValue(1.0)));
EXPECT_EQ(hash(TypedValue(1.5)), hash(TypedValue(1.5)));
EXPECT_EQ(hash(TypedValue::Null), hash(TypedValue::Null));
EXPECT_EQ(hash(TypedValue()), hash(TypedValue()));
EXPECT_EQ(hash(TypedValue("bla")), hash(TypedValue("bla")));
EXPECT_EQ(hash(TypedValue(std::vector<TypedValue>{1, 2})),
hash(TypedValue(std::vector<TypedValue>{1, 2})));
@ -186,8 +186,8 @@ TEST_F(AllTypesFixture, Less) {
for (TypedValue &value : values_) {
if (!(value.IsNumeric() || value.type() == TypedValue::Type::String))
continue;
EXPECT_PROP_ISNULL(value < TypedValue::Null);
EXPECT_PROP_ISNULL(TypedValue::Null < value);
EXPECT_PROP_ISNULL(value < TypedValue());
EXPECT_PROP_ISNULL(TypedValue() < value);
}
// int tests
@ -214,14 +214,14 @@ TEST_F(AllTypesFixture, Less) {
TEST(TypedValue, LogicalNot) {
EXPECT_PROP_EQ(!TypedValue(true), TypedValue(false));
EXPECT_PROP_ISNULL(!TypedValue::Null);
EXPECT_PROP_ISNULL(!TypedValue());
EXPECT_THROW(!TypedValue(0), TypedValueException);
EXPECT_THROW(!TypedValue(0.2), TypedValueException);
EXPECT_THROW(!TypedValue("something"), TypedValueException);
}
TEST(TypedValue, UnaryMinus) {
EXPECT_TRUE((-TypedValue::Null).type() == TypedValue::Type::Null);
EXPECT_TRUE((-TypedValue()).type() == TypedValue::Type::Null);
EXPECT_PROP_EQ((-TypedValue(2).Value<int64_t>()), -2);
EXPECT_FLOAT_EQ((-TypedValue(2.0).Value<double>()), -2.0);
@ -231,7 +231,7 @@ TEST(TypedValue, UnaryMinus) {
}
TEST(TypedValue, UnaryPlus) {
EXPECT_TRUE((+TypedValue::Null).type() == TypedValue::Type::Null);
EXPECT_TRUE((+TypedValue()).type() == TypedValue::Type::Null);
EXPECT_PROP_EQ((+TypedValue(2).Value<int64_t>()), 2);
EXPECT_FLOAT_EQ((+TypedValue(2.0).Value<double>()), 2.0);
@ -285,8 +285,8 @@ class TypedValueArithmeticTest : public AllTypesFixture {
// null resulting ops
for (const TypedValue &value : values_) {
EXPECT_PROP_ISNULL(op(value, TypedValue::Null));
EXPECT_PROP_ISNULL(op(TypedValue::Null, value));
EXPECT_PROP_ISNULL(op(value, TypedValue()));
EXPECT_PROP_ISNULL(op(TypedValue(), value));
}
}
};
@ -403,8 +403,8 @@ TEST_F(TypedValueLogicTest, LogicalAnd) {
TestLogicalThrows(
[](const TypedValue &p1, const TypedValue &p2) { return p1 && p2; });
EXPECT_PROP_ISNULL(TypedValue::Null && TypedValue(true));
EXPECT_PROP_EQ(TypedValue::Null && TypedValue(false), TypedValue(false));
EXPECT_PROP_ISNULL(TypedValue() && TypedValue(true));
EXPECT_PROP_EQ(TypedValue() && TypedValue(false), TypedValue(false));
EXPECT_PROP_EQ(TypedValue(true) && TypedValue(true), TypedValue(true));
EXPECT_PROP_EQ(TypedValue(false) && TypedValue(true), TypedValue(false));
}
@ -413,8 +413,8 @@ TEST_F(TypedValueLogicTest, LogicalOr) {
TestLogicalThrows(
[](const TypedValue &p1, const TypedValue &p2) { return p1 || p2; });
EXPECT_PROP_ISNULL(TypedValue::Null || TypedValue(false));
EXPECT_PROP_EQ(TypedValue::Null || TypedValue(true), TypedValue(true));
EXPECT_PROP_ISNULL(TypedValue() || TypedValue(false));
EXPECT_PROP_EQ(TypedValue() || TypedValue(true), TypedValue(true));
EXPECT_PROP_EQ(TypedValue(true) || TypedValue(true), TypedValue(true));
EXPECT_PROP_EQ(TypedValue(false) || TypedValue(true), TypedValue(true));
}
@ -423,7 +423,7 @@ TEST_F(TypedValueLogicTest, LogicalXor) {
TestLogicalThrows(
[](const TypedValue &p1, const TypedValue &p2) { return p1 ^ p2; });
EXPECT_PROP_ISNULL(TypedValue::Null && TypedValue(true));
EXPECT_PROP_ISNULL(TypedValue() && TypedValue(true));
EXPECT_PROP_EQ(TypedValue(true) ^ TypedValue(true), TypedValue(false));
EXPECT_PROP_EQ(TypedValue(false) ^ TypedValue(true), TypedValue(true));
EXPECT_PROP_EQ(TypedValue(true) ^ TypedValue(false), TypedValue(true));