-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from newzly/release/multipart_conditionals
PHANTOM-79: Added ability to chain multiple CAS clauses to a single quer...
- Loading branch information
Showing
6 changed files
with
570 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
phantom-test/src/test/scala/com/newzly/phantom/dsl/query/CASConditionalQueriesTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.newzly.phantom.dsl.query | ||
|
||
import org.scalatest.{ FlatSpec, Matchers, ParallelTestExecution } | ||
import com.datastax.driver.core.utils.UUIDs | ||
import com.newzly.phantom.Implicits._ | ||
import com.newzly.phantom.tables.{ Primitives, SecondaryIndexTable, TimeSeriesTable } | ||
import com.newzly.util.testing.Sampler | ||
|
||
class CASConditionalQueriesTest extends FlatSpec with Matchers { | ||
it should "allow using a non-index column in a conditional update clause" in { | ||
"Primitives.update.where(_.pkey eqs Sampler.getARandomString).onlyIf(_.long eqs 5L)" should compile | ||
} | ||
|
||
it should " not allow using a PartitionKey in a conditional clause" in { | ||
"Primitives.update.where(_.pkey eqs Sampler.getARandomString).onlyIf(_.pkey eqs Sampler.getARandomString)" shouldNot compile | ||
} | ||
|
||
it should " not allow using a PrimaryKey in a conditional clause " in { | ||
"TwoKeys.update.where(_.pkey eqs Sampler.getARandomString).onlyIf(_.intColumn1 eqs 5)" shouldNot compile | ||
} | ||
|
||
it should " not allow using an Index in a conditional clause " in { | ||
"SecondaryIndexTable.update.where(_.id eqs UUIDs.timeBased()).onlyIf(_.secondary eqs UUIDs.timeBased())" shouldNot compile | ||
} | ||
|
||
it should " not allow using an Index in the second part of a conditional clause " in { | ||
"SecondaryIndexTable.update.where(_.id eqs UUIDs.timeBased()).onlyIf(_.name eqs Sampler.getARandomString).and(_.secondary eqs UUIDs.timeBased())" shouldNot compile | ||
} | ||
|
||
it should " allow using a non Clustering column from a TimeSeries table in a conditional clause" in { | ||
"TimeSeriesTable.update.where(_.id eqs UUIDs.timeBased()).onlyIf(_.name eqs Sampler.getARandomString)" should compile | ||
} | ||
|
||
it should " not allow using a ClusteringColumn in a conditional clause" in { | ||
"TimeSeriesTable.update.where(_.id eqs UUIDs.timeBased()).onlyIf(_.timestamp eqs new DateTime)" shouldNot compile | ||
} | ||
|
||
it should " not allow using a ClusteringColumn in the second part of a conditional clause" in { | ||
"TimeSeriesTable.update.where(_.id eqs UUIDs.timeBased()).onlyIf(_.name eqs Sampler.getARandomString).and(_.timestamp eqs new DateTime)" shouldNot compile | ||
} | ||
|
||
it should "allow using multiple non-primary conditions in a CAS clase" in { | ||
"Primitives.update.where(_.pkey eqs Sampler.getARandomString).onlyIf(_.long eqs 5L).and(_.boolean eqs false)" should compile | ||
} | ||
|
||
it should "not allow using an index column condition in the AND part of a CAS clause" in { | ||
"Primitives.update.where(_.pkey eqs Sampler.getARandomString).onlyIf(_.long eqs 5L).and(_.pkey eqs Sampler.getARandomString)" shouldNot compile | ||
} | ||
|
||
it should "allow using 3 separate CAS conditions in an update query" in { | ||
"Primitives.update.where(_.pkey eqs Sampler.getARandomString).onlyIf(_.long eqs 5L).and(_.boolean eqs false).and(_.int eqs 10)" should compile | ||
} | ||
|
||
it should "not allow using 3 separate CAS conditions in an update query with the 3rd condition on an indexed column" in { | ||
"Primitives.update.where(_.pkey eqs Sampler.getARandomString).onlyIf(_.long eqs 5L).and(_.boolean eqs false).and(_.pkey eqs Sampler.getARandomString)" shouldNot compile | ||
} | ||
} |
34 changes: 0 additions & 34 deletions
34
phantom-test/src/test/scala/com/newzly/phantom/dsl/query/ConditionalQueryRestrictions.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.