mirror of
https://github.com/scylladb/scylladb.git
synced 2026-04-21 00:50:35 +00:00
Merge branch git@github.com:cloudius-systems/seastar-dev.git penberg/create-keyspace-stmt
From Pekka: Initial pass at converting create keyspace statement parsing to C++.
This commit is contained in:
38
cql3/Cql.g
38
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::vector<std::pair<::shared_ptr<cql3::column_identifi
|
||||
listener->syntax_error(*this, msg);
|
||||
}
|
||||
|
||||
std::map<sstring, sstring> convert_property_map(shared_ptr<cql3::maps::literal> map) {
|
||||
throw std::runtime_error("not implemented");
|
||||
#if 0
|
||||
public Map<String, String> convertPropertyMap(Maps.Literal map)
|
||||
{
|
||||
if (map == null || map.entries == null || map.entries.isEmpty())
|
||||
return Collections.<String, String>emptyMap();
|
||||
|
||||
@@ -187,9 +190,9 @@ using operations_type = std::vector<std::pair<::shared_ptr<cql3::column_identifi
|
||||
}
|
||||
|
||||
return res;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
void add_raw_update(std::vector<std::pair<::shared_ptr<cql3::column_identifier::raw>,::shared_ptr<cql3::operation::raw_update>>>& operations,
|
||||
::shared_ptr<cql3::column_identifier::raw> key, ::shared_ptr<cql3::operation::raw_update> update)
|
||||
{
|
||||
@@ -276,7 +279,9 @@ cqlStatement returns [shared_ptr<parsed_statement> 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] <KEYSPACE> WITH attr1 = value1 AND attr2 = value2;
|
||||
*/
|
||||
createKeyspaceStatement returns [CreateKeyspaceStatement expr]
|
||||
createKeyspaceStatement returns [shared_ptr<cql3::statements::create_keyspace_statement> expr]
|
||||
@init {
|
||||
KSPropDefs attrs = new KSPropDefs();
|
||||
boolean ifNotExists = false;
|
||||
auto attrs = make_shared<cql3::statements::ks_prop_defs>();
|
||||
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<cql3::statements::create_keyspace_statement>(ks, attrs, if_not_exists); }
|
||||
;
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* CREATE COLUMNFAMILY [IF NOT EXISTS] <CF> (
|
||||
* <name1> <type>,
|
||||
@@ -1220,22 +1227,19 @@ columnCondition[conditions_type& conditions]
|
||||
)
|
||||
;
|
||||
|
||||
#if 0
|
||||
|
||||
properties[PropertyDefinitions props]
|
||||
properties[::shared_ptr<cql3::statements::property_definitions> 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<cql3::statements::property_definitions> 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; }
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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 <code>CREATE KEYSPACE</code> 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<ks_prop_defs> _attrs;
|
||||
bool _if_not_exists;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Creates a new <code>CreateKeyspaceStatement</code> 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 <code>WITH</code> 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<ks_prop_defs> 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
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <unordered_map>
|
||||
#include <map>
|
||||
|
||||
#include <boost/any.hpp>
|
||||
|
||||
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<sstring, boost::any> _properties;
|
||||
|
||||
protected final Map<String, Object> properties = new HashMap<String, Object>();
|
||||
|
||||
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<String, String> 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<sstring, 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);
|
||||
}
|
||||
|
||||
#if 0
|
||||
public void validate(Set<String> keywords, Set<String> obsolete) throws SyntaxException
|
||||
{
|
||||
for (String name : properties.keySet())
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user