Skip to content

Commit

Permalink
[Schema] IndexMethod param in has/get_index()
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelmaltry committed Feb 12, 2024
1 parent bd8bdf2 commit bed06aa
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions include/mutable/catalog/Schema.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,19 +986,22 @@ struct M_EXPORT Database
if (it->name == index_name) return true;
return false;
}
/** Returns `true` iff there is an index on \p attribute_name of \p table_name. Throws `m::invalid_argument` if a
* `Table` with the given \p table_name does not exist. Throws `m::invalid_argument` if an `Attribute` with \p
* attribute_name does not exist in `Table` \p table_name. */
bool has_index(const char *table_name, const char *attribute_name) const {
/** Returns `true` iff there is an index using \p method on \p attribute_name of \p table_name. Throws
* `m::invalid_argument` if a `Table` with the given \p table_name does not exist. Throws `m::invalid_argument` if
* an `Attribute` with \p attribute_name does not exist in `Table` \p table_name. */
bool has_index(const char *table_name, const char *attribute_name, idx::IndexMethod method) const {
auto it = tables_.find(table_name);
if (it == tables_.end())
throw m::invalid_argument("Table with that name does not exist.");
auto &table = it->second;
if (not table->has_attribute(attribute_name))
throw m::invalid_argument("Attribute with that name does not exist.");
for (auto &entry : indexes_) {
if (entry.table.name() == table_name and entry.attribute.name == attribute_name)
if (entry.table.name() == table_name and entry.attribute.name == attribute_name and
entry.index->method() == method)
{
return true;
}
}
return false;
}
Expand All @@ -1011,22 +1014,25 @@ struct M_EXPORT Database
}
throw m::invalid_argument("Index of that name does not exist.");
}
/** Returns an index on `Attribute` \p attribute_name of `Table` \p table_name iff one exists. Throws
/** Returns an index using \p method on \p attribute_name of \p table_name iff one exists. Throws
* `m::invalid_argument` if such an index does not exist. Throws `m::invalid_argument` if a `Table` with the given
* \p table_name does not exist. Throws `m::invalid_argument` if an `Attribute` with \p attribute_name does not
* exist in `Table` \p table_name. */
const idx::IndexBase & get_index(const char *table_name, const char *attribute_name) const {
const idx::IndexBase & get_index(const char *table_name, const char *attribute_name, idx::IndexMethod method) const {
auto it = tables_.find(table_name);
if (it == tables_.end())
throw m::invalid_argument("Table with that name does not exist.");
auto &table = it->second;
if (not table->has_attribute(attribute_name))
throw m::invalid_argument("Attribute with that name does not exist.");
for (auto &entry : indexes_) {
if (entry.table.name() == table_name and entry.attribute.name == attribute_name)
if (entry.table.name() == table_name and entry.attribute.name == attribute_name and
entry.index->method() == method)
{
return *entry.index;
}
}
throw m::invalid_argument("Index on that attribute of that table does not exist.");
throw m::invalid_argument("Index of that method on that attribute of that table does not exist.");
}

};
Expand Down

0 comments on commit bed06aa

Please sign in to comment.