Return properties as a list in SHOW CONSTRAINT INFO for unique constraints

Summary:
Before this change properties were joined by ", " and returned as a single string,
which was ambiguous for properties that contain ", ". This diff solves this
problem by returning properties as a list type.

Reviewers: mferencevic

Reviewed By: mferencevic

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D2778
This commit is contained in:
Tonko Sabolcec 2020-05-29 12:01:49 +02:00
parent d36da12b48
commit 3932376301
2 changed files with 10 additions and 7 deletions

View File

@ -833,14 +833,14 @@ PreparedQuery PrepareInfoQuery(
TypedValue(db->PropertyToName(item.second))}); TypedValue(db->PropertyToName(item.second))});
} }
for (const auto &item : info.unique) { for (const auto &item : info.unique) {
std::stringstream properties; std::vector<TypedValue> properties;
utils::PrintIterable(properties, item.second, ", ", properties.reserve(item.second.size());
[&db](auto &stream, const auto &entry) { for (const auto &property : item.second) {
stream << db->PropertyToName(entry); properties.emplace_back(db->PropertyToName(property));
}); }
results.push_back({TypedValue("unique"), results.push_back({TypedValue("unique"),
TypedValue(db->LabelToName(item.first)), TypedValue(db->LabelToName(item.first)),
TypedValue(properties.str())}); TypedValue(std::move(properties))});
} }
return std::pair{results, QueryHandlerResult::NOTHING}; return std::pair{results, QueryHandlerResult::NOTHING};
}; };

View File

@ -402,7 +402,10 @@ TEST_F(InterpreterTest, UniqueConstraintTest) {
ASSERT_EQ(result.size(), 3U); ASSERT_EQ(result.size(), 3U);
ASSERT_EQ(result[0].ValueString(), "unique"); ASSERT_EQ(result[0].ValueString(), "unique");
ASSERT_EQ(result[1].ValueString(), "A"); ASSERT_EQ(result[1].ValueString(), "A");
ASSERT_EQ(result[2].ValueString(), "a, b"); const auto &properties = result[2].ValueList();
ASSERT_EQ(properties.size(), 2U);
ASSERT_EQ(properties[0].ValueString(), "a");
ASSERT_EQ(properties[1].ValueString(), "b");
} }
// Drop constraint. // Drop constraint.