From 47e006bfaeb96df82f7b6b77ddb3319a3ff72457 Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Wed, 22 Jul 2015 17:25:50 +0200 Subject: [PATCH 1/3] cql: token_restriction: Fix the check detecting contradicting restrictions The condition is incorrect after 9b52f5bf2bee8b1f1dd9d836ba8b227e5dab1fe3. We no longer express the full range as (min, min], and missing upper bound as bound as (x, min] so we don't need to exclude those cases in the check. --- cql3/restrictions/token_restriction.hh | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/cql3/restrictions/token_restriction.hh b/cql3/restrictions/token_restriction.hh index 485ae1affd..0b8c8da021 100644 --- a/cql3/restrictions/token_restriction.hh +++ b/cql3/restrictions/token_restriction.hh @@ -95,14 +95,10 @@ public: * * In practice, we want to return an empty result set if either startToken > endToken, or both are equal but * one of the bound is excluded (since [a, a] can contains something, but not (a, a], [a, a) or (a, a)). - * Note though that in the case where startToken or endToken is the minimum token, then this special case - * rule should not apply. */ - if (start_token.is_minimum() - && end_token.is_maximum() - && (start_token > end_token - || (start_token == end_token - && (!include_start || !include_end)))) { + if (start_token > end_token + || (start_token == end_token + && (!include_start || !include_end))) { return {query::partition_range::make_open_ended_both_sides()}; } From 76bf7b228caff2c64d07ce99473e709e72ebd588 Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Wed, 22 Jul 2015 17:55:50 +0200 Subject: [PATCH 2/3] cql: token_restriction: Fix range produced for contradicting restrictions We want to return no results in this case, so we should return no range instead of range open on both sides, which yields all data. --- cql3/restrictions/token_restriction.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cql3/restrictions/token_restriction.hh b/cql3/restrictions/token_restriction.hh index 0b8c8da021..4a634cefb1 100644 --- a/cql3/restrictions/token_restriction.hh +++ b/cql3/restrictions/token_restriction.hh @@ -99,7 +99,7 @@ public: if (start_token > end_token || (start_token == end_token && (!include_start || !include_end))) { - return {query::partition_range::make_open_ended_both_sides()}; + return {}; } typedef typename bounds_range_type::bound bound; From a71ac805373808dfdbe3d350f8bc80bab29e93c8 Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Wed, 22 Jul 2015 17:58:16 +0200 Subject: [PATCH 3/3] test: Add test for contradicting token restrictions --- tests/urchin/cql_query_test.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/urchin/cql_query_test.cc b/tests/urchin/cql_query_test.cc index ee6c930742..42db8a2798 100644 --- a/tests/urchin/cql_query_test.cc +++ b/tests/urchin/cql_query_test.cc @@ -591,6 +591,14 @@ SEASTAR_TEST_CASE(test_partition_range_queries_with_bounds) { {keys[3]} }); }); + }).then([keys, tokens, &e] { + return e.execute_cql(sprint("select k from cf where token(k) < 0x%s and token(k) > 0x%s;", to_hex(tokens[3]), to_hex(tokens[3]))).then([keys](auto msg) { + assert_that(msg).is_rows().is_empty(); + }); + }).then([keys, tokens, &e] { + return e.execute_cql(sprint("select k from cf where token(k) >= 0x%s and token(k) <= 0x%s;", to_hex(tokens[4]), to_hex(tokens[2]))).then([keys](auto msg) { + assert_that(msg).is_rows().is_empty(); + }); }); }); });