From 80ce9b72a1e703a6cb2e1cd90961676da400d2f3 Mon Sep 17 00:00:00 2001 From: Piotr Sarna Date: Wed, 11 Jul 2018 10:47:22 +0200 Subject: [PATCH] cql3: add value_for method In order to extract value from a restriction for just one column, value_for(column_name, options) method is implemented. It's needed because once ALLOW FILTERING support was introduced, index-related restrictions may contain more than 1 value. --- cql3/restrictions/restrictions.hh | 4 ++++ cql3/restrictions/single_column_primary_key_restrictions.hh | 5 +++++ cql3/restrictions/single_column_restrictions.hh | 5 +++++ cql3/restrictions/statement_restrictions.cc | 3 +++ 4 files changed, 17 insertions(+) diff --git a/cql3/restrictions/restrictions.hh b/cql3/restrictions/restrictions.hh index 111e182f6e..886ede07c3 100644 --- a/cql3/restrictions/restrictions.hh +++ b/cql3/restrictions/restrictions.hh @@ -68,6 +68,10 @@ public: virtual std::vector values(const query_options& options) const = 0; + virtual bytes_opt value_for(const column_definition& cdef, const query_options& options) const { + throw exceptions::invalid_request_exception("Single value can be obtained from single-column restrictions only"); + } + /** * Returns true if one of the restrictions use the specified function. * diff --git a/cql3/restrictions/single_column_primary_key_restrictions.hh b/cql3/restrictions/single_column_primary_key_restrictions.hh index d310f05211..5f6655ab4e 100644 --- a/cql3/restrictions/single_column_primary_key_restrictions.hh +++ b/cql3/restrictions/single_column_primary_key_restrictions.hh @@ -310,6 +310,11 @@ public: } return res; } + + virtual bytes_opt value_for(const column_definition& cdef, const query_options& options) const override { + return _restrictions->value_for(cdef, options); + } + std::vector bounds(statements::bound b, const query_options& options) const override { // TODO: if this proved to be required. fail(unimplemented::cause::LEGACY_COMPOSITE_KEYS); // not 100% correct... diff --git a/cql3/restrictions/single_column_restrictions.hh b/cql3/restrictions/single_column_restrictions.hh index 6408d53fee..63a97feb06 100644 --- a/cql3/restrictions/single_column_restrictions.hh +++ b/cql3/restrictions/single_column_restrictions.hh @@ -111,6 +111,11 @@ public: return r; } + virtual bytes_opt value_for(const column_definition& cdef, const query_options& options) const override { + auto it = _restrictions.find(std::addressof(cdef)); + return (it != _restrictions.end()) ? it->second->value(options) : bytes_opt{}; + } + /** * Returns the restriction associated to the specified column. * diff --git a/cql3/restrictions/statement_restrictions.cc b/cql3/restrictions/statement_restrictions.cc index 8772bfc028..2ced16c4bf 100644 --- a/cql3/restrictions/statement_restrictions.cc +++ b/cql3/restrictions/statement_restrictions.cc @@ -72,6 +72,9 @@ public: // throw? should not reach? return {}; } + bytes_opt value_for(const column_definition& cdef, const query_options& options) const override { + return {}; + } std::vector values_as_keys(const query_options& options) const override { // throw? should not reach? return {};