diff --git a/configure.py b/configure.py index f93464353b..1ce5d701c0 100755 --- a/configure.py +++ b/configure.py @@ -225,6 +225,7 @@ deps = { 'log.cc', 'cql3/abstract_marker.cc', 'cql3/cql3.cc', + 'cql3/cql3_type.cc', 'thrift/handler.cc', 'thrift/server.cc', 'utils/murmur_hash.cc', diff --git a/cql3/cql3.cc b/cql3/cql3.cc index 635f85e25a..2c5e7719d5 100644 --- a/cql3/cql3.cc +++ b/cql3/cql3.cc @@ -46,4 +46,5 @@ #include "term.hh" #include "sets.hh" #include "cql3_row.hh" +#include "cql3_type.hh" #include "attributes.hh" diff --git a/cql3/cql3_type.cc b/cql3/cql3_type.cc new file mode 100644 index 0000000000..2879994a01 --- /dev/null +++ b/cql3/cql3_type.cc @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2014 Cloudius Systems, Ltd. + */ + +#include "cql3_type.hh" + +namespace cql3 { + +thread_local shared_ptr native_cql3_type::ascii = make("ascii", ascii_type); +thread_local shared_ptr native_cql3_type::bigint = make("bigint", long_type); +thread_local shared_ptr native_cql3_type::blob = make("blob", bytes_type); +thread_local shared_ptr native_cql3_type::boolean = make("boolean", boolean_type); +//thread_local shared_ptr native_cql3_type::double = make("double", double_type); +//thread_local shared_ptr native_cql3_type::float = make("float", float_type); +thread_local shared_ptr native_cql3_type::int_ = make("int", int32_type); +thread_local shared_ptr native_cql3_type::text = make("text", utf8_type); +thread_local shared_ptr native_cql3_type::timestamp = make("timestamp", timestamp_type); +thread_local shared_ptr native_cql3_type::uuid = make("uuid", uuid_type); +thread_local shared_ptr native_cql3_type::varchar = make("varchar", utf8_type); +thread_local shared_ptr native_cql3_type::timeuuid = make("timeuuid", timeuuid_type); + +const std::vector>& +native_cql3_type::values() { + static thread_local std::vector> v = { + native_cql3_type::ascii, + native_cql3_type::bigint, + native_cql3_type::blob, + native_cql3_type::boolean, +#if 0 + native_cql3_type::double_, + native_cql3_type::float_, +#endif + native_cql3_type::int_, + native_cql3_type::text, + native_cql3_type::timestamp, + native_cql3_type::uuid, + native_cql3_type::varchar, + native_cql3_type::timeuuid, + }; + return v; +} + +} + + diff --git a/cql3/CQL3Type.java b/cql3/cql3_type.hh similarity index 90% rename from cql3/CQL3Type.java rename to cql3/cql3_type.hh index 98d1b15578..78a300b1b0 100644 --- a/cql3/CQL3Type.java +++ b/cql3/cql3_type.hh @@ -15,70 +15,65 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.cassandra.cql3; -import java.util.ArrayList; -import java.util.List; +/* + * Modified by Cloudius Systems + * + * Copyright 2015 Cloudius Systems + */ -import org.apache.cassandra.config.KSMetaData; -import org.apache.cassandra.config.Schema; -import org.apache.cassandra.db.marshal.*; -import org.apache.cassandra.exceptions.InvalidRequestException; -import org.apache.cassandra.exceptions.ConfigurationException; -import org.apache.cassandra.exceptions.SyntaxException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +#pragma once -public interface CQL3Type -{ - static final Logger logger = LoggerFactory.getLogger(CQL3Type.class); +#include "database.hh" +#include "exceptions/exceptions.hh" +#include - public boolean isCollection(); - public AbstractType getType(); +namespace cql3 { - public enum Native implements CQL3Type - { - ASCII (AsciiType.instance), - BIGINT (LongType.instance), - BLOB (BytesType.instance), - BOOLEAN (BooleanType.instance), +class cql3_type { + sstring _name; + data_type _type; +public: + cql3_type(sstring name, data_type type) : _name(std::move(name)), _type(std::move(type)) {} + virtual ~cql3_type() {} + virtual bool is_collection() const = 0; + data_type get_type() const { return _type; } + sstring to_string() const { return _name; } +}; + +class native_cql3_type : public cql3_type { + static shared_ptr make(sstring name, data_type type) { + return make_shared(std::move(name), std::move(type)); + } +public: + static thread_local shared_ptr ascii; + static thread_local shared_ptr bigint; + static thread_local shared_ptr blob; + static thread_local shared_ptr boolean; + //static thread_local shared_ptr double; + //static thread_local shared_ptr float; + static thread_local shared_ptr int_; + static thread_local shared_ptr text; + static thread_local shared_ptr timestamp; + static thread_local shared_ptr uuid; + static thread_local shared_ptr varchar; + static thread_local shared_ptr timeuuid; + +#if 0 COUNTER (CounterColumnType.instance), DECIMAL (DecimalType.instance), - DOUBLE (DoubleType.instance), - FLOAT (FloatType.instance), INET (InetAddressType.instance), - INT (Int32Type.instance), - TEXT (UTF8Type.instance), - TIMESTAMP(TimestampType.instance), - UUID (UUIDType.instance), - VARCHAR (UTF8Type.instance), VARINT (IntegerType.instance), - TIMEUUID (TimeUUIDType.instance); - - private final AbstractType type; - - private Native(AbstractType type) - { - this.type = type; - } - - public boolean isCollection() - { - return false; - } - - public AbstractType getType() - { - return type; - } - - @Override - public String toString() - { - return super.toString().toLowerCase(); - } +#endif + static const std::vector>& values(); +public: + using cql3_type::cql3_type; + virtual bool is_collection() const override { + return false; } +}; +#if 0 public static class Custom implements CQL3Type { private final AbstractType type; @@ -591,4 +586,6 @@ public interface CQL3Type } } } +#endif + }