treewide: Add new describe overloads to implementations of data_dictionary::keyspace_element
We're removing `data_dictionary::keyspace_element`. Before we can do that, we need to substitute the existing methods used for describing keyspace elements with their new versions returning `cql3::description`. That's what happens in this commit.
This commit is contained in:
@@ -355,10 +355,12 @@ user_aggregate::user_aggregate(function_name fname, bytes_opt initcond, ::shared
|
||||
|
||||
bool user_aggregate::has_finalfunc() const { return _agg.state_to_result_function != nullptr; }
|
||||
|
||||
std::ostream& user_aggregate::describe(std::ostream& os) const {
|
||||
description user_aggregate::describe() const {
|
||||
auto ks = cql3::util::maybe_quote(name().keyspace);
|
||||
auto na = cql3::util::maybe_quote(name().name);
|
||||
|
||||
std::ostringstream os;
|
||||
|
||||
os << "CREATE AGGREGATE " << ks << "." << na << "(";
|
||||
auto a = arg_types();
|
||||
for (size_t i = 0; i < a.size(); i++) {
|
||||
@@ -382,6 +384,17 @@ std::ostream& user_aggregate::describe(std::ostream& os) const {
|
||||
}
|
||||
os << ";";
|
||||
|
||||
return description {
|
||||
.keyspace = name().keyspace,
|
||||
.type = "aggregate",
|
||||
.name = name().name,
|
||||
.create_statement = std::move(os).str()
|
||||
};
|
||||
}
|
||||
|
||||
std::ostream& user_aggregate::describe(std::ostream& os) const {
|
||||
auto desc = describe();
|
||||
os << *desc.create_statement;
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "scalar_function.hh"
|
||||
#include "cql3/description.hh"
|
||||
#include "data_dictionary/keyspace_element.hh"
|
||||
#include "cql3/functions/function_name.hh"
|
||||
#include "db/functions/aggregate_function.hh"
|
||||
@@ -26,6 +27,8 @@ public:
|
||||
virtual sstring element_type() const override { return "aggregate"; }
|
||||
virtual std::ostream& describe(std::ostream& os) const override;
|
||||
|
||||
description describe() const;
|
||||
|
||||
seastar::shared_ptr<scalar_function> sfunc() const {
|
||||
return _agg.aggregation_function;
|
||||
}
|
||||
|
||||
@@ -66,10 +66,12 @@ bytes_opt user_function::execute(std::span<const bytes_opt> parameters) {
|
||||
});
|
||||
}
|
||||
|
||||
std::ostream& user_function::describe(std::ostream& os) const {
|
||||
description user_function::describe() const {
|
||||
auto ks = cql3::util::maybe_quote(name().keyspace);
|
||||
auto na = cql3::util::maybe_quote(name().name);
|
||||
|
||||
std::ostringstream os;
|
||||
|
||||
os << "CREATE FUNCTION " << ks << "." << na << "(";
|
||||
for (size_t i = 0; i < _arg_names.size(); i++) {
|
||||
if (i > 0) {
|
||||
@@ -91,6 +93,17 @@ std::ostream& user_function::describe(std::ostream& os) const {
|
||||
<< _body << "\n"
|
||||
<< "$$;";
|
||||
|
||||
return description {
|
||||
.keyspace = name().keyspace,
|
||||
.type = "function",
|
||||
.name = name().name,
|
||||
.create_statement = std::move(os).str()
|
||||
};
|
||||
}
|
||||
|
||||
std::ostream& user_function::describe(std::ostream& os) const {
|
||||
auto desc = describe();
|
||||
os << *desc.create_statement;
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "abstract_function.hh"
|
||||
#include "cql3/description.hh"
|
||||
#include "scalar_function.hh"
|
||||
#include "lang/lua.hh"
|
||||
#include "lang/wasm.hh"
|
||||
@@ -65,6 +66,8 @@ public:
|
||||
virtual sstring element_name() const override { return name().name; }
|
||||
virtual sstring element_type() const override { return "function"; }
|
||||
virtual std::ostream& describe(std::ostream& os) const override;
|
||||
|
||||
description describe() const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
#include "data_dictionary.hh"
|
||||
#include "cql3/description.hh"
|
||||
#include "impl.hh"
|
||||
#include "user_types_metadata.hh"
|
||||
#include "keyspace_metadata.hh"
|
||||
@@ -351,7 +352,9 @@ no_such_column_family::no_such_column_family(std::string_view ks_name, const tab
|
||||
{
|
||||
}
|
||||
|
||||
std::ostream& keyspace_metadata::describe(replica::database& db, std::ostream& os, bool with_internals) const {
|
||||
cql3::description keyspace_metadata::describe(const replica::database& db) const {
|
||||
std::ostringstream os;
|
||||
|
||||
os << "CREATE KEYSPACE " << cql3::util::maybe_quote(_name)
|
||||
<< " WITH replication = {'class': " << cql3::util::single_quote(_strategy_name);
|
||||
for (const auto& opt: _strategy_options) {
|
||||
@@ -373,10 +376,21 @@ std::ostream& keyspace_metadata::describe(replica::database& db, std::ostream& o
|
||||
}
|
||||
os << ";";
|
||||
|
||||
return cql3::description {
|
||||
.keyspace = name(),
|
||||
.type = "keyspace",
|
||||
.name = name(),
|
||||
.create_statement = std::move(os).str()
|
||||
};
|
||||
}
|
||||
|
||||
std::ostream& keyspace_metadata::describe(replica::database& db, std::ostream& os, bool with_internals) const {
|
||||
auto desc = describe(db);
|
||||
os << *desc.create_statement;
|
||||
return os;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace data_dictionary
|
||||
|
||||
template <>
|
||||
struct fmt::formatter<data_dictionary::user_types_metadata> {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <iosfwd>
|
||||
#include <seastar/core/sstring.hh>
|
||||
|
||||
#include "cql3/description.hh"
|
||||
#include "schema/schema.hh"
|
||||
#include "locator/abstract_replication_strategy.hh"
|
||||
#include "data_dictionary/user_types_metadata.hh"
|
||||
@@ -99,6 +100,8 @@ public:
|
||||
virtual sstring element_name() const override { return name(); }
|
||||
virtual sstring element_type() const override { return "keyspace"; }
|
||||
virtual std::ostream& describe(replica::database& db, std::ostream& os, bool with_internals) const override;
|
||||
|
||||
cql3::description describe(const replica::database& db) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <seastar/core/on_internal_error.hh>
|
||||
#include <map>
|
||||
#include "cql3/description.hh"
|
||||
#include "db/view/view.hh"
|
||||
#include "timestamp.hh"
|
||||
#include "utils/assert.hh"
|
||||
@@ -783,11 +784,11 @@ static std::ostream& column_definition_as_cql_key(std::ostream& os, const column
|
||||
return os;
|
||||
}
|
||||
|
||||
static bool is_global_index(replica::database& db, const table_id& id, const schema& s) {
|
||||
static bool is_global_index(const replica::database& db, const table_id& id, const schema& s) {
|
||||
return db.find_column_family(id).get_index_manager().is_global_index(s);
|
||||
}
|
||||
|
||||
static bool is_index(replica::database& db, const table_id& id, const schema& s) {
|
||||
static bool is_index(const replica::database& db, const table_id& id, const schema& s) {
|
||||
return db.find_column_family(id).get_index_manager().is_index(s);
|
||||
}
|
||||
|
||||
@@ -852,7 +853,9 @@ static void describe_index_columns(std::ostream& os, bool is_local, const schema
|
||||
os << ")";
|
||||
}
|
||||
|
||||
std::ostream& schema::describe(replica::database& db, std::ostream& os, bool with_internals) const {
|
||||
sstring schema::get_create_statement(const replica::database& db, bool with_internals) const {
|
||||
std::ostringstream os;
|
||||
|
||||
os << "CREATE ";
|
||||
int n = 0;
|
||||
|
||||
@@ -865,7 +868,8 @@ std::ostream& schema::describe(replica::database& db, std::ostream& os, bool wit
|
||||
|
||||
describe_index_columns(os, is_local, *this, db.find_schema(view_info()->base_id()));
|
||||
os << ";\n";
|
||||
return os;
|
||||
|
||||
return std::move(os).str();
|
||||
} else {
|
||||
os << "MATERIALIZED VIEW " << cql3::util::maybe_quote(ks_name()) << "." << cql3::util::maybe_quote(cf_name()) << " AS\n";
|
||||
os << " SELECT ";
|
||||
@@ -970,10 +974,34 @@ std::ostream& schema::describe(replica::database& db, std::ostream& os, bool wit
|
||||
}
|
||||
}
|
||||
|
||||
return std::move(os).str();
|
||||
}
|
||||
|
||||
cql3::description schema::describe(const replica::database& db, bool with_internals) const {
|
||||
const sstring type = std::invoke([&] {
|
||||
if (is_view()) {
|
||||
return is_index(db, view_info()->base_id(), *this)
|
||||
? "index"
|
||||
: "view";
|
||||
}
|
||||
return "table";
|
||||
});
|
||||
|
||||
return cql3::description {
|
||||
.keyspace = ks_name(),
|
||||
.type = std::move(type),
|
||||
.name = cf_name(),
|
||||
.create_statement = get_create_statement(db, with_internals)
|
||||
};
|
||||
}
|
||||
|
||||
std::ostream& schema::describe(replica::database& db, std::ostream& os, bool with_internals) const {
|
||||
auto desc = describe(db, with_internals);
|
||||
os << *desc.create_statement;
|
||||
return os;
|
||||
}
|
||||
|
||||
std::ostream& schema::schema_properties(replica::database& db, std::ostream& os) const {
|
||||
std::ostream& schema::schema_properties(const replica::database& db, std::ostream& os) const {
|
||||
os << "bloom_filter_fp_chance = " << bloom_filter_fp_chance();
|
||||
os << "\n AND caching = {";
|
||||
map_as_cql_param(os, caching_options().to_map());
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cql3/description.hh"
|
||||
#include "utils/assert.hh"
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
@@ -919,6 +920,9 @@ public:
|
||||
* (and `ALTER ADD` if the column has been re-added) to the description.
|
||||
*/
|
||||
virtual std::ostream& describe(replica::database& db, std::ostream& os, bool with_internals) const override;
|
||||
|
||||
cql3::description describe(const replica::database& db, bool with_internals) const;
|
||||
|
||||
// Generate ALTER TABLE/MATERIALIZED VIEW statement containing all properties with current values.
|
||||
// The method cannot be used on index, as indexes don't support alter statement.
|
||||
std::ostream& describe_alter_with_properties(replica::database& db, std::ostream& os) const;
|
||||
@@ -938,7 +942,9 @@ public:
|
||||
}
|
||||
private:
|
||||
// Print all schema properties in CQL syntax
|
||||
std::ostream& schema_properties(replica::database& db, std::ostream& os) const;
|
||||
std::ostream& schema_properties(const replica::database& db, std::ostream& os) const;
|
||||
|
||||
sstring get_create_statement(const replica::database& db, bool with_internals) const;
|
||||
public:
|
||||
const v3_columns& v3() const {
|
||||
return _v3_columns;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <algorithm>
|
||||
#include "cql3/cql3_type.hh"
|
||||
#include "cql3/description.hh"
|
||||
#include "cql3/lists.hh"
|
||||
#include "cql3/maps.hh"
|
||||
#include "cql3/sets.hh"
|
||||
@@ -3234,7 +3235,9 @@ sstring user_type_impl::get_name_as_cql_string() const {
|
||||
return cql3::util::maybe_quote(get_name_as_string());
|
||||
}
|
||||
|
||||
std::ostream& user_type_impl::describe(std::ostream& os) const {
|
||||
cql3::description user_type_impl::describe() const {
|
||||
std::ostringstream os;
|
||||
|
||||
os << "CREATE TYPE " << cql3::util::maybe_quote(_keyspace) << "." << get_name_as_cql_string() << " (\n";
|
||||
for (size_t i = 0; i < _string_field_names.size(); i++) {
|
||||
os << " " << cql3::util::maybe_quote(_string_field_names[i]) << " " << _types[i]->cql3_type_name();
|
||||
@@ -3245,6 +3248,17 @@ std::ostream& user_type_impl::describe(std::ostream& os) const {
|
||||
}
|
||||
os << ");";
|
||||
|
||||
return cql3::description {
|
||||
.keyspace = _keyspace,
|
||||
.type = "type",
|
||||
.name = get_name_as_string(),
|
||||
.create_statement = std::move(os).str()
|
||||
};
|
||||
}
|
||||
|
||||
std::ostream& user_type_impl::describe(std::ostream& os) const {
|
||||
auto desc = describe();
|
||||
os << *desc.create_statement;
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cql3/description.hh"
|
||||
#include "types/types.hh"
|
||||
#include "types/tuple.hh"
|
||||
#include "data_dictionary/keyspace_element.hh"
|
||||
@@ -64,6 +65,8 @@ public:
|
||||
virtual sstring element_type() const override { return "type"; }
|
||||
virtual std::ostream& describe(std::ostream& os) const override;
|
||||
|
||||
cql3::description describe() const;
|
||||
|
||||
private:
|
||||
static sstring make_name(sstring keyspace,
|
||||
bytes name,
|
||||
|
||||
Reference in New Issue
Block a user