Skip to content

Commit

Permalink
Merge "CQL 3.3.1 support" from Pekka
Browse files Browse the repository at this point in the history
"This patch series adds support for CQL 3.3.1. The changes to CQL are listed
here:

  https://github.com/apache/cassandra/blob/cassandra-2.2/doc/cql3/CQL.textile#changes

The following CQL features are already supported by Scylla:

  - TRUNCATE TABLE alias
  - Double-dollar string literals
  - Aggregate functions: MIN, MAX, SUM, and AVG

This series adds the following CQL features:

  - New data types: tinyint, smallint, date, and time
  - CQL binary protocol v4 (required by the new data types)
  - Advertise Cassandra 2.2.8 version from Scylla so that drivers correctly
    detect the presence of CQL 3.3.1

The following CQL features are not supported by Scylla:

  - Role-based access control (issue #1941)
  - JSON data type
  - User-defined functions (UDFs)
  - User-defined aggregates (UDAs)

The following CQL binary protocol v4 changes are not implemented by this
series:

  - Read_failure and Write_failure error codes are not implemented.
    They error codes not used by the smart drivers but as they are
    propagated to application code, we eventually need to wire them up
    to our storage proxy implementation.
  - Function_failure error code is only used by user-defined functions
    and the fromJson function, which are not implemented by Scylla.

Fixes #1284."

* 'penberg/cql-3.3.1/v5' of github.com:cloudius-systems/seastar-dev:
  version: Bump Cassandra version to 2.2.8
  db/schema_tables: Add schema_functions and schema_aggregates tables
  tests/type_tests: TIME type test cases
  tests/cql_query_test: TIME type test cases
  cql3: TIME data type support
  tests/type_tests: DATE type test cases
  tests/cql_query_test: DATE type test cases
  cql3: DATE type support
  date.h: 64-bit year and days representation
  licenses: Add utils/date.h license
  utils/date.h: Import date and time library sources
  tests/type_tests: TINYINT and SMALLINT type test cases
  tests/cql_query_test: TINYINT and SMALLINT type test cases
  cql3: TINYINT and SMALLINT data type support
  types: Fix integer_type_impl::parse_int() for bytes
  • Loading branch information
avikivity committed Jan 9, 2017
2 parents 8f36dca + 856d0e4 commit 77cb2b4
Show file tree
Hide file tree
Showing 15 changed files with 6,997 additions and 14 deletions.
8 changes: 8 additions & 0 deletions cql3/Cql.g
Expand Up @@ -1465,12 +1465,16 @@ 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; }
| K_TIMEUUID { $t = cql3_type::timeuuid; }
| K_DATE { $t = cql3_type::date; }
| K_TIME { $t = cql3_type::time; }
;

