Use ValueMap instead of Value<>
Reviewers: mtomic, llugovic, mferencevic Reviewed By: mtomic Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2114
This commit is contained in:
parent
6bb72d14a1
commit
fa62ea1920
@ -195,7 +195,7 @@ void ReconstructTypedValue(TypedValue &value) {
|
||||
ReconstructTypedValue(inner_value);
|
||||
break;
|
||||
case Type::Map:
|
||||
for (auto &kv : value.Value<std::map<std::string, TypedValue>>())
|
||||
for (auto &kv : value.ValueMap())
|
||||
ReconstructTypedValue(kv.second);
|
||||
break;
|
||||
case Type::Path:
|
||||
|
@ -39,7 +39,7 @@ void Save(const query::TypedValue &value, slk::Builder *builder,
|
||||
}
|
||||
case query::TypedValue::Type::Map: {
|
||||
slk::Save(static_cast<uint8_t>(6), builder);
|
||||
const auto &map = value.Value<std::map<std::string, query::TypedValue>>();
|
||||
const auto &map = value.ValueMap();
|
||||
size_t size = map.size();
|
||||
slk::Save(size, builder);
|
||||
for (const auto &kv : map) {
|
||||
|
@ -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<int64_t>(
|
||||
args[0].Value<std::map<std::string, TypedValue>>().size());
|
||||
args[0].ValueMap().size());
|
||||
case TypedValue::Type::Path:
|
||||
return static_cast<int64_t>(args[0].ValuePath().edges().size());
|
||||
default:
|
||||
|
@ -183,7 +183,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
|
||||
if (!index.IsString())
|
||||
throw QueryRuntimeException("Expected a string as a map index, got {}.",
|
||||
index.type());
|
||||
const auto &map = lhs.Value<std::map<std::string, TypedValue>>();
|
||||
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<TypedValue> {
|
||||
return expression_result.Value<EdgeAccessor>().PropsAt(
|
||||
GetProperty(property_lookup.property_));
|
||||
case TypedValue::Type::Map: {
|
||||
auto &map =
|
||||
expression_result.Value<std::map<std::string, TypedValue>>();
|
||||
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<TypedValue> {
|
||||
break;
|
||||
}
|
||||
case TypedValue::Type::Map: {
|
||||
auto &map = value.Value<std::map<std::string, TypedValue>>();
|
||||
auto &map = value.ValueMap();
|
||||
for (auto &kv : map) SwitchAccessors(kv.second);
|
||||
break;
|
||||
}
|
||||
|
@ -2034,7 +2034,7 @@ void SetProperties::SetPropertiesCursor::Set(TRecordAccessor &record,
|
||||
set_props(rhs.Value<VertexAccessor>().Properties());
|
||||
break;
|
||||
case TypedValue::Type::Map: {
|
||||
for (const auto &kv : rhs.Value<std::map<std::string, TypedValue>>())
|
||||
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<std::map<std::string, TypedValue>>().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<std::map<std::string, TypedValue>>().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
|
||||
|
@ -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<std::map<std::string, TypedValue>>(),
|
||||
", ", [](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<std::map<std::string, TypedValue>>();
|
||||
const auto &map_b = b.Value<std::map<std::string, TypedValue>>();
|
||||
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<std::map<std::string, TypedValue>>()) {
|
||||
for (const auto &kv : value.ValueMap()) {
|
||||
hash ^= std::hash<std::string>{}(kv.first);
|
||||
hash ^= this->operator()(kv.second);
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ auto ToList(const TypedValue &t) {
|
||||
template <typename TElement>
|
||||
auto ToMap(const TypedValue &t) {
|
||||
std::map<std::string, TElement> map;
|
||||
for (const auto &kv : t.Value<std::map<std::string, TypedValue>>())
|
||||
for (const auto &kv : t.ValueMap())
|
||||
map.emplace(kv.first, kv.second.Value<TElement>());
|
||||
return map;
|
||||
};
|
||||
|
@ -1008,7 +1008,7 @@ TEST_F(FunctionTest, Properties) {
|
||||
|
||||
auto prop_values_to_int = [](TypedValue t) {
|
||||
std::unordered_map<std::string, int> properties;
|
||||
for (auto property : t.Value<std::map<std::string, TypedValue>>()) {
|
||||
for (auto property : t.ValueMap()) {
|
||||
properties[property.first] = property.second.ValueInt();
|
||||
}
|
||||
return properties;
|
||||
|
Loading…
Reference in New Issue
Block a user