Use non-template Value invocation
Reviewers: mtomic, mferencevic Reviewed By: mtomic, mferencevic Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2317
This commit is contained in:
parent
529b7109f7
commit
97b20a9384
src
audit
database/single_node
glue
query
storage
common/types
single_node/indexes
single_node_ha/indexes
tests/unit
bfs_common.hppcypher_main_visitor.cppdatabase_dump.cppgraph_db_accessor.cppgraph_db_accessor_index_api.cppinterpreter.cppproperty_value_store.cppquery_common.hppquery_expression_evaluator.cppquery_plan_accumulate_aggregate.cppquery_plan_bag_semantics.cppquery_plan_create_set_remove_delete.cppquery_plan_match_filter_return.cppquery_pretty_print.cpprecord_edge_vertex_accessor.cppstate_delta.cppstripped.cpptyped_value.cpp
@ -17,28 +17,27 @@ inline nlohmann::json PropertyValueToJson(const PropertyValue &pv) {
|
||||
case PropertyValue::Type::Null:
|
||||
break;
|
||||
case PropertyValue::Type::Bool:
|
||||
ret = pv.Value<bool>();
|
||||
ret = pv.ValueBool();
|
||||
break;
|
||||
case PropertyValue::Type::Int:
|
||||
ret = pv.Value<int64_t>();
|
||||
ret = pv.ValueInt();
|
||||
break;
|
||||
case PropertyValue::Type::Double:
|
||||
ret = pv.Value<double>();
|
||||
ret = pv.ValueDouble();
|
||||
break;
|
||||
case PropertyValue::Type::String:
|
||||
ret = pv.Value<std::string>();
|
||||
ret = pv.ValueString();
|
||||
break;
|
||||
case PropertyValue::Type::List: {
|
||||
ret = nlohmann::json::array();
|
||||
for (const auto &item : pv.Value<std::vector<PropertyValue>>()) {
|
||||
for (const auto &item : pv.ValueList()) {
|
||||
ret.push_back(PropertyValueToJson(item));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PropertyValue::Type::Map: {
|
||||
ret = nlohmann::json::object();
|
||||
for (const auto &item :
|
||||
pv.Value<std::map<std::string, PropertyValue>>()) {
|
||||
for (const auto &item : pv.ValueMap()) {
|
||||
ret.push_back(nlohmann::json::object_t::value_type(
|
||||
item.first, PropertyValueToJson(item.second)));
|
||||
}
|
||||
|
@ -42,20 +42,20 @@ void DumpPropertyValue(std::ostream *os, const PropertyValue &value) {
|
||||
*os << "Null";
|
||||
return;
|
||||
case PropertyValue::Type::Bool:
|
||||
*os << (value.Value<bool>() ? "true" : "false");
|
||||
*os << (value.ValueBool() ? "true" : "false");
|
||||
return;
|
||||
case PropertyValue::Type::String:
|
||||
*os << ::utils::Escape(value.Value<std::string>());
|
||||
*os << ::utils::Escape(value.ValueString());
|
||||
return;
|
||||
case PropertyValue::Type::Int:
|
||||
*os << value.Value<int64_t>();
|
||||
*os << value.ValueInt();
|
||||
return;
|
||||
case PropertyValue::Type::Double:
|
||||
DumpPreciseDouble(os, value.Value<double>());
|
||||
DumpPreciseDouble(os, value.ValueDouble());
|
||||
return;
|
||||
case PropertyValue::Type::List: {
|
||||
*os << "[";
|
||||
const auto &list = value.Value<std::vector<PropertyValue>>();
|
||||
const auto &list = value.ValueList();
|
||||
utils::PrintIterable(*os, list, ", ", [](auto &os, const auto &item) {
|
||||
DumpPropertyValue(&os, item);
|
||||
});
|
||||
@ -64,7 +64,7 @@ void DumpPropertyValue(std::ostream *os, const PropertyValue &value) {
|
||||
}
|
||||
case PropertyValue::Type::Map: {
|
||||
*os << "{";
|
||||
const auto &map = value.Value<std::map<std::string, PropertyValue>>();
|
||||
const auto &map = value.ValueMap();
|
||||
utils::PrintIterable(*os, map, ", ", [](auto &os, const auto &kv) {
|
||||
os << kv.first << ": ";
|
||||
DumpPropertyValue(&os, kv.second);
|
||||
|
@ -160,16 +160,16 @@ Value ToBoltValue(const PropertyValue &value) {
|
||||
case PropertyValue::Type::Null:
|
||||
return Value();
|
||||
case PropertyValue::Type::Bool:
|
||||
return Value(value.Value<bool>());
|
||||
return Value(value.ValueBool());
|
||||
case PropertyValue::Type::Int:
|
||||
return Value(value.Value<int64_t>());
|
||||
return Value(value.ValueInt());
|
||||
break;
|
||||
case PropertyValue::Type::Double:
|
||||
return Value(value.Value<double>());
|
||||
return Value(value.ValueDouble());
|
||||
case PropertyValue::Type::String:
|
||||
return Value(value.Value<std::string>());
|
||||
return Value(value.ValueString());
|
||||
case PropertyValue::Type::List: {
|
||||
const auto &values = value.Value<std::vector<PropertyValue>>();
|
||||
const auto &values = value.ValueList();
|
||||
std::vector<Value> vec;
|
||||
vec.reserve(values.size());
|
||||
for (const auto &v : values) {
|
||||
@ -178,7 +178,7 @@ Value ToBoltValue(const PropertyValue &value) {
|
||||
return Value(vec);
|
||||
}
|
||||
case PropertyValue::Type::Map: {
|
||||
const auto &map = value.Value<std::map<std::string, PropertyValue>>();
|
||||
const auto &map = value.ValueMap();
|
||||
std::map<std::string, Value> dv_map;
|
||||
for (const auto &kv : map) {
|
||||
dv_map.emplace(kv.first, ToBoltValue(kv.second));
|
||||
|
@ -54,17 +54,17 @@ bool TypedValueCompare(const TypedValue &a, const TypedValue &b) {
|
||||
|
||||
switch (a.type()) {
|
||||
case TypedValue::Type::Bool:
|
||||
return !a.Value<bool>() && b.Value<bool>();
|
||||
return !a.ValueBool() && b.ValueBool();
|
||||
case TypedValue::Type::Int:
|
||||
if (b.type() == TypedValue::Type::Double)
|
||||
return a.Value<int64_t>() < b.Value<double>();
|
||||
return a.ValueInt() < b.ValueDouble();
|
||||
else
|
||||
return a.Value<int64_t>() < b.Value<int64_t>();
|
||||
return a.ValueInt() < b.ValueInt();
|
||||
case TypedValue::Type::Double:
|
||||
if (b.type() == TypedValue::Type::Int)
|
||||
return a.Value<double>() < b.Value<int64_t>();
|
||||
return a.ValueDouble() < b.ValueInt();
|
||||
else
|
||||
return a.Value<double>() < b.Value<double>();
|
||||
return a.ValueDouble() < b.ValueDouble();
|
||||
case TypedValue::Type::String:
|
||||
return a.ValueString() < b.ValueString();
|
||||
case TypedValue::Type::List:
|
||||
|
@ -124,27 +124,27 @@ void PrintObject(std::ostream *out, const PropertyValue &value) {
|
||||
break;
|
||||
|
||||
case PropertyValue::Type::String:
|
||||
PrintObject(out, value.Value<std::string>());
|
||||
PrintObject(out, value.ValueString());
|
||||
break;
|
||||
|
||||
case PropertyValue::Type::Bool:
|
||||
*out << (value.Value<bool>() ? "true" : "false");
|
||||
*out << (value.ValueBool() ? "true" : "false");
|
||||
break;
|
||||
|
||||
case PropertyValue::Type::Int:
|
||||
PrintObject(out, value.Value<std::int64_t>());
|
||||
PrintObject(out, value.ValueInt());
|
||||
break;
|
||||
|
||||
case PropertyValue::Type::Double:
|
||||
PrintObject(out, value.Value<double>());
|
||||
PrintObject(out, value.ValueDouble());
|
||||
break;
|
||||
|
||||
case PropertyValue::Type::List:
|
||||
PrintObject(out, value.Value<std::vector<PropertyValue>>());
|
||||
PrintObject(out, value.ValueList());
|
||||
break;
|
||||
|
||||
case PropertyValue::Type::Map:
|
||||
PrintObject(out, value.Value<std::map<std::string, PropertyValue>>());
|
||||
PrintObject(out, value.ValueMap());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -378,9 +378,9 @@ TypedValue Properties(TypedValue *args, int64_t nargs,
|
||||
case TypedValue::Type::Null:
|
||||
return TypedValue(ctx.memory);
|
||||
case TypedValue::Type::Vertex:
|
||||
return get_properties(args[0].Value<VertexAccessor>());
|
||||
return get_properties(args[0].ValueVertex());
|
||||
case TypedValue::Type::Edge:
|
||||
return get_properties(args[0].Value<EdgeAccessor>());
|
||||
return get_properties(args[0].ValueEdge());
|
||||
default:
|
||||
throw QueryRuntimeException(
|
||||
"'properties' argument must be a node or an edge.");
|
||||
@ -456,7 +456,7 @@ TypedValue ToBoolean(TypedValue *args, int64_t nargs,
|
||||
case TypedValue::Type::Null:
|
||||
return TypedValue(ctx.memory);
|
||||
case TypedValue::Type::Bool:
|
||||
return TypedValue(args[0].Value<bool>(), ctx.memory);
|
||||
return TypedValue(args[0].ValueBool(), ctx.memory);
|
||||
case TypedValue::Type::Int:
|
||||
return TypedValue(args[0].ValueInt() != 0L, ctx.memory);
|
||||
case TypedValue::Type::String: {
|
||||
@ -480,7 +480,7 @@ TypedValue ToFloat(TypedValue *args, int64_t nargs,
|
||||
case TypedValue::Type::Null:
|
||||
return TypedValue(ctx.memory);
|
||||
case TypedValue::Type::Int:
|
||||
return TypedValue(static_cast<double>(args[0].Value<int64_t>()),
|
||||
return TypedValue(static_cast<double>(args[0].ValueInt()),
|
||||
ctx.memory);
|
||||
case TypedValue::Type::Double:
|
||||
return TypedValue(args[0], ctx.memory);
|
||||
@ -509,7 +509,7 @@ TypedValue ToInteger(TypedValue *args, int64_t nargs,
|
||||
case TypedValue::Type::Int:
|
||||
return TypedValue(args[0], ctx.memory);
|
||||
case TypedValue::Type::Double:
|
||||
return TypedValue(static_cast<int64_t>(args[0].Value<double>()),
|
||||
return TypedValue(static_cast<int64_t>(args[0].ValueDouble()),
|
||||
ctx.memory);
|
||||
case TypedValue::Type::String:
|
||||
try {
|
||||
@ -549,9 +549,9 @@ TypedValue Keys(TypedValue *args, int64_t nargs, const EvaluationContext &ctx,
|
||||
case TypedValue::Type::Null:
|
||||
return TypedValue(ctx.memory);
|
||||
case TypedValue::Type::Vertex:
|
||||
return get_keys(args[0].Value<VertexAccessor>());
|
||||
return get_keys(args[0].ValueVertex());
|
||||
case TypedValue::Type::Edge:
|
||||
return get_keys(args[0].Value<EdgeAccessor>());
|
||||
return get_keys(args[0].ValueEdge());
|
||||
default:
|
||||
throw QueryRuntimeException("'keys' argument must be a node or an edge.");
|
||||
}
|
||||
@ -597,9 +597,9 @@ TypedValue Range(TypedValue *args, int64_t nargs, const EvaluationContext &ctx,
|
||||
Optional<Or<Null, NonZeroInteger>>>("range", args, nargs);
|
||||
for (int64_t i = 0; i < nargs; ++i)
|
||||
if (args[i].IsNull()) return TypedValue(ctx.memory);
|
||||
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;
|
||||
auto lbound = args[0].ValueInt();
|
||||
auto rbound = args[1].ValueInt();
|
||||
int64_t step = nargs == 3 ? args[2].ValueInt() : 1;
|
||||
TypedValue::TVector list(ctx.memory);
|
||||
if (lbound <= rbound && step > 0) {
|
||||
for (auto i = lbound; i <= rbound; i += step) {
|
||||
@ -650,9 +650,9 @@ TypedValue Abs(TypedValue *args, int64_t nargs, const EvaluationContext &ctx,
|
||||
case TypedValue::Type::Null:
|
||||
return TypedValue(ctx.memory);
|
||||
case TypedValue::Type::Int:
|
||||
return TypedValue(std::abs(args[0].Value<int64_t>()), ctx.memory);
|
||||
return TypedValue(std::abs(args[0].ValueInt()), ctx.memory);
|
||||
case TypedValue::Type::Double:
|
||||
return TypedValue(std::abs(args[0].Value<double>()), ctx.memory);
|
||||
return TypedValue(std::abs(args[0].ValueDouble()), ctx.memory);
|
||||
default:
|
||||
throw QueryRuntimeException("'abs' argument should be a number.");
|
||||
}
|
||||
@ -666,11 +666,9 @@ TypedValue Abs(TypedValue *args, int64_t nargs, const EvaluationContext &ctx,
|
||||
case TypedValue::Type::Null: \
|
||||
return TypedValue(ctx.memory); \
|
||||
case TypedValue::Type::Int: \
|
||||
return TypedValue(lowercased_name(args[0].Value<int64_t>()), \
|
||||
ctx.memory); \
|
||||
return TypedValue(lowercased_name(args[0].ValueInt()), ctx.memory); \
|
||||
case TypedValue::Type::Double: \
|
||||
return TypedValue(lowercased_name(args[0].Value<double>()), \
|
||||
ctx.memory); \
|
||||
return TypedValue(lowercased_name(args[0].ValueDouble()), ctx.memory); \
|
||||
default: \
|
||||
throw QueryRuntimeException(#lowercased_name \
|
||||
" argument must be a number."); \
|
||||
@ -703,9 +701,9 @@ TypedValue Atan2(TypedValue *args, int64_t nargs, const EvaluationContext &ctx,
|
||||
auto to_double = [](const TypedValue &t) -> double {
|
||||
switch (t.type()) {
|
||||
case TypedValue::Type::Int:
|
||||
return t.Value<int64_t>();
|
||||
return t.ValueInt();
|
||||
case TypedValue::Type::Double:
|
||||
return t.Value<double>();
|
||||
return t.ValueDouble();
|
||||
default:
|
||||
throw QueryRuntimeException("Arguments of 'atan2' must be numbers.");
|
||||
}
|
||||
@ -723,9 +721,9 @@ TypedValue Sign(TypedValue *args, int64_t nargs, const EvaluationContext &ctx,
|
||||
case TypedValue::Type::Null:
|
||||
return TypedValue(ctx.memory);
|
||||
case TypedValue::Type::Int:
|
||||
return sign(args[0].Value<int64_t>());
|
||||
return sign(args[0].ValueInt());
|
||||
case TypedValue::Type::Double:
|
||||
return sign(args[0].Value<double>());
|
||||
return sign(args[0].ValueDouble());
|
||||
default:
|
||||
throw QueryRuntimeException("'sign' argument must be a number.");
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
|
||||
|
||||
TypedValue Visit(AndOperator &op) override {
|
||||
auto value1 = op.expression1_->Accept(*this);
|
||||
if (value1.IsBool() && !value1.Value<bool>()) {
|
||||
if (value1.IsBool() && !value1.ValueBool()) {
|
||||
// If first expression is false, don't evaluate the second one.
|
||||
return value1;
|
||||
}
|
||||
@ -116,7 +116,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
|
||||
throw QueryRuntimeException("CASE expected boolean expression, got {}.",
|
||||
condition.type());
|
||||
}
|
||||
if (condition.Value<bool>()) {
|
||||
if (condition.ValueBool()) {
|
||||
return if_operator.then_expression_->Accept(*this);
|
||||
}
|
||||
return if_operator.else_expression_->Accept(*this);
|
||||
@ -147,7 +147,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
|
||||
auto result = literal == element;
|
||||
if (result.IsNull()) {
|
||||
has_null = true;
|
||||
} else if (result.Value<bool>()) {
|
||||
} else if (result.ValueBool()) {
|
||||
return TypedValue(true, ctx_->memory);
|
||||
}
|
||||
}
|
||||
@ -171,7 +171,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
|
||||
if (!index.IsInt())
|
||||
throw QueryRuntimeException(
|
||||
"Expected an integer as a list index, got {}.", index.type());
|
||||
auto index_int = index.Value<int64_t>();
|
||||
auto index_int = index.ValueInt();
|
||||
// NOTE: Take non-const reference to list, so that we can move out the
|
||||
// indexed element as the result.
|
||||
auto &list = lhs.ValueList();
|
||||
@ -203,7 +203,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
|
||||
if (!index.IsString())
|
||||
throw QueryRuntimeException(
|
||||
"Expected a string as a property name, got {}.", index.type());
|
||||
return TypedValue(lhs.Value<VertexAccessor>().PropsAt(
|
||||
return TypedValue(lhs.ValueVertex().PropsAt(
|
||||
dba_->Property(std::string(index.ValueString()))),
|
||||
ctx_->memory);
|
||||
}
|
||||
@ -212,7 +212,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
|
||||
if (!index.IsString())
|
||||
throw QueryRuntimeException(
|
||||
"Expected a string as a property name, got {}.", index.type());
|
||||
return TypedValue(lhs.Value<EdgeAccessor>().PropsAt(
|
||||
return TypedValue(lhs.ValueEdge().PropsAt(
|
||||
dba_->Property(std::string(index.ValueString()))),
|
||||
ctx_->memory);
|
||||
}
|
||||
@ -262,8 +262,8 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
|
||||
return std::max(static_cast<int64_t>(0),
|
||||
std::min(bound, static_cast<int64_t>(list.size())));
|
||||
};
|
||||
auto lower_bound = normalise_bound(_lower_bound.Value<int64_t>());
|
||||
auto upper_bound = normalise_bound(_upper_bound.Value<int64_t>());
|
||||
auto lower_bound = normalise_bound(_lower_bound.ValueInt());
|
||||
auto upper_bound = normalise_bound(_upper_bound.ValueInt());
|
||||
if (upper_bound <= lower_bound) {
|
||||
return TypedValue(TypedValue::TVector(ctx_->memory), ctx_->memory);
|
||||
}
|
||||
@ -282,11 +282,11 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
|
||||
case TypedValue::Type::Null:
|
||||
return TypedValue(ctx_->memory);
|
||||
case TypedValue::Type::Vertex:
|
||||
return TypedValue(expression_result.Value<VertexAccessor>().PropsAt(
|
||||
return TypedValue(expression_result.ValueVertex().PropsAt(
|
||||
GetProperty(property_lookup.property_)),
|
||||
ctx_->memory);
|
||||
case TypedValue::Type::Edge:
|
||||
return TypedValue(expression_result.Value<EdgeAccessor>().PropsAt(
|
||||
return TypedValue(expression_result.ValueEdge().PropsAt(
|
||||
GetProperty(property_lookup.property_)),
|
||||
ctx_->memory);
|
||||
case TypedValue::Type::Map: {
|
||||
@ -311,7 +311,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
|
||||
case TypedValue::Type::Null:
|
||||
return TypedValue(ctx_->memory);
|
||||
case TypedValue::Type::Vertex: {
|
||||
const auto &vertex = expression_result.Value<VertexAccessor>();
|
||||
const auto &vertex = expression_result.ValueVertex();
|
||||
for (const auto &label : labels_test.labels_) {
|
||||
if (!vertex.has_label(GetLabel(label))) {
|
||||
return TypedValue(false, ctx_->memory);
|
||||
@ -462,7 +462,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
|
||||
"Predicate of ALL must evaluate to boolean, got {}.",
|
||||
result.type());
|
||||
}
|
||||
if (result.IsNull() || !result.Value<bool>()) {
|
||||
if (result.IsNull() || !result.ValueBool()) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -489,7 +489,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
|
||||
"Predicate of SINGLE must evaluate to boolean, got {}.",
|
||||
result.type());
|
||||
}
|
||||
if (result.IsNull() || !result.Value<bool>()) {
|
||||
if (result.IsNull() || !result.ValueBool()) {
|
||||
continue;
|
||||
}
|
||||
// Return false if more than one element satisfies the predicate.
|
||||
@ -549,7 +549,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
|
||||
void SwitchAccessors(TypedValue &value) {
|
||||
switch (value.type()) {
|
||||
case TypedValue::Type::Vertex: {
|
||||
auto &vertex = value.Value<VertexAccessor>();
|
||||
auto &vertex = value.ValueVertex();
|
||||
switch (graph_view_) {
|
||||
case GraphView::NEW:
|
||||
vertex.SwitchNew();
|
||||
@ -563,7 +563,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
|
||||
break;
|
||||
}
|
||||
case TypedValue::Type::Edge: {
|
||||
auto &edge = value.Value<EdgeAccessor>();
|
||||
auto &edge = value.ValueEdge();
|
||||
switch (graph_view_) {
|
||||
case GraphView::NEW:
|
||||
edge.SwitchNew();
|
||||
@ -623,7 +623,7 @@ inline int64_t EvaluateInt(ExpressionEvaluator *evaluator, Expression *expr,
|
||||
const std::string &what) {
|
||||
TypedValue value = expr->Accept(*evaluator);
|
||||
try {
|
||||
return value.Value<int64_t>();
|
||||
return value.ValueInt();
|
||||
} catch (TypedValueException &e) {
|
||||
throw QueryRuntimeException(what + " must be an int");
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ bool EvaluateFilter(ExpressionEvaluator &evaluator, Expression *filter) {
|
||||
throw QueryRuntimeException(
|
||||
"Filter expression must evaluate to bool or null, got {}.",
|
||||
result.type());
|
||||
return result.Value<bool>();
|
||||
return result.ValueBool();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@ -218,7 +218,7 @@ bool CreateExpand::CreateExpandCursor::Pull(Frame &frame,
|
||||
// get the origin vertex
|
||||
TypedValue &vertex_value = frame[self_.input_symbol_];
|
||||
ExpectType(self_.input_symbol_, vertex_value, TypedValue::Type::Vertex);
|
||||
auto &v1 = vertex_value.Value<VertexAccessor>();
|
||||
auto &v1 = vertex_value.ValueVertex();
|
||||
|
||||
// Similarly to CreateNode, newly created edges and nodes should use the
|
||||
// latest accesors.
|
||||
@ -262,7 +262,7 @@ VertexAccessor &CreateExpand::CreateExpandCursor::OtherVertex(
|
||||
TypedValue &dest_node_value = frame[self_.node_info_.symbol];
|
||||
ExpectType(self_.node_info_.symbol, dest_node_value,
|
||||
TypedValue::Type::Vertex);
|
||||
return dest_node_value.Value<VertexAccessor>();
|
||||
return dest_node_value.ValueVertex();
|
||||
} else {
|
||||
return CreateLocalVertex(self_.node_info_, &frame, context);
|
||||
}
|
||||
@ -556,7 +556,7 @@ bool Expand::ExpandCursor::InitEdges(Frame &frame, ExecutionContext &context) {
|
||||
if (vertex_value.IsNull()) continue;
|
||||
|
||||
ExpectType(self_.input_symbol_, vertex_value, TypedValue::Type::Vertex);
|
||||
auto &vertex = vertex_value.Value<VertexAccessor>();
|
||||
auto &vertex = vertex_value.ValueVertex();
|
||||
SwitchAccessor(vertex, self_.graph_view_);
|
||||
|
||||
auto direction = self_.common_.direction;
|
||||
@ -711,8 +711,7 @@ class ExpandVariableCursor : public Cursor {
|
||||
if (PullInput(frame, context)) {
|
||||
// if lower bound is zero we also yield empty paths
|
||||
if (lower_bound_ == 0) {
|
||||
auto &start_vertex =
|
||||
frame[self_.input_symbol_].Value<VertexAccessor>();
|
||||
auto &start_vertex = frame[self_.input_symbol_].ValueVertex();
|
||||
if (!self_.common_.existing_node ||
|
||||
CheckExistingNode(start_vertex, self_.common_.node_symbol,
|
||||
frame)) {
|
||||
@ -776,7 +775,7 @@ class ExpandVariableCursor : public Cursor {
|
||||
if (vertex_value.IsNull()) continue;
|
||||
|
||||
ExpectType(self_.input_symbol_, vertex_value, TypedValue::Type::Vertex);
|
||||
auto &vertex = vertex_value.Value<VertexAccessor>();
|
||||
auto &vertex = vertex_value.ValueVertex();
|
||||
SwitchAccessor(vertex, GraphView::OLD);
|
||||
|
||||
// Evaluate the upper and lower bounds.
|
||||
@ -889,7 +888,7 @@ class ExpandVariableCursor : public Cursor {
|
||||
bool found_existing =
|
||||
std::any_of(edges_on_frame.begin(), edges_on_frame.end(),
|
||||
[¤t_edge](const TypedValue &edge) {
|
||||
return current_edge.first == edge.Value<EdgeAccessor>();
|
||||
return current_edge.first == edge.ValueEdge();
|
||||
});
|
||||
if (found_existing) continue;
|
||||
|
||||
@ -1211,7 +1210,7 @@ class SingleSourceShortestPathCursor : public query::plan::Cursor {
|
||||
case TypedValue::Type::Null:
|
||||
return;
|
||||
case TypedValue::Type::Bool:
|
||||
if (!result.Value<bool>()) return;
|
||||
if (!result.ValueBool()) return;
|
||||
break;
|
||||
default:
|
||||
throw QueryRuntimeException(
|
||||
@ -1265,7 +1264,7 @@ class SingleSourceShortestPathCursor : public query::plan::Cursor {
|
||||
|
||||
if (upper_bound_ < 1 || lower_bound_ > upper_bound_) continue;
|
||||
|
||||
const auto &vertex = vertex_value.Value<VertexAccessor>();
|
||||
const auto &vertex = vertex_value.ValueVertex();
|
||||
processed_.emplace(vertex, std::nullopt);
|
||||
expand_from_vertex(vertex);
|
||||
|
||||
@ -1284,7 +1283,7 @@ class SingleSourceShortestPathCursor : public query::plan::Cursor {
|
||||
edge_list.emplace_back(expansion.first);
|
||||
auto last_vertex = expansion.second;
|
||||
while (true) {
|
||||
const EdgeAccessor &last_edge = edge_list.back().Value<EdgeAccessor>();
|
||||
const EdgeAccessor &last_edge = edge_list.back().ValueEdge();
|
||||
last_vertex =
|
||||
last_edge.from() == last_vertex ? last_edge.to() : last_edge.from();
|
||||
// origin_vertex must be in processed
|
||||
@ -1389,7 +1388,7 @@ class ExpandWeightedShortestPathCursor : public query::plan::Cursor {
|
||||
throw QueryRuntimeException(
|
||||
"Calculated weight must be numeric, got {}.", typed_weight.type());
|
||||
}
|
||||
if ((typed_weight < TypedValue(0, memory)).Value<bool>()) {
|
||||
if ((typed_weight < TypedValue(0, memory)).ValueBool()) {
|
||||
throw QueryRuntimeException("Calculated weight must be non-negative!");
|
||||
}
|
||||
|
||||
@ -1397,10 +1396,10 @@ class ExpandWeightedShortestPathCursor : public query::plan::Cursor {
|
||||
auto next_weight = TypedValue(weight, memory) + typed_weight;
|
||||
auto found_it = total_cost_.find(next_state);
|
||||
if (found_it != total_cost_.end() &&
|
||||
found_it->second.Value<double>() <= next_weight.Value<double>())
|
||||
found_it->second.ValueDouble() <= next_weight.ValueDouble())
|
||||
return;
|
||||
|
||||
pq_.push({next_weight.Value<double>(), depth + 1, vertex, edge});
|
||||
pq_.push({next_weight.ValueDouble(), depth + 1, vertex, edge});
|
||||
};
|
||||
|
||||
// Populates the priority queue structure with expansions
|
||||
@ -1426,7 +1425,7 @@ class ExpandWeightedShortestPathCursor : public query::plan::Cursor {
|
||||
if (!input_cursor_->Pull(frame, context)) return false;
|
||||
const auto &vertex_value = frame[self_.input_symbol_];
|
||||
if (vertex_value.IsNull()) continue;
|
||||
auto vertex = vertex_value.Value<VertexAccessor>();
|
||||
auto vertex = vertex_value.ValueVertex();
|
||||
if (self_.common_.existing_node) {
|
||||
const auto &node = frame[self_.common_.node_symbol];
|
||||
// Due to optional matching the existing node could be null.
|
||||
@ -1507,7 +1506,7 @@ class ExpandWeightedShortestPathCursor : public query::plan::Cursor {
|
||||
// Place destination node on the frame, handle existence flag.
|
||||
if (self_.common_.existing_node) {
|
||||
const auto &node = frame[self_.common_.node_symbol];
|
||||
if ((node != TypedValue(current_vertex, pull_memory)).Value<bool>())
|
||||
if ((node != TypedValue(current_vertex, pull_memory)).ValueBool())
|
||||
continue;
|
||||
else
|
||||
// Prevent expanding other paths, because we found the
|
||||
@ -1841,7 +1840,7 @@ bool Delete::DeleteCursor::Pull(Frame &frame, ExecutionContext &context) {
|
||||
for (TypedValue &expression_result : expression_results) {
|
||||
if (dba.should_abort()) throw HintedAbortError();
|
||||
if (expression_result.type() == TypedValue::Type::Edge)
|
||||
dba.RemoveEdge(expression_result.Value<EdgeAccessor>());
|
||||
dba.RemoveEdge(expression_result.ValueEdge());
|
||||
}
|
||||
|
||||
// delete vertices
|
||||
@ -1849,7 +1848,7 @@ bool Delete::DeleteCursor::Pull(Frame &frame, ExecutionContext &context) {
|
||||
if (dba.should_abort()) throw HintedAbortError();
|
||||
switch (expression_result.type()) {
|
||||
case TypedValue::Type::Vertex: {
|
||||
VertexAccessor &va = expression_result.Value<VertexAccessor>();
|
||||
VertexAccessor &va = expression_result.ValueVertex();
|
||||
va.SwitchNew(); // necessary because an edge deletion could have
|
||||
// updated
|
||||
if (self_.detach_)
|
||||
@ -1912,10 +1911,10 @@ bool SetProperty::SetPropertyCursor::Pull(Frame &frame,
|
||||
|
||||
switch (lhs.type()) {
|
||||
case TypedValue::Type::Vertex:
|
||||
PropsSetChecked(&lhs.Value<VertexAccessor>(), self_.property_, rhs);
|
||||
PropsSetChecked(&lhs.ValueVertex(), self_.property_, rhs);
|
||||
break;
|
||||
case TypedValue::Type::Edge:
|
||||
PropsSetChecked(&lhs.Value<EdgeAccessor>(), self_.property_, rhs);
|
||||
PropsSetChecked(&lhs.ValueEdge(), self_.property_, rhs);
|
||||
break;
|
||||
case TypedValue::Type::Null:
|
||||
// Skip setting properties on Null (can occur in optional match).
|
||||
@ -1987,10 +1986,10 @@ void SetPropertiesOnRecord(database::GraphDbAccessor *dba,
|
||||
|
||||
switch (rhs.type()) {
|
||||
case TypedValue::Type::Edge:
|
||||
set_props(rhs.Value<EdgeAccessor>().Properties());
|
||||
set_props(rhs.ValueEdge().Properties());
|
||||
break;
|
||||
case TypedValue::Type::Vertex:
|
||||
set_props(rhs.Value<VertexAccessor>().Properties());
|
||||
set_props(rhs.ValueVertex().Properties());
|
||||
break;
|
||||
case TypedValue::Type::Map: {
|
||||
for (const auto &kv : rhs.ValueMap())
|
||||
@ -2023,12 +2022,12 @@ bool SetProperties::SetPropertiesCursor::Pull(Frame &frame,
|
||||
|
||||
switch (lhs.type()) {
|
||||
case TypedValue::Type::Vertex:
|
||||
SetPropertiesOnRecord(context.db_accessor, &lhs.Value<VertexAccessor>(),
|
||||
rhs, self_.op_);
|
||||
SetPropertiesOnRecord(context.db_accessor, &lhs.ValueVertex(), rhs,
|
||||
self_.op_);
|
||||
break;
|
||||
case TypedValue::Type::Edge:
|
||||
SetPropertiesOnRecord(context.db_accessor, &lhs.Value<EdgeAccessor>(),
|
||||
rhs, self_.op_);
|
||||
SetPropertiesOnRecord(context.db_accessor, &lhs.ValueEdge(), rhs,
|
||||
self_.op_);
|
||||
break;
|
||||
case TypedValue::Type::Null:
|
||||
// Skip setting properties on Null (can occur in optional match).
|
||||
@ -2074,7 +2073,7 @@ bool SetLabels::SetLabelsCursor::Pull(Frame &frame, ExecutionContext &context) {
|
||||
// Skip setting labels on Null (can occur in optional match).
|
||||
if (vertex_value.IsNull()) return true;
|
||||
ExpectType(self_.input_symbol_, vertex_value, TypedValue::Type::Vertex);
|
||||
auto &vertex = vertex_value.Value<VertexAccessor>();
|
||||
auto &vertex = vertex_value.ValueVertex();
|
||||
vertex.SwitchNew();
|
||||
try {
|
||||
for (auto label : self_.labels_) vertex.add_label(label);
|
||||
@ -2123,7 +2122,7 @@ bool RemoveProperty::RemovePropertyCursor::Pull(Frame &frame,
|
||||
switch (lhs.type()) {
|
||||
case TypedValue::Type::Vertex:
|
||||
try {
|
||||
lhs.Value<VertexAccessor>().PropsErase(self_.property_);
|
||||
lhs.ValueVertex().PropsErase(self_.property_);
|
||||
} catch (const RecordDeletedError &) {
|
||||
throw QueryRuntimeException(
|
||||
"Trying to remove properties from a deleted node.");
|
||||
@ -2131,7 +2130,7 @@ bool RemoveProperty::RemovePropertyCursor::Pull(Frame &frame,
|
||||
break;
|
||||
case TypedValue::Type::Edge:
|
||||
try {
|
||||
lhs.Value<EdgeAccessor>().PropsErase(self_.property_);
|
||||
lhs.ValueEdge().PropsErase(self_.property_);
|
||||
} catch (const RecordDeletedError &) {
|
||||
throw QueryRuntimeException(
|
||||
"Trying to remove properties from a deleted edge.");
|
||||
@ -2183,7 +2182,7 @@ bool RemoveLabels::RemoveLabelsCursor::Pull(Frame &frame,
|
||||
// Skip removing labels on Null (can occur in optional match).
|
||||
if (vertex_value.IsNull()) return true;
|
||||
ExpectType(self_.input_symbol_, vertex_value, TypedValue::Type::Vertex);
|
||||
auto &vertex = vertex_value.Value<VertexAccessor>();
|
||||
auto &vertex = vertex_value.ValueVertex();
|
||||
vertex.SwitchNew();
|
||||
try {
|
||||
for (auto label : self_.labels_) vertex.remove_label(label);
|
||||
@ -2237,7 +2236,7 @@ bool ContainsSameEdge(const TypedValue &a, const TypedValue &b) {
|
||||
if (a.type() == TypedValue::Type::List) return compare_to_list(a, b);
|
||||
if (b.type() == TypedValue::Type::List) return compare_to_list(b, a);
|
||||
|
||||
return a.Value<EdgeAccessor>() == b.Value<EdgeAccessor>();
|
||||
return a.ValueEdge() == b.ValueEdge();
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@ -2276,7 +2275,6 @@ Accumulate::Accumulate(const std::shared_ptr<LogicalOperator> &input,
|
||||
|
||||
ACCEPT_WITH_INPUT(Accumulate)
|
||||
|
||||
|
||||
std::vector<Symbol> Accumulate::ModifiedSymbols(const SymbolTable &) const {
|
||||
return symbols_;
|
||||
}
|
||||
@ -2617,7 +2615,7 @@ class AggregateCursor : public Cursor {
|
||||
// since we skip nulls we either have a valid comparison, or
|
||||
// an exception was just thrown above
|
||||
// safe to assume a bool TypedValue
|
||||
if (comparison_result.Value<bool>()) *value_it = input_value;
|
||||
if (comparison_result.ValueBool()) *value_it = input_value;
|
||||
} catch (const TypedValueException &) {
|
||||
throw QueryRuntimeException("Unable to get MIN of '{}' and '{}'.",
|
||||
input_value.type(), value_it->type());
|
||||
@ -2629,7 +2627,7 @@ class AggregateCursor : public Cursor {
|
||||
EnsureOkForMinMax(input_value);
|
||||
try {
|
||||
TypedValue comparison_result = input_value > *value_it;
|
||||
if (comparison_result.Value<bool>()) *value_it = input_value;
|
||||
if (comparison_result.ValueBool()) *value_it = input_value;
|
||||
} catch (const TypedValueException &) {
|
||||
throw QueryRuntimeException("Unable to get MAX of '{}' and '{}'.",
|
||||
input_value.type(), value_it->type());
|
||||
@ -2728,7 +2726,7 @@ bool Skip::SkipCursor::Pull(Frame &frame, ExecutionContext &context) {
|
||||
throw QueryRuntimeException(
|
||||
"Number of elements to skip must be an integer.");
|
||||
|
||||
to_skip_ = to_skip.Value<int64_t>();
|
||||
to_skip_ = to_skip.ValueInt();
|
||||
if (to_skip_ < 0)
|
||||
throw QueryRuntimeException(
|
||||
"Number of elements to skip must be non-negative.");
|
||||
@ -2789,7 +2787,7 @@ bool Limit::LimitCursor::Pull(Frame &frame, ExecutionContext &context) {
|
||||
throw QueryRuntimeException(
|
||||
"Limit on number of returned elements must be an integer.");
|
||||
|
||||
limit_ = limit.Value<int64_t>();
|
||||
limit_ = limit.ValueInt();
|
||||
if (limit_ < 0)
|
||||
throw QueryRuntimeException(
|
||||
"Limit on number of returned elements must be non-negative.");
|
||||
|
@ -28,23 +28,23 @@ TypedValue::TypedValue(const PropertyValue &value,
|
||||
return;
|
||||
case PropertyValue::Type::Bool:
|
||||
type_ = Type::Bool;
|
||||
bool_v = value.Value<bool>();
|
||||
bool_v = value.ValueBool();
|
||||
return;
|
||||
case PropertyValue::Type::Int:
|
||||
type_ = Type::Int;
|
||||
int_v = value.Value<int64_t>();
|
||||
int_v = value.ValueInt();
|
||||
return;
|
||||
case PropertyValue::Type::Double:
|
||||
type_ = Type::Double;
|
||||
double_v = value.Value<double>();
|
||||
double_v = value.ValueDouble();
|
||||
return;
|
||||
case PropertyValue::Type::String:
|
||||
type_ = Type::String;
|
||||
new (&string_v) TString(value.Value<std::string>(), memory_);
|
||||
new (&string_v) TString(value.ValueString(), memory_);
|
||||
return;
|
||||
case PropertyValue::Type::List: {
|
||||
type_ = Type::List;
|
||||
const auto &vec = value.Value<std::vector<PropertyValue>>();
|
||||
const auto &vec = value.ValueList();
|
||||
new (&list_v) TVector(memory_);
|
||||
list_v.reserve(vec.size());
|
||||
for (const auto &v : vec) list_v.emplace_back(v);
|
||||
@ -52,7 +52,7 @@ TypedValue::TypedValue(const PropertyValue &value,
|
||||
}
|
||||
case PropertyValue::Type::Map: {
|
||||
type_ = Type::Map;
|
||||
const auto &map = value.Value<std::map<std::string, PropertyValue>>();
|
||||
const auto &map = value.ValueMap();
|
||||
new (&map_v) TMap(memory_);
|
||||
for (const auto &kv : map) map_v.emplace(kv.first, kv.second);
|
||||
return;
|
||||
@ -73,23 +73,23 @@ TypedValue::TypedValue(PropertyValue &&other, utils::MemoryResource *memory)
|
||||
break;
|
||||
case PropertyValue::Type::Bool:
|
||||
type_ = Type::Bool;
|
||||
bool_v = other.Value<bool>();
|
||||
bool_v = other.ValueBool();
|
||||
break;
|
||||
case PropertyValue::Type::Int:
|
||||
type_ = Type::Int;
|
||||
int_v = other.Value<int64_t>();
|
||||
int_v = other.ValueInt();
|
||||
break;
|
||||
case PropertyValue::Type::Double:
|
||||
type_ = Type::Double;
|
||||
double_v = other.Value<double>();
|
||||
double_v = other.ValueDouble();
|
||||
break;
|
||||
case PropertyValue::Type::String:
|
||||
type_ = Type::String;
|
||||
new (&string_v) TString(other.Value<std::string>(), memory_);
|
||||
new (&string_v) TString(other.ValueString(), memory_);
|
||||
break;
|
||||
case PropertyValue::Type::List: {
|
||||
type_ = Type::List;
|
||||
auto &vec = other.Value<std::vector<PropertyValue>>();
|
||||
auto &vec = other.ValueList();
|
||||
new (&list_v) TVector(memory_);
|
||||
list_v.reserve(vec.size());
|
||||
for (auto &v : vec) list_v.emplace_back(std::move(v));
|
||||
@ -97,7 +97,7 @@ TypedValue::TypedValue(PropertyValue &&other, utils::MemoryResource *memory)
|
||||
}
|
||||
case PropertyValue::Type::Map: {
|
||||
type_ = Type::Map;
|
||||
auto &map = other.Value<std::map<std::string, PropertyValue>>();
|
||||
auto &map = other.ValueMap();
|
||||
new (&map_v) TMap(memory_);
|
||||
for (auto &kv : map) map_v.emplace(kv.first, std::move(kv.second));
|
||||
break;
|
||||
@ -214,31 +214,21 @@ TypedValue::operator PropertyValue() const {
|
||||
"Unsupported conversion from TypedValue to PropertyValue");
|
||||
}
|
||||
|
||||
#define DEFINE_VALUE_AND_TYPE_GETTERS(type_param, type_enum, field) \
|
||||
template <> \
|
||||
type_param &TypedValue::Value<type_param>() { \
|
||||
if (type_ != Type::type_enum) \
|
||||
throw TypedValueException( \
|
||||
"Incompatible template param '{}' and type '{}'", Type::type_enum, \
|
||||
type_); \
|
||||
return field; \
|
||||
} \
|
||||
\
|
||||
template <> \
|
||||
const type_param &TypedValue::Value<type_param>() const { \
|
||||
if (type_ != Type::type_enum) \
|
||||
throw TypedValueException( \
|
||||
"Incompatible template param '{}' and type '{}'", Type::type_enum, \
|
||||
type_); \
|
||||
return field; \
|
||||
} \
|
||||
\
|
||||
type_param &TypedValue::Value##type_enum() { return Value<type_param>(); } \
|
||||
\
|
||||
const type_param &TypedValue::Value##type_enum() const { \
|
||||
return Value<type_param>(); \
|
||||
} \
|
||||
\
|
||||
#define DEFINE_VALUE_AND_TYPE_GETTERS(type_param, type_enum, field) \
|
||||
type_param &TypedValue::Value##type_enum() { \
|
||||
if (type_ != Type::type_enum) \
|
||||
throw TypedValueException("TypedValue is of type '{}', not '{}'", type_, \
|
||||
Type::type_enum); \
|
||||
return field; \
|
||||
} \
|
||||
\
|
||||
const type_param &TypedValue::Value##type_enum() const { \
|
||||
if (type_ != Type::type_enum) \
|
||||
throw TypedValueException("TypedValue is of type '{}', not '{}'", type_, \
|
||||
Type::type_enum); \
|
||||
return field; \
|
||||
} \
|
||||
\
|
||||
bool TypedValue::Is##type_enum() const { return type_ == Type::type_enum; }
|
||||
|
||||
DEFINE_VALUE_AND_TYPE_GETTERS(bool, Bool, bool_v)
|
||||
@ -303,11 +293,11 @@ std::ostream &operator<<(std::ostream &os, const TypedValue &value) {
|
||||
case TypedValue::Type::Null:
|
||||
return os << "Null";
|
||||
case TypedValue::Type::Bool:
|
||||
return os << (value.Value<bool>() ? "true" : "false");
|
||||
return os << (value.ValueBool() ? "true" : "false");
|
||||
case TypedValue::Type::Int:
|
||||
return os << value.Value<int64_t>();
|
||||
return os << value.ValueInt();
|
||||
case TypedValue::Type::Double:
|
||||
return os << value.Value<double>();
|
||||
return os << value.ValueDouble();
|
||||
case TypedValue::Type::String:
|
||||
return os << value.ValueString();
|
||||
case TypedValue::Type::List:
|
||||
@ -322,11 +312,11 @@ std::ostream &operator<<(std::ostream &os, const TypedValue &value) {
|
||||
});
|
||||
return os << "}";
|
||||
case TypedValue::Type::Vertex:
|
||||
return os << value.Value<VertexAccessor>();
|
||||
return os << value.ValueVertex();
|
||||
case TypedValue::Type::Edge:
|
||||
return os << value.Value<EdgeAccessor>();
|
||||
return os << value.ValueEdge();
|
||||
case TypedValue::Type::Path:
|
||||
return os << value.Value<Path>();
|
||||
return os << value.ValuePath();
|
||||
}
|
||||
LOG(FATAL) << "Unsupported PropertyValue::Type";
|
||||
}
|
||||
@ -565,9 +555,9 @@ TypedValue::~TypedValue() {
|
||||
double ToDouble(const TypedValue &value) {
|
||||
switch (value.type()) {
|
||||
case TypedValue::Type::Int:
|
||||
return (double)value.Value<int64_t>();
|
||||
return (double)value.ValueInt();
|
||||
case TypedValue::Type::Double:
|
||||
return value.Value<double>();
|
||||
return value.ValueDouble();
|
||||
default:
|
||||
throw TypedValueException(
|
||||
"Unsupported TypedValue::Type conversion to double");
|
||||
@ -606,8 +596,7 @@ TypedValue operator<(const TypedValue &a, const TypedValue &b) {
|
||||
if (a.IsDouble() || b.IsDouble()) {
|
||||
return TypedValue(ToDouble(a) < ToDouble(b), a.GetMemoryResource());
|
||||
} else {
|
||||
return TypedValue(a.Value<int64_t>() < b.Value<int64_t>(),
|
||||
a.GetMemoryResource());
|
||||
return TypedValue(a.ValueInt() < b.ValueInt(), a.GetMemoryResource());
|
||||
}
|
||||
}
|
||||
|
||||
@ -621,25 +610,22 @@ TypedValue operator==(const TypedValue &a, const TypedValue &b) {
|
||||
|
||||
switch (a.type()) {
|
||||
case TypedValue::Type::Bool:
|
||||
return TypedValue(a.Value<bool>() == b.Value<bool>(),
|
||||
a.GetMemoryResource());
|
||||
return TypedValue(a.ValueBool() == b.ValueBool(), a.GetMemoryResource());
|
||||
case TypedValue::Type::Int:
|
||||
if (b.IsDouble())
|
||||
return TypedValue(ToDouble(a) == ToDouble(b), a.GetMemoryResource());
|
||||
else
|
||||
return TypedValue(a.Value<int64_t>() == b.Value<int64_t>(),
|
||||
a.GetMemoryResource());
|
||||
return TypedValue(a.ValueInt() == b.ValueInt(), a.GetMemoryResource());
|
||||
case TypedValue::Type::Double:
|
||||
return TypedValue(ToDouble(a) == ToDouble(b), a.GetMemoryResource());
|
||||
case TypedValue::Type::String:
|
||||
return TypedValue(a.ValueString() == b.ValueString(),
|
||||
a.GetMemoryResource());
|
||||
case TypedValue::Type::Vertex:
|
||||
return TypedValue(a.Value<VertexAccessor>() == b.Value<VertexAccessor>(),
|
||||
return TypedValue(a.ValueVertex() == b.ValueVertex(),
|
||||
a.GetMemoryResource());
|
||||
case TypedValue::Type::Edge:
|
||||
return TypedValue(a.Value<EdgeAccessor>() == b.Value<EdgeAccessor>(),
|
||||
a.GetMemoryResource());
|
||||
return TypedValue(a.ValueEdge() == b.ValueEdge(), a.GetMemoryResource());
|
||||
case TypedValue::Type::List: {
|
||||
// We are not compatible with neo4j at this point. In neo4j 2 = [2]
|
||||
// compares
|
||||
@ -672,7 +658,7 @@ TypedValue operator==(const TypedValue &a, const TypedValue &b) {
|
||||
if (found_b_it == map_b.end())
|
||||
return TypedValue(false, a.GetMemoryResource());
|
||||
TypedValue comparison = kv_a.second == found_b_it->second;
|
||||
if (comparison.IsNull() || !comparison.Value<bool>())
|
||||
if (comparison.IsNull() || !comparison.ValueBool())
|
||||
return TypedValue(false, a.GetMemoryResource());
|
||||
}
|
||||
return TypedValue(true, a.GetMemoryResource());
|
||||
@ -686,7 +672,7 @@ TypedValue operator==(const TypedValue &a, const TypedValue &b) {
|
||||
|
||||
TypedValue operator!(const TypedValue &a) {
|
||||
if (a.IsNull()) return TypedValue(a.GetMemoryResource());
|
||||
if (a.IsBool()) return TypedValue(!a.Value<bool>(), a.GetMemoryResource());
|
||||
if (a.IsBool()) return TypedValue(!a.ValueBool(), a.GetMemoryResource());
|
||||
throw TypedValueException("Invalid logical not operand type (!{})", a.type());
|
||||
}
|
||||
|
||||
@ -699,8 +685,8 @@ TypedValue operator!(const TypedValue &a) {
|
||||
std::string ValueToString(const TypedValue &value) {
|
||||
// TODO: Should this allocate a string through value.GetMemoryResource()?
|
||||
if (value.IsString()) return std::string(value.ValueString());
|
||||
if (value.IsInt()) return std::to_string(value.Value<int64_t>());
|
||||
if (value.IsDouble()) return fmt::format("{}", value.Value<double>());
|
||||
if (value.IsInt()) return std::to_string(value.ValueInt());
|
||||
if (value.IsDouble()) return fmt::format("{}", value.ValueDouble());
|
||||
// unsupported situations
|
||||
throw TypedValueException(
|
||||
"Unsupported TypedValue::Type conversion to string");
|
||||
@ -708,17 +694,15 @@ std::string ValueToString(const TypedValue &value) {
|
||||
|
||||
TypedValue operator-(const TypedValue &a) {
|
||||
if (a.IsNull()) return TypedValue(a.GetMemoryResource());
|
||||
if (a.IsInt()) return TypedValue(-a.Value<int64_t>(), a.GetMemoryResource());
|
||||
if (a.IsDouble())
|
||||
return TypedValue(-a.Value<double>(), a.GetMemoryResource());
|
||||
if (a.IsInt()) return TypedValue(-a.ValueInt(), a.GetMemoryResource());
|
||||
if (a.IsDouble()) return TypedValue(-a.ValueDouble(), a.GetMemoryResource());
|
||||
throw TypedValueException("Invalid unary minus operand type (-{})", a.type());
|
||||
}
|
||||
|
||||
TypedValue operator+(const TypedValue &a) {
|
||||
if (a.IsNull()) return TypedValue(a.GetMemoryResource());
|
||||
if (a.IsInt()) return TypedValue(+a.Value<int64_t>(), a.GetMemoryResource());
|
||||
if (a.IsDouble())
|
||||
return TypedValue(+a.Value<double>(), a.GetMemoryResource());
|
||||
if (a.IsInt()) return TypedValue(+a.ValueInt(), a.GetMemoryResource());
|
||||
if (a.IsDouble()) return TypedValue(+a.ValueDouble(), a.GetMemoryResource());
|
||||
throw TypedValueException("Invalid unary plus operand type (+{})", a.type());
|
||||
}
|
||||
|
||||
@ -778,8 +762,7 @@ TypedValue operator+(const TypedValue &a, const TypedValue &b) {
|
||||
if (a.IsDouble() || b.IsDouble()) {
|
||||
return TypedValue(ToDouble(a) + ToDouble(b), a.GetMemoryResource());
|
||||
} else {
|
||||
return TypedValue(a.Value<int64_t>() + b.Value<int64_t>(),
|
||||
a.GetMemoryResource());
|
||||
return TypedValue(a.ValueInt() + b.ValueInt(), a.GetMemoryResource());
|
||||
}
|
||||
}
|
||||
|
||||
@ -791,8 +774,7 @@ TypedValue operator-(const TypedValue &a, const TypedValue &b) {
|
||||
if (a.IsDouble() || b.IsDouble()) {
|
||||
return TypedValue(ToDouble(a) - ToDouble(b), a.GetMemoryResource());
|
||||
} else {
|
||||
return TypedValue(a.Value<int64_t>() - b.Value<int64_t>(),
|
||||
a.GetMemoryResource());
|
||||
return TypedValue(a.ValueInt() - b.ValueInt(), a.GetMemoryResource());
|
||||
}
|
||||
}
|
||||
|
||||
@ -804,10 +786,8 @@ TypedValue operator/(const TypedValue &a, const TypedValue &b) {
|
||||
if (a.IsDouble() || b.IsDouble()) {
|
||||
return TypedValue(ToDouble(a) / ToDouble(b), a.GetMemoryResource());
|
||||
} else {
|
||||
if (b.Value<int64_t>() == 0LL)
|
||||
throw TypedValueException("Division by zero");
|
||||
return TypedValue(a.Value<int64_t>() / b.Value<int64_t>(),
|
||||
a.GetMemoryResource());
|
||||
if (b.ValueInt() == 0LL) throw TypedValueException("Division by zero");
|
||||
return TypedValue(a.ValueInt() / b.ValueInt(), a.GetMemoryResource());
|
||||
}
|
||||
}
|
||||
|
||||
@ -819,8 +799,7 @@ TypedValue operator*(const TypedValue &a, const TypedValue &b) {
|
||||
if (a.IsDouble() || b.IsDouble()) {
|
||||
return TypedValue(ToDouble(a) * ToDouble(b), a.GetMemoryResource());
|
||||
} else {
|
||||
return TypedValue(a.Value<int64_t>() * b.Value<int64_t>(),
|
||||
a.GetMemoryResource());
|
||||
return TypedValue(a.ValueInt() * b.ValueInt(), a.GetMemoryResource());
|
||||
}
|
||||
}
|
||||
|
||||
@ -833,9 +812,8 @@ TypedValue operator%(const TypedValue &a, const TypedValue &b) {
|
||||
return TypedValue(static_cast<double>(fmod(ToDouble(a), ToDouble(b))),
|
||||
a.GetMemoryResource());
|
||||
} else {
|
||||
if (b.Value<int64_t>() == 0LL) throw TypedValueException("Mod with zero");
|
||||
return TypedValue(a.Value<int64_t>() % b.Value<int64_t>(),
|
||||
a.GetMemoryResource());
|
||||
if (b.ValueInt() == 0LL) throw TypedValueException("Mod with zero");
|
||||
return TypedValue(a.ValueInt() % b.ValueInt(), a.GetMemoryResource());
|
||||
}
|
||||
}
|
||||
|
||||
@ -850,9 +828,9 @@ TypedValue operator&&(const TypedValue &a, const TypedValue &b) {
|
||||
EnsureLogicallyOk(a, b, "logical AND");
|
||||
// at this point we only have null and bool
|
||||
// if either operand is false, the result is false
|
||||
if (a.IsBool() && !a.Value<bool>())
|
||||
if (a.IsBool() && !a.ValueBool())
|
||||
return TypedValue(false, a.GetMemoryResource());
|
||||
if (b.IsBool() && !b.Value<bool>())
|
||||
if (b.IsBool() && !b.ValueBool())
|
||||
return TypedValue(false, a.GetMemoryResource());
|
||||
if (a.IsNull() || b.IsNull()) return TypedValue(a.GetMemoryResource());
|
||||
// neither is false, neither is null, thus both are true
|
||||
@ -863,9 +841,9 @@ TypedValue operator||(const TypedValue &a, const TypedValue &b) {
|
||||
EnsureLogicallyOk(a, b, "logical OR");
|
||||
// at this point we only have null and bool
|
||||
// if either operand is true, the result is true
|
||||
if (a.IsBool() && a.Value<bool>())
|
||||
if (a.IsBool() && a.ValueBool())
|
||||
return TypedValue(true, a.GetMemoryResource());
|
||||
if (b.IsBool() && b.Value<bool>())
|
||||
if (b.IsBool() && b.ValueBool())
|
||||
return TypedValue(true, a.GetMemoryResource());
|
||||
if (a.IsNull() || b.IsNull()) return TypedValue(a.GetMemoryResource());
|
||||
// neither is true, neither is null, thus both are false
|
||||
@ -878,7 +856,7 @@ TypedValue operator^(const TypedValue &a, const TypedValue &b) {
|
||||
if (a.IsNull() || b.IsNull())
|
||||
return TypedValue(a.GetMemoryResource());
|
||||
else
|
||||
return TypedValue(static_cast<bool>(a.Value<bool>() ^ b.Value<bool>()),
|
||||
return TypedValue(static_cast<bool>(a.ValueBool() ^ b.ValueBool()),
|
||||
a.GetMemoryResource());
|
||||
}
|
||||
|
||||
@ -888,7 +866,7 @@ bool TypedValue::BoolEqual::operator()(const TypedValue &lhs,
|
||||
TypedValue equality_result = lhs == rhs;
|
||||
switch (equality_result.type()) {
|
||||
case TypedValue::Type::Bool:
|
||||
return equality_result.Value<bool>();
|
||||
return equality_result.ValueBool();
|
||||
case TypedValue::Type::Null:
|
||||
return false;
|
||||
default:
|
||||
@ -903,14 +881,14 @@ size_t TypedValue::Hash::operator()(const TypedValue &value) const {
|
||||
case TypedValue::Type::Null:
|
||||
return 31;
|
||||
case TypedValue::Type::Bool:
|
||||
return std::hash<bool>{}(value.Value<bool>());
|
||||
return std::hash<bool>{}(value.ValueBool());
|
||||
case TypedValue::Type::Int:
|
||||
// we cast int to double for hashing purposes
|
||||
// to be consistent with TypedValue equality
|
||||
// in which (2.0 == 2) returns true
|
||||
return std::hash<double>{}((double)value.Value<int64_t>());
|
||||
return std::hash<double>{}((double)value.ValueInt());
|
||||
case TypedValue::Type::Double:
|
||||
return std::hash<double>{}(value.Value<double>());
|
||||
return std::hash<double>{}(value.ValueDouble());
|
||||
case TypedValue::Type::String:
|
||||
return std::hash<std::string_view>{}(value.ValueString());
|
||||
case TypedValue::Type::List: {
|
||||
@ -926,9 +904,9 @@ size_t TypedValue::Hash::operator()(const TypedValue &value) const {
|
||||
return hash;
|
||||
}
|
||||
case TypedValue::Type::Vertex:
|
||||
return value.Value<VertexAccessor>().gid();
|
||||
return value.ValueVertex().gid();
|
||||
case TypedValue::Type::Edge:
|
||||
return value.Value<EdgeAccessor>().gid();
|
||||
return value.ValueEdge().gid();
|
||||
case TypedValue::Type::Path: {
|
||||
const auto &vertices = value.ValuePath().vertices();
|
||||
const auto &edges = value.ValuePath().edges();
|
||||
|
@ -48,6 +48,7 @@ class TypedValue {
|
||||
* then it implicitly instantiates TypedValue::Value<T> before
|
||||
* explicit instantiation in .cpp file. If the implementation is in
|
||||
* the .cpp file, it won't link.
|
||||
* TODO: No longer the case as Value<T> was removed.
|
||||
*/
|
||||
struct Hash {
|
||||
size_t operator()(const TypedValue &value) const;
|
||||
@ -454,19 +455,6 @@ class TypedValue {
|
||||
|
||||
Type type() const { return type_; }
|
||||
|
||||
/**
|
||||
* Returns the value of the property as given type T.
|
||||
* The behavior of this function is undefined if
|
||||
* T does not correspond to this property's type_.
|
||||
*
|
||||
* @tparam T Type to interpret the value as.
|
||||
* @return The value as type T.
|
||||
*/
|
||||
template <typename T>
|
||||
T &Value();
|
||||
template <typename T>
|
||||
const T &Value() const;
|
||||
|
||||
// TODO consider adding getters for primitives by value (and not by ref)
|
||||
|
||||
#define DECLARE_VALUE_AND_TYPE_GETTERS(type_param, field) \
|
||||
|
@ -1,106 +1,5 @@
|
||||
#include "storage/common/types/property_value.hpp"
|
||||
|
||||
// const value extraction template instantiations
|
||||
template <>
|
||||
const bool &PropertyValue::Value<bool>() const {
|
||||
if (type_ != Type::Bool) {
|
||||
throw PropertyValueException("Incompatible template param and type");
|
||||
}
|
||||
return bool_v;
|
||||
}
|
||||
|
||||
template <>
|
||||
const int64_t &PropertyValue::Value<int64_t>() const {
|
||||
if (type_ != Type::Int) {
|
||||
throw PropertyValueException("Incompatible template param and type");
|
||||
}
|
||||
return int_v;
|
||||
}
|
||||
|
||||
template <>
|
||||
const double &PropertyValue::Value<double>() const {
|
||||
if (type_ != Type::Double) {
|
||||
throw PropertyValueException("Incompatible template param and type");
|
||||
}
|
||||
return double_v;
|
||||
}
|
||||
|
||||
template <>
|
||||
const std::string &PropertyValue::Value<std::string>() const {
|
||||
if (type_ != Type::String) {
|
||||
throw PropertyValueException("Incompatible template param and type");
|
||||
}
|
||||
return string_v;
|
||||
}
|
||||
|
||||
template <>
|
||||
const std::vector<PropertyValue>
|
||||
&PropertyValue::Value<std::vector<PropertyValue>>() const {
|
||||
if (type_ != Type::List) {
|
||||
throw PropertyValueException("Incompatible template param and type");
|
||||
}
|
||||
return list_v;
|
||||
}
|
||||
|
||||
template <>
|
||||
const std::map<std::string, PropertyValue>
|
||||
&PropertyValue::Value<std::map<std::string, PropertyValue>>() const {
|
||||
if (type_ != Type::Map) {
|
||||
throw PropertyValueException("Incompatible template param and type");
|
||||
}
|
||||
return map_v;
|
||||
}
|
||||
|
||||
// value extraction template instantiations
|
||||
template <>
|
||||
bool &PropertyValue::Value<bool>() {
|
||||
if (type_ != Type::Bool) {
|
||||
throw PropertyValueException("Incompatible template param and type");
|
||||
}
|
||||
return bool_v;
|
||||
}
|
||||
|
||||
template <>
|
||||
int64_t &PropertyValue::Value<int64_t>() {
|
||||
if (type_ != Type::Int) {
|
||||
throw PropertyValueException("Incompatible template param and type");
|
||||
}
|
||||
return int_v;
|
||||
}
|
||||
|
||||
template <>
|
||||
double &PropertyValue::Value<double>() {
|
||||
if (type_ != Type::Double) {
|
||||
throw PropertyValueException("Incompatible template param and type");
|
||||
}
|
||||
return double_v;
|
||||
}
|
||||
|
||||
template <>
|
||||
std::string &PropertyValue::Value<std::string>() {
|
||||
if (type_ != Type::String) {
|
||||
throw PropertyValueException("Incompatible template param and type");
|
||||
}
|
||||
return string_v;
|
||||
}
|
||||
|
||||
template <>
|
||||
std::vector<PropertyValue> &PropertyValue::Value<std::vector<PropertyValue>>() {
|
||||
if (type_ != Type::List) {
|
||||
throw PropertyValueException("Incompatible template param and type");
|
||||
}
|
||||
return list_v;
|
||||
}
|
||||
|
||||
template <>
|
||||
std::map<std::string, PropertyValue>
|
||||
&PropertyValue::Value<std::map<std::string, PropertyValue>>() {
|
||||
if (type_ != Type::Map) {
|
||||
throw PropertyValueException("Incompatible template param and type");
|
||||
}
|
||||
return map_v;
|
||||
}
|
||||
|
||||
// constructors
|
||||
PropertyValue::PropertyValue(const PropertyValue &other) : type_(other.type_) {
|
||||
switch (other.type_) {
|
||||
@ -273,23 +172,23 @@ std::ostream &operator<<(std::ostream &os, const PropertyValue &value) {
|
||||
case PropertyValue::Type::Null:
|
||||
return os << "Null";
|
||||
case PropertyValue::Type::Bool:
|
||||
return os << (value.Value<bool>() ? "true" : "false");
|
||||
return os << (value.ValueBool() ? "true" : "false");
|
||||
case PropertyValue::Type::String:
|
||||
return os << value.Value<std::string>();
|
||||
return os << value.ValueString();
|
||||
case PropertyValue::Type::Int:
|
||||
return os << value.Value<int64_t>();
|
||||
return os << value.ValueInt();
|
||||
case PropertyValue::Type::Double:
|
||||
return os << value.Value<double>();
|
||||
return os << value.ValueDouble();
|
||||
case PropertyValue::Type::List:
|
||||
os << "[";
|
||||
for (const auto &x : value.Value<std::vector<PropertyValue>>()) {
|
||||
for (const auto &x : value.ValueList()) {
|
||||
os << x << ",";
|
||||
}
|
||||
return os << "]";
|
||||
case PropertyValue::Type::Map:
|
||||
os << "{";
|
||||
for (const auto &kv :
|
||||
value.Value<std::map<std::string, PropertyValue>>()) {
|
||||
value.ValueMap()) {
|
||||
os << kv.first << ": " << kv.second << ",";
|
||||
}
|
||||
return os << "}";
|
||||
@ -302,19 +201,17 @@ bool operator==(const PropertyValue &first, const PropertyValue &second) {
|
||||
case PropertyValue::Type::Null:
|
||||
return true;
|
||||
case PropertyValue::Type::Bool:
|
||||
return first.Value<bool>() == second.Value<bool>();
|
||||
return first.ValueBool() == second.ValueBool();
|
||||
case PropertyValue::Type::Int:
|
||||
return first.Value<int64_t>() == second.Value<int64_t>();
|
||||
return first.ValueInt() == second.ValueInt();
|
||||
case PropertyValue::Type::Double:
|
||||
return first.Value<double>() == second.Value<double>();
|
||||
return first.ValueDouble() == second.ValueDouble();
|
||||
case PropertyValue::Type::String:
|
||||
return first.Value<std::string>() == second.Value<std::string>();
|
||||
return first.ValueString() == second.ValueString();
|
||||
case PropertyValue::Type::List:
|
||||
return first.Value<std::vector<PropertyValue>>() ==
|
||||
second.Value<std::vector<PropertyValue>>();
|
||||
return first.ValueList() == second.ValueList();
|
||||
case PropertyValue::Type::Map:
|
||||
return first.Value<std::map<std::string, PropertyValue>>() ==
|
||||
second.Value<std::map<std::string, PropertyValue>>();
|
||||
return first.ValueMap() == second.ValueMap();
|
||||
}
|
||||
}
|
||||
|
||||
@ -324,18 +221,16 @@ bool operator<(const PropertyValue &first, const PropertyValue &second) {
|
||||
case PropertyValue::Type::Null:
|
||||
return false;
|
||||
case PropertyValue::Type::Bool:
|
||||
return first.Value<bool>() < second.Value<bool>();
|
||||
return first.ValueBool() < second.ValueBool();
|
||||
case PropertyValue::Type::Int:
|
||||
return first.Value<int64_t>() < second.Value<int64_t>();
|
||||
return first.ValueInt() < second.ValueInt();
|
||||
case PropertyValue::Type::Double:
|
||||
return first.Value<double>() < second.Value<double>();
|
||||
return first.ValueDouble() < second.ValueDouble();
|
||||
case PropertyValue::Type::String:
|
||||
return first.Value<std::string>() < second.Value<std::string>();
|
||||
return first.ValueString() < second.ValueString();
|
||||
case PropertyValue::Type::List:
|
||||
return first.Value<std::vector<PropertyValue>>() <
|
||||
second.Value<std::vector<PropertyValue>>();
|
||||
return first.ValueList() < second.ValueList();
|
||||
case PropertyValue::Type::Map:
|
||||
return first.Value<std::map<std::string, PropertyValue>>() <
|
||||
second.Value<std::map<std::string, PropertyValue>>();
|
||||
return first.ValueMap() < second.ValueMap();
|
||||
}
|
||||
}
|
||||
|
@ -89,19 +89,6 @@ class PropertyValue {
|
||||
|
||||
bool IsNull() const { return type_ == Type::Null; }
|
||||
|
||||
/**
|
||||
* Returns the value of the property as given type T.
|
||||
* The behavior of this function is undefined if
|
||||
* T does not correspond to this property's type_.
|
||||
*
|
||||
* @tparam T Type to interpret the value as.
|
||||
* @return The value as type T.
|
||||
*/
|
||||
template <typename T>
|
||||
const T &Value() const;
|
||||
template <typename T>
|
||||
T &Value();
|
||||
|
||||
bool ValueBool() const {
|
||||
if (type_ != Type::Bool) {
|
||||
throw PropertyValueException("This value isn't a bool!");
|
||||
|
@ -9,23 +9,23 @@ void Save(const PropertyValue &value, slk::Builder *builder) {
|
||||
return;
|
||||
case PropertyValue::Type::Bool:
|
||||
slk::Save(static_cast<uint8_t>(1), builder);
|
||||
slk::Save(value.Value<bool>(), builder);
|
||||
slk::Save(value.ValueBool(), builder);
|
||||
return;
|
||||
case PropertyValue::Type::Int:
|
||||
slk::Save(static_cast<uint8_t>(2), builder);
|
||||
slk::Save(value.Value<int64_t>(), builder);
|
||||
slk::Save(value.ValueInt(), builder);
|
||||
return;
|
||||
case PropertyValue::Type::Double:
|
||||
slk::Save(static_cast<uint8_t>(3), builder);
|
||||
slk::Save(value.Value<double>(), builder);
|
||||
slk::Save(value.ValueDouble(), builder);
|
||||
return;
|
||||
case PropertyValue::Type::String:
|
||||
slk::Save(static_cast<uint8_t>(4), builder);
|
||||
slk::Save(value.Value<std::string>(), builder);
|
||||
slk::Save(value.ValueString(), builder);
|
||||
return;
|
||||
case PropertyValue::Type::List: {
|
||||
slk::Save(static_cast<uint8_t>(5), builder);
|
||||
const auto &values = value.Value<std::vector<PropertyValue>>();
|
||||
const auto &values = value.ValueList();
|
||||
size_t size = values.size();
|
||||
slk::Save(size, builder);
|
||||
for (const auto &v : values) {
|
||||
@ -35,7 +35,7 @@ void Save(const PropertyValue &value, slk::Builder *builder) {
|
||||
}
|
||||
case PropertyValue::Type::Map: {
|
||||
slk::Save(static_cast<uint8_t>(6), builder);
|
||||
const auto &map = value.Value<std::map<std::string, PropertyValue>>();
|
||||
const auto &map = value.ValueMap();
|
||||
size_t size = map.size();
|
||||
slk::Save(size, builder);
|
||||
for (const auto &kv : map) {
|
||||
|
@ -409,23 +409,23 @@ class LabelPropertyIndex {
|
||||
case PropertyValue::Type::Null:
|
||||
return false;
|
||||
case PropertyValue::Type::String:
|
||||
return a.Value<std::string>() < b.Value<std::string>();
|
||||
return a.ValueString() < b.ValueString();
|
||||
case PropertyValue::Type::Bool:
|
||||
return a.Value<bool>() < b.Value<bool>();
|
||||
return a.ValueBool() < b.ValueBool();
|
||||
case PropertyValue::Type::Int:
|
||||
return a.Value<int64_t>() < b.Value<int64_t>();
|
||||
return a.ValueInt() < b.ValueInt();
|
||||
case PropertyValue::Type::Double:
|
||||
return a.Value<double>() < b.Value<double>();
|
||||
return a.ValueDouble() < b.ValueDouble();
|
||||
case PropertyValue::Type::List: {
|
||||
auto va = a.Value<std::vector<PropertyValue>>();
|
||||
auto vb = b.Value<std::vector<PropertyValue>>();
|
||||
auto va = a.ValueList();
|
||||
auto vb = b.ValueList();
|
||||
if (va.size() != vb.size()) return va.size() < vb.size();
|
||||
return lexicographical_compare(va.begin(), va.end(), vb.begin(),
|
||||
vb.end(), Less);
|
||||
}
|
||||
case PropertyValue::Type::Map: {
|
||||
auto ma = a.Value<std::map<std::string, PropertyValue>>();
|
||||
auto mb = b.Value<std::map<std::string, PropertyValue>>();
|
||||
auto ma = a.ValueMap();
|
||||
auto mb = b.ValueMap();
|
||||
if (ma.size() != mb.size()) return ma.size() < mb.size();
|
||||
const auto cmp = [](const auto &a, const auto &b) {
|
||||
if (a.first != b.first)
|
||||
@ -445,8 +445,8 @@ class LabelPropertyIndex {
|
||||
value.type() == PropertyValue::Type::Double)
|
||||
<< "Invalid data type.";
|
||||
if (value.type() == PropertyValue::Type::Int)
|
||||
return static_cast<double>(value.Value<int64_t>());
|
||||
return value.Value<double>();
|
||||
return static_cast<double>(value.ValueInt());
|
||||
return value.ValueDouble();
|
||||
};
|
||||
|
||||
// Types are int and double - convert int to double
|
||||
|
@ -409,23 +409,23 @@ class LabelPropertyIndex {
|
||||
case PropertyValue::Type::Null:
|
||||
return false;
|
||||
case PropertyValue::Type::String:
|
||||
return a.Value<std::string>() < b.Value<std::string>();
|
||||
return a.ValueString() < b.ValueString();
|
||||
case PropertyValue::Type::Bool:
|
||||
return a.Value<bool>() < b.Value<bool>();
|
||||
return a.ValueBool() < b.ValueBool();
|
||||
case PropertyValue::Type::Int:
|
||||
return a.Value<int64_t>() < b.Value<int64_t>();
|
||||
return a.ValueInt() < b.ValueInt();
|
||||
case PropertyValue::Type::Double:
|
||||
return a.Value<double>() < b.Value<double>();
|
||||
return a.ValueDouble() < b.ValueDouble();
|
||||
case PropertyValue::Type::List: {
|
||||
auto va = a.Value<std::vector<PropertyValue>>();
|
||||
auto vb = b.Value<std::vector<PropertyValue>>();
|
||||
auto va = a.ValueList();
|
||||
auto vb = b.ValueList();
|
||||
if (va.size() != vb.size()) return va.size() < vb.size();
|
||||
return lexicographical_compare(va.begin(), va.end(), vb.begin(),
|
||||
vb.end(), Less);
|
||||
}
|
||||
case PropertyValue::Type::Map: {
|
||||
auto ma = a.Value<std::map<std::string, PropertyValue>>();
|
||||
auto mb = b.Value<std::map<std::string, PropertyValue>>();
|
||||
auto ma = a.ValueMap();
|
||||
auto mb = b.ValueMap();
|
||||
if (ma.size() != mb.size()) return ma.size() < mb.size();
|
||||
const auto cmp = [](const auto &a, const auto &b) {
|
||||
if (a.first != b.first)
|
||||
@ -445,8 +445,8 @@ class LabelPropertyIndex {
|
||||
value.type() == PropertyValue::Type::Double)
|
||||
<< "Invalid data type.";
|
||||
if (value.type() == PropertyValue::Type::Int)
|
||||
return static_cast<double>(value.Value<int64_t>());
|
||||
return value.Value<double>();
|
||||
return static_cast<double>(value.ValueInt());
|
||||
return value.ValueDouble();
|
||||
};
|
||||
|
||||
// Types are int and double - convert int to double
|
||||
|
@ -274,8 +274,8 @@ void CheckPath(database::GraphDbAccessor *dba, const VertexAccessor &source,
|
||||
ASSERT_TRUE(edge.from() == curr || edge.to() == curr);
|
||||
VertexAccessor next = edge.from_is(curr) ? edge.to() : edge.from();
|
||||
|
||||
int from = GetProp(curr, "id", dba).Value<int64_t>();
|
||||
int to = GetProp(next, "id", dba).Value<int64_t>();
|
||||
int from = GetProp(curr, "id", dba).ValueInt();
|
||||
int to = GetProp(next, "id", dba).ValueInt();
|
||||
ASSERT_TRUE(utils::Contains(edges, std::make_pair(from, to)));
|
||||
|
||||
curr = next;
|
||||
@ -295,8 +295,8 @@ std::vector<std::vector<int>> CheckPathsAndExtractDistances(
|
||||
for (size_t i = 0; i < kVertexCount; ++i) distances[i][i] = 0;
|
||||
|
||||
for (const auto &row : results) {
|
||||
auto source = GetProp(row[0].ValueVertex(), "id", dba).Value<int64_t>();
|
||||
auto sink = GetProp(row[1].ValueVertex(), "id", dba).Value<int64_t>();
|
||||
auto source = GetProp(row[0].ValueVertex(), "id", dba).ValueInt();
|
||||
auto sink = GetProp(row[1].ValueVertex(), "id", dba).ValueInt();
|
||||
distances[source][sink] = row[2].ValueList().size();
|
||||
CheckPath(dba, row[0].ValueVertex(), row[1].ValueVertex(),
|
||||
row[2].ValueList(), edges);
|
||||
@ -433,9 +433,9 @@ void BfsTest(Database *db, int lower_bound, int upper_bound,
|
||||
auto edges = kEdges;
|
||||
if (blocked.IsEdge()) {
|
||||
int from =
|
||||
GetProp(blocked.ValueEdge(), "from", dba_ptr.get()).Value<int64_t>();
|
||||
GetProp(blocked.ValueEdge(), "from", dba_ptr.get()).ValueInt();
|
||||
int to =
|
||||
GetProp(blocked.ValueEdge(), "to", dba_ptr.get()).Value<int64_t>();
|
||||
GetProp(blocked.ValueEdge(), "to", dba_ptr.get()).ValueInt();
|
||||
edges.erase(std::remove_if(edges.begin(), edges.end(),
|
||||
[from, to](const auto &e) {
|
||||
return std::get<0>(e) == from &&
|
||||
@ -450,7 +450,7 @@ void BfsTest(Database *db, int lower_bound, int upper_bound,
|
||||
// When a vertex is blocked, we remove all edges that lead into it.
|
||||
if (blocked.IsVertex()) {
|
||||
int id =
|
||||
GetProp(blocked.ValueVertex(), "id", dba_ptr.get()).Value<int64_t>();
|
||||
GetProp(blocked.ValueVertex(), "id", dba_ptr.get()).ValueInt();
|
||||
edges_blocked.erase(
|
||||
std::remove_if(edges_blocked.begin(), edges_blocked.end(),
|
||||
[id](const auto &e) { return e.second == id; }),
|
||||
|
@ -1027,7 +1027,7 @@ TEST_P(CypherMainVisitorTest, NodePattern) {
|
||||
for (auto x : node->properties_) {
|
||||
TypedValue value = ast_generator.LiteralValue(x.second);
|
||||
ASSERT_TRUE(value.type() == TypedValue::Type::Int);
|
||||
properties[x.first] = value.Value<int64_t>();
|
||||
properties[x.first] = value.ValueInt();
|
||||
}
|
||||
EXPECT_THAT(properties,
|
||||
UnorderedElementsAre(Pair(ast_generator.Prop("a"), 5),
|
||||
@ -1153,7 +1153,7 @@ TEST_P(CypherMainVisitorTest, RelationshipPatternDetails) {
|
||||
for (auto x : edge->properties_) {
|
||||
TypedValue value = ast_generator.LiteralValue(x.second);
|
||||
ASSERT_TRUE(value.type() == TypedValue::Type::Int);
|
||||
properties[x.first] = value.Value<int64_t>();
|
||||
properties[x.first] = value.ValueInt();
|
||||
}
|
||||
EXPECT_THAT(properties,
|
||||
UnorderedElementsAre(Pair(ast_generator.Prop("a"), 5),
|
||||
|
@ -139,7 +139,7 @@ class DatabaseEnvironment {
|
||||
props.emplace(dba.PropertyName(kv.first), kv.second);
|
||||
}
|
||||
CHECK(props.count(kPropertyId) == 1);
|
||||
const auto id = props[kPropertyId].Value<int64_t>();
|
||||
const auto id = props[kPropertyId].ValueInt();
|
||||
gid_mapping[vertex.gid()] = id;
|
||||
vertices.insert({id, labels, props});
|
||||
}
|
||||
|
@ -387,8 +387,8 @@ TEST(GraphDbAccessorTest, Transfer) {
|
||||
auto dba3 = db.Access();
|
||||
// we can transfer accessors even though the GraphDbAccessor they
|
||||
// belong to is not alive anymore
|
||||
EXPECT_EQ(dba3.Transfer(v1)->PropsAt(prop).Value<int64_t>(), 1);
|
||||
EXPECT_EQ(dba3.Transfer(e12)->PropsAt(prop).Value<int64_t>(), 12);
|
||||
EXPECT_EQ(dba3.Transfer(v1)->PropsAt(prop).ValueInt(), 1);
|
||||
EXPECT_EQ(dba3.Transfer(e12)->PropsAt(prop).ValueInt(), 12);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
@ -316,43 +316,37 @@ TEST_F(GraphDbAccessorIndex, LabelPropertyValueSorting) {
|
||||
EXPECT_EQ(property_value.type(), expected_property_value[cnt].type());
|
||||
switch (property_value.type()) {
|
||||
case PropertyValue::Type::Bool:
|
||||
EXPECT_EQ(property_value.Value<bool>(),
|
||||
expected_property_value[cnt].Value<bool>());
|
||||
EXPECT_EQ(property_value.ValueBool(),
|
||||
expected_property_value[cnt].ValueBool());
|
||||
break;
|
||||
case PropertyValue::Type::Double:
|
||||
EXPECT_EQ(property_value.Value<double>(),
|
||||
expected_property_value[cnt].Value<double>());
|
||||
EXPECT_EQ(property_value.ValueDouble(),
|
||||
expected_property_value[cnt].ValueDouble());
|
||||
break;
|
||||
case PropertyValue::Type::Int:
|
||||
EXPECT_EQ(property_value.Value<int64_t>(),
|
||||
expected_property_value[cnt].Value<int64_t>());
|
||||
EXPECT_EQ(property_value.ValueInt(),
|
||||
expected_property_value[cnt].ValueInt());
|
||||
break;
|
||||
case PropertyValue::Type::String:
|
||||
EXPECT_EQ(property_value.Value<std::string>(),
|
||||
expected_property_value[cnt].Value<std::string>());
|
||||
EXPECT_EQ(property_value.ValueString(),
|
||||
expected_property_value[cnt].ValueString());
|
||||
break;
|
||||
case PropertyValue::Type::List: {
|
||||
auto received_value =
|
||||
property_value.Value<std::vector<PropertyValue>>();
|
||||
auto expected_value =
|
||||
expected_property_value[cnt].Value<std::vector<PropertyValue>>();
|
||||
auto received_value = property_value.ValueList();
|
||||
auto expected_value = expected_property_value[cnt].ValueList();
|
||||
EXPECT_EQ(received_value.size(), expected_value.size());
|
||||
EXPECT_EQ(received_value.size(), 1);
|
||||
EXPECT_EQ(received_value[0].Value<int64_t>(),
|
||||
expected_value[0].Value<int64_t>());
|
||||
EXPECT_EQ(received_value[0].ValueInt(), expected_value[0].ValueInt());
|
||||
break;
|
||||
}
|
||||
case PropertyValue::Type::Map: {
|
||||
auto received_value =
|
||||
property_value.Value<std::map<std::string, PropertyValue>>();
|
||||
auto expected_value =
|
||||
expected_property_value[cnt]
|
||||
.Value<std::map<std::string, PropertyValue>>();
|
||||
auto received_value = property_value.ValueMap();
|
||||
auto expected_value = expected_property_value[cnt].ValueMap();
|
||||
EXPECT_EQ(received_value.size(), expected_value.size());
|
||||
for (const auto &kv : expected_value) {
|
||||
auto found = expected_value.find(kv.first);
|
||||
EXPECT_NE(found, expected_value.end());
|
||||
EXPECT_EQ(kv.second.Value<int64_t>(), found->second.Value<int64_t>());
|
||||
EXPECT_EQ(kv.second.ValueInt(), found->second.ValueInt());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -38,42 +38,42 @@ TEST_F(InterpreterTest, AstCache) {
|
||||
EXPECT_EQ(stream.GetHeader()[0], "2 + 3");
|
||||
ASSERT_EQ(stream.GetResults().size(), 1U);
|
||||
ASSERT_EQ(stream.GetResults()[0].size(), 1U);
|
||||
ASSERT_EQ(stream.GetResults()[0][0].Value<int64_t>(), 5);
|
||||
ASSERT_EQ(stream.GetResults()[0][0].ValueInt(), 5);
|
||||
}
|
||||
{
|
||||
// Cached ast, different literals.
|
||||
auto stream = Interpret("RETURN 5 + 4");
|
||||
ASSERT_EQ(stream.GetResults().size(), 1U);
|
||||
ASSERT_EQ(stream.GetResults()[0].size(), 1U);
|
||||
ASSERT_EQ(stream.GetResults()[0][0].Value<int64_t>(), 9);
|
||||
ASSERT_EQ(stream.GetResults()[0][0].ValueInt(), 9);
|
||||
}
|
||||
{
|
||||
// Different ast (because of different types).
|
||||
auto stream = Interpret("RETURN 5.5 + 4");
|
||||
ASSERT_EQ(stream.GetResults().size(), 1U);
|
||||
ASSERT_EQ(stream.GetResults()[0].size(), 1U);
|
||||
ASSERT_EQ(stream.GetResults()[0][0].Value<double>(), 9.5);
|
||||
ASSERT_EQ(stream.GetResults()[0][0].ValueDouble(), 9.5);
|
||||
}
|
||||
{
|
||||
// Cached ast, same literals.
|
||||
auto stream = Interpret("RETURN 2 + 3");
|
||||
ASSERT_EQ(stream.GetResults().size(), 1U);
|
||||
ASSERT_EQ(stream.GetResults()[0].size(), 1U);
|
||||
ASSERT_EQ(stream.GetResults()[0][0].Value<int64_t>(), 5);
|
||||
ASSERT_EQ(stream.GetResults()[0][0].ValueInt(), 5);
|
||||
}
|
||||
{
|
||||
// Cached ast, different literals.
|
||||
auto stream = Interpret("RETURN 10.5 + 1");
|
||||
ASSERT_EQ(stream.GetResults().size(), 1U);
|
||||
ASSERT_EQ(stream.GetResults()[0].size(), 1U);
|
||||
ASSERT_EQ(stream.GetResults()[0][0].Value<double>(), 11.5);
|
||||
ASSERT_EQ(stream.GetResults()[0][0].ValueDouble(), 11.5);
|
||||
}
|
||||
{
|
||||
// Cached ast, same literals, different whitespaces.
|
||||
auto stream = Interpret("RETURN 10.5 + 1");
|
||||
ASSERT_EQ(stream.GetResults().size(), 1U);
|
||||
ASSERT_EQ(stream.GetResults()[0].size(), 1U);
|
||||
ASSERT_EQ(stream.GetResults()[0][0].Value<double>(), 11.5);
|
||||
ASSERT_EQ(stream.GetResults()[0][0].ValueDouble(), 11.5);
|
||||
}
|
||||
{
|
||||
// Cached ast, same literals, different named header.
|
||||
@ -82,7 +82,7 @@ TEST_F(InterpreterTest, AstCache) {
|
||||
EXPECT_EQ(stream.GetHeader()[0], "10.5+1");
|
||||
ASSERT_EQ(stream.GetResults().size(), 1U);
|
||||
ASSERT_EQ(stream.GetResults()[0].size(), 1U);
|
||||
ASSERT_EQ(stream.GetResults()[0][0].Value<double>(), 11.5);
|
||||
ASSERT_EQ(stream.GetResults()[0][0].ValueDouble(), 11.5);
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,7 +94,7 @@ TEST_F(InterpreterTest, Parameters) {
|
||||
EXPECT_EQ(stream.GetHeader()[0], "$2 + $`a b`");
|
||||
ASSERT_EQ(stream.GetResults().size(), 1U);
|
||||
ASSERT_EQ(stream.GetResults()[0].size(), 1U);
|
||||
ASSERT_EQ(stream.GetResults()[0][0].Value<int64_t>(), 25);
|
||||
ASSERT_EQ(stream.GetResults()[0][0].ValueInt(), 25);
|
||||
}
|
||||
{
|
||||
// Not needed parameter.
|
||||
@ -104,7 +104,7 @@ TEST_F(InterpreterTest, Parameters) {
|
||||
EXPECT_EQ(stream.GetHeader()[0], "$2 + $`a b`");
|
||||
ASSERT_EQ(stream.GetResults().size(), 1U);
|
||||
ASSERT_EQ(stream.GetResults()[0].size(), 1U);
|
||||
ASSERT_EQ(stream.GetResults()[0][0].Value<int64_t>(), 25);
|
||||
ASSERT_EQ(stream.GetResults()[0][0].ValueInt(), 25);
|
||||
}
|
||||
{
|
||||
// Cached ast, different parameters.
|
||||
@ -119,8 +119,7 @@ TEST_F(InterpreterTest, Parameters) {
|
||||
Interpret("RETURN $2", {{"2", std::vector<PropertyValue>{5, 2, 3}}});
|
||||
ASSERT_EQ(stream.GetResults().size(), 1U);
|
||||
ASSERT_EQ(stream.GetResults()[0].size(), 1U);
|
||||
auto result =
|
||||
query::test_common::ToList<int64_t>(stream.GetResults()[0][0]);
|
||||
auto result = query::test_common::ToIntList(stream.GetResults()[0][0]);
|
||||
ASSERT_THAT(result, testing::ElementsAre(5, 2, 3));
|
||||
}
|
||||
{
|
||||
@ -218,20 +217,20 @@ TEST_F(InterpreterTest, Bfs) {
|
||||
std::unordered_set<int64_t> matched_ids;
|
||||
|
||||
for (const auto &result : stream.GetResults()) {
|
||||
const auto &edges = query::test_common::ToList<EdgeAccessor>(result[0]);
|
||||
const auto &edges = query::test_common::ToEdgeList(result[0]);
|
||||
// Check that path is of expected length. Returned paths should be from
|
||||
// shorter to longer ones.
|
||||
EXPECT_EQ(edges.size(), expected_level);
|
||||
// Check that starting node is correct.
|
||||
EXPECT_EQ(
|
||||
edges[0].from().PropsAt(dba.Property(kId)).template Value<int64_t>(),
|
||||
edges[0].from().PropsAt(dba.Property(kId)).ValueInt(),
|
||||
0);
|
||||
for (int i = 1; i < static_cast<int>(edges.size()); ++i) {
|
||||
// Check that edges form a connected path.
|
||||
EXPECT_EQ(edges[i - 1].to(), edges[i].from());
|
||||
}
|
||||
auto matched_id =
|
||||
edges.back().to().PropsAt(dba.Property(kId)).Value<int64_t>();
|
||||
edges.back().to().PropsAt(dba.Property(kId)).ValueInt();
|
||||
// Check that we didn't match that node already.
|
||||
EXPECT_TRUE(matched_ids.insert(matched_id).second);
|
||||
// Check that shortest path was found.
|
||||
@ -283,7 +282,7 @@ TEST_F(InterpreterTest, ShortestPath) {
|
||||
{"r1"}, {"r2"}, {"r1", "r2"}};
|
||||
|
||||
for (const auto &result : stream.GetResults()) {
|
||||
const auto &edges = query::test_common::ToList<EdgeAccessor>(result[0]);
|
||||
const auto &edges = query::test_common::ToEdgeList(result[0]);
|
||||
|
||||
std::vector<std::string> datum;
|
||||
for (const auto &edge : edges) {
|
||||
|
@ -58,10 +58,10 @@ TEST_F(PropertyValueStoreTest, AtMemory) {
|
||||
EXPECT_EQ(PropertyValue(At(0, Location::Memory)).type(),
|
||||
PropertyValue::Type::Null);
|
||||
Set(0, Location::Memory, some_string);
|
||||
EXPECT_EQ(PropertyValue(At(0, Location::Memory)).Value<std::string>(),
|
||||
EXPECT_EQ(PropertyValue(At(0, Location::Memory)).ValueString(),
|
||||
some_string);
|
||||
Set(120, Location::Memory, 42);
|
||||
EXPECT_EQ(PropertyValue(At(120, Location::Memory)).Value<int64_t>(), 42);
|
||||
EXPECT_EQ(PropertyValue(At(120, Location::Memory)).ValueInt(), 42);
|
||||
}
|
||||
|
||||
TEST_F(PropertyValueStoreTest, AtDisk) {
|
||||
@ -70,10 +70,10 @@ TEST_F(PropertyValueStoreTest, AtDisk) {
|
||||
EXPECT_EQ(PropertyValue(At(0, Location::Disk)).type(),
|
||||
PropertyValue::Type::Null);
|
||||
Set(0, Location::Disk, some_string);
|
||||
EXPECT_EQ(PropertyValue(At(0, Location::Disk)).Value<std::string>(),
|
||||
EXPECT_EQ(PropertyValue(At(0, Location::Disk)).ValueString(),
|
||||
some_string);
|
||||
Set(120, Location::Disk, 42);
|
||||
EXPECT_EQ(PropertyValue(At(120, Location::Disk)).Value<int64_t>(), 42);
|
||||
EXPECT_EQ(PropertyValue(At(120, Location::Disk)).ValueInt(), 42);
|
||||
}
|
||||
|
||||
TEST_F(PropertyValueStoreTest, AtNull) {
|
||||
@ -155,18 +155,18 @@ TEST_F(PropertyValueStoreTest, ClearDisk) {
|
||||
|
||||
TEST_F(PropertyValueStoreTest, ReplaceMemory) {
|
||||
Set(10, Location::Memory, 42);
|
||||
EXPECT_EQ(At(10, Location::Memory).Value<int64_t>(), 42);
|
||||
EXPECT_EQ(At(10, Location::Memory).ValueInt(), 42);
|
||||
Set(10, Location::Memory, 0.25f);
|
||||
EXPECT_EQ(At(10, Location::Memory).type(), PropertyValue::Type::Double);
|
||||
EXPECT_FLOAT_EQ(At(10, Location::Memory).Value<double>(), 0.25);
|
||||
EXPECT_FLOAT_EQ(At(10, Location::Memory).ValueDouble(), 0.25);
|
||||
}
|
||||
|
||||
TEST_F(PropertyValueStoreTest, ReplaceDisk) {
|
||||
Set(10, Location::Disk, 42);
|
||||
EXPECT_EQ(At(10, Location::Disk).Value<int64_t>(), 42);
|
||||
EXPECT_EQ(At(10, Location::Disk).ValueInt(), 42);
|
||||
Set(10, Location::Disk, 0.25f);
|
||||
EXPECT_EQ(At(10, Location::Disk).type(), PropertyValue::Type::Double);
|
||||
EXPECT_FLOAT_EQ(At(10, Location::Disk).Value<double>(), 0.25);
|
||||
EXPECT_FLOAT_EQ(At(10, Location::Disk).ValueDouble(), 0.25);
|
||||
}
|
||||
|
||||
TEST_F(PropertyValueStoreTest, SizeMemory) {
|
||||
@ -236,16 +236,16 @@ TEST_F(PropertyValueStoreTest, InsertRetrieveListMemory) {
|
||||
auto p = At(0, Location::Memory);
|
||||
|
||||
EXPECT_EQ(p.type(), PropertyValue::Type::List);
|
||||
auto l = p.Value<std::vector<PropertyValue>>();
|
||||
auto l = p.ValueList();
|
||||
EXPECT_EQ(l.size(), 5);
|
||||
EXPECT_EQ(l[0].type(), PropertyValue::Type::Int);
|
||||
EXPECT_EQ(l[0].Value<int64_t>(), 1);
|
||||
EXPECT_EQ(l[0].ValueInt(), 1);
|
||||
EXPECT_EQ(l[1].type(), PropertyValue::Type::Bool);
|
||||
EXPECT_EQ(l[1].Value<bool>(), true);
|
||||
EXPECT_EQ(l[1].ValueBool(), true);
|
||||
EXPECT_EQ(l[2].type(), PropertyValue::Type::Double);
|
||||
EXPECT_EQ(l[2].Value<double>(), 2.5);
|
||||
EXPECT_EQ(l[2].ValueDouble(), 2.5);
|
||||
EXPECT_EQ(l[3].type(), PropertyValue::Type::String);
|
||||
EXPECT_EQ(l[3].Value<std::string>(), "something");
|
||||
EXPECT_EQ(l[3].ValueString(), "something");
|
||||
EXPECT_EQ(l[4].type(), PropertyValue::Type::Null);
|
||||
}
|
||||
|
||||
@ -256,16 +256,16 @@ TEST_F(PropertyValueStoreTest, InsertRetrieveListDisk) {
|
||||
auto p = At(0, Location::Disk);
|
||||
|
||||
EXPECT_EQ(p.type(), PropertyValue::Type::List);
|
||||
auto l = p.Value<std::vector<PropertyValue>>();
|
||||
auto l = p.ValueList();
|
||||
EXPECT_EQ(l.size(), 5);
|
||||
EXPECT_EQ(l[0].type(), PropertyValue::Type::Int);
|
||||
EXPECT_EQ(l[0].Value<int64_t>(), 1);
|
||||
EXPECT_EQ(l[0].ValueInt(), 1);
|
||||
EXPECT_EQ(l[1].type(), PropertyValue::Type::Bool);
|
||||
EXPECT_EQ(l[1].Value<bool>(), true);
|
||||
EXPECT_EQ(l[1].ValueBool(), true);
|
||||
EXPECT_EQ(l[2].type(), PropertyValue::Type::Double);
|
||||
EXPECT_EQ(l[2].Value<double>(), 2.5);
|
||||
EXPECT_EQ(l[2].ValueDouble(), 2.5);
|
||||
EXPECT_EQ(l[3].type(), PropertyValue::Type::String);
|
||||
EXPECT_EQ(l[3].Value<std::string>(), "something");
|
||||
EXPECT_EQ(l[3].ValueString(), "something");
|
||||
EXPECT_EQ(l[4].type(), PropertyValue::Type::Null);
|
||||
}
|
||||
|
||||
@ -275,17 +275,17 @@ TEST_F(PropertyValueStoreTest, InsertRetrieveMap) {
|
||||
|
||||
auto p = At(0, Location::Memory);
|
||||
EXPECT_EQ(p.type(), PropertyValue::Type::Map);
|
||||
auto m = p.Value<std::map<std::string, PropertyValue>>();
|
||||
auto m = p.ValueMap();
|
||||
EXPECT_EQ(m.size(), 3);
|
||||
auto get = [&m](const std::string &prop_name) {
|
||||
return m.find(prop_name)->second;
|
||||
};
|
||||
EXPECT_EQ(get("a").type(), PropertyValue::Type::Int);
|
||||
EXPECT_EQ(get("a").Value<int64_t>(), 1);
|
||||
EXPECT_EQ(get("a").ValueInt(), 1);
|
||||
EXPECT_EQ(get("b").type(), PropertyValue::Type::Bool);
|
||||
EXPECT_EQ(get("b").Value<bool>(), true);
|
||||
EXPECT_EQ(get("b").ValueBool(), true);
|
||||
EXPECT_EQ(get("c").type(), PropertyValue::Type::String);
|
||||
EXPECT_EQ(get("c").Value<std::string>(), "something");
|
||||
EXPECT_EQ(get("c").ValueString(), "something");
|
||||
}
|
||||
|
||||
TEST_F(PropertyValueStoreTest, InsertRetrieveMapDisk) {
|
||||
@ -294,17 +294,17 @@ TEST_F(PropertyValueStoreTest, InsertRetrieveMapDisk) {
|
||||
|
||||
auto p = At(0, Location::Disk);
|
||||
EXPECT_EQ(p.type(), PropertyValue::Type::Map);
|
||||
auto m = p.Value<std::map<std::string, PropertyValue>>();
|
||||
auto m = p.ValueMap();
|
||||
EXPECT_EQ(m.size(), 3);
|
||||
auto get = [&m](const std::string &prop_name) {
|
||||
return m.find(prop_name)->second;
|
||||
};
|
||||
EXPECT_EQ(get("a").type(), PropertyValue::Type::Int);
|
||||
EXPECT_EQ(get("a").Value<int64_t>(), 1);
|
||||
EXPECT_EQ(get("a").ValueInt(), 1);
|
||||
EXPECT_EQ(get("b").type(), PropertyValue::Type::Bool);
|
||||
EXPECT_EQ(get("b").Value<bool>(), true);
|
||||
EXPECT_EQ(get("b").ValueBool(), true);
|
||||
EXPECT_EQ(get("c").type(), PropertyValue::Type::String);
|
||||
EXPECT_EQ(get("c").Value<std::string>(), "something");
|
||||
EXPECT_EQ(get("c").ValueString(), "something");
|
||||
}
|
||||
|
||||
TEST_F(PropertyValueStoreTest, Iterator) {
|
||||
@ -316,22 +316,22 @@ TEST_F(PropertyValueStoreTest, Iterator) {
|
||||
auto it = Begin();
|
||||
ASSERT_TRUE(it != End());
|
||||
EXPECT_EQ(it->first.Id(), 0);
|
||||
EXPECT_EQ((*it).second.Value<std::string>(), "a");
|
||||
EXPECT_EQ((*it).second.ValueString(), "a");
|
||||
|
||||
++it;
|
||||
ASSERT_TRUE(it != End());
|
||||
EXPECT_EQ((*it).first.Id(), 1);
|
||||
EXPECT_EQ(it->second.Value<int64_t>(), 1);
|
||||
EXPECT_EQ(it->second.ValueInt(), 1);
|
||||
|
||||
++it;
|
||||
ASSERT_TRUE(it != End());
|
||||
EXPECT_EQ(it->first.Id(), 2);
|
||||
EXPECT_EQ((*it).second.Value<std::string>(), "b");
|
||||
EXPECT_EQ((*it).second.ValueString(), "b");
|
||||
|
||||
++it;
|
||||
ASSERT_TRUE(it != End());
|
||||
EXPECT_EQ((*it).first.Id(), 3);
|
||||
EXPECT_EQ(it->second.Value<int64_t>(), 2);
|
||||
EXPECT_EQ(it->second.ValueInt(), 2);
|
||||
|
||||
++it;
|
||||
ASSERT_TRUE(it == End());
|
||||
@ -348,30 +348,26 @@ TEST_F(PropertyValueStoreTest, CopyConstructor) {
|
||||
|
||||
PropertyValueStore new_props = props;
|
||||
for (int i = 1; i <= 3; ++i)
|
||||
EXPECT_EQ(new_props.at(storage::Property(i, Location::Memory))
|
||||
.Value<std::string>(),
|
||||
"mem_" + std::to_string(i));
|
||||
for (int i = 4; i <= 5; ++i)
|
||||
EXPECT_EQ(
|
||||
new_props.at(storage::Property(i, Location::Disk)).Value<std::string>(),
|
||||
"disk_" + std::to_string(i));
|
||||
new_props.at(storage::Property(i, Location::Memory)).ValueString(),
|
||||
"mem_" + std::to_string(i));
|
||||
for (int i = 4; i <= 5; ++i)
|
||||
EXPECT_EQ(new_props.at(storage::Property(i, Location::Disk)).ValueString(),
|
||||
"disk_" + std::to_string(i));
|
||||
|
||||
props.set(storage::Property(1, Location::Memory), "mem_1_update");
|
||||
EXPECT_EQ(
|
||||
new_props.at(storage::Property(1, Location::Memory)).Value<std::string>(),
|
||||
"mem_1");
|
||||
EXPECT_EQ(new_props.at(storage::Property(1, Location::Memory)).ValueString(),
|
||||
"mem_1");
|
||||
|
||||
new_props.set(storage::Property(2, Location::Memory), "mem_2_update");
|
||||
EXPECT_EQ(
|
||||
props.at(storage::Property(2, Location::Memory)).Value<std::string>(),
|
||||
"mem_2");
|
||||
EXPECT_EQ(props.at(storage::Property(2, Location::Memory)).ValueString(),
|
||||
"mem_2");
|
||||
|
||||
props.set(storage::Property(4, Location::Disk), "disk_4_update");
|
||||
EXPECT_EQ(
|
||||
new_props.at(storage::Property(4, Location::Disk)).Value<std::string>(),
|
||||
"disk_4");
|
||||
EXPECT_EQ(new_props.at(storage::Property(4, Location::Disk)).ValueString(),
|
||||
"disk_4");
|
||||
|
||||
new_props.set(storage::Property(5, Location::Disk), "disk_5_update");
|
||||
EXPECT_EQ(props.at(storage::Property(5, Location::Disk)).Value<std::string>(),
|
||||
EXPECT_EQ(props.at(storage::Property(5, Location::Disk)).ValueString(),
|
||||
"disk_5");
|
||||
}
|
||||
|
@ -39,20 +39,26 @@ namespace query {
|
||||
|
||||
namespace test_common {
|
||||
|
||||
template <typename T>
|
||||
auto ToList(const TypedValue &t) {
|
||||
std::vector<T> list;
|
||||
auto ToIntList(const TypedValue &t) {
|
||||
std::vector<int64_t> list;
|
||||
for (auto x : t.ValueList()) {
|
||||
list.push_back(x.Value<T>());
|
||||
list.push_back(x.ValueInt());
|
||||
}
|
||||
return list;
|
||||
};
|
||||
|
||||
template <typename TElement>
|
||||
auto ToMap(const TypedValue &t) {
|
||||
std::map<std::string, TElement> map;
|
||||
auto ToEdgeList(const TypedValue &t) {
|
||||
std::vector<EdgeAccessor> list;
|
||||
for (auto x : t.ValueList()) {
|
||||
list.push_back(x.ValueEdge());
|
||||
}
|
||||
return list;
|
||||
};
|
||||
|
||||
auto ToIntMap(const TypedValue &t) {
|
||||
std::map<std::string, int64_t> map;
|
||||
for (const auto &kv : t.ValueMap())
|
||||
map.emplace(kv.first, kv.second.Value<TElement>());
|
||||
map.emplace(kv.first, kv.second.ValueInt());
|
||||
return map;
|
||||
};
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include "query_common.hpp"
|
||||
|
||||
using namespace query;
|
||||
using query::test_common::ToList;
|
||||
using query::test_common::ToIntList;
|
||||
using testing::ElementsAre;
|
||||
using testing::UnorderedElementsAre;
|
||||
|
||||
@ -1240,24 +1240,19 @@ TEST_F(FunctionTest, Range) {
|
||||
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)),
|
||||
ElementsAre(1, 2, 3));
|
||||
EXPECT_THAT(ToList<int64_t>(EvaluateFunction("RANGE", -1, 5, 2)),
|
||||
EXPECT_THAT(ToIntList(EvaluateFunction("RANGE", 1, 3)), ElementsAre(1, 2, 3));
|
||||
EXPECT_THAT(ToIntList(EvaluateFunction("RANGE", -1, 5, 2)),
|
||||
ElementsAre(-1, 1, 3, 5));
|
||||
EXPECT_THAT(ToList<int64_t>(EvaluateFunction("RANGE", 2, 10, 3)),
|
||||
EXPECT_THAT(ToIntList(EvaluateFunction("RANGE", 2, 10, 3)),
|
||||
ElementsAre(2, 5, 8));
|
||||
EXPECT_THAT(ToList<int64_t>(EvaluateFunction("RANGE", 2, 2, 2)),
|
||||
ElementsAre(2));
|
||||
EXPECT_THAT(ToList<int64_t>(EvaluateFunction("RANGE", 3, 0, 5)),
|
||||
ElementsAre());
|
||||
EXPECT_THAT(ToList<int64_t>(EvaluateFunction("RANGE", 5, 1, -2)),
|
||||
EXPECT_THAT(ToIntList(EvaluateFunction("RANGE", 2, 2, 2)), ElementsAre(2));
|
||||
EXPECT_THAT(ToIntList(EvaluateFunction("RANGE", 3, 0, 5)), ElementsAre());
|
||||
EXPECT_THAT(ToIntList(EvaluateFunction("RANGE", 5, 1, -2)),
|
||||
ElementsAre(5, 3, 1));
|
||||
EXPECT_THAT(ToList<int64_t>(EvaluateFunction("RANGE", 6, 1, -2)),
|
||||
EXPECT_THAT(ToIntList(EvaluateFunction("RANGE", 6, 1, -2)),
|
||||
ElementsAre(6, 4, 2));
|
||||
EXPECT_THAT(ToList<int64_t>(EvaluateFunction("RANGE", 2, 2, -3)),
|
||||
ElementsAre(2));
|
||||
EXPECT_THAT(ToList<int64_t>(EvaluateFunction("RANGE", -2, 4, -1)),
|
||||
ElementsAre());
|
||||
EXPECT_THAT(ToIntList(EvaluateFunction("RANGE", 2, 2, -3)), ElementsAre(2));
|
||||
EXPECT_THAT(ToIntList(EvaluateFunction("RANGE", -2, 4, -1)), ElementsAre());
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, Keys) {
|
||||
|
@ -15,8 +15,8 @@
|
||||
|
||||
using namespace query;
|
||||
using namespace query::plan;
|
||||
using query::test_common::ToList;
|
||||
using query::test_common::ToMap;
|
||||
using query::test_common::ToIntList;
|
||||
using query::test_common::ToIntMap;
|
||||
using testing::UnorderedElementsAre;
|
||||
|
||||
TEST(QueryPlan, Accumulate) {
|
||||
@ -70,7 +70,7 @@ TEST(QueryPlan, Accumulate) {
|
||||
std::vector<int> results_data;
|
||||
for (const auto &row : results)
|
||||
for (const auto &column : row)
|
||||
results_data.emplace_back(column.Value<int64_t>());
|
||||
results_data.emplace_back(column.ValueInt());
|
||||
if (accumulate)
|
||||
EXPECT_THAT(results_data, testing::ElementsAre(2, 2, 2, 2));
|
||||
else
|
||||
@ -195,28 +195,28 @@ TEST_F(QueryPlanAggregateOps, WithData) {
|
||||
ASSERT_EQ(results[0].size(), 8);
|
||||
// count(*)
|
||||
ASSERT_EQ(results[0][0].type(), TypedValue::Type::Int);
|
||||
EXPECT_EQ(results[0][0].Value<int64_t>(), 4);
|
||||
EXPECT_EQ(results[0][0].ValueInt(), 4);
|
||||
// count
|
||||
ASSERT_EQ(results[0][1].type(), TypedValue::Type::Int);
|
||||
EXPECT_EQ(results[0][1].Value<int64_t>(), 3);
|
||||
EXPECT_EQ(results[0][1].ValueInt(), 3);
|
||||
// min
|
||||
ASSERT_EQ(results[0][2].type(), TypedValue::Type::Int);
|
||||
EXPECT_EQ(results[0][2].Value<int64_t>(), 5);
|
||||
EXPECT_EQ(results[0][2].ValueInt(), 5);
|
||||
// max
|
||||
ASSERT_EQ(results[0][3].type(), TypedValue::Type::Int);
|
||||
EXPECT_EQ(results[0][3].Value<int64_t>(), 12);
|
||||
EXPECT_EQ(results[0][3].ValueInt(), 12);
|
||||
// sum
|
||||
ASSERT_EQ(results[0][4].type(), TypedValue::Type::Int);
|
||||
EXPECT_EQ(results[0][4].Value<int64_t>(), 24);
|
||||
EXPECT_EQ(results[0][4].ValueInt(), 24);
|
||||
// avg
|
||||
ASSERT_EQ(results[0][5].type(), TypedValue::Type::Double);
|
||||
EXPECT_FLOAT_EQ(results[0][5].Value<double>(), 24 / 3.0);
|
||||
EXPECT_FLOAT_EQ(results[0][5].ValueDouble(), 24 / 3.0);
|
||||
// collect list
|
||||
ASSERT_EQ(results[0][6].type(), TypedValue::Type::List);
|
||||
EXPECT_THAT(ToList<int64_t>(results[0][6]), UnorderedElementsAre(5, 7, 12));
|
||||
EXPECT_THAT(ToIntList(results[0][6]), UnorderedElementsAre(5, 7, 12));
|
||||
// collect map
|
||||
ASSERT_EQ(results[0][7].type(), TypedValue::Type::Map);
|
||||
auto map = ToMap<int64_t>(results[0][7]);
|
||||
auto map = ToIntMap(results[0][7]);
|
||||
ASSERT_EQ(map.size(), 1);
|
||||
EXPECT_EQ(map.begin()->first, "key");
|
||||
EXPECT_FALSE(std::set<int>({5, 7, 12}).insert(map.begin()->second).second);
|
||||
@ -259,10 +259,10 @@ TEST_F(QueryPlanAggregateOps, WithoutDataWithoutGroupBy) {
|
||||
ASSERT_EQ(results[0].size(), 8);
|
||||
// count(*)
|
||||
ASSERT_EQ(results[0][0].type(), TypedValue::Type::Int);
|
||||
EXPECT_EQ(results[0][0].Value<int64_t>(), 0);
|
||||
EXPECT_EQ(results[0][0].ValueInt(), 0);
|
||||
// count
|
||||
ASSERT_EQ(results[0][1].type(), TypedValue::Type::Int);
|
||||
EXPECT_EQ(results[0][1].Value<int64_t>(), 0);
|
||||
EXPECT_EQ(results[0][1].ValueInt(), 0);
|
||||
// min
|
||||
EXPECT_TRUE(results[0][2].IsNull());
|
||||
// max
|
||||
@ -273,10 +273,10 @@ TEST_F(QueryPlanAggregateOps, WithoutDataWithoutGroupBy) {
|
||||
EXPECT_TRUE(results[0][5].IsNull());
|
||||
// collect list
|
||||
ASSERT_EQ(results[0][6].type(), TypedValue::Type::List);
|
||||
EXPECT_EQ(ToList<int64_t>(results[0][6]).size(), 0);
|
||||
EXPECT_EQ(ToIntList(results[0][6]).size(), 0);
|
||||
// collect map
|
||||
ASSERT_EQ(results[0][7].type(), TypedValue::Type::Map);
|
||||
EXPECT_EQ(ToMap<int64_t>(results[0][7]).size(), 0);
|
||||
EXPECT_EQ(ToIntMap(results[0][7]).size(), 0);
|
||||
}
|
||||
|
||||
TEST(QueryPlan, AggregateGroupByValues) {
|
||||
@ -392,7 +392,7 @@ TEST(QueryPlan, AggregateNoInput) {
|
||||
EXPECT_EQ(1, results.size());
|
||||
EXPECT_EQ(1, results[0].size());
|
||||
EXPECT_EQ(TypedValue::Type::Int, results[0][0].type());
|
||||
EXPECT_EQ(1, results[0][0].Value<int64_t>());
|
||||
EXPECT_EQ(1, results[0][0].ValueInt());
|
||||
}
|
||||
|
||||
TEST(QueryPlan, AggregateCountEdgeCases) {
|
||||
@ -425,7 +425,7 @@ TEST(QueryPlan, AggregateCountEdgeCases) {
|
||||
EXPECT_EQ(1, results.size());
|
||||
EXPECT_EQ(1, results[0].size());
|
||||
EXPECT_EQ(TypedValue::Type::Int, results[0][0].type());
|
||||
return results[0][0].Value<int64_t>();
|
||||
return results[0][0].ValueInt();
|
||||
};
|
||||
|
||||
// no vertices yet in database
|
||||
|
@ -217,9 +217,9 @@ TEST(QueryPlan, OrderByMultiple) {
|
||||
ASSERT_EQ(N * N, results.size());
|
||||
for (int j = 0; j < N * N; ++j) {
|
||||
ASSERT_EQ(results[j][0].type(), TypedValue::Type::Int);
|
||||
EXPECT_EQ(results[j][0].Value<int64_t>(), j / N);
|
||||
EXPECT_EQ(results[j][0].ValueInt(), j / N);
|
||||
ASSERT_EQ(results[j][1].type(), TypedValue::Type::Int);
|
||||
EXPECT_EQ(results[j][1].Value<int64_t>(), N - 1 - j % N);
|
||||
EXPECT_EQ(results[j][1].ValueInt(), N - 1 - j % N);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ TEST(QueryPlan, CreateNodeWithAttributes) {
|
||||
auto prop_eq =
|
||||
TypedValue(vertex.PropsAt(property.second)) == TypedValue(42);
|
||||
ASSERT_EQ(prop_eq.type(), TypedValue::Type::Bool);
|
||||
EXPECT_TRUE(prop_eq.Value<bool>());
|
||||
EXPECT_TRUE(prop_eq.ValueBool());
|
||||
}
|
||||
EXPECT_EQ(vertex_count, 1);
|
||||
}
|
||||
@ -82,10 +82,10 @@ TEST(QueryPlan, CreateReturn) {
|
||||
EXPECT_EQ(1, results.size());
|
||||
EXPECT_EQ(2, results[0].size());
|
||||
EXPECT_EQ(TypedValue::Type::Vertex, results[0][0].type());
|
||||
EXPECT_EQ(1, results[0][0].Value<VertexAccessor>().labels().size());
|
||||
EXPECT_EQ(label, results[0][0].Value<VertexAccessor>().labels()[0]);
|
||||
EXPECT_EQ(1, results[0][0].ValueVertex().labels().size());
|
||||
EXPECT_EQ(label, results[0][0].ValueVertex().labels()[0]);
|
||||
EXPECT_EQ(TypedValue::Type::Int, results[0][1].type());
|
||||
EXPECT_EQ(42, results[0][1].Value<int64_t>());
|
||||
EXPECT_EQ(42, results[0][1].ValueInt());
|
||||
|
||||
dba.AdvanceCommand();
|
||||
EXPECT_EQ(1, CountIterable(dba.Vertices(false)));
|
||||
@ -146,10 +146,10 @@ TEST(QueryPlan, CreateExpand) {
|
||||
storage::Label label = vertex.labels()[0];
|
||||
if (label == label_node_1) {
|
||||
// node created by first op
|
||||
EXPECT_EQ(vertex.PropsAt(property.second).Value<int64_t>(), 1);
|
||||
EXPECT_EQ(vertex.PropsAt(property.second).ValueInt(), 1);
|
||||
} else if (label == label_node_2) {
|
||||
// node create by expansion
|
||||
EXPECT_EQ(vertex.PropsAt(property.second).Value<int64_t>(), 2);
|
||||
EXPECT_EQ(vertex.PropsAt(property.second).ValueInt(), 2);
|
||||
} else {
|
||||
// should not happen
|
||||
FAIL();
|
||||
@ -157,7 +157,7 @@ TEST(QueryPlan, CreateExpand) {
|
||||
|
||||
for (EdgeAccessor edge : dba.Edges(false)) {
|
||||
EXPECT_EQ(edge.EdgeType(), edge_type);
|
||||
EXPECT_EQ(edge.PropsAt(property.second).Value<int64_t>(), 3);
|
||||
EXPECT_EQ(edge.PropsAt(property.second).ValueInt(), 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -487,11 +487,11 @@ TEST(QueryPlan, SetProperty) {
|
||||
EXPECT_EQ(CountIterable(dba.Edges(false)), 2);
|
||||
for (EdgeAccessor edge : dba.Edges(false)) {
|
||||
ASSERT_EQ(edge.PropsAt(prop1).type(), PropertyValue::Type::Int);
|
||||
EXPECT_EQ(edge.PropsAt(prop1).Value<int64_t>(), 42);
|
||||
EXPECT_EQ(edge.PropsAt(prop1).ValueInt(), 42);
|
||||
VertexAccessor from = edge.from();
|
||||
VertexAccessor to = edge.to();
|
||||
ASSERT_EQ(from.PropsAt(prop1).type(), PropertyValue::Type::Int);
|
||||
EXPECT_EQ(from.PropsAt(prop1).Value<int64_t>(), 42);
|
||||
EXPECT_EQ(from.PropsAt(prop1).ValueInt(), 42);
|
||||
ASSERT_EQ(to.PropsAt(prop1).type(), PropertyValue::Type::Null);
|
||||
}
|
||||
}
|
||||
@ -542,23 +542,23 @@ TEST(QueryPlan, SetProperties) {
|
||||
EXPECT_EQ(from.Properties().size(), update ? 2 : 1);
|
||||
if (update) {
|
||||
ASSERT_EQ(from.PropsAt(prop_a).type(), PropertyValue::Type::Int);
|
||||
EXPECT_EQ(from.PropsAt(prop_a).Value<int64_t>(), 0);
|
||||
EXPECT_EQ(from.PropsAt(prop_a).ValueInt(), 0);
|
||||
}
|
||||
ASSERT_EQ(from.PropsAt(prop_b).type(), PropertyValue::Type::Int);
|
||||
EXPECT_EQ(from.PropsAt(prop_b).Value<int64_t>(), 1);
|
||||
EXPECT_EQ(from.PropsAt(prop_b).ValueInt(), 1);
|
||||
|
||||
EXPECT_EQ(edge.Properties().size(), update ? 2 : 1);
|
||||
if (update) {
|
||||
ASSERT_EQ(edge.PropsAt(prop_b).type(), PropertyValue::Type::Int);
|
||||
EXPECT_EQ(edge.PropsAt(prop_b).Value<int64_t>(), 1);
|
||||
EXPECT_EQ(edge.PropsAt(prop_b).ValueInt(), 1);
|
||||
}
|
||||
ASSERT_EQ(edge.PropsAt(prop_c).type(), PropertyValue::Type::Int);
|
||||
EXPECT_EQ(edge.PropsAt(prop_c).Value<int64_t>(), 2);
|
||||
EXPECT_EQ(edge.PropsAt(prop_c).ValueInt(), 2);
|
||||
|
||||
VertexAccessor to = edge.to();
|
||||
EXPECT_EQ(to.Properties().size(), 1);
|
||||
ASSERT_EQ(to.PropsAt(prop_c).type(), PropertyValue::Type::Int);
|
||||
EXPECT_EQ(to.PropsAt(prop_c).Value<int64_t>(), 2);
|
||||
EXPECT_EQ(to.PropsAt(prop_c).ValueInt(), 2);
|
||||
}
|
||||
};
|
||||
|
||||
@ -719,7 +719,7 @@ TEST(QueryPlan, NodeFilterSet) {
|
||||
v1.Reconstruct();
|
||||
auto prop_eq = TypedValue(v1.PropsAt(prop.second)) == TypedValue(42 + 2);
|
||||
ASSERT_EQ(prop_eq.type(), TypedValue::Type::Bool);
|
||||
EXPECT_TRUE(prop_eq.Value<bool>());
|
||||
EXPECT_TRUE(prop_eq.ValueBool());
|
||||
}
|
||||
|
||||
TEST(QueryPlan, FilterRemove) {
|
||||
@ -827,11 +827,11 @@ TEST(QueryPlan, Merge) {
|
||||
v3.Reconstruct();
|
||||
|
||||
ASSERT_EQ(v1.PropsAt(prop.second).type(), PropertyValue::Type::Int);
|
||||
ASSERT_EQ(v1.PropsAt(prop.second).Value<int64_t>(), 1);
|
||||
ASSERT_EQ(v1.PropsAt(prop.second).ValueInt(), 1);
|
||||
ASSERT_EQ(v2.PropsAt(prop.second).type(), PropertyValue::Type::Int);
|
||||
ASSERT_EQ(v2.PropsAt(prop.second).Value<int64_t>(), 1);
|
||||
ASSERT_EQ(v2.PropsAt(prop.second).ValueInt(), 1);
|
||||
ASSERT_EQ(v3.PropsAt(prop.second).type(), PropertyValue::Type::Int);
|
||||
ASSERT_EQ(v3.PropsAt(prop.second).Value<int64_t>(), 2);
|
||||
ASSERT_EQ(v3.PropsAt(prop.second).ValueInt(), 2);
|
||||
}
|
||||
|
||||
TEST(QueryPlan, MergeNoInput) {
|
||||
|
@ -35,12 +35,11 @@ class MatchReturnFixture : public testing::Test {
|
||||
for (int i = 0; i < count; i++) dba_.InsertVertex();
|
||||
}
|
||||
|
||||
template <typename TResult>
|
||||
std::vector<TResult> Results(std::shared_ptr<Produce> &op) {
|
||||
std::vector<TResult> res;
|
||||
std::vector<Path> PathResults(std::shared_ptr<Produce> &op) {
|
||||
std::vector<Path> res;
|
||||
auto context = MakeContext(storage, symbol_table, &dba_);
|
||||
for (const auto &row : CollectProduce(*op, &context))
|
||||
res.emplace_back(row[0].Value<TResult>());
|
||||
res.emplace_back(row[0].ValuePath());
|
||||
return res;
|
||||
}
|
||||
};
|
||||
@ -81,7 +80,7 @@ TEST_F(MatchReturnFixture, MatchReturnPath) {
|
||||
NEXPR("path", IDENT("path")->MapTo(path_sym))
|
||||
->MapTo(symbol_table.CreateSymbol("named_expression_1", true));
|
||||
auto produce = MakeProduce(make_path, output);
|
||||
auto results = Results<query::Path>(produce);
|
||||
auto results = PathResults(produce);
|
||||
ASSERT_EQ(results.size(), 2);
|
||||
std::vector<query::Path> expected_paths;
|
||||
for (const auto &v : dba_.Vertices(false)) expected_paths.emplace_back(v);
|
||||
@ -115,10 +114,8 @@ TEST(QueryPlan, MatchReturnCartesian) {
|
||||
EXPECT_EQ(results.size(), 4);
|
||||
// ensure the result ordering is OK:
|
||||
// "n" from the results is the same for the first two rows, while "m" isn't
|
||||
EXPECT_EQ(results[0][0].Value<VertexAccessor>(),
|
||||
results[1][0].Value<VertexAccessor>());
|
||||
EXPECT_NE(results[0][1].Value<VertexAccessor>(),
|
||||
results[1][1].Value<VertexAccessor>());
|
||||
EXPECT_EQ(results[0][0].ValueVertex(), results[1][0].ValueVertex());
|
||||
EXPECT_NE(results[0][1].ValueVertex(), results[1][1].ValueVertex());
|
||||
}
|
||||
|
||||
TEST(QueryPlan, StandaloneReturn) {
|
||||
@ -141,7 +138,7 @@ TEST(QueryPlan, StandaloneReturn) {
|
||||
auto results = CollectProduce(*produce, &context);
|
||||
EXPECT_EQ(results.size(), 1);
|
||||
EXPECT_EQ(results[0].size(), 1);
|
||||
EXPECT_EQ(results[0][0].Value<int64_t>(), 42);
|
||||
EXPECT_EQ(results[0][0].ValueInt(), 42);
|
||||
}
|
||||
|
||||
TEST(QueryPlan, NodeFilterLabelsAndProperties) {
|
||||
@ -288,8 +285,8 @@ TEST(QueryPlan, Cartesian) {
|
||||
EXPECT_EQ(results.size(), 9);
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
EXPECT_EQ(results[3 * i + j][0].Value<VertexAccessor>(), vertices[j]);
|
||||
EXPECT_EQ(results[3 * i + j][1].Value<VertexAccessor>(), vertices[i]);
|
||||
EXPECT_EQ(results[3 * i + j][0].ValueVertex(), vertices[j]);
|
||||
EXPECT_EQ(results[3 * i + j][1].ValueVertex(), vertices[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -368,9 +365,9 @@ TEST(QueryPlan, CartesianThreeWay) {
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
for (int k = 0; k < 3; ++k) {
|
||||
EXPECT_EQ(results[id][0].Value<VertexAccessor>(), vertices[k]);
|
||||
EXPECT_EQ(results[id][1].Value<VertexAccessor>(), vertices[j]);
|
||||
EXPECT_EQ(results[id][2].Value<VertexAccessor>(), vertices[i]);
|
||||
EXPECT_EQ(results[id][0].ValueVertex(), vertices[k]);
|
||||
EXPECT_EQ(results[id][1].ValueVertex(), vertices[j]);
|
||||
EXPECT_EQ(results[id][2].ValueVertex(), vertices[i]);
|
||||
++id;
|
||||
}
|
||||
}
|
||||
@ -580,18 +577,27 @@ class QueryPlanExpandVariable : public testing::Test {
|
||||
|
||||
/**
|
||||
* Pulls from the given input and returns the results under the given symbol.
|
||||
*
|
||||
* @return a vector of values of the given type.
|
||||
* @tparam TResult type of the result that is sought.
|
||||
*/
|
||||
template <typename TResult>
|
||||
auto GetResults(std::shared_ptr<LogicalOperator> input_op, Symbol symbol) {
|
||||
auto GetListResults(std::shared_ptr<LogicalOperator> input_op, Symbol symbol) {
|
||||
Frame frame(symbol_table.max_position());
|
||||
auto cursor = input_op->MakeCursor(utils::NewDeleteResource());
|
||||
auto context = MakeContext(storage, symbol_table, &dba_);
|
||||
std::vector<TResult> results;
|
||||
std::vector<utils::AVector<TypedValue>> results;
|
||||
while (cursor->Pull(frame, context))
|
||||
results.emplace_back(frame[symbol].Value<TResult>());
|
||||
results.emplace_back(frame[symbol].ValueList());
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pulls from the given input and returns the results under the given symbol.
|
||||
*/
|
||||
auto GetPathResults(std::shared_ptr<LogicalOperator> input_op, Symbol symbol) {
|
||||
Frame frame(symbol_table.max_position());
|
||||
auto cursor = input_op->MakeCursor(utils::NewDeleteResource());
|
||||
auto context = MakeContext(storage, symbol_table, &dba_);
|
||||
std::vector<Path> results;
|
||||
while (cursor->Pull(frame, context))
|
||||
results.emplace_back(frame[symbol].ValuePath());
|
||||
return results;
|
||||
}
|
||||
|
||||
@ -604,9 +610,7 @@ class QueryPlanExpandVariable : public testing::Test {
|
||||
auto GetEdgeListSizes(std::shared_ptr<LogicalOperator> input_op,
|
||||
Symbol symbol) {
|
||||
map_int count_per_length;
|
||||
for (const auto &edge_list :
|
||||
GetResults<std::vector<TypedValue, utils::Allocator<TypedValue>>>(
|
||||
input_op, symbol)) {
|
||||
for (const auto &edge_list : GetListResults(input_op, symbol)) {
|
||||
auto length = edge_list.size();
|
||||
auto found = count_per_length.find(length);
|
||||
if (found == count_per_length.end())
|
||||
@ -772,7 +776,7 @@ TEST_F(QueryPlanExpandVariable, NamedPath) {
|
||||
expected_paths.emplace_back(v, e1, e1.to(), e2, e2.to());
|
||||
ASSERT_EQ(expected_paths.size(), 8);
|
||||
|
||||
auto results = GetResults<query::Path>(create_path, path_symbol);
|
||||
auto results = GetPathResults(create_path, path_symbol);
|
||||
ASSERT_EQ(results.size(), 8);
|
||||
EXPECT_TRUE(std::is_permutation(results.begin(), results.end(),
|
||||
expected_paths.begin()));
|
||||
@ -890,10 +894,10 @@ class QueryPlanExpandWeightedShortestPath : public testing::Test {
|
||||
auto context = MakeContext(storage, symbol_table, &dba);
|
||||
while (cursor->Pull(frame, context)) {
|
||||
results.push_back(ResultType{std::vector<EdgeAccessor>(),
|
||||
frame[node_sym].Value<VertexAccessor>(),
|
||||
frame[total_weight].Value<double>()});
|
||||
frame[node_sym].ValueVertex(),
|
||||
frame[total_weight].ValueDouble()});
|
||||
for (const TypedValue &edge : frame[edge_list_sym].ValueList())
|
||||
results.back().path.emplace_back(edge.Value<EdgeAccessor>());
|
||||
results.back().path.emplace_back(edge.ValueEdge());
|
||||
}
|
||||
|
||||
return results;
|
||||
@ -901,12 +905,12 @@ class QueryPlanExpandWeightedShortestPath : public testing::Test {
|
||||
|
||||
template <typename TAccessor>
|
||||
auto GetProp(const TAccessor &accessor) {
|
||||
return accessor.PropsAt(prop.second).template Value<int64_t>();
|
||||
return accessor.PropsAt(prop.second).ValueInt();
|
||||
}
|
||||
|
||||
template <typename TAccessor>
|
||||
auto GetDoubleProp(const TAccessor &accessor) {
|
||||
return accessor.PropsAt(prop.second).template Value<double>();
|
||||
return accessor.PropsAt(prop.second).ValueDouble();
|
||||
}
|
||||
|
||||
Expression *PropNe(Symbol symbol, int value) {
|
||||
@ -1167,10 +1171,10 @@ TEST(QueryPlan, ExpandOptional) {
|
||||
int v1_is_n_count = 0;
|
||||
for (auto &row : results) {
|
||||
ASSERT_EQ(row[0].type(), TypedValue::Type::Vertex);
|
||||
VertexAccessor &va = row[0].Value<VertexAccessor>();
|
||||
VertexAccessor &va = row[0].ValueVertex();
|
||||
auto va_p = va.PropsAt(prop);
|
||||
ASSERT_EQ(va_p.type(), PropertyValue::Type::Int);
|
||||
if (va_p.Value<int64_t>() == 1) {
|
||||
if (va_p.ValueInt() == 1) {
|
||||
v1_is_n_count++;
|
||||
EXPECT_EQ(row[1].type(), TypedValue::Type::Edge);
|
||||
EXPECT_EQ(row[2].type(), TypedValue::Type::Vertex);
|
||||
@ -1535,8 +1539,7 @@ TEST(QueryPlan, Distinct) {
|
||||
for (const auto &row : results) {
|
||||
ASSERT_EQ(1, row.size());
|
||||
ASSERT_EQ(row[0].type(), output_it->type());
|
||||
if (assume_int_value)
|
||||
EXPECT_EQ(output_it->Value<int64_t>(), row[0].Value<int64_t>());
|
||||
if (assume_int_value) EXPECT_EQ(output_it->ValueInt(), row[0].ValueInt());
|
||||
output_it++;
|
||||
}
|
||||
};
|
||||
@ -1581,7 +1584,7 @@ TEST(QueryPlan, ScanAllByLabel) {
|
||||
ASSERT_EQ(results.size(), 1);
|
||||
auto result_row = results[0];
|
||||
ASSERT_EQ(result_row.size(), 1);
|
||||
EXPECT_EQ(result_row[0].Value<VertexAccessor>(), labeled_vertex);
|
||||
EXPECT_EQ(result_row[0].ValueVertex(), labeled_vertex);
|
||||
}
|
||||
|
||||
TEST(QueryPlan, ScanAllByLabelProperty) {
|
||||
@ -1626,10 +1629,9 @@ TEST(QueryPlan, ScanAllByLabelProperty) {
|
||||
ASSERT_EQ(results.size(), expected.size());
|
||||
for (size_t i = 0; i < expected.size(); i++) {
|
||||
TypedValue equal =
|
||||
TypedValue(results[i][0].Value<VertexAccessor>().PropsAt(prop)) ==
|
||||
expected[i];
|
||||
TypedValue(results[i][0].ValueVertex().PropsAt(prop)) == expected[i];
|
||||
ASSERT_EQ(equal.type(), TypedValue::Type::Bool);
|
||||
EXPECT_TRUE(equal.Value<bool>());
|
||||
EXPECT_TRUE(equal.ValueBool());
|
||||
}
|
||||
};
|
||||
|
||||
@ -1696,7 +1698,7 @@ TEST(QueryPlan, ScanAllByLabelPropertyEqualityNoError) {
|
||||
ASSERT_EQ(results.size(), 1);
|
||||
const auto &row = results[0];
|
||||
ASSERT_EQ(row.size(), 1);
|
||||
auto vertex = row[0].Value<VertexAccessor>();
|
||||
auto vertex = row[0].ValueVertex();
|
||||
TypedValue value(vertex.PropsAt(prop));
|
||||
TypedValue::BoolEqual eq;
|
||||
EXPECT_TRUE(eq(value, TypedValue(42)));
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include "utils/string.hpp"
|
||||
|
||||
using namespace query;
|
||||
using query::test_common::ToList;
|
||||
using query::test_common::ToString;
|
||||
using testing::ElementsAre;
|
||||
using testing::UnorderedElementsAre;
|
||||
|
@ -23,8 +23,8 @@ TEST(RecordAccessor, Properties) {
|
||||
EXPECT_EQ(vertex.PropsAt(property).type(), PropertyValue::Type::Null);
|
||||
|
||||
vertex.PropsSet(property, 42);
|
||||
EXPECT_EQ(vertex.PropsAt(property).Value<int64_t>(), 42);
|
||||
EXPECT_EQ(properties.at(property).Value<int64_t>(), 42);
|
||||
EXPECT_EQ(vertex.PropsAt(property).ValueInt(), 42);
|
||||
EXPECT_EQ(properties.at(property).ValueInt(), 42);
|
||||
EXPECT_EQ(vertex.PropsAt(property_other).type(), PropertyValue::Type::Null);
|
||||
EXPECT_EQ(properties.at(property_other).type(), PropertyValue::Type::Null);
|
||||
|
||||
|
@ -173,7 +173,7 @@ TEST(StateDelta, SetPropertyVertex) {
|
||||
auto vertex = dba.FindVertexOptional(gid0, false);
|
||||
EXPECT_TRUE(vertex);
|
||||
auto prop = vertex->PropsAt(dba.Property("property"));
|
||||
EXPECT_EQ(prop.Value<int64_t>(), 2212);
|
||||
EXPECT_EQ(prop.ValueInt(), 2212);
|
||||
}
|
||||
}
|
||||
|
||||
@ -203,6 +203,6 @@ TEST(StateDelta, SetPropertyEdge) {
|
||||
auto edge = dba.FindEdgeOptional(gid2, false);
|
||||
EXPECT_TRUE(edge);
|
||||
auto prop = edge->PropsAt(dba.Property("property"));
|
||||
EXPECT_EQ(prop.Value<int64_t>(), 2212);
|
||||
EXPECT_EQ(prop.ValueInt(), 2212);
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,10 @@
|
||||
// Created by Florijan Stamenkovic on 07.03.17.
|
||||
//
|
||||
|
||||
#include "query/frontend/stripped.hpp"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "query/exceptions.hpp"
|
||||
#include "query/frontend/stripped.hpp"
|
||||
#include "query/typed_value.hpp"
|
||||
|
||||
using namespace query;
|
||||
@ -18,7 +18,7 @@ using testing::Pair;
|
||||
using testing::UnorderedElementsAre;
|
||||
|
||||
void EXPECT_PROP_TRUE(const TypedValue &a) {
|
||||
EXPECT_TRUE(a.type() == TypedValue::Type::Bool && a.Value<bool>());
|
||||
EXPECT_TRUE(a.type() == TypedValue::Type::Bool && a.ValueBool());
|
||||
}
|
||||
|
||||
void EXPECT_PROP_EQ(const TypedValue &a, const TypedValue &b) {
|
||||
@ -39,8 +39,8 @@ TEST(QueryStripper, ZeroInteger) {
|
||||
StrippedQuery stripped("RETURN 0");
|
||||
EXPECT_EQ(stripped.literals().size(), 1);
|
||||
EXPECT_EQ(stripped.literals().At(0).first, 1);
|
||||
EXPECT_EQ(stripped.literals().At(0).second.Value<int64_t>(), 0);
|
||||
EXPECT_EQ(stripped.literals().AtTokenPosition(1).Value<int64_t>(), 0);
|
||||
EXPECT_EQ(stripped.literals().At(0).second.ValueInt(), 0);
|
||||
EXPECT_EQ(stripped.literals().AtTokenPosition(1).ValueInt(), 0);
|
||||
EXPECT_EQ(stripped.query(), "RETURN " + kStrippedIntToken);
|
||||
}
|
||||
|
||||
@ -48,57 +48,57 @@ TEST(QueryStripper, DecimalInteger) {
|
||||
StrippedQuery stripped("RETURN 42");
|
||||
EXPECT_EQ(stripped.literals().size(), 1);
|
||||
EXPECT_EQ(stripped.literals().At(0).first, 1);
|
||||
EXPECT_EQ(stripped.literals().At(0).second.Value<int64_t>(), 42);
|
||||
EXPECT_EQ(stripped.literals().AtTokenPosition(1).Value<int64_t>(), 42);
|
||||
EXPECT_EQ(stripped.literals().At(0).second.ValueInt(), 42);
|
||||
EXPECT_EQ(stripped.literals().AtTokenPosition(1).ValueInt(), 42);
|
||||
EXPECT_EQ(stripped.query(), "RETURN " + kStrippedIntToken);
|
||||
}
|
||||
|
||||
TEST(QueryStripper, OctalInteger) {
|
||||
StrippedQuery stripped("RETURN 010");
|
||||
EXPECT_EQ(stripped.literals().size(), 1);
|
||||
EXPECT_EQ(stripped.literals().At(0).second.Value<int64_t>(), 8);
|
||||
EXPECT_EQ(stripped.literals().At(0).second.ValueInt(), 8);
|
||||
EXPECT_EQ(stripped.query(), "RETURN " + kStrippedIntToken);
|
||||
}
|
||||
|
||||
TEST(QueryStripper, HexInteger) {
|
||||
StrippedQuery stripped("RETURN 0xa");
|
||||
EXPECT_EQ(stripped.literals().size(), 1);
|
||||
EXPECT_EQ(stripped.literals().At(0).second.Value<int64_t>(), 10);
|
||||
EXPECT_EQ(stripped.literals().At(0).second.ValueInt(), 10);
|
||||
EXPECT_EQ(stripped.query(), "RETURN " + kStrippedIntToken);
|
||||
}
|
||||
|
||||
TEST(QueryStripper, RegularDecimal) {
|
||||
StrippedQuery stripped("RETURN 42.3");
|
||||
EXPECT_EQ(stripped.literals().size(), 1);
|
||||
EXPECT_FLOAT_EQ(stripped.literals().At(0).second.Value<double>(), 42.3);
|
||||
EXPECT_FLOAT_EQ(stripped.literals().At(0).second.ValueDouble(), 42.3);
|
||||
EXPECT_EQ(stripped.query(), "RETURN " + kStrippedDoubleToken);
|
||||
}
|
||||
|
||||
TEST(QueryStripper, ExponentDecimal) {
|
||||
StrippedQuery stripped("RETURN 4e2");
|
||||
EXPECT_EQ(stripped.literals().size(), 1);
|
||||
EXPECT_FLOAT_EQ(stripped.literals().At(0).second.Value<double>(), 4e2);
|
||||
EXPECT_FLOAT_EQ(stripped.literals().At(0).second.ValueDouble(), 4e2);
|
||||
EXPECT_EQ(stripped.query(), "RETURN " + kStrippedDoubleToken);
|
||||
}
|
||||
|
||||
TEST(QueryStripper, ExponentDecimal2) {
|
||||
StrippedQuery stripped("RETURN 4e-2");
|
||||
EXPECT_EQ(stripped.literals().size(), 1);
|
||||
EXPECT_FLOAT_EQ(stripped.literals().At(0).second.Value<double>(), 4e-2);
|
||||
EXPECT_FLOAT_EQ(stripped.literals().At(0).second.ValueDouble(), 4e-2);
|
||||
EXPECT_EQ(stripped.query(), "RETURN " + kStrippedDoubleToken);
|
||||
}
|
||||
|
||||
TEST(QueryStripper, ExponentDecimal3) {
|
||||
StrippedQuery stripped("RETURN 0.1e-2");
|
||||
EXPECT_EQ(stripped.literals().size(), 1);
|
||||
EXPECT_FLOAT_EQ(stripped.literals().At(0).second.Value<double>(), 0.1e-2);
|
||||
EXPECT_FLOAT_EQ(stripped.literals().At(0).second.ValueDouble(), 0.1e-2);
|
||||
EXPECT_EQ(stripped.query(), "RETURN " + kStrippedDoubleToken);
|
||||
}
|
||||
|
||||
TEST(QueryStripper, ExponentDecimal4) {
|
||||
StrippedQuery stripped("RETURN .1e-2");
|
||||
EXPECT_EQ(stripped.literals().size(), 1);
|
||||
EXPECT_FLOAT_EQ(stripped.literals().At(0).second.Value<double>(), .1e-2);
|
||||
EXPECT_FLOAT_EQ(stripped.literals().At(0).second.ValueDouble(), .1e-2);
|
||||
EXPECT_EQ(stripped.query(), "RETURN " + kStrippedDoubleToken);
|
||||
}
|
||||
|
||||
@ -111,28 +111,28 @@ TEST(QueryStripper, SymbolicNameStartingWithE) {
|
||||
TEST(QueryStripper, StringLiteral) {
|
||||
StrippedQuery stripped("RETURN 'something'");
|
||||
EXPECT_EQ(stripped.literals().size(), 1);
|
||||
EXPECT_EQ(stripped.literals().At(0).second.Value<std::string>(), "something");
|
||||
EXPECT_EQ(stripped.literals().At(0).second.ValueString(), "something");
|
||||
EXPECT_EQ(stripped.query(), "RETURN " + kStrippedStringToken);
|
||||
}
|
||||
|
||||
TEST(QueryStripper, StringLiteral2) {
|
||||
StrippedQuery stripped("RETURN 'so\\'me'");
|
||||
EXPECT_EQ(stripped.literals().size(), 1);
|
||||
EXPECT_EQ(stripped.literals().At(0).second.Value<std::string>(), "so'me");
|
||||
EXPECT_EQ(stripped.literals().At(0).second.ValueString(), "so'me");
|
||||
EXPECT_EQ(stripped.query(), "RETURN " + kStrippedStringToken);
|
||||
}
|
||||
|
||||
TEST(QueryStripper, StringLiteral3) {
|
||||
StrippedQuery stripped("RETURN \"so\\\"me'\"");
|
||||
EXPECT_EQ(stripped.literals().size(), 1);
|
||||
EXPECT_EQ(stripped.literals().At(0).second.Value<std::string>(), "so\"me'");
|
||||
EXPECT_EQ(stripped.literals().At(0).second.ValueString(), "so\"me'");
|
||||
EXPECT_EQ(stripped.query(), "RETURN " + kStrippedStringToken);
|
||||
}
|
||||
|
||||
TEST(QueryStripper, StringLiteral4) {
|
||||
StrippedQuery stripped("RETURN '\\u1Aa4'");
|
||||
EXPECT_EQ(stripped.literals().size(), 1);
|
||||
EXPECT_EQ(stripped.literals().At(0).second.Value<std::string>(), u8"\u1Aa4");
|
||||
EXPECT_EQ(stripped.literals().At(0).second.ValueString(), u8"\u1Aa4");
|
||||
EXPECT_EQ(stripped.query(), "RETURN " + kStrippedStringToken);
|
||||
}
|
||||
|
||||
@ -147,8 +147,7 @@ TEST(QueryStripper, LowSurrogateAlone) {
|
||||
TEST(QueryStripper, Surrogates) {
|
||||
StrippedQuery stripped("RETURN '\\ud83d\\udeeb'");
|
||||
EXPECT_EQ(stripped.literals().size(), 1);
|
||||
EXPECT_EQ(stripped.literals().At(0).second.Value<std::string>(),
|
||||
u8"\U0001f6eb");
|
||||
EXPECT_EQ(stripped.literals().At(0).second.ValueString(), u8"\U0001f6eb");
|
||||
EXPECT_EQ(stripped.query(), "RETURN " + kStrippedStringToken);
|
||||
}
|
||||
|
||||
@ -192,8 +191,8 @@ TEST(QueryStripper, MapLiteral) {
|
||||
TEST(QueryStripper, RangeLiteral) {
|
||||
StrippedQuery stripped("MATCH (n)-[*2..3]-() RETURN n");
|
||||
EXPECT_EQ(stripped.literals().size(), 2);
|
||||
EXPECT_EQ(stripped.literals().At(0).second.Value<int64_t>(), 2);
|
||||
EXPECT_EQ(stripped.literals().At(1).second.Value<int64_t>(), 3);
|
||||
EXPECT_EQ(stripped.literals().At(0).second.ValueInt(), 2);
|
||||
EXPECT_EQ(stripped.literals().At(1).second.ValueInt(), 3);
|
||||
EXPECT_EQ(stripped.query(), "MATCH ( n ) - [ * " + kStrippedIntToken +
|
||||
" .. " + kStrippedIntToken +
|
||||
" ] - ( ) RETURN n");
|
||||
|
@ -44,11 +44,11 @@ class AllTypesFixture : public testing::Test {
|
||||
};
|
||||
|
||||
void EXPECT_PROP_FALSE(const TypedValue &a) {
|
||||
EXPECT_TRUE(a.type() == TypedValue::Type::Bool && !a.Value<bool>());
|
||||
EXPECT_TRUE(a.type() == TypedValue::Type::Bool && !a.ValueBool());
|
||||
}
|
||||
|
||||
void EXPECT_PROP_TRUE(const TypedValue &a) {
|
||||
EXPECT_TRUE(a.type() == TypedValue::Type::Bool && a.Value<bool>());
|
||||
EXPECT_TRUE(a.type() == TypedValue::Type::Bool && a.ValueBool());
|
||||
}
|
||||
|
||||
void EXPECT_PROP_EQ(const TypedValue &a, const TypedValue &b) {
|
||||
@ -79,15 +79,15 @@ TEST(TypedValue, CreationTypes) {
|
||||
}
|
||||
|
||||
TEST(TypedValue, CreationValues) {
|
||||
EXPECT_EQ(TypedValue(true).Value<bool>(), true);
|
||||
EXPECT_EQ(TypedValue(false).Value<bool>(), false);
|
||||
EXPECT_EQ(TypedValue(true).ValueBool(), true);
|
||||
EXPECT_EQ(TypedValue(false).ValueBool(), false);
|
||||
|
||||
EXPECT_EQ(TypedValue(std::string("bla")).ValueString(), "bla");
|
||||
EXPECT_EQ(TypedValue("bla2").ValueString(), "bla2");
|
||||
|
||||
EXPECT_EQ(TypedValue(55).Value<int64_t>(), 55);
|
||||
EXPECT_EQ(TypedValue(55).ValueInt(), 55);
|
||||
|
||||
EXPECT_FLOAT_EQ(TypedValue(66.6).Value<double>(), 66.6);
|
||||
EXPECT_FLOAT_EQ(TypedValue(66.6).ValueDouble(), 66.6);
|
||||
}
|
||||
|
||||
TEST(TypedValue, Equals) {
|
||||
@ -238,8 +238,8 @@ TEST(TypedValue, LogicalNot) {
|
||||
TEST(TypedValue, UnaryMinus) {
|
||||
EXPECT_TRUE((-TypedValue()).type() == TypedValue::Type::Null);
|
||||
|
||||
EXPECT_PROP_EQ(TypedValue(-TypedValue(2).Value<int64_t>()), TypedValue(-2));
|
||||
EXPECT_FLOAT_EQ((-TypedValue(2.0).Value<double>()), -2.0);
|
||||
EXPECT_PROP_EQ(TypedValue(-TypedValue(2).ValueInt()), TypedValue(-2));
|
||||
EXPECT_FLOAT_EQ((-TypedValue(2.0).ValueDouble()), -2.0);
|
||||
|
||||
EXPECT_THROW(-TypedValue(true), TypedValueException);
|
||||
EXPECT_THROW(-TypedValue("something"), TypedValueException);
|
||||
@ -248,8 +248,8 @@ TEST(TypedValue, UnaryMinus) {
|
||||
TEST(TypedValue, UnaryPlus) {
|
||||
EXPECT_TRUE((+TypedValue()).type() == TypedValue::Type::Null);
|
||||
|
||||
EXPECT_PROP_EQ(TypedValue(+TypedValue(2).Value<int64_t>()), TypedValue(2));
|
||||
EXPECT_FLOAT_EQ((+TypedValue(2.0).Value<double>()), 2.0);
|
||||
EXPECT_PROP_EQ(TypedValue(+TypedValue(2).ValueInt()), TypedValue(2));
|
||||
EXPECT_FLOAT_EQ((+TypedValue(2.0).ValueDouble()), 2.0);
|
||||
|
||||
EXPECT_THROW(+TypedValue(true), TypedValueException);
|
||||
EXPECT_THROW(+TypedValue("something"), TypedValueException);
|
||||
@ -311,8 +311,8 @@ TEST_F(TypedValueArithmeticTest, Sum) {
|
||||
true, [](const TypedValue &a, const TypedValue &b) { return a + b; });
|
||||
|
||||
// sum of props of the same type
|
||||
EXPECT_EQ((TypedValue(2) + TypedValue(3)).Value<int64_t>(), 5);
|
||||
EXPECT_FLOAT_EQ((TypedValue(2.5) + TypedValue(1.25)).Value<double>(), 3.75);
|
||||
EXPECT_EQ((TypedValue(2) + TypedValue(3)).ValueInt(), 5);
|
||||
EXPECT_FLOAT_EQ((TypedValue(2.5) + TypedValue(1.25)).ValueDouble(), 3.75);
|
||||
EXPECT_EQ((TypedValue("one") + TypedValue("two")).ValueString(), "onetwo");
|
||||
|
||||
// sum of string and numbers
|
||||
@ -339,12 +339,12 @@ TEST_F(TypedValueArithmeticTest, Difference) {
|
||||
false, [](const TypedValue &a, const TypedValue &b) { return a - b; });
|
||||
|
||||
// difference of props of the same type
|
||||
EXPECT_EQ((TypedValue(2) - TypedValue(3)).Value<int64_t>(), -1);
|
||||
EXPECT_FLOAT_EQ((TypedValue(2.5) - TypedValue(2.25)).Value<double>(), 0.25);
|
||||
EXPECT_EQ((TypedValue(2) - TypedValue(3)).ValueInt(), -1);
|
||||
EXPECT_FLOAT_EQ((TypedValue(2.5) - TypedValue(2.25)).ValueDouble(), 0.25);
|
||||
|
||||
// implicit casting
|
||||
EXPECT_FLOAT_EQ((TypedValue(2) - TypedValue(0.5)).Value<double>(), 1.5);
|
||||
EXPECT_FLOAT_EQ((TypedValue(2.5) - TypedValue(2)).Value<double>(), 0.5);
|
||||
EXPECT_FLOAT_EQ((TypedValue(2) - TypedValue(0.5)).ValueDouble(), 1.5);
|
||||
EXPECT_FLOAT_EQ((TypedValue(2.5) - TypedValue(2)).ValueDouble(), 0.5);
|
||||
}
|
||||
|
||||
TEST_F(TypedValueArithmeticTest, Divison) {
|
||||
@ -356,10 +356,10 @@ TEST_F(TypedValueArithmeticTest, Divison) {
|
||||
EXPECT_PROP_EQ(TypedValue(10) / TypedValue(4), TypedValue(2));
|
||||
|
||||
EXPECT_PROP_EQ(TypedValue(10.0) / TypedValue(2.0), TypedValue(5.0));
|
||||
EXPECT_FLOAT_EQ((TypedValue(10.0) / TypedValue(4.0)).Value<double>(), 2.5);
|
||||
EXPECT_FLOAT_EQ((TypedValue(10.0) / TypedValue(4.0)).ValueDouble(), 2.5);
|
||||
|
||||
EXPECT_FLOAT_EQ((TypedValue(10) / TypedValue(4.0)).Value<double>(), 2.5);
|
||||
EXPECT_FLOAT_EQ((TypedValue(10.0) / TypedValue(4)).Value<double>(), 2.5);
|
||||
EXPECT_FLOAT_EQ((TypedValue(10) / TypedValue(4.0)).ValueDouble(), 2.5);
|
||||
EXPECT_FLOAT_EQ((TypedValue(10.0) / TypedValue(4)).ValueDouble(), 2.5);
|
||||
}
|
||||
|
||||
TEST_F(TypedValueArithmeticTest, Multiplication) {
|
||||
@ -367,10 +367,10 @@ TEST_F(TypedValueArithmeticTest, Multiplication) {
|
||||
false, [](const TypedValue &a, const TypedValue &b) { return a * b; });
|
||||
|
||||
EXPECT_PROP_EQ(TypedValue(10) * TypedValue(2), TypedValue(20));
|
||||
EXPECT_FLOAT_EQ((TypedValue(12.5) * TypedValue(6.6)).Value<double>(),
|
||||
EXPECT_FLOAT_EQ((TypedValue(12.5) * TypedValue(6.6)).ValueDouble(),
|
||||
12.5 * 6.6);
|
||||
EXPECT_FLOAT_EQ((TypedValue(10) * TypedValue(4.5)).Value<double>(), 10 * 4.5);
|
||||
EXPECT_FLOAT_EQ((TypedValue(10.2) * TypedValue(4)).Value<double>(), 10.2 * 4);
|
||||
EXPECT_FLOAT_EQ((TypedValue(10) * TypedValue(4.5)).ValueDouble(), 10 * 4.5);
|
||||
EXPECT_FLOAT_EQ((TypedValue(10.2) * TypedValue(4)).ValueDouble(), 10.2 * 4);
|
||||
}
|
||||
|
||||
TEST_F(TypedValueArithmeticTest, Modulo) {
|
||||
@ -382,10 +382,10 @@ TEST_F(TypedValueArithmeticTest, Modulo) {
|
||||
EXPECT_PROP_EQ(TypedValue(10) % TypedValue(4), TypedValue(2));
|
||||
|
||||
EXPECT_PROP_EQ(TypedValue(10.0) % TypedValue(2.0), TypedValue(0.0));
|
||||
EXPECT_FLOAT_EQ((TypedValue(10.0) % TypedValue(3.25)).Value<double>(), 0.25);
|
||||
EXPECT_FLOAT_EQ((TypedValue(10.0) % TypedValue(3.25)).ValueDouble(), 0.25);
|
||||
|
||||
EXPECT_FLOAT_EQ((TypedValue(10) % TypedValue(4.0)).Value<double>(), 2.0);
|
||||
EXPECT_FLOAT_EQ((TypedValue(10.0) % TypedValue(4)).Value<double>(), 2.0);
|
||||
EXPECT_FLOAT_EQ((TypedValue(10) % TypedValue(4.0)).ValueDouble(), 2.0);
|
||||
EXPECT_FLOAT_EQ((TypedValue(10.0) % TypedValue(4)).ValueDouble(), 2.0);
|
||||
}
|
||||
|
||||
class TypedValueLogicTest : public AllTypesFixture {
|
||||
|
Loading…
Reference in New Issue
Block a user