collection_type returns [shared_ptr<cql3::cql3_type::raw> pt]
Expand Down Expand Up @@ -1644,13 +1648,17 @@ 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;
K_VARINT: V A R I N T;
K_TIMEUUID: T I M E U U I D;
K_TOKEN: T O K E N;
K_WRITETIME: W R I T E T I M E;
K_DATE: D A T E;
K_TIME: T I M E;
K_NULL: N U L L;
K_NOT: N O T;
Expand Down
7 changes: 6 additions & 1 deletion cql3/constants.cc
Expand Up @@ -97,7 +97,9 @@ constants::literal::test_assignment(database& db, const sstring& keyspace, ::sha
cql3_type::kind::TEXT,
cql3_type::kind::INET,
cql3_type::kind::VARCHAR,
cql3_type::kind::TIMESTAMP>::contains(kind)) {
cql3_type::kind::TIMESTAMP,
cql3_type::kind::DATE,
cql3_type::kind::TIME>::contains(kind)) {
return assignment_testable::test_result::WEAKLY_ASSIGNABLE;
}
break;
Expand All @@ -109,7 +111,10 @@ 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::DATE,
cql3_type::kind::TINYINT,
cql3_type::kind::VARINT>::contains(kind)) {
return assignment_testable::test_result::WEAKLY_ASSIGNABLE;
}
Expand Down
8 changes: 8 additions & 0 deletions cql3/cql3_type.cc
Expand Up @@ -273,11 +273,15 @@ 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);
thread_local shared_ptr<cql3_type> cql3_type::date = make("date", simple_date_type, cql3_type::kind::DATE);
thread_local shared_ptr<cql3_type> cql3_type::time = make("time", time_type, cql3_type::kind::TIME);
thread_local shared_ptr<cql3_type> cql3_type::inet = make("inet", inet_addr_type, cql3_type::kind::INET);
thread_local shared_ptr<cql3_type> cql3_type::varint = make("varint", varint_type, cql3_type::kind::VARINT);
thread_local shared_ptr<cql3_type> cql3_type::decimal = make("decimal", decimal_type, cql3_type::kind::DECIMAL);
Expand All @@ -296,12 +300,16 @@ 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,
cql3_type::timeuuid,
cql3_type::date,
cql3_type::time,
};
return v;
}
Expand Down
12 changes: 10 additions & 2 deletions cql3/cql3_type.hh
Expand Up @@ -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, DATE, TIME
};
using kind_enum = super_enum<kind,
kind::ASCII,
Expand All @@ -111,12 +111,16 @@ public:
kind::FLOAT,
kind::INET,
kind::INT,
kind::SMALLINT,
kind::TINYINT,
kind::TEXT,
kind::TIMESTAMP,
kind::UUID,
kind::VARCHAR,
kind::VARINT,
kind::TIMEUUID>;
kind::TIMEUUID,
kind::DATE,
kind::TIME>;
using kind_enum_set = enum_set<kind_enum>;
private:
std::experimental::optional<kind_enum_set::prepared> _kind;
Expand All @@ -131,11 +135,15 @@ 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;
static thread_local shared_ptr<cql3_type> date;
static thread_local shared_ptr<cql3_type> time;
static thread_local shared_ptr<cql3_type> inet;
static thread_local shared_ptr<cql3_type> varint;
static thread_local shared_ptr<cql3_type> decimal;
Expand Down
2 changes: 1 addition & 1 deletion cql3/query_processor.cc
Expand Up @@ -59,7 +59,7 @@ logging::logger log("query_processor");

distributed<query_processor> _the_query_processor;

const sstring query_processor::CQL_VERSION = "3.2.1";
const sstring query_processor::CQL_VERSION = "3.3.1";

