From d1fe54b0ce7732810dae839aa952264407205326 Mon Sep 17 00:00:00 2001 From: Greg Burd Date: Thu, 2 Nov 2017 15:46:49 -0400 Subject: [PATCH] Add ALLOW FILTERING in the cases Cassandra requires it based on query. More result info formatting. --- .../net/helenus/core/operation/Operation.java | 7 ++++--- .../core/operation/SelectOperation.java | 19 +++++++++++++++++-- .../core/unitofwork/UnitOfWorkTest.java | 7 +++++-- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/helenus/core/operation/Operation.java b/src/main/java/net/helenus/core/operation/Operation.java index 02f1127..f0d82ce 100644 --- a/src/main/java/net/helenus/core/operation/Operation.java +++ b/src/main/java/net/helenus/core/operation/Operation.java @@ -122,9 +122,10 @@ public abstract class Operation { ConsistencyLevel cl = ei.getAchievedConsistencyLevel(); int se = ei.getSpeculativeExecutions(); String warn = ei.getWarnings().stream().collect(Collectors.joining(", ")); - String ri = String.format("%s %s %s %s %sd%s%s spec-retries: %d", "C* v" + qh.getCassandraVersion(), - qh.getAddress().toString(), qh.getDatacenter(), qh.getRack(), - (oh != null && !oh.equals("")) ? "[" + oh + "] " : "", + String ri = String.format("%s %s %s %s %s %s%sspec-retries: %d", + "server v" + qh.getCassandraVersion(), qh.getAddress().toString(), + (oh != null && !oh.equals("")) ? " [tried: " + oh + "]" : "", qh.getDatacenter(), + qh.getRack(), (cl != null) ? (" consistency: " + cl.name() + (cl.isDCLocal() ? " DC " : "") + (cl.isSerial() ? " SC " : "")) diff --git a/src/main/java/net/helenus/core/operation/SelectOperation.java b/src/main/java/net/helenus/core/operation/SelectOperation.java index 6a39912..17fe8bb 100644 --- a/src/main/java/net/helenus/core/operation/SelectOperation.java +++ b/src/main/java/net/helenus/core/operation/SelectOperation.java @@ -289,8 +289,23 @@ public final class SelectOperation extends AbstractFilterStreamOperation filter : filters.values()) { where.and(filter.getClause(sessionOps.getValuePreparer())); - if (filter.getNode().getProperty().caseSensitiveIndex()) { - allowFiltering = true; + HelenusProperty prop = filter.getNode().getProperty(); + boolean isFirstIndex = true; + switch (prop.getColumnType()) { + case PARTITION_KEY : + case CLUSTERING_COLUMN : + break; + default : + // When using non-Cassandra-standard 2i types or when using more than one + // indexed column or non-indexed columns the query must include ALLOW FILTERING. + if (prop.caseSensitiveIndex()) { + allowFiltering = true; + } else if (prop.getIndexName() != null) { + allowFiltering |= !isFirstIndex; + isFirstIndex = false; + } else { + allowFiltering = true; + } } } } diff --git a/src/test/java/net/helenus/test/integration/core/unitofwork/UnitOfWorkTest.java b/src/test/java/net/helenus/test/integration/core/unitofwork/UnitOfWorkTest.java index a80d1f9..9de6e1b 100644 --- a/src/test/java/net/helenus/test/integration/core/unitofwork/UnitOfWorkTest.java +++ b/src/test/java/net/helenus/test/integration/core/unitofwork/UnitOfWorkTest.java @@ -19,6 +19,7 @@ import static net.helenus.core.Query.eq; import java.util.UUID; +import com.datastax.driver.core.ConsistencyLevel; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; @@ -54,7 +55,8 @@ public class UnitOfWorkTest extends AbstractEmbeddedCassandraTest { @BeforeClass public static void beforeTest() { - session = Helenus.init(getSession()).showCql().add(Widget.class).autoCreateDrop().get(); + session = Helenus.init(getSession()).showCql().add(Widget.class).autoCreateDrop().consistencyLevel( + ConsistencyLevel.ONE).idempotentQueryExecution(true).get(); widget = session.dsl(Widget.class); } @@ -71,7 +73,8 @@ public class UnitOfWorkTest extends AbstractEmbeddedCassandraTest { uow.setPurpose("testSelectAfterSelect"); // This should read from the database and return a Widget. - w2 = session.select(widget).where(widget::id, eq(key)).single().sync(uow).orElse(null); + w2 = session.select(widget).where(widget::id, eq(key)).single() + .sync(uow).orElse(null); // This should read from the cache and get the same instance of a Widget. w3 = session.select(widget).where(widget::id, eq(key)).single().sync(uow).orElse(null);