4 Commits

Author SHA1 Message Date
EmanueleMinotto
2117eef3e3 Implement cassandra range query 2019-09-04 22:17:30 +02:00
EmanueleMinotto
ff58187a3b Upgrade doctrine/couchdb to include range query 2019-09-04 22:17:04 +02:00
EmanueleMinotto
e878a42d81 Add drivers to Travis 2019-09-04 22:16:08 +02:00
EmanueleMinotto
55f0840706 Use array as operation result 2019-09-04 22:15:56 +02:00
6 changed files with 89 additions and 7 deletions

View File

@@ -1,6 +1,8 @@
language: php
services:
- cassandra
- couchdb
- mongodb
- redis-server

View File

@@ -6,7 +6,7 @@
},
"require-dev": {
"datastax/php-driver": "^1.0",
"doctrine/couchdb": "^1.0.0-beta4",
"doctrine/couchdb": "^2.0@alpha",
"phpunit/phpunit": "^4.8|^5.0",
"aws/aws-sdk-php": "^3.8",
"riak/riak-client": "dev-master"

View File

@@ -202,7 +202,7 @@ class RangeQuery
/**
* Execute query and return a result iterator.
*
* @return ResultIterator
* @return array
*/
public function execute()
{

View File

@@ -29,14 +29,14 @@ namespace Doctrine\KeyValueStore\Query;
interface RangeQueryStorage
{
/**
* Execute the range query and return a ResultIterator
* Execute the range query and return an array
*
* @param RangeQuery $query
* @param string $storageName
* @param array $key
* @param Closure $hydrateRow
*
* @return ResultIterator
* @return array
*/
public function executeRangeQuery(RangeQuery $query, $storageName, $key, \Closure $hydrateRow = null);
}

View File

@@ -23,6 +23,8 @@ namespace Doctrine\KeyValueStore\Storage;
use Cassandra\ExecutionOptions;
use Cassandra\Session;
use Doctrine\KeyValueStore\NotFoundException;
use Doctrine\KeyValueStore\Query\RangeQuery;
use Doctrine\KeyValueStore\Query\RangeQueryStorage;
/**
* Cassandra Storage Engine for KeyValueStore.
@@ -31,7 +33,7 @@ use Doctrine\KeyValueStore\NotFoundException;
*
* @uses https://github.com/datastax/php-driver
*/
class CassandraStorage implements Storage
class CassandraStorage implements Storage, RangeQueryStorage
{
/**
* @var \Cassandra\Session
@@ -176,6 +178,13 @@ class CassandraStorage implements Storage
return $data;
}
/**
* {@inheritDoc}
*/
public function executeRangeQuery(RangeQuery $query, $storageName, $key, \Closure $hydrateRow = null)
{
}
/**
* {@inheritDoc}
*/

View File

@@ -21,6 +21,9 @@
namespace Doctrine\KeyValueStore\Storage;
use Doctrine\CouchDB\CouchDBClient;
use Doctrine\CouchDB\Mango\MangoQuery;
use Doctrine\KeyValueStore\Query\RangeQuery;
use Doctrine\KeyValueStore\Query\RangeQueryStorage;
/**
* Key-Value-Storage using a Doctrine CouchDB Client library as backend.
@@ -30,7 +33,7 @@ use Doctrine\CouchDB\CouchDBClient;
*
* @author Emanuele Minotto <minottoemanuele@gmail.com>
*/
final class CouchDbStorage implements Storage
final class CouchDbStorage implements Storage, RangeQueryStorage
{
/**
* @var CouchDBClient
@@ -116,7 +119,7 @@ final class CouchDbStorage implements Storage
/**
* @param string $storageName
* @param array|string $key
*
*
* @return string
*/
private function flattenKey($storageName, $key)
@@ -137,4 +140,72 @@ final class CouchDbStorage implements Storage
return $finalKey;
}
/**
* {@inheritDoc}
*/
public function executeRangeQuery(RangeQuery $query, $storageName, $key, \Closure $hydrateRow = null)
{
$mangoQuery = new MangoQuery();
$partitionKey = $query->getPartitionKey();
$conditions = [];
foreach ($query->getConditions() as $condition) {
switch ($condition[0]) {
case RangeQuery::CONDITION_LE:
$conditions[] = [
$partitionKey => [
'$lte' => $condition[1],
],
];
break;
case RangeQuery::CONDITION_GE:
$conditions[] = [
$partitionKey => [
'$gte' => $condition[1],
],
];
break;
case RangeQuery::CONDITION_NEQ:
$conditions[] = [
$partitionKey => [
'$ne' => $condition[1],
],
];
break;
case RangeQuery::CONDITION_STARTSWITH:
$conditions[] = [
$partitionKey => [
'$regex' => '^'.$condition[1],
],
];
break;
default:
$conditions[] = [
$partitionKey => [
'$'.$condition[0] => $condition[1],
],
];
break;
}
}
$mangoQuery
->select(['_id', $key])
->where(['$and' => $conditions])
->limit($query->getLimit());
$results = [];
$mangoResults = $this->client->find($query);
foreach ($mangoResults as $mangoResult) {
$results[] = $hydrateRow($mangoResult);
}
return $results;
}
}