mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-12 19:02:12 +00:00
cql3: TINYINT and SMALLINT data type support
This adds support for the TINYINT and SMALLINT data types introduced in CQL 3.3.1. Refs #1284
This commit is contained in:
@@ -1465,8 +1465,10 @@ native_type returns [shared_ptr<cql3_type> t]
|
||||
| K_FLOAT { $t = cql3_type::float_; }
|
||||
| K_INET { $t = cql3_type::inet; }
|
||||
| K_INT { $t = cql3_type::int_; }
|
||||
| K_SMALLINT { $t = cql3_type::smallint; }
|
||||
| K_TEXT { $t = cql3_type::text; }
|
||||
| K_TIMESTAMP { $t = cql3_type::timestamp; }
|
||||
| K_TINYINT { $t = cql3_type::tinyint; }
|
||||
| K_UUID { $t = cql3_type::uuid; }
|
||||
| K_VARCHAR { $t = cql3_type::varchar; }
|
||||
| K_VARINT { $t = cql3_type::varint; }
|
||||
@@ -1644,6 +1646,8 @@ K_DOUBLE: D O U B L E;
|
||||
K_FLOAT: F L O A T;
|
||||
K_INET: I N E T;
|
||||
K_INT: I N T;
|
||||
K_SMALLINT: S M A L L I N T;
|
||||
K_TINYINT: T I N Y I N T;
|
||||
K_TEXT: T E X T;
|
||||
K_UUID: U U I D;
|
||||
K_VARCHAR: V A R C H A R;
|
||||
|
||||
@@ -109,7 +109,9 @@ constants::literal::test_assignment(database& db, const sstring& keyspace, ::sha
|
||||
cql3_type::kind::DOUBLE,
|
||||
cql3_type::kind::FLOAT,
|
||||
cql3_type::kind::INT,
|
||||
cql3_type::kind::SMALLINT,
|
||||
cql3_type::kind::TIMESTAMP,
|
||||
cql3_type::kind::TINYINT,
|
||||
cql3_type::kind::VARINT>::contains(kind)) {
|
||||
return assignment_testable::test_result::WEAKLY_ASSIGNABLE;
|
||||
}
|
||||
|
||||
@@ -273,8 +273,10 @@ thread_local shared_ptr<cql3_type> cql3_type::boolean = make("boolean", boolean_
|
||||
thread_local shared_ptr<cql3_type> cql3_type::double_ = make("double", double_type, cql3_type::kind::DOUBLE);
|
||||
thread_local shared_ptr<cql3_type> cql3_type::float_ = make("float", float_type, cql3_type::kind::FLOAT);
|
||||
thread_local shared_ptr<cql3_type> cql3_type::int_ = make("int", int32_type, cql3_type::kind::INT);
|
||||
thread_local shared_ptr<cql3_type> cql3_type::smallint = make("smallint", short_type, cql3_type::kind::SMALLINT);
|
||||
thread_local shared_ptr<cql3_type> cql3_type::text = make("text", utf8_type, cql3_type::kind::TEXT);
|
||||
thread_local shared_ptr<cql3_type> cql3_type::timestamp = make("timestamp", timestamp_type, cql3_type::kind::TIMESTAMP);
|
||||
thread_local shared_ptr<cql3_type> cql3_type::tinyint = make("tinyint", byte_type, cql3_type::kind::TINYINT);
|
||||
thread_local shared_ptr<cql3_type> cql3_type::uuid = make("uuid", uuid_type, cql3_type::kind::UUID);
|
||||
thread_local shared_ptr<cql3_type> cql3_type::varchar = make("varchar", utf8_type, cql3_type::kind::TEXT);
|
||||
thread_local shared_ptr<cql3_type> cql3_type::timeuuid = make("timeuuid", timeuuid_type, cql3_type::kind::TIMEUUID);
|
||||
@@ -296,8 +298,10 @@ cql3_type::values() {
|
||||
cql3_type::float_,
|
||||
cql3_type:inet,
|
||||
cql3_type::int_,
|
||||
cql3_type::smallint,
|
||||
cql3_type::text,
|
||||
cql3_type::timestamp,
|
||||
cql3_type::tinyint,
|
||||
cql3_type::uuid,
|
||||
cql3_type::varchar,
|
||||
cql3_type::varint,
|
||||
|
||||
@@ -98,7 +98,7 @@ private:
|
||||
|
||||
public:
|
||||
enum class kind : int8_t {
|
||||
ASCII, BIGINT, BLOB, BOOLEAN, COUNTER, DECIMAL, DOUBLE, FLOAT, INT, INET, TEXT, TIMESTAMP, UUID, VARCHAR, VARINT, TIMEUUID
|
||||
ASCII, BIGINT, BLOB, BOOLEAN, COUNTER, DECIMAL, DOUBLE, FLOAT, INT, SMALLINT, TINYINT, INET, TEXT, TIMESTAMP, UUID, VARCHAR, VARINT, TIMEUUID
|
||||
};
|
||||
using kind_enum = super_enum<kind,
|
||||
kind::ASCII,
|
||||
@@ -111,6 +111,8 @@ public:
|
||||
kind::FLOAT,
|
||||
kind::INET,
|
||||
kind::INT,
|
||||
kind::SMALLINT,
|
||||
kind::TINYINT,
|
||||
kind::TEXT,
|
||||
kind::TIMESTAMP,
|
||||
kind::UUID,
|
||||
@@ -131,8 +133,10 @@ public:
|
||||
static thread_local shared_ptr<cql3_type> double_;
|
||||
static thread_local shared_ptr<cql3_type> float_;
|
||||
static thread_local shared_ptr<cql3_type> int_;
|
||||
static thread_local shared_ptr<cql3_type> smallint;
|
||||
static thread_local shared_ptr<cql3_type> text;
|
||||
static thread_local shared_ptr<cql3_type> timestamp;
|
||||
static thread_local shared_ptr<cql3_type> tinyint;
|
||||
static thread_local shared_ptr<cql3_type> uuid;
|
||||
static thread_local shared_ptr<cql3_type> varchar;
|
||||
static thread_local shared_ptr<cql3_type> timeuuid;
|
||||
|
||||
@@ -1724,6 +1724,8 @@ private:
|
||||
VARINT = 0x000E,
|
||||
TIMEUUID = 0x000F,
|
||||
INET = 0x0010,
|
||||
SMALLINT = 0x0013,
|
||||
TINYINT = 0x0014,
|
||||
LIST = 0x0020,
|
||||
MAP = 0x0021,
|
||||
SET = 0x0022,
|
||||
@@ -1809,6 +1811,8 @@ thread_local const type_codec::type_id_to_type_type type_codec::type_id_to_type
|
||||
(type_id::DOUBLE , double_type)
|
||||
(type_id::FLOAT , float_type)
|
||||
(type_id::INT , int32_type)
|
||||
(type_id::TINYINT , byte_type)
|
||||
(type_id::SMALLINT , short_type)
|
||||
(type_id::TIMESTAMP , timestamp_type)
|
||||
(type_id::UUID , uuid_type)
|
||||
(type_id::VARCHAR , utf8_type)
|
||||
|
||||
42
types.cc
42
types.cc
@@ -51,6 +51,8 @@ sstring time_point_to_string(const T& tp)
|
||||
return boost::posix_time::to_iso_extended_string(time);
|
||||
}
|
||||
|
||||
static const char* byte_type_name = "org.apache.cassandra.db.marshal.ByteType";
|
||||
static const char* short_type_name = "org.apache.cassandra.db.marshal.ShortType";
|
||||
static const char* int32_type_name = "org.apache.cassandra.db.marshal.Int32Type";
|
||||
static const char* long_type_name = "org.apache.cassandra.db.marshal.LongType";
|
||||
static const char* ascii_type_name = "org.apache.cassandra.db.marshal.AsciiType";
|
||||
@@ -193,6 +195,36 @@ struct integer_type_impl : simple_type_impl<T> {
|
||||
}
|
||||
};
|
||||
|
||||
struct byte_type_impl : integer_type_impl<int8_t> {
|
||||
byte_type_impl() : integer_type_impl{byte_type_name}
|
||||
{ }
|
||||
|
||||
virtual void validate(bytes_view v) const override {
|
||||
if (v.size() != 0 && v.size() != 1) {
|
||||
throw marshal_exception(sprint("Expected 1 byte for a tinyint (%d)", v.size()));
|
||||
}
|
||||
}
|
||||
|
||||
virtual ::shared_ptr<cql3::cql3_type> as_cql3_type() const override {
|
||||
return cql3::cql3_type::tinyint;
|
||||
}
|
||||
};
|
||||
|
||||
struct short_type_impl : integer_type_impl<int16_t> {
|
||||
short_type_impl() : integer_type_impl{short_type_name}
|
||||
{ }
|
||||
|
||||
virtual void validate(bytes_view v) const override {
|
||||
if (v.size() != 0 && v.size() != 2) {
|
||||
throw marshal_exception(sprint("Expected 2 bytes for a smallint (%d)", v.size()));
|
||||
}
|
||||
}
|
||||
|
||||
virtual ::shared_ptr<cql3::cql3_type> as_cql3_type() const override {
|
||||
return cql3::cql3_type::smallint;
|
||||
}
|
||||
};
|
||||
|
||||
struct int32_type_impl : integer_type_impl<int32_t> {
|
||||
int32_type_impl() : integer_type_impl{int32_type_name}
|
||||
{ }
|
||||
@@ -2816,6 +2848,8 @@ reversed_type_impl::native_typeid() const {
|
||||
return _underlying_type->native_typeid();
|
||||
}
|
||||
|
||||
thread_local const shared_ptr<const abstract_type> byte_type(make_shared<byte_type_impl>());
|
||||
thread_local const shared_ptr<const abstract_type> short_type(make_shared<short_type_impl>());
|
||||
thread_local const shared_ptr<const abstract_type> int32_type(make_shared<int32_type_impl>());
|
||||
thread_local const shared_ptr<const abstract_type> long_type(make_shared<long_type_impl>());
|
||||
thread_local const shared_ptr<const abstract_type> ascii_type(make_shared<ascii_type_impl>());
|
||||
@@ -2837,6 +2871,8 @@ thread_local const data_type empty_type(make_shared<empty_type_impl>());
|
||||
data_type abstract_type::parse_type(const sstring& name)
|
||||
{
|
||||
static thread_local const std::unordered_map<sstring, data_type> types = {
|
||||
{ byte_type_name, byte_type },
|
||||
{ short_type_name, short_type },
|
||||
{ int32_type_name, int32_type },
|
||||
{ long_type_name, long_type },
|
||||
{ ascii_type_name, ascii_type },
|
||||
@@ -2894,6 +2930,12 @@ data_value::data_value(const char* v) : data_value(make_new(utf8_type, sstring(v
|
||||
data_value::data_value(bool v) : data_value(make_new(boolean_type, v)) {
|
||||
}
|
||||
|
||||
data_value::data_value(int8_t v) : data_value(make_new(byte_type, v)) {
|
||||
}
|
||||
|
||||
data_value::data_value(int16_t v) : data_value(make_new(short_type, v)) {
|
||||
}
|
||||
|
||||
data_value::data_value(int32_t v) : data_value(make_new(int32_type, v)) {
|
||||
}
|
||||
|
||||
|
||||
16
types.hh
16
types.hh
@@ -310,6 +310,8 @@ public:
|
||||
data_value(sstring);
|
||||
data_value(const char*);
|
||||
data_value(bool);
|
||||
data_value(int8_t);
|
||||
data_value(int16_t);
|
||||
data_value(int32_t);
|
||||
data_value(int64_t);
|
||||
data_value(utils::UUID);
|
||||
@@ -1082,6 +1084,8 @@ abstract_type::as_tri_comparator() const {
|
||||
using key_compare = serialized_compare;
|
||||
|
||||
// Remember to update type_codec in transport/server.cc and cql3/cql3_type.cc
|
||||
extern thread_local const shared_ptr<const abstract_type> byte_type;
|
||||
extern thread_local const shared_ptr<const abstract_type> short_type;
|
||||
extern thread_local const shared_ptr<const abstract_type> int32_type;
|
||||
extern thread_local const shared_ptr<const abstract_type> long_type;
|
||||
extern thread_local const shared_ptr<const abstract_type> ascii_type;
|
||||
@@ -1100,6 +1104,18 @@ extern thread_local const shared_ptr<const abstract_type> decimal_type;
|
||||
extern thread_local const shared_ptr<const abstract_type> counter_type;
|
||||
extern thread_local const data_type empty_type;
|
||||
|
||||
template <>
|
||||
inline
|
||||
shared_ptr<const abstract_type> data_type_for<int8_t>() {
|
||||
return byte_type;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline
|
||||
shared_ptr<const abstract_type> data_type_for<int16_t>() {
|
||||
return short_type;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline
|
||||
shared_ptr<const abstract_type> data_type_for<int32_t>() {
|
||||
|
||||
Reference in New Issue
Block a user