Commit Graph

16 Commits (c7e43d4cf7edb1311b14d63aba5041a949eb162f)

Author SHA1 Message Date
Jonathan A. Sternberg 0a7f379768
Fixing the stream iterator to not ignore the error
The stream iterator would ignore an error that happened when reading
points. This may have caused it to potentially return an error that got
ignored and then to try invoking `Next()` on an iterator in an invalid
state and that iterator would then actually return a point which it
wasn't supposed to.

Also added some defensive coding to that same call to prevent a nil map
from being assigned to in the event of an invalid iterator returning
junk data.
2018-10-10 16:26:55 -05:00
Jonathan A. Sternberg 22fc9f6a19
Strip tags from a subquery when the outer query does not group by that tag
The following would, erroneously, not strip the tag from the inner
query:

    SELECT value FROM (SELECT value FROM cpu GROUP BY host)

The inner query was supposed to group by the host tag, but the outer
query should strip it away since it is not being grouped by anymore.
This fixes things so that the result will have the tags stripped away
when they are not requested in the grouping.
2018-10-04 10:05:46 -05:00
Jonathan A. Sternberg 0f304690c5 Enable casting values from a subquery
This also fixes the cursor system to abandon iterators that will not
produce meaningful results since the variables are all unknown types.

This creates a weird behavior that existed in previous releases and we
are keeping here for backwards compatibility. If a subquery referenced a
field that didn't exist in the subquery, it will return nothing. But, if
there are two subqueries and one of them has the field exist and the
other doesn't, the second will return all null values.
2018-03-30 16:58:37 -05:00
Jonathan A. Sternberg a49a8dce6b Remove unused query code
This code was previously used to implement binary expressions and other
transfomation iterators. It is no longer needed.
2018-03-28 13:24:45 -05:00
Jonathan A. Sternberg f8d60a881d Refactor the math engine to compile the query and use eval
This change makes it so that we simplify the math engine so it doesn't
use a complicated set of nested iterators. That way, we have to change
math in one fewer place.

It also greatly simplifies the query engine as now we can create the
necessary iterators, join them by time, name, and tags, and then use the
cursor interface to read them and use eval to compute the result. It
makes it so the auxiliary iterators and all of their complexity can be
removed.

This also makes use of the new eval functionality that was recently
added to the influxql package.

No math functions have been added, but the scaffolding has been included
so things like trigonometry functions are just a single commit away.

This also introduces a small breaking change. Because of the call
optimization, it is now possible to use the same selector multiple times
as a selector. So if you do this:

    SELECT max(value) * 2, max(value) / 2 FROM cpu

This will now return the timestamp of the max value rather than zero
since this query is considered to have only a single selector rather
than multiple separate selectors. If any aspect of the selector is
different, such as different selector functions or different arguments,
it will consider the selectors to be aggregates like the old behavior.
2018-03-19 15:01:15 -05:00
Jonathan A. Sternberg df7a660fb3 Modify the Select call to return a Cursor
The Cursor returned will be capable of scanning rows into a structure.
It replaces part of the function for why the Emitter existed. The
Emitter would both join the resulting rows and then transform the values
into a models.Row so it could be returned to the results.

In the future, we will be able to use the Cursor directly to write out
values which should be more memory efficient.
2018-03-09 12:47:41 -06:00
Edd Robinson 21f0c6415b Cleanup query package 2018-01-21 12:08:23 -08:00
Jonathan A. Sternberg a73c3a1965 Fix race condition in the merge iterator close method
If the close happens when next is being called, it can result in a race
condition where the current iterator gets set to nil after the initial
check.

This also fixes the finalizer so it runs the close method in a goroutine
instead of running it by itself. This is because all finalizers run on
the same goroutine so a close that takes a long time can cause a backup
for all finalizers. This also removes the redundant call to
`runtime.SetFinalizer` from the finalizer itself because a finalizer,
when called, has already cleared itself.
2017-11-27 16:55:41 -06:00
Jonathan A. Sternberg 748fc4ae79 Update the influxql path inside of the template files 2017-11-03 10:57:17 -05:00
Stuart Carnie c51ba16287 fixes #9007 2017-10-25 13:08:55 -07:00
Stuart Carnie e9313876ab EXPLAIN ANALYZE
* Introduces EXPLAIN ANALYZE command, which
  produces a detailed tree of operations used to
  execute the query.

introduce context.Context to APIs

metrics package

* create groups of named measurements
* safe for concurrent access

tracing package

EXPLAIN ANALYZE implementation for OSS

Serialize EXPLAIN ANALYZE traces from remote nodes

use context.Background for tests

group with other stdlib packages

additional documentation and remove unused API

use influxdb/pkg/testing/assert

remove testify reference
2017-10-20 08:01:37 -07:00
Jonathan A. Sternberg f20cab6e99 Implicitly decide on the lower limit for fill queries when none is present
This allows the query:

    SELECT mean(value) FROM cpu GROUP BY time(1d)

To function in some way that makes sense. The upper limit is implicitly
the `now()` starting time and the lower limit will be whichever interval
the lowest point falls into.

When no lower bound is specified and `max-select-buckets` is specified,
the query will only consider points that would satisfy
`max-select-buckets`. So if you have one point written in 1970, have
another point within the last minute, and then do the above query with
`max-select-buckets` being equal to 10, the older point from 1970 will
not be considered.
2017-10-05 15:56:44 -05:00
Jonathan A. Sternberg 0ef94e0cf0 Add unsigned iterators for all types
This allows unsigned data to be queried from the storage engine.

Binary math is not yet implemented for unsigned types.
2017-09-18 15:09:10 -05:00
Jonathan A. Sternberg 5a9553b2c4 Remove unused casting code from the query engine
Originally, casting was performed inside of the query engine especially
for call iterators. Currently, the engine takes care of all casting so
we just need to normalize the iterators types for type safety reasons
rather than actual functional reasons.

Removing this code. Cover coverage showed that it was not hit when run
against the actual server. I ran the tests package and got code coverage
of the query package while running the tests in that package.
2017-09-18 12:33:34 -05:00
Edd Robinson 8c4686fb1b Ensure that sorted heaps are merged correctly
When merging streams of system iterators we don't use tags or time.
Instead we add series keys (in the case of, for example, `SHOW SERIES`)
to the `Aux` field of the iterators' elements. This is because we only
emit merged and sorted sets of series key to the client.

We currently use `SortedMergeHeap`s to merge together multiple
iterators, and the comparitor function did not consider `Aux` fields
when determining which heap to pop the next item off during a merge. As
such, `SHOW SERIES` and `SHOW TAG KEYS` (any meta query that gets
converted into a special type of `SELECT`) were returning results in
arbitrary order.

This issue was never noticed on the `inmem` index because the streams
are always duplicates of each other, and of course it doesn't matter if
you arbitrarily merge together two idential, sorted streams...

The issue first manifested itself on the `tsi1` index, but this fix will
apply to both indexes.
2017-08-23 17:21:24 +01:00
Jonathan A. Sternberg 9a2357c2c0 Separate the query engine into a separate package
This change provides a clear separation between the query engine
mechanics and the query language so that the language can be parsed and
dealt with separate from the query engine itself.
2017-08-16 13:38:43 -05:00