cql3: Simplify primary key membership checks

This commit is contained in:
Tomasz Grabiec
2015-02-26 19:56:12 +01:00
parent 609e893055
commit b77367dabe
3 changed files with 23 additions and 37 deletions

View File

@@ -340,7 +340,7 @@ modification_statement::execute_with_condition(service::storage_proxy& proxy, se
void
modification_statement::add_key_values(column_definition& def, ::shared_ptr<restrictions::restriction> values) {
if (def.kind == column_definition::CLUSTERING) {
if (def.is_clustering_key()) {
_has_no_clustering_columns = false;
}
@@ -373,16 +373,14 @@ modification_statement::process_where_clause(std::vector<relation_ptr> where_cla
throw exceptions::invalid_request_exception(sprint("Unknown key identifier %s", *id));
}
switch (def->kind) {
case column_definition::column_kind::PARTITION:
case column_definition::column_kind::CLUSTERING:
if (rel->is_EQ() || (def->is_partition_key() && rel->is_IN())) {
add_key_values(*def, rel->to_restriction(s, std::move(names)));
break;
}
if (def->is_primary_key()) {
if (rel->is_EQ() || (def->is_partition_key() && rel->is_IN())) {
add_key_values(*def, rel->to_restriction(s, std::move(names)));
} else {
throw exceptions::invalid_request_exception(sprint("Invalid operator %s for PRIMARY KEY part %s", rel->get_operator(), def->name_as_text()));
default:
throw exceptions::invalid_request_exception(sprint("Non PRIMARY KEY %s found in where clause", def->name_as_text()));
}
} else {
throw exceptions::invalid_request_exception(sprint("Non PRIMARY KEY %s found in where clause", def->name_as_text()));
}
}
}
@@ -432,13 +430,10 @@ modification_statement::parsed::prepare(database& db, ::shared_ptr<variable_spec
auto condition = entry.second->prepare(keyspace(), *def);
condition->collect_marker_specificaton(bound_names);
switch (def->kind) {
case column_definition::PARTITION:
case column_definition::CLUSTERING:
throw exceptions::invalid_request_exception(sprint("PRIMARY KEY column '%s' cannot have IF conditions", *id));
default:
stmt->add_condition(condition);
if (def->is_primary_key()) {
throw exceptions::invalid_request_exception(sprint("PRIMARY KEY column '%s' cannot have IF conditions", *id));
}
stmt->add_condition(condition);
}
}
stmt->validate_where_clause_for_conditions();

View File

@@ -117,20 +117,14 @@ update_statement::parsed_insert::prepare_internal(schema_ptr schema,
auto&& value = _column_values[i];
switch(def->kind) {
case column_definition::PARTITION:
case column_definition::CLUSTERING: {
auto t = value->prepare(keyspace(), def->column_specification);
t->collect_marker_specification(bound_names);
stmt->add_key_value(*def, std::move(t));
break;
}
default: {
auto operation = operation::set_value(value).prepare(keyspace(), *def);
operation->collect_marker_specification(bound_names);
stmt->add_operation(std::move(operation));
break;
}
if (def->is_primary_key()) {
auto t = value->prepare(keyspace(), def->column_specification);
t->collect_marker_specification(bound_names);
stmt->add_key_value(*def, std::move(t));
} else {
auto operation = operation::set_value(value).prepare(keyspace(), *def);
operation->collect_marker_specification(bound_names);
stmt->add_operation(std::move(operation));
};
}
return stmt;
@@ -152,14 +146,10 @@ update_statement::parsed_update::prepare_internal(schema_ptr schema,
auto operation = entry.second->prepare(keyspace(), *def);
operation->collect_marker_specification(bound_names);
switch (def->kind) {
case column_definition::column_kind::PARTITION:
case column_definition::column_kind::CLUSTERING:
throw exceptions::invalid_request_exception(sprint("PRIMARY KEY part %s found in SET part", *entry.first));
default:
stmt->add_operation(std::move(operation));
break;
if (def->is_primary_key()) {
throw exceptions::invalid_request_exception(sprint("PRIMARY KEY part %s found in SET part", *entry.first));
}
stmt->add_operation(std::move(operation));
}
stmt->process_where_clause(_where_clause, bound_names);

View File

@@ -26,6 +26,7 @@ public:
::shared_ptr<cql3::column_specification> column_specification;
bool is_static() const { return kind == column_kind::STATIC; }
bool is_partition_key() const { return kind == column_kind::PARTITION; }
bool is_clustering_key() const { return kind == column_kind::CLUSTERING; }
bool is_primary_key() const { return kind == column_kind::PARTITION || kind == column_kind::CLUSTERING; }
bool is_atomic() const { return !type->is_multi_cell(); }
bool is_compact_value() const;