From e369530539fd1a146486dfe11b46d598eb321468 Mon Sep 17 00:00:00 2001 From: Gianluca Arbezzano Date: Thu, 7 May 2015 14:51:26 +0200 Subject: [PATCH] Remove filters --- README.md | 51 +--------------- spec/InfluxDB/ClientSpec.php | 12 ---- .../Filter/ColumnsPointsFilterSpec.php | 58 ------------------- src/InfluxDB/Client.php | 29 ---------- src/InfluxDB/ClientFactory.php | 8 --- src/InfluxDB/Filter/ColumnsPointsFilter.php | 28 --------- src/InfluxDB/Filter/FilterInterface.php | 14 ----- tests/InfluxDB/ClientFactoryTest.php | 18 ------ tests/InfluxDB/ClientTest.php | 16 ----- tests/InfluxDB/HttpAdapterTest.php | 15 ----- 10 files changed, 1 insertion(+), 248 deletions(-) delete mode 100644 spec/InfluxDB/Filter/ColumnsPointsFilterSpec.php delete mode 100644 src/InfluxDB/Filter/ColumnsPointsFilter.php delete mode 100644 src/InfluxDB/Filter/FilterInterface.php diff --git a/README.md b/README.md index ac7051628..5d766d332 100644 --- a/README.md +++ b/README.md @@ -114,12 +114,7 @@ $options = [ ], "options" => [ "host" => "my.influx.domain.tld", - ], - "filters" => [ - "query" => [ - "name" => "InfluxDB\\Filter\\ColumnsPointsFilter" - ], - ], + ] ]; $client = \InfluxDB\ClientFactory::create($options); @@ -187,30 +182,6 @@ array(1) { } ``` -By default data is returned as is. You can add filters in order to change a -response as you prefer, by default this library carries a common filter that -simplifies the response. - -``` -$client->setFilter(new ColumnsPointsFilter()); - -$data = $client->query("select * from hd_used"); -``` - -With the "ColumnsPointsFilter" you get a list of dictionaries, something like: - -``` -[ - "serie_name" => [ - [ - "time" => 410545635590, - "sequence_number" => 390001, - "mark" => "element", - ], - ] -] -``` - ## Database operations You can create, list or destroy databases using dedicated methods @@ -237,23 +208,3 @@ Corley\Benchmarks\InfluxDB\AdapterEvent sendDataUsingHttpAdapter: [1,000 ] [0.0026700308323] [374.52751] sendDataUsingUdpAdapter : [1,000 ] [0.0000436344147] [22,917.69026] ``` - -### Filters - -Just what append when you apply the `ColumnsPointsFilter` - -``` -Corley\Benchmarks\InfluxDB\FilterEvent - Method Name Iterations Average Time Ops/second - ------------------------ ------------ -------------- ------------- - get10PointDirectData : [10,000 ] [0.0001383633137] [7,227.34931] - get10PointFilteredData : [10,000 ] [0.0001662570953] [6,014.78089] - get100PointDirectData : [1,000 ] [0.0002406690121] [4,155.08416] - get100PointFilteredData : [1,000 ] [0.0008374640942] [1,194.08104] - get1000PointDirectData : [100 ] [0.0011058974266] [904.24299] - get1000PointFilteredData: [100 ] [0.0074790692329] [133.70648] -``` - -in order to eliminate the http handshake and bandwidth overhead network -operations are completely skipped - diff --git a/spec/InfluxDB/ClientSpec.php b/spec/InfluxDB/ClientSpec.php index 126ac4f05..84e5753db 100644 --- a/spec/InfluxDB/ClientSpec.php +++ b/spec/InfluxDB/ClientSpec.php @@ -6,7 +6,6 @@ use Prophecy\Argument; use InfluxDB\Adapter\GuzzleAdapter; use InfluxDB\Adapter\UdpAdapter; use InfluxDB\Adapter\AdapterInterface; -use InfluxDB\Filter\FilterInterface; use InfluxDb\Adapter\QueryableInterface; class ClientSpec extends ObjectBehavior @@ -84,15 +83,4 @@ class ClientSpec extends ObjectBehavior $this->shouldThrow("\\BadMethodCallException")->duringQuery("select * from tcp.test"); } - - function it_should_filter_returned_data(FilterInterface $filter, QueryableInterface $adapter) - { - $adapter->query(Argument::Any(), Argument::Any())->willReturn(null); - $filter->filter(Argument::Any())->shouldBeCalledTimes(1)->willReturn([]); - - $this->setFilter($filter); - $this->setAdapter($adapter); - - $this->query("select * from tcp.test")->shouldReturn([]); - } } diff --git a/spec/InfluxDB/Filter/ColumnsPointsFilterSpec.php b/spec/InfluxDB/Filter/ColumnsPointsFilterSpec.php deleted file mode 100644 index efe19eeb0..000000000 --- a/spec/InfluxDB/Filter/ColumnsPointsFilterSpec.php +++ /dev/null @@ -1,58 +0,0 @@ -shouldHaveType('InfluxDB\Filter\ColumnsPointsFilter'); - } - - function it_is_a_valid_filter() - { - $this->shouldImplement("InfluxDb\\Filter\\FilterInterface"); - } - - function it_should_map_columns_with_points() - { - $response = json_decode('[{"name":"hd_used","columns":["time","sequence_number","value","host","mount","time_precision"],"points":[[1410591684,11820001,23.2,"serverA","/mnt","s"]]}]', true); - - $this->filter($response)->shouldBeEqualTo([ - "hd_used" => [ - [ - "time" => 1410591684, - "sequence_number" => 11820001, - "value" => 23.2, - "host" => "serverA", - "mount" => "/mnt", - "time_precision" => "s", - ], - ], - ]); - } - - function it_should_map_also_a_series_list() - { - $response = json_decode('[{"name":"list_series_result","columns":["time","name"],"points":[[0,"hd_used"]]}]', true); - - $this->filter($response)->shouldBeEqualTo([ - "list_series_result" => [ - [ - "time" => 0, - "name" => "hd_used", - ], - ], - ]); - } - - function it_should_reply_to_an_empty_set() - { - $response = json_decode('[]', true); - - $this->filter($response)->shouldBeEqualTo([]); - } -} diff --git a/src/InfluxDB/Client.php b/src/InfluxDB/Client.php index b7215244f..8baa37d4a 100644 --- a/src/InfluxDB/Client.php +++ b/src/InfluxDB/Client.php @@ -15,31 +15,6 @@ class Client */ private $adapter; - /** - * @var \InfluxDB\Filter\FilterInterface - */ - private $filter; - - /** - * Set filter - * @param Filter\FilterInterface $filter - * @return Client - */ - public function setFilter(Filter\FilterInterface $filter) - { - $this->filter = $filter; - return $this; - } - - /** - * Get filter - * @return Filter\FilterInterface - */ - public function getFilter() - { - return $this->filter; - } - /** * Set InfluxDB adapter * @param Adapter\AdapterInterface @@ -96,10 +71,6 @@ class Client $return = $this->getAdapter()->query($query, $timePrecision); - if ($this->getFilter() instanceOf FilterInterface) { - $return = $this->getFilter()->filter($return); - } - return $return; } diff --git a/src/InfluxDB/ClientFactory.php b/src/InfluxDB/ClientFactory.php index a466cfc54..9fdeb4d25 100644 --- a/src/InfluxDB/ClientFactory.php +++ b/src/InfluxDB/ClientFactory.php @@ -14,7 +14,6 @@ abstract class ClientFactory * @param array $options * @return Client * @throws InvalidArgumentException If not exist adapter name - * or not find adapter */ public static function create(array $options) { @@ -24,9 +23,6 @@ abstract class ClientFactory "options" => [], ], "options" => [], - "filters" => [ - "query" => false - ], ]; $options = array_replace_recursive($defaultOptions, $options); @@ -58,10 +54,6 @@ abstract class ClientFactory $client = new Client(); $client->setAdapter($adapter); - if ($options["filters"]["query"]) { - $client->setFilter(new $options["filters"]["query"]["name"]); - } - return $client; } } diff --git a/src/InfluxDB/Filter/ColumnsPointsFilter.php b/src/InfluxDB/Filter/ColumnsPointsFilter.php deleted file mode 100644 index dcc974d39..000000000 --- a/src/InfluxDB/Filter/ColumnsPointsFilter.php +++ /dev/null @@ -1,28 +0,0 @@ - ["name" => "InfluxDB\\Adapter\\GuzzleAdapter"]]); - - $this->assertNull($client->getFilter()); - } - /** * @group factory * @expectedException InvalidArgumentException @@ -95,7 +85,6 @@ class ClientFactoryTest extends \PHPUnit_Framework_TestCase /** * @group factory - * @group filters * @dataProvider getTcpAdapters */ public function testCreateTcpClientWithFilter($adapter) @@ -109,11 +98,6 @@ class ClientFactoryTest extends \PHPUnit_Framework_TestCase "username" => "user", "password" => "pass", ], - "filters" => [ - "query" => [ - "name" => "InfluxDB\\Filter\\ColumnsPointsFilter", - ], - ], ]; $client = ClientFactory::create($options); @@ -123,7 +107,5 @@ class ClientFactoryTest extends \PHPUnit_Framework_TestCase $this->assertEquals("127.0.0.1", $client->getAdapter()->getOptions()->getHost()); $this->assertEquals("user", $client->getAdapter()->getOptions()->getUsername()); $this->assertEquals("pass", $client->getAdapter()->getOptions()->getPassword()); - - $this->assertInstanceOf("InfluxDB\\Filter\\ColumnsPointsFilter", $client->getFilter()); } } diff --git a/tests/InfluxDB/ClientTest.php b/tests/InfluxDB/ClientTest.php index 2a4bf78ea..45ea0397e 100644 --- a/tests/InfluxDB/ClientTest.php +++ b/tests/InfluxDB/ClientTest.php @@ -5,7 +5,6 @@ use InfluxDB\Adapter\GuzzleAdapter as InfluxHttpAdapter; use InfluxDB\Options; use InfluxDB\Adapter\UdpAdapter; use GuzzleHttp\Client as GuzzleHttpClient; -use InfluxDB\Filter\ColumnsPointsFilter; class ClientTest extends \PHPUnit_Framework_TestCase { @@ -147,21 +146,6 @@ class ClientTest extends \PHPUnit_Framework_TestCase $this->assertEquals("udp.test", $body[0]["name"]); } - /** - * @group filter - */ - public function testColumnsPointsFilterWorksCorrectly() - { - $this->object->setFilter(new ColumnsPointsFilter()); - $this->object->mark("tcp.test", ["time" => 1410591552, "mark" => "element"], "s"); - - $body = $this->object->query("select mark from tcp.test", "ms"); - - $this->assertCount(1, $body); - $this->assertEquals("element", $body["tcp.test"][0]["mark"]); - $this->assertSame(1410591552000, $body["tcp.test"][0]["time"]); - } - public function testListActiveDatabses() { $databases = $this->object->getDatabases(); diff --git a/tests/InfluxDB/HttpAdapterTest.php b/tests/InfluxDB/HttpAdapterTest.php index d6f868982..9cd2fca8f 100644 --- a/tests/InfluxDB/HttpAdapterTest.php +++ b/tests/InfluxDB/HttpAdapterTest.php @@ -110,21 +110,6 @@ class HttpAdapterTest extends \PHPUnit_Framework_TestCase $this->assertEquals("1410591552000", $body[0]["points"][0][0]); } - /** - * @group filter - */ - public function testColumnsPointsFilterWorksCorrectly() - { - $this->object->setFilter(new ColumnsPointsFilter()); - $this->object->mark("tcp.test", ["time" => 1410591552, "mark" => "element"], "s"); - - $body = $this->object->query("select mark from tcp.test", "ms"); - - $this->assertCount(1, $body); - $this->assertEquals("element", $body["tcp.test"][0]["mark"]); - $this->assertSame(1410591552000, $body["tcp.test"][0]["time"]); - } - public function testListActiveDatabses() { $databases = $this->object->getDatabases();