Skip to content
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
phantom [![Build Status](https://travis-ci.org/outworkers/phantom.svg?branch=develop)](https://travis-ci.org/outworkers/phantom) [![Coverage Status](https://coveralls.io/repos/outworkers/phantom/badge.svg)](https://coveralls.io/r/outworkers/phantom) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.websudos/phantom_2.10/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.websudos/phantom_2.10) [![Bintray](https://api.bintray.com/packages/websudos/oss-releases/phantom/images/download.svg) ](https://bintray.com/websudos/oss-releases/phantom/_latestVersion) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/outworkers/phantom?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
phantom [![Build Status](https://travis-ci.org/outworkers/phantom.svg?branch=develop)](https://travis-ci.org/outworkers/phantom) [![Coverage Status](https://coveralls.io/repos/outworkers/phantom/badge.svg)](https://coveralls.io/r/outworkers/phantom) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.websudos/phantom_2.10/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.websudos/phantom_2.10) [![Bintray](https://api.bintray.com/packages/websudos/oss-releases/phantom/images/download.svg) ](https://bintray.com/websudos/oss-releases/phantom/_latestVersion) [![Codacy Rating](https://api.codacy.com/project/badge/grade/25bee222a7d142ff8151e6ceb39151b4)](https://www.codacy.com/app/flavian/phantom_2) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/outworkers/phantom?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
==================================================================================================

Reactive type-safe Scala DSL for Cassandra
Expand Down
32 changes: 25 additions & 7 deletions build/publish_develop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,30 @@ then
echo "The current JDK version is ${TRAVIS_JDK_VERSION}"
echo "The current Scala version is ${TRAVIS_SCALA_VERSION}"

CURRENT_VERSION = "$(sbt version)"
echo "Bumping release version with a patch increment from $CURRENT_VERSION"
echo "Creating credentials file"
if [ -e "$HOME/.bintray/.credentials" ]; then
echo "Bintray redentials file already exists"
else
mkdir -p "$HOME/.bintray/"
touch "$HOME/.bintray/.credentials"
echo "realm = Bintray API Realm" >> "$HOME/.bintray/.credentials"
echo "host = api.bintray.com" >> "$HOME/.bintray/.credentials"
echo "user = $bintray_user" >> "$HOME/.bintray/.credentials"
echo "password = $bintray_password" >> "$HOME/.bintray/.credentials"
fi

if [ -e "$HOME/.bintray/.credentials" ]; then
echo "Bintray credentials file succesfully created"
else
echo "Bintray credentials still not found"
fi


echo "Bumping release version with a patch increment from $(sbt version)"
sbt version-bump-patch

NEW_VERSION = "$(sbt version)"
echo "Creating Git tag for version $NEW_VERSION"
SET NEW_VERSION = "$(sbt version)"
echo "Creating Git tag for version $(sbt version)"

echo "Pushing tag to GitHub."
git push --tags "https://${github_token}@${GH_REF}" > /dev/null 2>&1
Expand All @@ -19,16 +37,16 @@ then

if [ "${TRAVIS_SCALA_VERSION}" == "2.11.7" ] && [ "${TRAVIS_JDK_VERSION}" == "oraclejdk8" ];
then
"Publishing $NEW_VERSION to bintray"
sbt bintray:publish
"Publishing $(sbt version) to bintray"
sbt +publish
else
echo "Only publishing version for Scala 2.11.7 and Oracle JDK 8 to prevent multiple artifacts"
fi

git checkout master
git merge develop

git push --all "https://${github_token}@${GH_REF}" master > /dev/null 2>&1
git push --all "https://${github_token}@${GH_REF}" develop:master > /dev/null 2>&1


else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,30 @@ sealed class QueryColumn[RR : Primitive](val col: AbstractColumn[RR]) {
final def eqs(value: PrepareMark): PreparedWhereClause.ParametricCondition[RR] = {
new PreparedWhereClause.ParametricCondition[RR](QueryBuilder.Where.eqs(col.name, value.symbol))
}

final def lt(value: PrepareMark): PreparedWhereClause.ParametricCondition[RR] = {
new PreparedWhereClause.ParametricCondition[RR](QueryBuilder.Where.lt(col.name, value.symbol))
}

final def <(value: PrepareMark): PreparedWhereClause.ParametricCondition[RR] = lt(value)

final def lte(value: PrepareMark): PreparedWhereClause.ParametricCondition[RR] = {
new PreparedWhereClause.ParametricCondition[RR](QueryBuilder.Where.lte(col.name, value.symbol))
}

final def <=(value: PrepareMark): PreparedWhereClause.ParametricCondition[RR] = lte(value)

final def gt(value: PrepareMark): PreparedWhereClause.ParametricCondition[RR] = {
new PreparedWhereClause.ParametricCondition[RR](QueryBuilder.Where.gt(col.name, value.symbol))
}

final def >(value: PrepareMark): PreparedWhereClause.ParametricCondition[RR] = gt(value)

final def gte(value: PrepareMark): PreparedWhereClause.ParametricCondition[RR] = {
new PreparedWhereClause.ParametricCondition[RR](QueryBuilder.Where.gte(col.name, value.symbol))
}

final def >=(value: PrepareMark): PreparedWhereClause.ParametricCondition[RR] = gte(value)
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,283 @@
/*
* Copyright 2013-2016 Websudos, Limited.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Explicit consent must be obtained from the copyright owner, Websudos Limited before any redistribution is made.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package com.websudos.phantom.builder.query.db.crud

import com.twitter.util.{Future => TwitterFuture}
import com.websudos.phantom.PhantomSuite
import com.websudos.phantom.builder.query.db.ordering.TimeSeriesTest
import com.websudos.phantom.builder.query.prepared._
import com.websudos.phantom.dsl._
import com.websudos.phantom.tables._
import com.websudos.util.testing._
import org.slf4j.LoggerFactory
import scala.concurrent.{Future => ScalaFuture}

class RelationalOperatorsTest extends PhantomSuite {
val logger = LoggerFactory.getLogger(this.getClass)

val numRecords = 100
val records: Seq[TimeSeriesRecord] = TimeSeriesTest.genSequentialRecords(numRecords)

override def beforeAll(): Unit = {
super.beforeAll()

TestDatabase.timeSeriesTable.insertSchema()

val chain = for {
truncate <- TestDatabase.timeSeriesTable.truncate.future()
inserts <- TimeSeriesTest.addRecordsToBatch(records).future()
} yield inserts

chain.successful { inserts =>
logger.debug(s"Initialized table with $numRecords records")
}
}

it should "fetch records using less than operator" in {
val maxIndex = 50
val maxTimestamp = records(maxIndex).timestamp

val futureResults = TestDatabase.timeSeriesTable.select
.where(_.timestamp < maxTimestamp)
.allowFiltering()
.fetch()

val expected = records.filter(_.timestamp.isBefore(maxTimestamp))
verifyResults(futureResults, expected)
}

it should "fetch records using less than operator with Twitter Futures" in {
val maxIndex = 50
val maxTimestamp = records(maxIndex).timestamp

val futureResults = TestDatabase.timeSeriesTable.select
.where(_.timestamp < maxTimestamp)
.allowFiltering()
.collect()

val expected = records.filter(_.timestamp.isBefore(maxTimestamp))
verifyResults(futureResults, expected)
}

it should "fetch records using less than operator with prepared statement" in {
val maxIndex = 50
val maxTimestamp = records(maxIndex).timestamp

val query = TestDatabase.timeSeriesTable.select
.p_where(_.timestamp < ?)
.allowFiltering()
.prepare()

val futureResults = query.bind(maxTimestamp).fetch()
val expected = records.filter(_.timestamp.isBefore(maxTimestamp))
verifyResults(futureResults, expected)
}

it should "fetch records using less than or equal operator" in {
val maxIndex = 40
val maxTimestamp = records(maxIndex).timestamp

val futureResults = TestDatabase.timeSeriesTable.select
.where(_.timestamp <= maxTimestamp)
.allowFiltering()
.fetch()

val expected = records.filter(!_.timestamp.isAfter(maxTimestamp))
verifyResults(futureResults, expected)
}

it should "fetch records using less than or equal operator with Twitter Futures" in {
val maxIndex = 40
val maxTimestamp = records(maxIndex).timestamp

val futureResults = TestDatabase.timeSeriesTable.select
.where(_.timestamp <= maxTimestamp)
.allowFiltering()
.collect()

val expected = records.filter(!_.timestamp.isAfter(maxTimestamp))
verifyResults(futureResults, expected)
}

it should "fetch records using less than or equal operator with prepared statement" in {
val maxIndex = 40
val maxTimestamp = records(maxIndex).timestamp

val query = TestDatabase.timeSeriesTable.select
.p_where(_.timestamp <= ?)
.allowFiltering()
.prepare()

val futureResults = query.bind(maxTimestamp).fetch()
val expected = records.filter(!_.timestamp.isAfter(maxTimestamp))
verifyResults(futureResults, expected)
}

it should "fetch records using greater than operator" in {
val minIndex = 60
val minTimestamp = records(minIndex).timestamp

val futureResults = TestDatabase.timeSeriesTable.select
.where(_.timestamp > minTimestamp)
.allowFiltering()
.fetch()

val expected = records.filter(_.timestamp.isAfter(minTimestamp))
verifyResults(futureResults, expected)
}

it should "fetch records using greater than operator with Twitter Futures" in {
val minIndex = 60
val minTimestamp = records(minIndex).timestamp

val futureResults = TestDatabase.timeSeriesTable.select
.where(_.timestamp > minTimestamp)
.allowFiltering()
.collect()

val expected = records.filter(_.timestamp.isAfter(minTimestamp))
verifyResults(futureResults, expected)
}

it should "fetch records using greater than operator with prepared statement" in {
val minIndex = 60
val minTimestamp = records(minIndex).timestamp

val query = TestDatabase.timeSeriesTable.select
.p_where(_.timestamp > ?)
.allowFiltering()
.prepare()

val futureResults = query.bind(minTimestamp).fetch()
val expected = records.filter(_.timestamp.isAfter(minTimestamp))
verifyResults(futureResults, expected)
}

it should "fetch records using greater than or equal operator" in {
val minIndex = 75
val minTimestamp = records(minIndex).timestamp

val futureResults = TestDatabase.timeSeriesTable.select
.where(_.timestamp >= minTimestamp)
.allowFiltering()
.fetch()

val expected = records.filter(!_.timestamp.isBefore(minTimestamp))
verifyResults(futureResults, expected)
}

it should "fetch records using greater than or equal operator with Twitter Futures" in {
val minIndex = 75
val minTimestamp = records(minIndex).timestamp

val futureResults = TestDatabase.timeSeriesTable.select
.where(_.timestamp >= minTimestamp)
.allowFiltering()
.collect()

val expected = records.filter(!_.timestamp.isBefore(minTimestamp))
verifyResults(futureResults, expected)
}

it should "fetch records using greater than or equal operator with prepared statement" in {
val minIndex = 75
val minTimestamp = records(minIndex).timestamp

val query = TestDatabase.timeSeriesTable.select
.p_where(_.timestamp >= ?)
.allowFiltering()
.prepare()

val futureResults = query.bind(minTimestamp).fetch()
val expected = records.filter(!_.timestamp.isBefore(minTimestamp))
verifyResults(futureResults, expected)
}

it should "fetch records using less than and greater than operators" in {
val minIndex = 10
val maxIndex = 40
val minTimestamp = records(minIndex).timestamp
val maxTimestamp = records(maxIndex).timestamp

val futureResults = TestDatabase.timeSeriesTable.select
.where(_.timestamp > minTimestamp)
.and(_.timestamp < maxTimestamp)
.allowFiltering()
.fetch()

val expected = records.filter(r => r.timestamp.isAfter(minTimestamp) && r.timestamp.isBefore(maxTimestamp))
verifyResults(futureResults, expected)
}

it should "fetch records using less than and greater than operators with Twitter Futures" in {
val minIndex = 10
val maxIndex = 40
val minTimestamp = records(minIndex).timestamp
val maxTimestamp = records(maxIndex).timestamp

val futureResults = TestDatabase.timeSeriesTable.select
.where(_.timestamp > minTimestamp)
.and(_.timestamp < maxTimestamp)
.allowFiltering()
.collect()

val expected = records.filter(r => r.timestamp.isAfter(minTimestamp) && r.timestamp.isBefore(maxTimestamp))
verifyResults(futureResults, expected)
}

it should "fetch records using less than and greater than operators with prepared statement" in {
val minIndex = 10
val maxIndex = 40
val minTimestamp = records(minIndex).timestamp
val maxTimestamp = records(maxIndex).timestamp

val query = TestDatabase.timeSeriesTable.select
.p_where(_.timestamp > ?)
.p_and(_.timestamp < ?)
.allowFiltering()
.prepare()

val futureResults = query.bind(minTimestamp, maxTimestamp).fetch()
val expected = records.filter(r => r.timestamp.isAfter(minTimestamp) && r.timestamp.isBefore(maxTimestamp))
verifyResults(futureResults, expected)
}

def verifyResults(futureResults: ScalaFuture[Seq[TimeSeriesRecord]], expected: Seq[TimeSeriesRecord]): Unit = {
futureResults.successful { results =>
results.toSet shouldEqual expected.toSet
}
}

def verifyResults(futureResults: TwitterFuture[Seq[TimeSeriesRecord]], expected: Seq[TimeSeriesRecord]): Unit = {
futureResults.successful { results =>
results.toSet shouldEqual expected.toSet
}
}
}
Loading