schema: rename column accessors to be in line with origin
More pointedly: Expose columns as is (currently all_columns_in_select_order), expose name->column mapping more appropriately named. Renaming like this is not strictly neccesary, but there is a point to trying to keep nomenclature similar-ish with origin, esp. when select order column need to become filtered (spoiler alert).
This commit is contained in:
@@ -105,12 +105,12 @@ void alter_type_statement::do_announce_migration(database& db, ::keyspace& ks, b
|
||||
for (auto&& schema : ks.metadata()->cf_meta_data() | boost::adaptors::map_values) {
|
||||
auto cfm = schema_builder(schema);
|
||||
bool modified = false;
|
||||
for (auto&& column : schema->all_columns() | boost::adaptors::map_values) {
|
||||
auto t_opt = column->type->update_user_type(updated);
|
||||
for (auto&& column : schema->all_columns()) {
|
||||
auto t_opt = column.type->update_user_type(updated);
|
||||
if (t_opt) {
|
||||
modified = true;
|
||||
// We need to update this column
|
||||
cfm.with_altered_column_type(column->name(), *t_opt);
|
||||
cfm.with_altered_column_type(column.name(), *t_opt);
|
||||
}
|
||||
}
|
||||
if (modified) {
|
||||
|
||||
@@ -279,18 +279,18 @@ future<shared_ptr<transport::event::schema_change>> create_view_statement::annou
|
||||
// the view because if we need to generate a tombstone, we have no way of knowing which value is currently being
|
||||
// used in the view and whether or not to generate a tombstone. In order to not surprise our users, we require
|
||||
// that they include all of the columns. We provide them with a list of all of the columns left to include.
|
||||
for (auto* def : schema->all_columns() | boost::adaptors::map_values) {
|
||||
bool included_def = included.empty() || included.find(def) != included.end();
|
||||
if (included_def && def->is_static()) {
|
||||
for (auto& def : schema->all_columns()) {
|
||||
bool included_def = included.empty() || included.find(&def) != included.end();
|
||||
if (included_def && def.is_static()) {
|
||||
throw exceptions::invalid_request_exception(sprint(
|
||||
"Unable to include static column '%s' which would be included by Materialized View SELECT * statement", *def));
|
||||
"Unable to include static column '%s' which would be included by Materialized View SELECT * statement", def));
|
||||
}
|
||||
|
||||
bool def_in_target_pk = std::find(target_primary_keys.begin(), target_primary_keys.end(), def) != target_primary_keys.end();
|
||||
bool def_in_target_pk = std::find(target_primary_keys.begin(), target_primary_keys.end(), &def) != target_primary_keys.end();
|
||||
if (included_def && !def_in_target_pk) {
|
||||
target_non_pk_columns.push_back(def);
|
||||
} else if (def->is_primary_key() && !def_in_target_pk) {
|
||||
missing_pk_columns.push_back(def);
|
||||
target_non_pk_columns.push_back(&def);
|
||||
} else if (def.is_primary_key() && !def_in_target_pk) {
|
||||
missing_pk_columns.push_back(&def);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1236,8 +1236,8 @@ static inline void ensure_type_is_unused(distributed<service::storage_proxy>& pr
|
||||
}
|
||||
|
||||
for (auto&& cfm : ks.metadata()->cf_meta_data() | boost::adaptors::map_values) {
|
||||
for (auto&& col : cfm->all_columns() | boost::adaptors::map_values) {
|
||||
if (col->type->references_user_type(keyspace, name)) {
|
||||
for (auto&& col : cfm->all_columns()) {
|
||||
if (col.type->references_user_type(keyspace, name)) {
|
||||
throw exceptions::invalid_request_exception(sprint("Cannot drop user type %s.%s as it is still used by table %s.%s", keyspace, type->get_name_as_string(), cfm->ks_name(), cfm->cf_name()));
|
||||
}
|
||||
}
|
||||
@@ -1667,7 +1667,7 @@ static schema_mutations make_table_mutations(schema_ptr table, api::timestamp_ty
|
||||
mutation columns_mutation(pkey, columns());
|
||||
mutation indices_mutation(pkey, indexes());
|
||||
if (with_columns_and_triggers) {
|
||||
for (auto&& column : table->all_columns_in_select_order()) {
|
||||
for (auto&& column : table->all_columns()) {
|
||||
add_column_to_schema_mutation(table, column, timestamp, columns_mutation);
|
||||
}
|
||||
for (auto&& index : table->indices()) {
|
||||
@@ -1718,13 +1718,13 @@ static void make_update_columns_mutations(schema_ptr old_table,
|
||||
std::vector<mutation>& mutations) {
|
||||
mutation columns_mutation(partition_key::from_singular(*columns(), old_table->ks_name()), columns());
|
||||
|
||||
auto diff = difference(old_table->all_columns(), new_table->all_columns());
|
||||
auto diff = difference(old_table->columns_by_name(), new_table->columns_by_name());
|
||||
|
||||
// columns that are no longer needed
|
||||
for (auto&& name : diff.entries_only_on_left) {
|
||||
// Thrift only knows about the REGULAR ColumnDefinition type, so don't consider other type
|
||||
// are being deleted just because they are not here.
|
||||
const column_definition& column = *old_table->all_columns().at(name);
|
||||
const column_definition& column = *old_table->columns_by_name().at(name);
|
||||
if (from_thrift && !column.is_regular()) {
|
||||
continue;
|
||||
}
|
||||
@@ -1734,7 +1734,7 @@ static void make_update_columns_mutations(schema_ptr old_table,
|
||||
|
||||
// newly added columns and old columns with updated attributes
|
||||
for (auto&& name : boost::range::join(diff.entries_differing, diff.entries_only_on_right)) {
|
||||
const column_definition& column = *new_table->all_columns().at(name);
|
||||
const column_definition& column = *new_table->columns_by_name().at(name);
|
||||
add_column_to_schema_mutation(new_table, column, timestamp, columns_mutation);
|
||||
}
|
||||
|
||||
@@ -1778,7 +1778,7 @@ static void make_drop_table_or_view_mutations(schema_ptr schema_table,
|
||||
auto ckey = clustering_key::from_singular(*schema_table, table_or_view->cf_name());
|
||||
m.partition().apply_delete(*schema_table, std::move(ckey), tombstone(timestamp, gc_clock::now()));
|
||||
mutations.emplace_back(m);
|
||||
for (auto &column : table_or_view->all_columns_in_select_order()) {
|
||||
for (auto &column : table_or_view->all_columns()) {
|
||||
drop_column_from_schema_mutation(table_or_view, column, timestamp, mutations);
|
||||
}
|
||||
}
|
||||
@@ -2368,7 +2368,7 @@ static schema_mutations make_view_mutations(view_ptr view, api::timestamp_type t
|
||||
mutation columns_mutation(pkey, columns());
|
||||
mutation index_mutation(pkey, indexes());
|
||||
if (with_columns) {
|
||||
for (auto&& column : view->all_columns_in_select_order()) {
|
||||
for (auto&& column : view->all_columns()) {
|
||||
add_column_to_schema_mutation(view, column, timestamp, columns_mutation);
|
||||
}
|
||||
for (auto&& index : view->indices()) {
|
||||
|
||||
@@ -63,8 +63,8 @@ cql3::statements::select_statement& view_info::select_statement() const {
|
||||
if (!_select_statement) {
|
||||
std::vector<sstring_view> included;
|
||||
if (!include_all_columns()) {
|
||||
included.reserve(_schema.all_columns_in_select_order().size());
|
||||
boost::transform(_schema.all_columns_in_select_order(), std::back_inserter(included), std::mem_fn(&column_definition::name_as_text));
|
||||
included.reserve(_schema.all_columns().size());
|
||||
boost::transform(_schema.all_columns(), std::back_inserter(included), std::mem_fn(&column_definition::name_as_text));
|
||||
}
|
||||
auto raw = cql3::util::build_select_statement(base_name(), where_clause(), std::move(included));
|
||||
raw->prepare_keyspace(_schema.ks_name());
|
||||
|
||||
10
schema.cc
10
schema.cc
@@ -114,7 +114,7 @@ void schema::rebuild() {
|
||||
_columns_by_name.clear();
|
||||
_regular_columns_by_name.clear();
|
||||
|
||||
for (const column_definition& def : all_columns_in_select_order()) {
|
||||
for (const column_definition& def : all_columns()) {
|
||||
_columns_by_name[def.name()] = &def;
|
||||
}
|
||||
|
||||
@@ -149,8 +149,8 @@ void schema::rebuild() {
|
||||
}
|
||||
} else {
|
||||
for (auto&& cdef : all_columns()) {
|
||||
if (cdef.second->type->is_counter()) {
|
||||
throw exceptions::configuration_exception(sprint("Cannot add a counter column (%s) in a non counter column family", cdef.second->name_as_text()));
|
||||
if (cdef.type->is_counter()) {
|
||||
throw exceptions::configuration_exception(sprint("Cannot add a counter column (%s) in a non counter column family", cdef.name_as_text()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -334,7 +334,7 @@ sstring schema::thrift_key_validator() const {
|
||||
|
||||
bool
|
||||
schema::has_multi_cell_collections() const {
|
||||
return boost::algorithm::any_of(all_columns_in_select_order(), [] (const column_definition& cdef) {
|
||||
return boost::algorithm::any_of(all_columns(), [] (const column_definition& cdef) {
|
||||
return cdef.type->is_collection() && cdef.type->is_multi_cell();
|
||||
});
|
||||
}
|
||||
@@ -1113,7 +1113,7 @@ bool schema::is_synced() const {
|
||||
}
|
||||
|
||||
bool schema::equal_columns(const schema& other) const {
|
||||
return boost::equal(all_columns_in_select_order(), other.all_columns_in_select_order());
|
||||
return boost::equal(all_columns(), other.all_columns());
|
||||
}
|
||||
|
||||
raw_view_info::raw_view_info(utils::UUID base_id, sstring base_name, bool include_all_columns, sstring where_clause)
|
||||
|
||||
@@ -610,7 +610,13 @@ public:
|
||||
const columns_type& all_columns_in_select_order() const;
|
||||
uint32_t position(const column_definition& column) const;
|
||||
|
||||
const auto& all_columns() const { return _columns_by_name; }
|
||||
const columns_type& all_columns() const {
|
||||
return _raw._columns;
|
||||
}
|
||||
|
||||
const std::unordered_map<bytes, const column_definition*>& columns_by_name() const {
|
||||
return _columns_by_name;
|
||||
}
|
||||
|
||||
const auto& dropped_columns() const {
|
||||
return _raw._dropped_columns;
|
||||
|
||||
@@ -138,9 +138,9 @@ SEASTAR_TEST_CASE(test_column_is_dropped) {
|
||||
e.execute_cql("alter table tests.table1 add s1 int;").get();
|
||||
|
||||
schema_ptr s = e.db().local().find_schema("tests", "table1");
|
||||
BOOST_REQUIRE(s->all_columns().count(to_bytes("c1")));
|
||||
BOOST_REQUIRE(!s->all_columns().count(to_bytes("c2")));
|
||||
BOOST_REQUIRE(s->all_columns().count(to_bytes("s1")));
|
||||
BOOST_REQUIRE(s->columns_by_name().count(to_bytes("c1")));
|
||||
BOOST_REQUIRE(!s->columns_by_name().count(to_bytes("c2")));
|
||||
BOOST_REQUIRE(s->columns_by_name().count(to_bytes("s1")));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user