IndexInfo function added
Summary: - Keys() functions in the indices can't be const because ConcurrentMap doesn't provide const accessors (and they are broken in skiplist) :D - no cucumber tests because many tests create indices so it's hard to say what's inside and what not Reviewers: buda, mislav.bradac Reviewed By: mislav.bradac Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D797
This commit is contained in:
parent
a14f8c6516
commit
48e446688f
@ -12,6 +12,7 @@
|
||||
* `assert` function added.
|
||||
* Use \u to specify 4 digit codepoint and \U for 8 digit
|
||||
* `counter` and `counterSet` functions added.
|
||||
* `indexInfo` function added.
|
||||
|
||||
### Bug Fixes and Other Changes
|
||||
|
||||
|
@ -502,6 +502,7 @@ functions.
|
||||
`assert` | Raises an exception reported to the client if the given argument is not `true`.
|
||||
`counter` | Generates integers that are guaranteed to be unique on the database level, for the given counter name.
|
||||
`counterSet` | Sets the counter with the given name to the given value.
|
||||
`indexInfo` | Returns a list of all the indexes available in the database. The list includes indexes that are not yet ready for use (they are concurrently being built by another transaction).
|
||||
|
||||
#### String Operators
|
||||
|
||||
|
@ -341,3 +341,19 @@ void GraphDbAccessor::CounterSet(const std::string &name, int64_t value) {
|
||||
if (!name_counter_pair.second)
|
||||
name_counter_pair.first->second.store(value);
|
||||
}
|
||||
|
||||
std::vector<std::string> GraphDbAccessor::IndexInfo() const {
|
||||
std::vector<std::string> info;
|
||||
for (GraphDbTypes::Label label : db_.labels_index_.Keys()) {
|
||||
info.emplace_back(":" + LabelName(label));
|
||||
}
|
||||
|
||||
// Edge indices are not shown because they are never used.
|
||||
|
||||
for (LabelPropertyIndex::Key key : db_.label_property_index_.Keys()) {
|
||||
info.emplace_back(fmt::format(":{}({})", LabelName(key.label_),
|
||||
PropertyName(key.property_)));
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
@ -575,6 +575,11 @@ class GraphDbAccessor {
|
||||
*/
|
||||
void CounterSet(const std::string &name, int64_t value);
|
||||
|
||||
/*
|
||||
* Returns a list of index names present in the database.
|
||||
*/
|
||||
std::vector<std::string> IndexInfo() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Insert this vertex into corresponding label and label+property (if it
|
||||
|
@ -96,6 +96,16 @@ class KeyIndex {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a vector of keys present in this index.
|
||||
*/
|
||||
std::vector<TKey> Keys() {
|
||||
std::vector<TKey> keys;
|
||||
for (auto &kv : indices_.access())
|
||||
keys.push_back(kv.first);
|
||||
return keys;
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief - Contains vlist and record pointers.
|
||||
|
@ -389,6 +389,16 @@ class LabelPropertyIndex {
|
||||
return indices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a vector of keys present in this index.
|
||||
*/
|
||||
std::vector<Key> Keys() {
|
||||
std::vector<Key> keys;
|
||||
for (auto &kv : indices_.access())
|
||||
keys.push_back(kv.first);
|
||||
return keys;
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief - Contains value, vlist and vertex record to distinguish between
|
||||
|
@ -545,6 +545,15 @@ TypedValue CounterSet(const std::vector<TypedValue> &args, GraphDbAccessor &dba)
|
||||
dba.CounterSet(args[0].ValueString(), args[1].ValueInt());
|
||||
return TypedValue::Null;
|
||||
}
|
||||
|
||||
TypedValue IndexInfo(const std::vector<TypedValue> &args,
|
||||
GraphDbAccessor &dba) {
|
||||
if (args.size() != 0U)
|
||||
throw QueryRuntimeException("indexInfo takes zero arguments");
|
||||
|
||||
auto info = dba.IndexInfo();
|
||||
return std::vector<TypedValue>(info.begin(), info.end());
|
||||
}
|
||||
} // annonymous namespace
|
||||
|
||||
std::function<TypedValue(const std::vector<TypedValue> &, GraphDbAccessor &)>
|
||||
@ -590,6 +599,7 @@ NameToFunction(const std::string &function_name) {
|
||||
if (function_name == "ASSERT") return Assert;
|
||||
if (function_name == "COUNTER") return Counter;
|
||||
if (function_name == "COUNTERSET") return CounterSet;
|
||||
if (function_name == "INDEXINFO") return IndexInfo;
|
||||
return nullptr;
|
||||
}
|
||||
} // namespace query
|
||||
|
@ -1235,4 +1235,23 @@ TEST(ExpressionEvaluator, FunctionCounterSet) {
|
||||
EXPECT_EQ(EvaluateFunction("COUNTER", {"c1"}, dbms).ValueInt(), 13);
|
||||
EXPECT_EQ(EvaluateFunction("COUNTER", {"c2"}, dbms).ValueInt(), 43);
|
||||
}
|
||||
|
||||
TEST(ExpressionEvaluator, FunctionIndexInfo) {
|
||||
Dbms dbms;
|
||||
EXPECT_THROW(EvaluateFunction("INDEXINFO", {1}, dbms), QueryRuntimeException);
|
||||
EXPECT_EQ(EvaluateFunction("INDEXINFO", {}, dbms).ValueList().size(), 0);
|
||||
auto dba = dbms.active();
|
||||
dba->InsertVertex().add_label(dba->Label("l1"));
|
||||
{
|
||||
auto info = ToList<std::string>(EvaluateFunction("INDEXINFO", {}, dbms));
|
||||
EXPECT_EQ(info.size(), 1);
|
||||
EXPECT_EQ(info[0], ":l1");
|
||||
}
|
||||
{
|
||||
dba->BuildIndex(dba->Label("l1"), dba->Property("prop"));
|
||||
auto info = ToList<std::string>(EvaluateFunction("INDEXINFO", {}, dbms));
|
||||
EXPECT_EQ(info.size(), 2);
|
||||
EXPECT_THAT(info, testing::UnorderedElementsAre(":l1", ":l1(prop)"));
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
Loading…
Reference in New Issue
Block a user