From fa62ea19203e3f577f9d5748e771592ee6cdaf0f Mon Sep 17 00:00:00 2001 From: Teon Banek Date: Thu, 30 May 2019 13:33:20 +0200 Subject: [PATCH] Use ValueMap instead of Value<> Reviewers: mtomic, llugovic, mferencevic Reviewed By: mtomic Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2114 --- src/query/common.cpp | 2 +- src/query/distributed/serialization.cpp | 2 +- src/query/interpret/awesome_memgraph_functions.cpp | 2 +- src/query/interpret/eval.hpp | 7 +++---- src/query/plan/operator.cpp | 8 +++----- src/query/typed_value.cpp | 10 +++++----- tests/unit/query_common.hpp | 2 +- tests/unit/query_expression_evaluator.cpp | 2 +- 8 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/query/common.cpp b/src/query/common.cpp index cea9d760a..f72ddde55 100644 --- a/src/query/common.cpp +++ b/src/query/common.cpp @@ -195,7 +195,7 @@ void ReconstructTypedValue(TypedValue &value) { ReconstructTypedValue(inner_value); break; case Type::Map: - for (auto &kv : value.Value>()) + for (auto &kv : value.ValueMap()) ReconstructTypedValue(kv.second); break; case Type::Path: diff --git a/src/query/distributed/serialization.cpp b/src/query/distributed/serialization.cpp index 6a36698fa..17e5ed024 100644 --- a/src/query/distributed/serialization.cpp +++ b/src/query/distributed/serialization.cpp @@ -39,7 +39,7 @@ void Save(const query::TypedValue &value, slk::Builder *builder, } case query::TypedValue::Type::Map: { slk::Save(static_cast(6), builder); - const auto &map = value.Value>(); + const auto &map = value.ValueMap(); size_t size = map.size(); slk::Save(size, builder); for (const auto &kv : map) { diff --git a/src/query/interpret/awesome_memgraph_functions.cpp b/src/query/interpret/awesome_memgraph_functions.cpp index 02a164b8d..9959b5d73 100644 --- a/src/query/interpret/awesome_memgraph_functions.cpp +++ b/src/query/interpret/awesome_memgraph_functions.cpp @@ -128,7 +128,7 @@ TypedValue Size(TypedValue *args, int64_t nargs, const EvaluationContext &, // neo4j doesn't implement size for map, but I don't see a good reason not // to do it. return static_cast( - args[0].Value>().size()); + args[0].ValueMap().size()); case TypedValue::Type::Path: return static_cast(args[0].ValuePath().edges().size()); default: diff --git a/src/query/interpret/eval.hpp b/src/query/interpret/eval.hpp index abca88edc..4a65d8e14 100644 --- a/src/query/interpret/eval.hpp +++ b/src/query/interpret/eval.hpp @@ -183,7 +183,7 @@ class ExpressionEvaluator : public ExpressionVisitor { if (!index.IsString()) throw QueryRuntimeException("Expected a string as a map index, got {}.", index.type()); - const auto &map = lhs.Value>(); + const auto &map = lhs.ValueMap(); auto found = map.find(std::string(index.ValueString())); if (found == map.end()) return TypedValue::Null; return found->second; @@ -276,8 +276,7 @@ class ExpressionEvaluator : public ExpressionVisitor { return expression_result.Value().PropsAt( GetProperty(property_lookup.property_)); case TypedValue::Type::Map: { - auto &map = - expression_result.Value>(); + auto &map = expression_result.ValueMap(); auto found = map.find(property_lookup.property_.name); if (found == map.end()) return TypedValue::Null; return found->second; @@ -555,7 +554,7 @@ class ExpressionEvaluator : public ExpressionVisitor { break; } case TypedValue::Type::Map: { - auto &map = value.Value>(); + auto &map = value.ValueMap(); for (auto &kv : map) SwitchAccessors(kv.second); break; } diff --git a/src/query/plan/operator.cpp b/src/query/plan/operator.cpp index 9170e606a..7c3ad4233 100644 --- a/src/query/plan/operator.cpp +++ b/src/query/plan/operator.cpp @@ -2034,7 +2034,7 @@ void SetProperties::SetPropertiesCursor::Set(TRecordAccessor &record, set_props(rhs.Value().Properties()); break; case TypedValue::Type::Map: { - for (const auto &kv : rhs.Value>()) + for (const auto &kv : rhs.ValueMap()) PropsSetChecked(&record, db_.Property(kv.first), kv.second); break; } @@ -2611,8 +2611,7 @@ class AggregateCursor : public Cursor { auto key = agg_elem_it->key->Accept(*evaluator); if (key.type() != TypedValue::Type::String) throw QueryRuntimeException("Map key must be a string."); - value_it->Value>().emplace( - key.ValueString(), input_value); + value_it->ValueMap().emplace(key.ValueString(), input_value); break; } continue; @@ -2663,8 +2662,7 @@ class AggregateCursor : public Cursor { auto key = agg_elem_it->key->Accept(*evaluator); if (key.type() != TypedValue::Type::String) throw QueryRuntimeException("Map key must be a string."); - value_it->Value>().emplace( - key.ValueString(), input_value); + value_it->ValueMap().emplace(key.ValueString(), input_value); break; } // end switch over Aggregation::Op enum } // end loop over all aggregations diff --git a/src/query/typed_value.cpp b/src/query/typed_value.cpp index b6bc89a48..7b1714904 100644 --- a/src/query/typed_value.cpp +++ b/src/query/typed_value.cpp @@ -315,8 +315,8 @@ std::ostream &operator<<(std::ostream &os, const TypedValue &value) { return os << "]"; case TypedValue::Type::Map: os << "{"; - utils::PrintIterable(os, value.Value>(), - ", ", [](auto &stream, const auto &pair) { + utils::PrintIterable(os, value.ValueMap(), ", ", + [](auto &stream, const auto &pair) { stream << pair.first << ": " << pair.second; }); return os << "}"; @@ -647,8 +647,8 @@ TypedValue operator==(const TypedValue &a, const TypedValue &b) { a.GetMemoryResource()); } case TypedValue::Type::Map: { - const auto &map_a = a.Value>(); - const auto &map_b = b.Value>(); + const auto &map_a = a.ValueMap(); + const auto &map_b = b.ValueMap(); if (map_a.size() != map_b.size()) return TypedValue(false, a.GetMemoryResource()); for (const auto &kv_a : map_a) { @@ -903,7 +903,7 @@ size_t TypedValue::Hash::operator()(const TypedValue &value) const { } case TypedValue::Type::Map: { size_t hash = 6543457; - for (const auto &kv : value.Value>()) { + for (const auto &kv : value.ValueMap()) { hash ^= std::hash{}(kv.first); hash ^= this->operator()(kv.second); } diff --git a/tests/unit/query_common.hpp b/tests/unit/query_common.hpp index 61cc4b0a2..822ce03e4 100644 --- a/tests/unit/query_common.hpp +++ b/tests/unit/query_common.hpp @@ -51,7 +51,7 @@ auto ToList(const TypedValue &t) { template auto ToMap(const TypedValue &t) { std::map map; - for (const auto &kv : t.Value>()) + for (const auto &kv : t.ValueMap()) map.emplace(kv.first, kv.second.Value()); return map; }; diff --git a/tests/unit/query_expression_evaluator.cpp b/tests/unit/query_expression_evaluator.cpp index 5f7aff4d8..98dcaa649 100644 --- a/tests/unit/query_expression_evaluator.cpp +++ b/tests/unit/query_expression_evaluator.cpp @@ -1008,7 +1008,7 @@ TEST_F(FunctionTest, Properties) { auto prop_values_to_int = [](TypedValue t) { std::unordered_map properties; - for (auto property : t.Value>()) { + for (auto property : t.ValueMap()) { properties[property.first] = property.second.ValueInt(); } return properties;