Use ValueString instead of Value<>
Reviewers: mtomic, llugovic, msantl, mferencevic Reviewed By: msantl Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2101
This commit is contained in:
parent
bb2dbc290f
commit
c0dc37fe34
@ -245,7 +245,7 @@ bool TypedValueCompare(const TypedValue &a, const TypedValue &b) {
|
||||
else
|
||||
return a.Value<double>() < b.Value<double>();
|
||||
case TypedValue::Type::String:
|
||||
return a.Value<std::string>() < b.Value<std::string>();
|
||||
return a.ValueString() < b.ValueString();
|
||||
case TypedValue::Type::List:
|
||||
case TypedValue::Type::Map:
|
||||
case TypedValue::Type::Vertex:
|
||||
|
@ -25,7 +25,7 @@ void Save(const query::TypedValue &value, slk::Builder *builder,
|
||||
return;
|
||||
case query::TypedValue::Type::String:
|
||||
slk::Save(static_cast<uint8_t>(4), builder);
|
||||
slk::Save(value.Value<std::string>(), builder);
|
||||
slk::Save(value.ValueString(), builder);
|
||||
return;
|
||||
case query::TypedValue::Type::List: {
|
||||
slk::Save(static_cast<uint8_t>(5), builder);
|
||||
|
@ -122,7 +122,7 @@ TypedValue Size(TypedValue *args, int64_t nargs, const EvaluationContext &,
|
||||
return static_cast<int64_t>(
|
||||
args[0].ValueList().size());
|
||||
case TypedValue::Type::String:
|
||||
return static_cast<int64_t>(args[0].Value<std::string>().size());
|
||||
return static_cast<int64_t>(args[0].ValueString().size());
|
||||
case TypedValue::Type::Map:
|
||||
// neo4j doesn't implement size for map, but I don't see a good reason not
|
||||
// to do it.
|
||||
@ -217,7 +217,7 @@ TypedValue ToBoolean(TypedValue *args, int64_t nargs, const EvaluationContext &,
|
||||
case TypedValue::Type::Int:
|
||||
return args[0].ValueInt() != 0L;
|
||||
case TypedValue::Type::String: {
|
||||
auto s = utils::ToUpperCase(utils::Trim(args[0].Value<std::string>()));
|
||||
auto s = utils::ToUpperCase(utils::Trim(args[0].ValueString()));
|
||||
if (s == "TRUE") return true;
|
||||
if (s == "FALSE") return false;
|
||||
// I think this is just stupid and that exception should be thrown, but
|
||||
@ -244,7 +244,7 @@ TypedValue ToFloat(TypedValue *args, int64_t nargs, const EvaluationContext &,
|
||||
return args[0];
|
||||
case TypedValue::Type::String:
|
||||
try {
|
||||
return utils::ParseDouble(utils::Trim(args[0].Value<std::string>()));
|
||||
return utils::ParseDouble(utils::Trim(args[0].ValueString()));
|
||||
} catch (const utils::BasicException &) {
|
||||
return TypedValue::Null;
|
||||
}
|
||||
@ -273,7 +273,7 @@ TypedValue ToInteger(TypedValue *args, int64_t nargs, const EvaluationContext &,
|
||||
// Yup, this is correct. String is valid if it has floating point
|
||||
// number, then it is parsed and converted to int.
|
||||
return static_cast<int64_t>(
|
||||
utils::ParseDouble(utils::Trim(args[0].Value<std::string>())));
|
||||
utils::ParseDouble(utils::Trim(args[0].ValueString())));
|
||||
} catch (const utils::BasicException &) {
|
||||
return TypedValue::Null;
|
||||
}
|
||||
@ -603,8 +603,8 @@ TypedValue StringMatchOperator(TypedValue *args, int64_t nargs,
|
||||
check_arg(args[0]);
|
||||
check_arg(args[1]);
|
||||
if (has_null) return TypedValue::Null;
|
||||
const auto &s1 = args[0].Value<std::string>();
|
||||
const auto &s2 = args[1].Value<std::string>();
|
||||
const auto &s1 = args[0].ValueString();
|
||||
const auto &s2 = args[1].ValueString();
|
||||
return Predicate(s1, s2);
|
||||
}
|
||||
|
||||
|
@ -184,7 +184,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
|
||||
throw QueryRuntimeException("Expected a string as a map index, got {}.",
|
||||
index.type());
|
||||
const auto &map = lhs.Value<std::map<std::string, TypedValue>>();
|
||||
auto found = map.find(index.Value<std::string>());
|
||||
auto found = map.find(index.ValueString());
|
||||
if (found == map.end()) return TypedValue::Null;
|
||||
return found->second;
|
||||
}
|
||||
@ -194,7 +194,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
|
||||
throw QueryRuntimeException(
|
||||
"Expected a string as a property name, got {}.", index.type());
|
||||
return lhs.Value<VertexAccessor>().PropsAt(
|
||||
dba_->Property(index.Value<std::string>()));
|
||||
dba_->Property(index.ValueString()));
|
||||
}
|
||||
|
||||
if (lhs.IsEdge()) {
|
||||
@ -202,7 +202,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
|
||||
throw QueryRuntimeException(
|
||||
"Expected a string as a property name, got {}.", index.type());
|
||||
return lhs.Value<EdgeAccessor>().PropsAt(
|
||||
dba_->Property(index.Value<std::string>()));
|
||||
dba_->Property(index.ValueString()));
|
||||
}
|
||||
|
||||
// lhs is Null
|
||||
|
@ -2612,7 +2612,7 @@ class AggregateCursor : public Cursor {
|
||||
if (key.type() != TypedValue::Type::String)
|
||||
throw QueryRuntimeException("Map key must be a string.");
|
||||
value_it->Value<std::map<std::string, TypedValue>>().emplace(
|
||||
key.Value<std::string>(), input_value);
|
||||
key.ValueString(), input_value);
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
@ -2664,7 +2664,7 @@ class AggregateCursor : public Cursor {
|
||||
if (key.type() != TypedValue::Type::String)
|
||||
throw QueryRuntimeException("Map key must be a string.");
|
||||
value_it->Value<std::map<std::string, TypedValue>>().emplace(
|
||||
key.Value<std::string>(), input_value);
|
||||
key.ValueString(), input_value);
|
||||
break;
|
||||
} // end switch over Aggregation::Op enum
|
||||
} // end loop over all aggregations
|
||||
|
@ -307,7 +307,7 @@ std::ostream &operator<<(std::ostream &os, const TypedValue &value) {
|
||||
case TypedValue::Type::Double:
|
||||
return os << value.Value<double>();
|
||||
case TypedValue::Type::String:
|
||||
return os << value.Value<std::string>();
|
||||
return os << value.ValueString();
|
||||
case TypedValue::Type::List:
|
||||
os << "[";
|
||||
utils::PrintIterable(os, value.ValueList());
|
||||
@ -580,7 +580,7 @@ TypedValue operator<(const TypedValue &a, const TypedValue &b) {
|
||||
throw TypedValueException("Invalid 'less' operand types({} + {})",
|
||||
a.type(), b.type());
|
||||
} else {
|
||||
return TypedValue(a.Value<std::string>() < b.Value<std::string>(),
|
||||
return TypedValue(a.ValueString() < b.ValueString(),
|
||||
a.GetMemoryResource());
|
||||
}
|
||||
}
|
||||
@ -615,7 +615,7 @@ TypedValue operator==(const TypedValue &a, const TypedValue &b) {
|
||||
case TypedValue::Type::Double:
|
||||
return TypedValue(ToDouble(a) == ToDouble(b), a.GetMemoryResource());
|
||||
case TypedValue::Type::String:
|
||||
return TypedValue(a.Value<std::string>() == b.Value<std::string>(),
|
||||
return TypedValue(a.ValueString() == b.ValueString(),
|
||||
a.GetMemoryResource());
|
||||
case TypedValue::Type::Vertex:
|
||||
return TypedValue(a.Value<VertexAccessor>() == b.Value<VertexAccessor>(),
|
||||
@ -680,7 +680,7 @@ TypedValue operator!(const TypedValue &a) {
|
||||
* @return A string.
|
||||
*/
|
||||
std::string ValueToString(const TypedValue &value) {
|
||||
if (value.IsString()) return value.Value<std::string>();
|
||||
if (value.IsString()) return value.ValueString();
|
||||
if (value.IsInt()) return std::to_string(value.Value<int64_t>());
|
||||
if (value.IsDouble()) return fmt::format("{}", value.Value<double>());
|
||||
// unsupported situations
|
||||
@ -894,7 +894,7 @@ size_t TypedValue::Hash::operator()(const TypedValue &value) const {
|
||||
case TypedValue::Type::Double:
|
||||
return std::hash<double>{}(value.Value<double>());
|
||||
case TypedValue::Type::String:
|
||||
return std::hash<std::string>{}(value.Value<std::string>());
|
||||
return std::hash<std::string>{}(value.ValueString());
|
||||
case TypedValue::Type::List: {
|
||||
return utils::FnvCollection<TypedValue::TVector, TypedValue, Hash>{}(
|
||||
value.ValueList());
|
||||
|
@ -153,7 +153,7 @@ TEST_F(DistributedInterpretationTest, RemoteExpandTest2) {
|
||||
std::vector<std::string> row;
|
||||
row.reserve(res.size());
|
||||
for (const auto &col : res) {
|
||||
row.push_back(col.Value<std::string>());
|
||||
row.push_back(col.ValueString());
|
||||
}
|
||||
got.push_back(row);
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ TEST_F(InterpreterTest, Parameters) {
|
||||
auto stream = Interpret("RETURN $2 + $`a b`", {{"2", "da"}, {"a b", "ne"}});
|
||||
ASSERT_EQ(stream.GetResults().size(), 1U);
|
||||
ASSERT_EQ(stream.GetResults()[0].size(), 1U);
|
||||
ASSERT_EQ(stream.GetResults()[0][0].Value<std::string>(), "dane");
|
||||
ASSERT_EQ(stream.GetResults()[0][0].ValueString(), "dane");
|
||||
}
|
||||
{
|
||||
// Non-primitive literal.
|
||||
|
@ -82,8 +82,8 @@ TEST(TypedValue, CreationValues) {
|
||||
EXPECT_EQ(TypedValue(true).Value<bool>(), true);
|
||||
EXPECT_EQ(TypedValue(false).Value<bool>(), false);
|
||||
|
||||
EXPECT_EQ(TypedValue(std::string("bla")).Value<std::string>(), "bla");
|
||||
EXPECT_EQ(TypedValue("bla2").Value<std::string>(), "bla2");
|
||||
EXPECT_EQ(TypedValue(std::string("bla")).ValueString(), "bla");
|
||||
EXPECT_EQ(TypedValue("bla2").ValueString(), "bla2");
|
||||
|
||||
EXPECT_EQ(TypedValue(55).Value<int64_t>(), 55);
|
||||
|
||||
@ -298,15 +298,15 @@ TEST_F(TypedValueArithmeticTest, Sum) {
|
||||
// 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("one") + TypedValue("two")).Value<std::string>(),
|
||||
EXPECT_EQ((TypedValue("one") + TypedValue("two")).ValueString(),
|
||||
"onetwo");
|
||||
|
||||
// sum of string and numbers
|
||||
EXPECT_EQ((TypedValue("one") + TypedValue(1)).Value<std::string>(), "one1");
|
||||
EXPECT_EQ((TypedValue(1) + TypedValue("one")).Value<std::string>(), "1one");
|
||||
EXPECT_EQ((TypedValue("one") + TypedValue(3.2)).Value<std::string>(),
|
||||
EXPECT_EQ((TypedValue("one") + TypedValue(1)).ValueString(), "one1");
|
||||
EXPECT_EQ((TypedValue(1) + TypedValue("one")).ValueString(), "1one");
|
||||
EXPECT_EQ((TypedValue("one") + TypedValue(3.2)).ValueString(),
|
||||
"one3.2");
|
||||
EXPECT_EQ((TypedValue(3.2) + TypedValue("one")).Value<std::string>(),
|
||||
EXPECT_EQ((TypedValue(3.2) + TypedValue("one")).ValueString(),
|
||||
"3.2one");
|
||||
std::vector<TypedValue> in = {1, 2, true, "a"};
|
||||
std::vector<TypedValue> out1 = {2, 1, 2, true, "a"};
|
||||
|
@ -49,7 +49,7 @@ TEST_F(RecoveryTest, TestPropertyNull) {
|
||||
for (const auto &vertex : dba.Vertices(dba.Label("Comment"), false)) {
|
||||
auto id_prop = query::TypedValue(vertex.PropsAt(dba.Property("id")));
|
||||
auto browser = query::TypedValue(vertex.PropsAt(dba.Property("browser")));
|
||||
if (id_prop.IsString() && id_prop.Value<std::string>() == "2") {
|
||||
if (id_prop.IsString() && id_prop.ValueString() == "2") {
|
||||
EXPECT_FALSE(found);
|
||||
found = true;
|
||||
EXPECT_TRUE(browser.IsNull());
|
||||
@ -73,9 +73,9 @@ TEST_F(RecoveryTest, TestQuote) {
|
||||
for (const auto &vertex : dba.Vertices(dba.Label("Comment"), false)) {
|
||||
auto id_prop = query::TypedValue(vertex.PropsAt(dba.Property("id")));
|
||||
auto country = query::TypedValue(vertex.PropsAt(dba.Property("country")));
|
||||
if (id_prop.IsString() && id_prop.Value<std::string>() == "1") {
|
||||
if (id_prop.IsString() && id_prop.ValueString() == "1") {
|
||||
EXPECT_TRUE(country.IsString());
|
||||
EXPECT_EQ(country.Value<std::string>(), "United Kingdom");
|
||||
EXPECT_EQ(country.ValueString(), "United Kingdom");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user