class query_processor::internal_state {
service::query_state _qs;
Expand Down
2 changes: 1 addition & 1 deletion cql_serialization_format.hh
Expand Up @@ -35,7 +35,7 @@ using cql_protocol_version_type = uint8_t;
class cql_serialization_format {
cql_protocol_version_type _version;
public:
static constexpr cql_protocol_version_type latest_version = 3;
static constexpr cql_protocol_version_type latest_version = 4;
explicit cql_serialization_format(cql_protocol_version_type version) : _version(version) {}
static cql_serialization_format latest() { return cql_serialization_format{latest_version}; }
static cql_serialization_format internal() { return latest(); }
Expand Down
2 changes: 1 addition & 1 deletion db/schema_tables.cc
Expand Up @@ -2175,7 +2175,7 @@ data_type parse_type(sstring str)

std::vector<schema_ptr> all_tables() {
return {
keyspaces(), columnfamilies(), columns(), triggers(), usertypes(), /* Not in 2.1.8 functions(), aggregates() */
keyspaces(), columnfamilies(), columns(), triggers(), usertypes(), functions(), aggregates(),
views(),
};
}
Expand Down
32 changes: 32 additions & 0 deletions licenses/date-license.txt
@@ -0,0 +1,32 @@
The license for utils/date.h is:

The MIT License (MIT)

Copyright (c) 2015, 2016 Howard Hinnant
Copyright (c) 2016 Adrian Colomitchi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Our apologies. When the previous paragraph was written, lowercase had not yet
been invented (that woud involve another several millennia of evolution).
We did not mean to shout.

Source code was imported from the following repository:

https://github.com/HowardHinnant/date
32 changes: 26 additions & 6 deletions tests/cql_query_test.cc
Expand Up @@ -1358,11 +1358,15 @@ SEASTAR_TEST_CASE(test_types) {
" m varchar,"
" n varint,"
" o decimal,"
" p tinyint,"
" q smallint,"
" r date,"
" s time,"
");").discard_result();
}).then([&e] {
e.require_table_exists("ks", "all_types");
return e.execute_cql(
"INSERT INTO all_types (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) VALUES ("
"INSERT INTO all_types (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s) VALUES ("
" 'ascii',"
" 123456789,"
" 0xdeadbeef,"
Expand All @@ -1377,7 +1381,11 @@ SEASTAR_TEST_CASE(test_types) {
" d2177dd0-eaa2-11de-a572-001b779c76e3,"
" 'varchar',"
" 123,"
" 1.23"
" 1.23,"
" 3,"
" 3,"
" '1970-01-02',"
" '00:00:00.000000001'"
");").discard_result();
}).then([&e] {
return e.execute_cql("SELECT * FROM all_types WHERE a = 'ascii'");
Expand All @@ -1401,11 +1409,15 @@ SEASTAR_TEST_CASE(test_types) {
timeuuid_type->decompose(utils::UUID(sstring("d2177dd0-eaa2-11de-a572-001b779c76e3"))),
uuid_type->decompose(utils::UUID(sstring("d2177dd0-eaa2-11de-a572-001b779c76e3"))),
utf8_type->decompose(sstring("varchar")), varint_type->decompose(boost::multiprecision::cpp_int(123)),
decimal_type->decompose(big_decimal { 2, boost::multiprecision::cpp_int(123) })
decimal_type->decompose(big_decimal { 2, boost::multiprecision::cpp_int(123) }),
byte_type->decompose(int8_t(3)),
short_type->decompose(int16_t(3)),
simple_date_type->decompose(int32_t(0x80000001)),
time_type->decompose(int64_t(0x0000000000000001)),
}
});
return e.execute_cql(
"INSERT INTO all_types (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) VALUES ("
"INSERT INTO all_types (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s) VALUES ("
" blobAsAscii(asciiAsBlob('ascii2')),"
" blobAsBigint(bigintAsBlob(123456789)),"
" bigintAsBlob(12),"
Expand All @@ -1419,7 +1431,11 @@ SEASTAR_TEST_CASE(test_types) {
" blobAsTimeuuid(timeuuidAsBlob(d2177dd0-eaa2-11de-a572-001b779c76e3)),"
" blobAsUuid(uuidAsBlob(d2177dd0-eaa2-11de-a572-001b779c76e3)),"
" blobAsVarchar(varcharAsBlob('varchar')), blobAsVarint(varintAsBlob(123)),"
" blobAsDecimal(decimalAsBlob(1.23))"
" blobAsDecimal(decimalAsBlob(1.23)),"
" blobAsTinyint(tinyintAsBlob(3)),"
" blobAsSmallint(smallintAsBlob(3)),"
" blobAsDate(dateAsBlob('1970-01-02')),"
" blobAsTime(timeAsBlob('00:00:00.000000001'))"
");").discard_result();
}).then([&e] {
return e.execute_cql("SELECT * FROM all_types WHERE a = 'ascii2'");
Expand All @@ -1443,7 +1459,11 @@ SEASTAR_TEST_CASE(test_types) {
timeuuid_type->decompose(utils::UUID(sstring("d2177dd0-eaa2-11de-a572-001b779c76e3"))),
uuid_type->decompose(utils::UUID(sstring("d2177dd0-eaa2-11de-a572-001b779c76e3"))),
utf8_type->decompose(sstring("varchar")), varint_type->decompose(boost::multiprecision::cpp_int(123)),
decimal_type->decompose(big_decimal { 2, boost::multiprecision::cpp_int(123) })
decimal_type->decompose(big_decimal { 2, boost::multiprecision::cpp_int(123) }),
byte_type->decompose(int8_t(3)),
short_type->decompose(int16_t(3)),
simple_date_type->decompose(int32_t(0x80000001)),
time_type->decompose(int64_t(0x0000000000000001)),
}
});
});
Expand Down

0 comments on commit 77cb2b4

Please sign in to comment.