Skip to content

Commit

Permalink
schema_builder: calculate is_dense from the schema builder
Browse files Browse the repository at this point in the history
We currently have code to calculate "is_dense" in the create statement handler.
That obviously don't work for the system schemas, which are not defined this
way.

Since all of our schemas now have to pass through the schema_builder one way or
another, that is the best place in which to do that calculation.

Note that unfortunately, that does not mean we can just get rid of
set_is_dense() in the schema builder: we still need to set it in some
situations, where for instance, we read that property in schema_columnfamilies,
and then apply to the relevant CF. Those uses are, however, all internal to
legacy_schema_tables.cc

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
  • Loading branch information
glommer committed Jul 23, 2015
1 parent 45c5b0c commit cb94f3f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
10 changes: 3 additions & 7 deletions cql3/statements/create_table_statement.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ shared_ptr<transport::event::schema_change> create_table_statement::change_event
schema_ptr create_table_statement::get_cf_meta_data() {
schema_builder builder{keyspace(), column_family()};
apply_properties_to(builder);
return builder.build();
return builder.build(_use_compact_storage ? schema_builder::compact_storage::yes : schema_builder::compact_storage::no);
}

void create_table_statement::apply_properties_to(schema_builder& builder) {
Expand All @@ -118,8 +118,6 @@ void create_table_statement::apply_properties_to(schema_builder& builder) {
cfmd.defaultValidator(defaultValidator)
.addAllColumnDefinitions(getColumns(cfmd))
#endif
builder.set_is_dense(_is_dense);

add_column_metadata_from_aliases(builder, _key_aliases, _partition_key_types, column_kind::partition_key);
add_column_metadata_from_aliases(builder, _column_aliases, _clustering_key_types, column_kind::clustering_key);
#if 0
Expand Down Expand Up @@ -187,6 +185,8 @@ ::shared_ptr<parsed_statement::prepared> create_table_statement::raw_statement::
throw exceptions::invalid_request_exception("Multiple PRIMARY KEYs specifed (exactly one required)");
}

stmt->_use_compact_storage = _use_compact_storage;

auto& key_aliases = _key_aliases[0];
std::vector<data_type> key_types;
for (auto&& alias : key_aliases) {
Expand All @@ -202,10 +202,6 @@ ::shared_ptr<parsed_statement::prepared> create_table_statement::raw_statement::
}
stmt->_partition_key_types = key_types;

// Dense means that no part of the comparator stores a CQL column name. This means
// COMPACT STORAGE with at least one columnAliases (otherwise it's a thrift "static" CF).
stmt->_is_dense = _use_compact_storage && !_column_aliases.empty();

// Handle column aliases
if (_column_aliases.empty()) {
if (_use_compact_storage) {
Expand Down
2 changes: 1 addition & 1 deletion cql3/statements/create_table_statement.hh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class create_table_statement : public schema_altering_statement {
#if 0
private ByteBuffer valueAlias;
#endif
bool _is_dense;
bool _use_compact_storage;

using column_map_type =
std::unordered_map<::shared_ptr<column_identifier>,
Expand Down
9 changes: 7 additions & 2 deletions schema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,11 @@ schema_builder& schema_builder::with_column(bytes name, data_type type, index_in
return *this;
}

schema_ptr schema_builder::build() {
return make_lw_shared<schema>(schema(_raw));
schema_ptr schema_builder::build(compact_storage cp) {
schema s(_raw);

// Dense means that no part of the comparator stores a CQL column name. This means
// COMPACT STORAGE with at least one columnAliases (otherwise it's a thrift "static" CF).
s._raw._is_dense = (cp == compact_storage::yes) && (s.clustering_key_size() > 0);
return make_lw_shared<schema>(std::move(s));
}
3 changes: 2 additions & 1 deletion schema_builder.hh
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,6 @@ public:

void add_default_index_names(database&);

schema_ptr build();
enum class compact_storage { no, yes };
schema_ptr build(compact_storage = compact_storage::no);
};

0 comments on commit cb94f3f

Please sign in to comment.