Use ValueList instead of Value<>

Summary:
This change will make the transition to allocator backed TypedValue
smoother.

Reviewers: mtomic, llugovic, mferencevic, msantl

Reviewed By: mtomic, llugovic

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D2084
This commit is contained in:
Teon Banek 2019-05-21 16:06:05 +02:00
parent 18cf877a47
commit f6264ab2ae
10 changed files with 30 additions and 30 deletions

View File

@ -191,7 +191,7 @@ void ReconstructTypedValue(TypedValue &value) {
if (!value.ValueEdge().Reconstruct()) throw ReconstructionException();
break;
case Type::List:
for (TypedValue &inner_value : value.Value<std::vector<TypedValue>>())
for (TypedValue &inner_value : value.ValueList())
ReconstructTypedValue(inner_value);
break;
case Type::Map:

View File

@ -29,7 +29,7 @@ void Save(const query::TypedValue &value, slk::Builder *builder,
return;
case query::TypedValue::Type::List: {
slk::Save(static_cast<uint8_t>(5), builder);
const auto &values = value.Value<std::vector<query::TypedValue>>();
const auto &values = value.ValueList();
size_t size = values.size();
slk::Save(size, builder);
for (const auto &v : values) {

View File

@ -57,7 +57,7 @@ TypedValue Head(TypedValue *args, int64_t nargs, const EvaluationContext &,
case TypedValue::Type::Null:
return TypedValue::Null;
case TypedValue::Type::List: {
const auto &list = args[0].Value<std::vector<TypedValue>>();
const auto &list = args[0].ValueList();
if (list.empty()) return TypedValue::Null;
return list[0];
}
@ -75,7 +75,7 @@ TypedValue Last(TypedValue *args, int64_t nargs, const EvaluationContext &,
case TypedValue::Type::Null:
return TypedValue::Null;
case TypedValue::Type::List: {
const auto &list = args[0].Value<std::vector<TypedValue>>();
const auto &list = args[0].ValueList();
if (list.empty()) return TypedValue::Null;
return list.back();
}
@ -120,7 +120,7 @@ TypedValue Size(TypedValue *args, int64_t nargs, const EvaluationContext &,
return TypedValue::Null;
case TypedValue::Type::List:
return static_cast<int64_t>(
args[0].Value<std::vector<TypedValue>>().size());
args[0].ValueList().size());
case TypedValue::Type::String:
return static_cast<int64_t>(args[0].Value<std::string>().size());
case TypedValue::Type::Map:
@ -413,7 +413,7 @@ TypedValue Tail(TypedValue *args, int64_t nargs, const EvaluationContext &,
case TypedValue::Type::Null:
return TypedValue::Null;
case TypedValue::Type::List: {
auto list = args[0].Value<std::vector<TypedValue>>();
auto list = args[0].ValueList();
if (list.empty()) return list;
list.erase(list.begin());
return list;
@ -440,7 +440,7 @@ TypedValue UniformSample(TypedValue *args, int64_t nargs,
"Second argument of 'uniformSample' must be a non-negative integer.");
case TypedValue::Type::List:
if (args[1].IsInt() && args[1].ValueInt() >= 0) {
auto &population = args[0].Value<std::vector<TypedValue>>();
auto &population = args[0].ValueList();
auto population_size = population.size();
if (population_size == 0) return TypedValue::Null;
auto desired_length = args[1].ValueInt();

View File

@ -131,7 +131,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
if (_list.type() != TypedValue::Type::List) {
throw QueryRuntimeException("IN expected a list, got {}.", _list.type());
}
auto list = _list.Value<std::vector<TypedValue>>();
auto list = _list.ValueList();
// If literal is NULL there is no need to try to compare it with every
// element in the list since result of every comparison will be NULL. There
@ -170,7 +170,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
throw QueryRuntimeException(
"Expected an integer as a list index, got {}.", index.type());
auto index_int = index.Value<int64_t>();
const auto &list = lhs.Value<std::vector<TypedValue>>();
const auto &list = lhs.ValueList();
if (index_int < 0) {
index_int += static_cast<int64_t>(list.size());
}
@ -242,7 +242,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
if (is_null) {
return TypedValue::Null;
}
const auto &list = _list.Value<std::vector<TypedValue>>();
const auto &list = _list.ValueList();
auto normalise_bound = [&](int64_t bound) {
if (bound < 0) {
bound = static_cast<int64_t>(list.size()) + bound;
@ -382,7 +382,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
throw QueryRuntimeException("REDUCE expected a list, got {}.",
list_value.type());
}
const auto &list = list_value.Value<std::vector<TypedValue>>();
const auto &list = list_value.ValueList();
const auto &element_symbol = symbol_table_->at(*reduce.identifier_);
const auto &accumulator_symbol = symbol_table_->at(*reduce.accumulator_);
auto accumulator = reduce.initializer_->Accept(*this);
@ -403,7 +403,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
throw QueryRuntimeException("EXTRACT expected a list, got {}.",
list_value.type());
}
const auto &list = list_value.Value<std::vector<TypedValue>>();
const auto &list = list_value.ValueList();
const auto &element_symbol = symbol_table_->at(*extract.identifier_);
std::vector<TypedValue> result;
result.reserve(list.size());
@ -427,7 +427,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
throw QueryRuntimeException("ALL expected a list, got {}.",
list_value.type());
}
const auto &list = list_value.Value<std::vector<TypedValue>>();
const auto &list = list_value.ValueList();
const auto &symbol = symbol_table_->at(*all.identifier_);
for (const auto &element : list) {
frame_->at(symbol) = element;
@ -453,7 +453,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
throw QueryRuntimeException("SINGLE expected a list, got {}.",
list_value.type());
}
const auto &list = list_value.Value<std::vector<TypedValue>>();
const auto &list = list_value.ValueList();
const auto &symbol = symbol_table_->at(*single.identifier_);
bool predicate_satisfied = false;
for (const auto &element : list) {
@ -550,7 +550,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
break;
}
case TypedValue::Type::List: {
auto &list = value.Value<std::vector<TypedValue>>();
auto &list = value.ValueList();
for (auto &list_value : list) SwitchAccessors(list_value);
break;
}

View File

@ -873,7 +873,7 @@ class ExpandVariableCursor : public Cursor {
// we use this a lot
std::vector<TypedValue> &edges_on_frame =
frame[self_.common_.edge_symbol].Value<std::vector<TypedValue>>();
frame[self_.common_.edge_symbol].ValueList();
// it is possible that edges_on_frame does not contain as many
// elements as edges_ due to edge-uniqueness (when a whole layer
@ -2242,7 +2242,7 @@ namespace {
*/
bool ContainsSameEdge(const TypedValue &a, const TypedValue &b) {
auto compare_to_list = [](const TypedValue &list, const TypedValue &other) {
for (const TypedValue &list_elem : list.Value<std::vector<TypedValue>>())
for (const TypedValue &list_elem : list.ValueList())
if (ContainsSameEdge(list_elem, other)) return true;
return false;
};
@ -2605,7 +2605,7 @@ class AggregateCursor : public Cursor {
*value_it = 1;
break;
case Aggregation::Op::COLLECT_LIST:
value_it->Value<std::vector<TypedValue>>().push_back(input_value);
value_it->ValueList().push_back(input_value);
break;
case Aggregation::Op::COLLECT_MAP:
auto key = agg_elem_it->key->Accept(*evaluator);
@ -2657,7 +2657,7 @@ class AggregateCursor : public Cursor {
*value_it = *value_it + input_value;
break;
case Aggregation::Op::COLLECT_LIST:
value_it->Value<std::vector<TypedValue>>().push_back(input_value);
value_it->ValueList().push_back(input_value);
break;
case Aggregation::Op::COLLECT_MAP:
auto key = agg_elem_it->key->Accept(*evaluator);

View File

@ -287,7 +287,7 @@ std::ostream &operator<<(std::ostream &os, const TypedValue &value) {
return os << value.Value<std::string>();
case TypedValue::Type::List:
os << "[";
utils::PrintIterable(os, value.Value<std::vector<TypedValue>>());
utils::PrintIterable(os, value.ValueList());
return os << "]";
case TypedValue::Type::Map:
os << "{";
@ -576,8 +576,8 @@ TypedValue operator==(const TypedValue &a, const TypedValue &b) {
// well. Because, why not?
// At memgraph we prefer sanity so [1,2] = [1,2] compares to true and
// 2 = [2] compares to false.
auto &list_a = a.Value<std::vector<TypedValue>>();
auto &list_b = b.Value<std::vector<TypedValue>>();
auto &list_a = a.ValueList();
auto &list_b = b.ValueList();
if (list_a.size() != list_b.size()) return false;
// two arrays are considered equal (by neo) if all their
// elements are bool-equal. this means that:
@ -675,7 +675,7 @@ TypedValue operator+(const TypedValue &a, const TypedValue &b) {
std::vector<TypedValue> list;
auto append_list = [&list](const TypedValue &v) {
if (v.IsList()) {
auto list2 = v.Value<std::vector<TypedValue>>();
auto list2 = v.ValueList();
list.insert(list.end(), list2.begin(), list2.end());
} else {
list.push_back(v);
@ -821,7 +821,7 @@ size_t TypedValue::Hash::operator()(const TypedValue &value) const {
return std::hash<std::string>{}(value.Value<std::string>());
case TypedValue::Type::List: {
return utils::FnvCollection<std::vector<TypedValue>, TypedValue, Hash>{}(
value.Value<std::vector<TypedValue>>());
value.ValueList());
}
case TypedValue::Type::Map: {
size_t hash = 6543457;

View File

@ -120,7 +120,7 @@ TEST_F(InterpreterTest, Parameters) {
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].Value<std::vector<query::TypedValue>>());
stream.GetResults()[0][0].ValueList());
ASSERT_THAT(result, testing::ElementsAre(5, 2, 3));
}
{

View File

@ -42,7 +42,7 @@ namespace test_common {
template <typename T>
auto ToList(const TypedValue &t) {
std::vector<T> list;
for (auto x : t.Value<std::vector<TypedValue>>()) {
for (auto x : t.ValueList()) {
list.push_back(x.Value<T>());
}
return list;

View File

@ -595,7 +595,7 @@ TEST(QueryPlan, Unwind) {
for (const auto &row : results) {
ASSERT_EQ(2, row.size());
ASSERT_EQ(row[0].type(), TypedValue::Type::List);
EXPECT_EQ(row[0].Value<std::vector<TypedValue>>().size(),
EXPECT_EQ(row[0].ValueList().size(),
*expected_x_card_it);
EXPECT_EQ(row[1].type(), expected_y_it->type());
expected_x_card_it++;

View File

@ -313,11 +313,11 @@ TEST_F(TypedValueArithmeticTest, Sum) {
std::vector<TypedValue> out2 = {1, 2, true, "a", 2};
std::vector<TypedValue> out3 = {1, 2, true, "a", 1, 2, true, "a"};
EXPECT_PROP_EQ(
(TypedValue(2) + TypedValue(in)).Value<std::vector<TypedValue>>(), out1);
(TypedValue(2) + TypedValue(in)).ValueList(), out1);
EXPECT_PROP_EQ(
(TypedValue(in) + TypedValue(2)).Value<std::vector<TypedValue>>(), out2);
(TypedValue(in) + TypedValue(2)).ValueList(), out2);
EXPECT_PROP_EQ(
(TypedValue(in) + TypedValue(in)).Value<std::vector<TypedValue>>(), out3);
(TypedValue(in) + TypedValue(in)).ValueList(), out3);
}
TEST_F(TypedValueArithmeticTest, Difference) {