diff --git a/cql3/Cql.g b/cql3/Cql.g index 3f075ee375..6797179171 100644 --- a/cql3/Cql.g +++ b/cql3/Cql.g @@ -30,9 +30,12 @@ options { } @parser::includes { +#include "cql3/statements/create_keyspace_statement.hh" +#include "cql3/statements/property_definitions.hh" #include "cql3/statements/select_statement.hh" #include "cql3/statements/update_statement.hh" #include "cql3/statements/use_statement.hh" +#include "cql3/statements/ks_prop_defs.hh" #include "cql3/selection/raw_selector.hh" #include "cql3/constants.hh" #include "cql3/operation_impl.hh" @@ -150,9 +153,9 @@ using operations_type = std::vectorsyntax_error(*this, msg); } + std::map convert_property_map(shared_ptr map) { + throw std::runtime_error("not implemented"); #if 0 - public Map convertPropertyMap(Maps.Literal map) - { if (map == null || map.entries == null || map.entries.isEmpty()) return Collections.emptyMap(); @@ -187,9 +190,9 @@ using operations_type = std::vector,::shared_ptr>>& operations, ::shared_ptr key, ::shared_ptr update) { @@ -276,7 +279,9 @@ cqlStatement returns [shared_ptr stmt] | st6= useStatement { $stmt = st6; } #if 0 | st7= truncateStatement { $stmt = st7; } +#endif | st8= createKeyspaceStatement { $stmt = st8; } +#if 0 | st9= createTableStatement { $stmt = st9; } | st10=createIndexStatement { $stmt = st10; } | st11=dropKeyspaceStatement { $stmt = st11; } @@ -657,19 +662,21 @@ dropFunctionStatement returns [DropFunctionStatement expr] )? { $expr = new DropFunctionStatement(fn, argsTypes, argsPresent, ifExists); } ; +#endif /** * CREATE KEYSPACE [IF NOT EXISTS] WITH attr1 = value1 AND attr2 = value2; */ -createKeyspaceStatement returns [CreateKeyspaceStatement expr] +createKeyspaceStatement returns [shared_ptr expr] @init { - KSPropDefs attrs = new KSPropDefs(); - boolean ifNotExists = false; + auto attrs = make_shared(); + bool if_not_exists = false; } - : K_CREATE K_KEYSPACE (K_IF K_NOT K_EXISTS { ifNotExists = true; } )? ks=keyspaceName - K_WITH properties[attrs] { $expr = new CreateKeyspaceStatement(ks, attrs, ifNotExists); } + : K_CREATE K_KEYSPACE (K_IF K_NOT K_EXISTS { if_not_exists = true; } )? ks=keyspaceName + K_WITH properties[attrs] { $expr = make_shared(ks, attrs, if_not_exists); } ; +#if 0 /** * CREATE COLUMNFAMILY [IF NOT EXISTS] ( * , @@ -1220,22 +1227,19 @@ columnCondition[conditions_type& conditions] ) ; -#if 0 - -properties[PropertyDefinitions props] +properties[::shared_ptr props] : property[props] (K_AND property[props])* ; -property[PropertyDefinitions props] - : k=ident '=' (simple=propertyValue { try { $props.addProperty(k.toString(), simple); } catch (SyntaxException e) { addRecognitionError(e.getMessage()); } } - | map=mapLiteral { try { $props.addProperty(k.toString(), convertPropertyMap(map)); } catch (SyntaxException e) { addRecognitionError(e.getMessage()); } }) +property[::shared_ptr props] + : k=ident '=' (simple=propertyValue { try { $props->add_property(k->to_string(), simple); } catch (exceptions::syntax_exception e) { add_recognition_error(e.what()); } } + | map=mapLiteral { try { $props->add_property(k->to_string(), convert_property_map(map)); } catch (exceptions::syntax_exception e) { add_recognition_error(e.what()); } }) ; -propertyValue returns [String str] - : c=constant { $str = c.getRawText(); } +propertyValue returns [sstring str] + : c=constant { $str = c->get_raw_text(); } | u=unreserved_keyword { $str = u; } ; -#endif relationType returns [const cql3::operator_type* op = nullptr] : '=' { $op = &cql3::operator_type::EQ; } diff --git a/cql3/cql3.cc b/cql3/cql3.cc index 22861233c5..0a72a8ba6e 100644 --- a/cql3/cql3.cc +++ b/cql3/cql3.cc @@ -20,6 +20,7 @@ #include "functions/bytes_conversion_fcts.hh" #include "functions/functions.hh" +#include "statements/create_keyspace_statement.hh" #include "statements/alter_keyspace_statement.hh" #include "statements/alter_type_statement.hh" #include "statements/cf_statement.hh" diff --git a/cql3/statements/CreateKeyspaceStatement.java b/cql3/statements/create_keyspace_statement.hh similarity index 81% rename from cql3/statements/CreateKeyspaceStatement.java rename to cql3/statements/create_keyspace_statement.hh index 8281cbd0f7..88cf06b3fb 100644 --- a/cql3/statements/CreateKeyspaceStatement.java +++ b/cql3/statements/create_keyspace_statement.hh @@ -15,6 +15,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +/* + * Copyright 2015 Cloudius Systems + * + * Modified by Cloudius Systems + */ + +#pragma once + +#include "cql3/statements/schema_altering_statement.hh" +#include "cql3/statements/ks_prop_defs.hh" + +#include "core/shared_ptr.hh" + +#if 0 package org.apache.cassandra.cql3.statements; import org.apache.cassandra.exceptions.ConfigurationException; @@ -31,14 +46,20 @@ import org.apache.cassandra.service.MigrationManager; import org.apache.cassandra.service.StorageService; import org.apache.cassandra.thrift.ThriftValidation; import org.apache.cassandra.transport.Event; +#endif + +namespace cql3 { + +namespace statements { /** A CREATE KEYSPACE statement parsed from a CQL query. */ -public class CreateKeyspaceStatement extends SchemaAlteringStatement -{ - private final String name; - private final KSPropDefs attrs; - private final boolean ifNotExists; +class create_keyspace_statement : public schema_altering_statement { +private: + sstring _name; + shared_ptr _attrs; + bool _if_not_exists; +public: /** * Creates a new CreateKeyspaceStatement instance for a given * keyspace name and keyword arguments. @@ -46,23 +67,21 @@ public class CreateKeyspaceStatement extends SchemaAlteringStatement * @param name the name of the keyspace to create * @param attrs map of the raw keyword arguments that followed the WITH keyword. */ - public CreateKeyspaceStatement(String name, KSPropDefs attrs, boolean ifNotExists) - { - super(); - this.name = name; - this.attrs = attrs; - this.ifNotExists = ifNotExists; + create_keyspace_statement(const sstring& name, shared_ptr attrs, bool if_not_exists) + : _name{name} + , _attrs{attrs} + , _if_not_exists{if_not_exists} + { } + + virtual const sstring& keyspace() const override { + return _name; } - @Override - public String keyspace() - { - return name; - } - - public void checkAccess(ClientState state) throws UnauthorizedException - { + virtual void check_access(const service::client_state& state) override { + warn(unimplemented::cause::PERMISSIONS); +#if 0 state.hasAllKeyspacesAccess(Permission.CREATE); +#endif } /** @@ -72,8 +91,8 @@ public class CreateKeyspaceStatement extends SchemaAlteringStatement * * @throws InvalidRequestException if arguments are missing or unacceptable */ - public void validate(ClientState state) throws RequestValidationException - { + virtual void validate(const service::client_state& state) override { +#if 0 ThriftValidation.validateKeyspaceNotSystem(name); // keyspace name @@ -95,8 +114,10 @@ public class CreateKeyspaceStatement extends SchemaAlteringStatement StorageService.instance.getTokenMetadata(), DatabaseDescriptor.getEndpointSnitch(), attrs.getReplicationOptions()); +#endif } +#if 0 public boolean announceMigration(boolean isLocalOnly) throws RequestValidationException { try @@ -116,4 +137,9 @@ public class CreateKeyspaceStatement extends SchemaAlteringStatement { return new Event.SchemaChange(Event.SchemaChange.Change.CREATED, keyspace()); } +#endif +}; + +} + } diff --git a/cql3/statements/property_definitions.hh b/cql3/statements/property_definitions.hh index 583e62accc..a9e57b091c 100644 --- a/cql3/statements/property_definitions.hh +++ b/cql3/statements/property_definitions.hh @@ -25,6 +25,15 @@ #ifndef CQL3_STATEMENTS_PROPERTY_DEFINITIONS_HH #define CQL3_STATEMENTS_PROPERTY_DEFINITIONS_HH +#include "exceptions/exceptions.hh" +#include "core/print.hh" +#include "core/sstring.hh" + +#include +#include + +#include + namespace cql3 { namespace statements { @@ -41,23 +50,33 @@ import org.apache.cassandra.exceptions.SyntaxException; #endif class property_definitions { +protected: #if 0 protected static final Logger logger = LoggerFactory.getLogger(PropertyDefinitions.class); +#endif + std::unordered_map _properties; - protected final Map properties = new HashMap(); - - public void addProperty(String name, String value) throws SyntaxException - { - if (properties.put(name, value) != null) - throw new SyntaxException(String.format("Multiple definition for property '%s'", name)); + property_definitions() + : _properties{} + { } +public: + virtual void add_property(const sstring& name, sstring value) { + auto it = _properties.find(name); + if (it != _properties.end()) { + throw exceptions::syntax_exception(sprint("Multiple definition for property '%s'", name)); + } + _properties.emplace(name, value); } - public void addProperty(String name, Map value) throws SyntaxException - { - if (properties.put(name, value) != null) - throw new SyntaxException(String.format("Multiple definition for property '%s'", name)); + virtual void add_property(const sstring& name, const std::map& value) { + auto it = _properties.find(name); + if (it != _properties.end()) { + throw exceptions::syntax_exception(sprint("Multiple definition for property '%s'", name)); + } + _properties.emplace(name, value); } +#if 0 public void validate(Set keywords, Set obsolete) throws SyntaxException { for (String name : properties.keySet()) diff --git a/cql3/statements/schema_altering_statement.hh b/cql3/statements/schema_altering_statement.hh index 89c7f0a558..14b634c9b8 100644 --- a/cql3/statements/schema_altering_statement.hh +++ b/cql3/statements/schema_altering_statement.hh @@ -54,6 +54,9 @@ protected: , _is_column_family_level{true} { } + virtual bool uses_function(const sstring& ks_name, const sstring& function_name) const override { + return cf_statement::uses_function(ks_name, function_name); + } virtual uint32_t get_bound_terms() override { return 0;