You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by xe...@apache.org on 2016/08/17 21:40:59 UTC
cassandra git commit: Fix queries on columns with reversed type on
SASI indexes
Repository: cassandra
Updated Branches:
refs/heads/trunk d4d71cd33 -> 55a45b58d
Fix queries on columns with reversed type on SASI indexes
Patch by Alex Petrov; reviewed by xedin for CASSANDRA-12223
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/55a45b58
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/55a45b58
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/55a45b58
Branch: refs/heads/trunk
Commit: 55a45b58d678eb919fa6b5a4c224fb43791e0234
Parents: d4d71cd
Author: Alex Petrov <ol...@gmail.com>
Authored: Fri Aug 5 16:01:50 2016 +0200
Committer: Pavel Yaskevich <xe...@apache.org>
Committed: Wed Aug 17 14:40:17 2016 -0700
----------------------------------------------------------------------
CHANGES.txt | 1 +
.../cassandra/index/sasi/plan/Expression.java | 21 ++++++--
.../cassandra/index/sasi/SASIIndexTest.java | 54 ++++++++++++++++++++
3 files changed, 72 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/55a45b58/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 51b87db..d5e220c 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
3.10
+ * Fix queries on columns with reversed type on SASI indexes (CASSANDRA-12223)
* Added slow query log (CASSANDRA-12403)
* Count full coordinated request against timeout (CASSANDRA-12256)
* Allow TTL with null value on insert and update (CASSANDRA-12216)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/55a45b58/src/java/org/apache/cassandra/index/sasi/plan/Expression.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/index/sasi/plan/Expression.java b/src/java/org/apache/cassandra/index/sasi/plan/Expression.java
index cc156ee..93f1938 100644
--- a/src/java/org/apache/cassandra/index/sasi/plan/Expression.java
+++ b/src/java/org/apache/cassandra/index/sasi/plan/Expression.java
@@ -166,17 +166,30 @@ public class Expression
break;
case LTE:
- upperInclusive = true;
+ if (index.getDefinition().isReversedType())
+ lowerInclusive = true;
+ else
+ upperInclusive = true;
case LT:
operation = Op.RANGE;
- upper = new Bound(value, upperInclusive);
+ if (index.getDefinition().isReversedType())
+ lower = new Bound(value, lowerInclusive);
+ else
+ upper = new Bound(value, upperInclusive);
break;
case GTE:
- lowerInclusive = true;
+ if (index.getDefinition().isReversedType())
+ upperInclusive = true;
+ else
+ lowerInclusive = true;
case GT:
operation = Op.RANGE;
- lower = new Bound(value, lowerInclusive);
+ if (index.getDefinition().isReversedType())
+ upper = new Bound(value, upperInclusive);
+ else
+ lower = new Bound(value, lowerInclusive);
+
break;
}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/55a45b58/test/unit/org/apache/cassandra/index/sasi/SASIIndexTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/index/sasi/SASIIndexTest.java b/test/unit/org/apache/cassandra/index/sasi/SASIIndexTest.java
index 47e3895..da1d0e3 100644
--- a/test/unit/org/apache/cassandra/index/sasi/SASIIndexTest.java
+++ b/test/unit/org/apache/cassandra/index/sasi/SASIIndexTest.java
@@ -2119,6 +2119,60 @@ public class SASIIndexTest
}
@Test
+ public void testConditionalsWithReversedType()
+ {
+ final String TABLE_NAME = "reversed_clustering";
+
+ QueryProcessor.executeOnceInternal(String.format("CREATE TABLE IF NOT EXISTS %s.%s (pk text, ck int, v int, PRIMARY KEY (pk, ck)) " +
+ "WITH CLUSTERING ORDER BY (ck DESC);", KS_NAME, TABLE_NAME));
+ QueryProcessor.executeOnceInternal(String.format("CREATE CUSTOM INDEX ON %s.%s (ck) USING 'org.apache.cassandra.index.sasi.SASIIndex'", KS_NAME, TABLE_NAME));
+ QueryProcessor.executeOnceInternal(String.format("CREATE CUSTOM INDEX ON %s.%s (v) USING 'org.apache.cassandra.index.sasi.SASIIndex'", KS_NAME, TABLE_NAME));
+
+ QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (pk, ck, v) VALUES ('Alex', 1, 1);", KS_NAME, TABLE_NAME));
+ QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (pk, ck, v) VALUES ('Alex', 2, 2);", KS_NAME, TABLE_NAME));
+ QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (pk, ck, v) VALUES ('Alex', 3, 3);", KS_NAME, TABLE_NAME));
+ QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (pk, ck, v) VALUES ('Tom', 1, 1);", KS_NAME, TABLE_NAME));
+ QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (pk, ck, v) VALUES ('Tom', 2, 2);", KS_NAME, TABLE_NAME));
+ QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (pk, ck, v) VALUES ('Tom', 3, 3);", KS_NAME, TABLE_NAME));
+
+ UntypedResultSet resultSet = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE ck <= 2;", KS_NAME, TABLE_NAME));
+
+ CQLTester.assertRowsIgnoringOrder(resultSet,
+ CQLTester.row("Alex", 1, 1),
+ CQLTester.row("Alex", 2, 2),
+ CQLTester.row("Tom", 1, 1),
+ CQLTester.row("Tom", 2, 2));
+
+ resultSet = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE ck <= 2 AND v > 1 ALLOW FILTERING;", KS_NAME, TABLE_NAME));
+
+ CQLTester.assertRowsIgnoringOrder(resultSet,
+ CQLTester.row("Alex", 2, 2),
+ CQLTester.row("Tom", 2, 2));
+
+ resultSet = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE ck < 2;", KS_NAME, TABLE_NAME));
+ CQLTester.assertRowsIgnoringOrder(resultSet,
+ CQLTester.row("Alex", 1, 1),
+ CQLTester.row("Tom", 1, 1));
+
+ resultSet = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE ck >= 2;", KS_NAME, TABLE_NAME));
+ CQLTester.assertRowsIgnoringOrder(resultSet,
+ CQLTester.row("Alex", 2, 2),
+ CQLTester.row("Alex", 3, 3),
+ CQLTester.row("Tom", 2, 2),
+ CQLTester.row("Tom", 3, 3));
+
+ resultSet = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE ck >= 2 AND v < 3 ALLOW FILTERING;", KS_NAME, TABLE_NAME));
+ CQLTester.assertRowsIgnoringOrder(resultSet,
+ CQLTester.row("Alex", 2, 2),
+ CQLTester.row("Tom", 2, 2));
+
+ resultSet = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE ck > 2;", KS_NAME, TABLE_NAME));
+ CQLTester.assertRowsIgnoringOrder(resultSet,
+ CQLTester.row("Alex", 3, 3),
+ CQLTester.row("Tom", 3, 3));
+ }
+
+ @Test
public void testIndexMemtableSwitching()
{
// write some data but don't flush