influxdata / influxdb-php

influxdb-php: A PHP Client for InfluxDB, a time series database

Home Page:http://influxdb.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exception using getPoints on empty metric

andig opened this issue · comments

commented

PHP Warning: Invalid argument supplied for foreach() in src/InfluxDB/ResultSet.php on line 68

Getting this warning when writing against Telegraf v1 listener

commented

I think root cause is getSeries which has meanwhile been modified:

    public function getSeries()
    {
        $series = array_map(
            function ($object) {
                if (isset($object['error'])) {
                    throw new ClientException($object['error']);
                }

                return isset($object['series']) ? $object['series'] : [];
            },
            $this->parsedResults['results']
        );

        return array_shift($series);
    }

array_shift($series); on empty array will yield NULL and hence yield the notice.

commented

Seems this was changed in ba96a93. However, upgrading to 1.15, I'm getting:

In ResultSet.php line 107: Invalid statement index provided  
commented

I feel the reason is that in

$series = $this->getSeries();
getSeries() is called without parameter which means default value of 0.

In getSeries(), in

if ($queryIndex !== null && !array_key_exists($queryIndex, $results)) {
this will throw when the result does not contain any and hence no 0 series.

Is that the desired behaviour?