diff --git a/idl/query.idl.hh b/idl/query.idl.hh index 71ce893e50..08a7e182db 100644 --- a/idl/query.idl.hh +++ b/idl/query.idl.hh @@ -6,6 +6,8 @@ class qr_cell stub [[writable]] { // Specified by CQL binary protocol, according to cql_serialization_format in read_command. bytes value; + + std::experimental::optional ttl [[version 1.3]] = { }; // present when send_ttl option set in partition_slice }; class qr_row stub [[writable]] { diff --git a/mutation_partition.cc b/mutation_partition.cc index b3516c868b..97c6ad795c 100644 --- a/mutation_partition.cc +++ b/mutation_partition.cc @@ -564,14 +564,20 @@ void write_cell(RowWriter& w, const query::partition_slice& slice, ::atomic_cell return std::move(wr).skip_timestamp(); } }(); - [&, wr = std::move(after_timestamp)] () mutable { + auto after_value = [&, wr = std::move(after_timestamp)] () mutable { if (slice.options.contains() && c.is_live_and_has_ttl()) { return std::move(wr).write_expiry(c.expiry()); } else { return std::move(wr).skip_expiry(); } - }().write_value(c.value()) - .end_qr_cell(); + }().write_value(c.value()); + [&, wr = std::move(after_value)] () mutable { + if (slice.options.contains() && c.is_live_and_has_ttl()) { + return std::move(wr).write_ttl(c.ttl()); + } else { + return std::move(wr).skip_ttl(); + } + }().end_qr_cell(); } template @@ -583,6 +589,7 @@ void write_cell(RowWriter& w, const query::partition_slice& slice, const data_ty w.add().write().skip_timestamp() .skip_expiry() .write_value(ctype->to_value(v, slice.cql_format())) + .skip_ttl() .end_qr_cell(); } diff --git a/query-request.hh b/query-request.hh index d76c9bcb68..755369fe9f 100644 --- a/query-request.hh +++ b/query-request.hh @@ -103,7 +103,7 @@ constexpr auto max_rows = std::numeric_limits::max(); // Schema-dependent. class partition_slice { public: - enum class option { send_clustering_key, send_partition_key, send_timestamp, send_expiry, reversed, distinct, collections_as_maps }; + enum class option { send_clustering_key, send_partition_key, send_timestamp, send_expiry, reversed, distinct, collections_as_maps, send_ttl }; using option_set = enum_set>; + option::collections_as_maps, + option::send_ttl>>; clustering_row_ranges _row_ranges; public: std::vector static_columns; // TODO: consider using bitmap diff --git a/query-result-reader.hh b/query-result-reader.hh index 78dc794b48..331c845b38 100644 --- a/query-result-reader.hh +++ b/query-result-reader.hh @@ -39,10 +39,11 @@ namespace query { class result_atomic_cell_view { api::timestamp_type _timestamp; expiry_opt _expiry; + ttl_opt _ttl; bytes_view _value; public: - result_atomic_cell_view(api::timestamp_type timestamp, expiry_opt expiry, bytes_view value) - : _timestamp(timestamp), _expiry(expiry), _value(value) { } + result_atomic_cell_view(api::timestamp_type timestamp, expiry_opt expiry, ttl_opt ttl, bytes_view value) + : _timestamp(timestamp), _expiry(expiry), _ttl(ttl), _value(value) { } api::timestamp_type timestamp() const { return _timestamp; @@ -52,6 +53,10 @@ public: return _expiry; } + ttl_opt ttl() const { + return _ttl; + } + bytes_view value() const { return _value; } @@ -82,8 +87,9 @@ public: ser::qr_cell_view v = *cell_opt; api::timestamp_type timestamp = v.timestamp().value_or(api::missing_timestamp); expiry_opt expiry = v.expiry(); + ttl_opt ttl = v.ttl(); _tmp_value = v.value(); - return {result_atomic_cell_view(timestamp, expiry, _tmp_value)}; + return {result_atomic_cell_view(timestamp, expiry, ttl, _tmp_value)}; } std::experimental::optional next_collection_cell() { auto cell_opt = *_i++;