github.com/influxdata/influxdb/v2@v2.7.6/influxql/query/select_test.go (about)

     1  package query_test
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"math/rand"
     7  	"reflect"
     8  	"runtime"
     9  	"testing"
    10  	"time"
    11  
    12  	"github.com/davecgh/go-spew/spew"
    13  	"github.com/google/go-cmp/cmp"
    14  	"github.com/influxdata/influxdb/v2/influxql/query"
    15  	"github.com/influxdata/influxql"
    16  )
    17  
    18  // Second represents a helper for type converting durations.
    19  const Second = int64(time.Second)
    20  
    21  func randomFloatSlice(seed int64, length int) []float64 {
    22  	r := rand.New(rand.NewSource(seed))
    23  	out := make([]float64, 0, length)
    24  	for i := 0; i < 3000; i++ {
    25  		out = append(out, r.Float64())
    26  	}
    27  	return out
    28  }
    29  
    30  func floatIterator(fSlice []float64, name, tags string, startTime, step int64) *FloatIterator {
    31  	p := make([]query.FloatPoint, 0, len(fSlice))
    32  	currentTime := startTime
    33  	for _, f := range fSlice {
    34  		p = append(p, query.FloatPoint{Name: name, Tags: ParseTags(tags), Time: currentTime, Value: f})
    35  		currentTime += step
    36  	}
    37  	return &FloatIterator{
    38  		Points: p,
    39  	}
    40  }
    41  
    42  func TestSelect(t *testing.T) {
    43  	for _, tt := range []struct {
    44  		name     string
    45  		q        string
    46  		typ      influxql.DataType
    47  		fields   map[string]influxql.DataType
    48  		expr     string
    49  		itrs     []query.Iterator
    50  		rows     []query.Row
    51  		now      time.Time
    52  		err      string
    53  		onlyArch string
    54  	}{
    55  		{
    56  			name: "Min",
    57  			q:    `SELECT min(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
    58  			typ:  influxql.Float,
    59  			expr: `min(value::float)`,
    60  			itrs: []query.Iterator{
    61  				&FloatIterator{Points: []query.FloatPoint{
    62  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
    63  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3},
    64  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100},
    65  				}},
    66  				&FloatIterator{Points: []query.FloatPoint{
    67  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
    68  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
    69  				}},
    70  				&FloatIterator{Points: []query.FloatPoint{
    71  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
    72  				}},
    73  			},
    74  			rows: []query.Row{
    75  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(19)}},
    76  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(2)}},
    77  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(100)}},
    78  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(10)}},
    79  			},
    80  		},
    81  		{
    82  			name: "count_hll",
    83  			q:    `SELECT count_hll(sum_hll(value)) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
    84  			typ:  influxql.Float,
    85  			itrs: []query.Iterator{
    86  				floatIterator(randomFloatSlice(42, 2000), "cpu", "region=west,host=A", 0*Second, 1),
    87  				&FloatIterator{Points: []query.FloatPoint{
    88  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 0 * Second, Value: 20},
    89  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 11 * Second, Value: 3},
    90  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 31 * Second, Value: 100},
    91  				}},
    92  				floatIterator(randomFloatSlice(42, 3000)[1000:], "cpu", "region=south,host=A", 0*Second, 1),
    93  				&FloatIterator{Points: []query.FloatPoint{
    94  					{Name: "cpu", Tags: ParseTags("region=east,host=B"), Time: 0 * Second, Value: 20},
    95  				}},
    96  			},
    97  			rows: []query.Row{
    98  				// Note that for the first aggregate there are 2000 points in each series, but only 3000 unique points, 2994 ≈ 3000
    99  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(2994)}},
   100  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(1)}},
   101  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(1)}},
   102  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{uint64(1)}},
   103  			},
   104  		},
   105  		{
   106  			name: "Distinct_Float",
   107  			q:    `SELECT distinct(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
   108  			typ:  influxql.Float,
   109  			itrs: []query.Iterator{
   110  				&FloatIterator{Points: []query.FloatPoint{
   111  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
   112  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 1 * Second, Value: 19},
   113  				}},
   114  				&FloatIterator{Points: []query.FloatPoint{
   115  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
   116  				}},
   117  				&FloatIterator{Points: []query.FloatPoint{
   118  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
   119  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
   120  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 11 * Second, Value: 2},
   121  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 12 * Second, Value: 2},
   122  				}},
   123  			},
   124  			rows: []query.Row{
   125  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(20)}},
   126  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(19)}},
   127  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(2)}},
   128  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(10)}},
   129  			},
   130  		},
   131  		{
   132  			name: "Distinct_Integer",
   133  			q:    `SELECT distinct(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
   134  			typ:  influxql.Integer,
   135  			itrs: []query.Iterator{
   136  				&IntegerIterator{Points: []query.IntegerPoint{
   137  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
   138  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 1 * Second, Value: 19},
   139  				}},
   140  				&IntegerIterator{Points: []query.IntegerPoint{
   141  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
   142  				}},
   143  				&IntegerIterator{Points: []query.IntegerPoint{
   144  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
   145  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
   146  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 11 * Second, Value: 2},
   147  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 12 * Second, Value: 2},
   148  				}},
   149  			},
   150  			rows: []query.Row{
   151  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(20)}},
   152  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(19)}},
   153  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(2)}},
   154  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{int64(10)}},
   155  			},
   156  		},
   157  		{
   158  			name: "Distinct_Unsigned",
   159  			q:    `SELECT distinct(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
   160  			typ:  influxql.Unsigned,
   161  			itrs: []query.Iterator{
   162  				&UnsignedIterator{Points: []query.UnsignedPoint{
   163  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
   164  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 1 * Second, Value: 19},
   165  				}},
   166  				&UnsignedIterator{Points: []query.UnsignedPoint{
   167  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
   168  				}},
   169  				&UnsignedIterator{Points: []query.UnsignedPoint{
   170  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
   171  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
   172  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 11 * Second, Value: 2},
   173  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 12 * Second, Value: 2},
   174  				}},
   175  			},
   176  			rows: []query.Row{
   177  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(20)}},
   178  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(19)}},
   179  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(2)}},
   180  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{uint64(10)}},
   181  			},
   182  		},
   183  		{
   184  			name: "Distinct_String",
   185  			q:    `SELECT distinct(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
   186  			typ:  influxql.String,
   187  			itrs: []query.Iterator{
   188  				&StringIterator{Points: []query.StringPoint{
   189  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: "a"},
   190  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 1 * Second, Value: "b"},
   191  				}},
   192  				&StringIterator{Points: []query.StringPoint{
   193  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: "c"},
   194  				}},
   195  				&StringIterator{Points: []query.StringPoint{
   196  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: "b"},
   197  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: "d"},
   198  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 11 * Second, Value: "d"},
   199  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 12 * Second, Value: "d"},
   200  				}},
   201  			},
   202  			rows: []query.Row{
   203  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{"a"}},
   204  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{"b"}},
   205  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{"d"}},
   206  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{"c"}},
   207  			},
   208  		},
   209  		{
   210  			name: "Distinct_Boolean",
   211  			q:    `SELECT distinct(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
   212  			typ:  influxql.Boolean,
   213  			itrs: []query.Iterator{
   214  				&BooleanIterator{Points: []query.BooleanPoint{
   215  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: true},
   216  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 1 * Second, Value: false},
   217  				}},
   218  				&BooleanIterator{Points: []query.BooleanPoint{
   219  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: false},
   220  				}},
   221  				&BooleanIterator{Points: []query.BooleanPoint{
   222  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: true},
   223  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: false},
   224  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 11 * Second, Value: false},
   225  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 12 * Second, Value: true},
   226  				}},
   227  			},
   228  			rows: []query.Row{
   229  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{true}},
   230  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{false}},
   231  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{false}},
   232  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{true}},
   233  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{false}},
   234  			},
   235  		},
   236  		{
   237  			name: "Mean_Float",
   238  			q:    `SELECT mean(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
   239  			typ:  influxql.Float,
   240  			expr: `mean(value::float)`,
   241  			itrs: []query.Iterator{
   242  				&FloatIterator{Points: []query.FloatPoint{
   243  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
   244  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3},
   245  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100},
   246  				}},
   247  				&FloatIterator{Points: []query.FloatPoint{
   248  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
   249  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1},
   250  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2},
   251  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 4},
   252  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4},
   253  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5},
   254  				}},
   255  				&FloatIterator{Points: []query.FloatPoint{
   256  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
   257  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
   258  				}},
   259  			},
   260  			rows: []query.Row{
   261  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{19.5}},
   262  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{2.5}},
   263  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(100)}},
   264  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(10)}},
   265  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{3.2}},
   266  			},
   267  		},
   268  		{
   269  			name: "Mean_Integer",
   270  			q:    `SELECT mean(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
   271  			typ:  influxql.Integer,
   272  			expr: `mean(value::integer)`,
   273  			itrs: []query.Iterator{
   274  				&IntegerIterator{Points: []query.IntegerPoint{
   275  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
   276  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3},
   277  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100},
   278  				}},
   279  				&IntegerIterator{Points: []query.IntegerPoint{
   280  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
   281  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1},
   282  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2},
   283  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 4},
   284  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4},
   285  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5},
   286  				}},
   287  				&IntegerIterator{Points: []query.IntegerPoint{
   288  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
   289  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
   290  				}},
   291  			},
   292  			rows: []query.Row{
   293  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{19.5}},
   294  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{2.5}},
   295  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(100)}},
   296  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(10)}},
   297  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{3.2}},
   298  			},
   299  		},
   300  		{
   301  			name: "Mean_Unsigned",
   302  			q:    `SELECT mean(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
   303  			typ:  influxql.Unsigned,
   304  			expr: `mean(value::Unsigned)`,
   305  			itrs: []query.Iterator{
   306  				&UnsignedIterator{Points: []query.UnsignedPoint{
   307  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
   308  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3},
   309  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100},
   310  				}},
   311  				&UnsignedIterator{Points: []query.UnsignedPoint{
   312  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
   313  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1},
   314  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2},
   315  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 4},
   316  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4},
   317  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5},
   318  				}},
   319  				&UnsignedIterator{Points: []query.UnsignedPoint{
   320  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
   321  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
   322  				}},
   323  			},
   324  			rows: []query.Row{
   325  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{19.5}},
   326  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{2.5}},
   327  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(100)}},
   328  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(10)}},
   329  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{3.2}},
   330  			},
   331  		},
   332  		{
   333  			name: "Mean_String",
   334  			q:    `SELECT mean(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
   335  			typ:  influxql.String,
   336  			itrs: []query.Iterator{&StringIterator{}},
   337  			err:  `unsupported mean iterator type: *query_test.StringIterator`,
   338  		},
   339  		{
   340  			name: "Mean_Boolean",
   341  			q:    `SELECT mean(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
   342  			typ:  influxql.Boolean,
   343  			itrs: []query.Iterator{&BooleanIterator{}},
   344  			err:  `unsupported mean iterator type: *query_test.BooleanIterator`,
   345  		},
   346  		{
   347  			name: "Median_Float",
   348  			q:    `SELECT median(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
   349  			typ:  influxql.Float,
   350  			itrs: []query.Iterator{
   351  				&FloatIterator{Points: []query.FloatPoint{
   352  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
   353  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3},
   354  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100},
   355  				}},
   356  				&FloatIterator{Points: []query.FloatPoint{
   357  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
   358  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1},
   359  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2},
   360  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 3},
   361  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4},
   362  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5},
   363  				}},
   364  				&FloatIterator{Points: []query.FloatPoint{
   365  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
   366  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
   367  				}},
   368  			},
   369  			rows: []query.Row{
   370  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{19.5}},
   371  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{2.5}},
   372  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(100)}},
   373  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(10)}},
   374  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(3)}},
   375  			},
   376  		},
   377  		{
   378  			name: "Median_Integer",
   379  			q:    `SELECT median(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
   380  			typ:  influxql.Integer,
   381  			itrs: []query.Iterator{
   382  				&IntegerIterator{Points: []query.IntegerPoint{
   383  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
   384  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3},
   385  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100},
   386  				}},
   387  				&IntegerIterator{Points: []query.IntegerPoint{
   388  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
   389  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1},
   390  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2},
   391  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 3},
   392  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4},
   393  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5},
   394  				}},
   395  				&IntegerIterator{Points: []query.IntegerPoint{
   396  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
   397  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
   398  				}},
   399  			},
   400  			rows: []query.Row{
   401  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{19.5}},
   402  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{2.5}},
   403  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(100)}},
   404  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(10)}},
   405  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(3)}},
   406  			},
   407  		},
   408  		{
   409  			name: "Median_Unsigned",
   410  			q:    `SELECT median(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
   411  			typ:  influxql.Unsigned,
   412  			itrs: []query.Iterator{
   413  				&UnsignedIterator{Points: []query.UnsignedPoint{
   414  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
   415  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3},
   416  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100},
   417  				}},
   418  				&UnsignedIterator{Points: []query.UnsignedPoint{
   419  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
   420  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1},
   421  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2},
   422  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 3},
   423  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4},
   424  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5},
   425  				}},
   426  				&UnsignedIterator{Points: []query.UnsignedPoint{
   427  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
   428  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
   429  				}},
   430  			},
   431  			rows: []query.Row{
   432  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{19.5}},
   433  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{2.5}},
   434  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(100)}},
   435  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(10)}},
   436  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(3)}},
   437  			},
   438  		},
   439  		{
   440  			name: "Median_String",
   441  			q:    `SELECT median(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
   442  			typ:  influxql.String,
   443  			itrs: []query.Iterator{&StringIterator{}},
   444  			err:  `unsupported median iterator type: *query_test.StringIterator`,
   445  		},
   446  		{
   447  			name: "Median_Boolean",
   448  			q:    `SELECT median(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
   449  			typ:  influxql.Boolean,
   450  			itrs: []query.Iterator{&BooleanIterator{}},
   451  			err:  `unsupported median iterator type: *query_test.BooleanIterator`,
   452  		},
   453  		{
   454  			name: "Mode_Float",
   455  			q:    `SELECT mode(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
   456  			typ:  influxql.Float,
   457  			itrs: []query.Iterator{
   458  				&FloatIterator{Points: []query.FloatPoint{
   459  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 10},
   460  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 2},
   461  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100},
   462  				}},
   463  				&FloatIterator{Points: []query.FloatPoint{
   464  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
   465  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1},
   466  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2},
   467  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 3},
   468  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4},
   469  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5},
   470  				}},
   471  				&FloatIterator{Points: []query.FloatPoint{
   472  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
   473  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
   474  				}},
   475  			},
   476  			rows: []query.Row{
   477  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(10)}},
   478  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(2)}},
   479  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(100)}},
   480  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(10)}},
   481  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(1)}},
   482  			},
   483  		},
   484  		{
   485  			name: "Mode_Integer",
   486  			q:    `SELECT mode(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
   487  			typ:  influxql.Integer,
   488  			itrs: []query.Iterator{
   489  				&IntegerIterator{Points: []query.IntegerPoint{
   490  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 10},
   491  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 2},
   492  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100},
   493  				}},
   494  				&IntegerIterator{Points: []query.IntegerPoint{
   495  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
   496  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1},
   497  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2},
   498  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 3},
   499  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4},
   500  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 54 * Second, Value: 5},
   501  				}},
   502  				&IntegerIterator{Points: []query.IntegerPoint{
   503  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
   504  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
   505  				}},
   506  			},
   507  			rows: []query.Row{
   508  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(10)}},
   509  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(2)}},
   510  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(100)}},
   511  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{int64(10)}},
   512  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{int64(1)}},
   513  			},
   514  		},
   515  		{
   516  			name: "Mode_Unsigned",
   517  			q:    `SELECT mode(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
   518  			typ:  influxql.Unsigned,
   519  			itrs: []query.Iterator{
   520  				&UnsignedIterator{Points: []query.UnsignedPoint{
   521  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 10},
   522  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 2},
   523  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100},
   524  				}},
   525  				&UnsignedIterator{Points: []query.UnsignedPoint{
   526  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
   527  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1},
   528  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2},
   529  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 3},
   530  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4},
   531  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 54 * Second, Value: 5},
   532  				}},
   533  				&UnsignedIterator{Points: []query.UnsignedPoint{
   534  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
   535  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
   536  				}},
   537  			},
   538  			rows: []query.Row{
   539  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(10)}},
   540  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(2)}},
   541  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(100)}},
   542  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{uint64(10)}},
   543  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{uint64(1)}},
   544  			},
   545  		},
   546  		{
   547  			name: "Mode_String",
   548  			q:    `SELECT mode(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
   549  			typ:  influxql.String,
   550  			itrs: []query.Iterator{
   551  				&StringIterator{Points: []query.StringPoint{
   552  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: "a"},
   553  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 1 * Second, Value: "a"},
   554  				}},
   555  				&StringIterator{Points: []query.StringPoint{
   556  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: "cxxx"},
   557  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 6 * Second, Value: "zzzz"},
   558  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 7 * Second, Value: "zzzz"},
   559  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 8 * Second, Value: "zxxx"},
   560  				}},
   561  				&StringIterator{Points: []query.StringPoint{
   562  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: "b"},
   563  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: "d"},
   564  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 11 * Second, Value: "d"},
   565  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 12 * Second, Value: "d"},
   566  				}},
   567  			},
   568  			rows: []query.Row{
   569  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{"a"}},
   570  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{"d"}},
   571  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{"zzzz"}},
   572  			},
   573  		},
   574  		{
   575  			name: "Mode_Boolean",
   576  			q:    `SELECT mode(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
   577  			typ:  influxql.Boolean,
   578  			itrs: []query.Iterator{
   579  				&BooleanIterator{Points: []query.BooleanPoint{
   580  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: true},
   581  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 1 * Second, Value: false},
   582  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 2 * Second, Value: false},
   583  				}},
   584  				&BooleanIterator{Points: []query.BooleanPoint{
   585  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: true},
   586  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 6 * Second, Value: false},
   587  				}},
   588  				&BooleanIterator{Points: []query.BooleanPoint{
   589  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: false},
   590  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: true},
   591  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 11 * Second, Value: false},
   592  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 12 * Second, Value: true},
   593  				}},
   594  			},
   595  			rows: []query.Row{
   596  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{false}},
   597  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{true}},
   598  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{true}},
   599  			},
   600  		},
   601  		{
   602  			name: "Top_NoTags_Float",
   603  			q:    `SELECT top(value, 2) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(30s), host fill(none)`,
   604  			typ:  influxql.Float,
   605  			itrs: []query.Iterator{
   606  				&FloatIterator{Points: []query.FloatPoint{
   607  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
   608  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3},
   609  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100},
   610  				}},
   611  				&FloatIterator{Points: []query.FloatPoint{
   612  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
   613  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1},
   614  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2},
   615  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 3},
   616  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4},
   617  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5},
   618  				}},
   619  				&FloatIterator{Points: []query.FloatPoint{
   620  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
   621  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
   622  				}},
   623  			},
   624  			rows: []query.Row{
   625  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(20)}},
   626  				{Time: 9 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(19)}},
   627  				{Time: 31 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(100)}},
   628  				{Time: 5 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(10)}},
   629  				{Time: 53 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(5)}},
   630  				{Time: 53 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(4)}},
   631  			},
   632  		},
   633  		{
   634  			name: "Top_NoTags_Integer",
   635  			q:    `SELECT top(value, 2) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(30s), host fill(none)`,
   636  			typ:  influxql.Integer,
   637  			itrs: []query.Iterator{
   638  				&IntegerIterator{Points: []query.IntegerPoint{
   639  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
   640  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3},
   641  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100},
   642  				}},
   643  				&IntegerIterator{Points: []query.IntegerPoint{
   644  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
   645  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1},
   646  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2},
   647  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 3},
   648  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4},
   649  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5},
   650  				}},
   651  				&IntegerIterator{Points: []query.IntegerPoint{
   652  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
   653  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
   654  				}},
   655  			},
   656  			rows: []query.Row{
   657  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(20)}},
   658  				{Time: 9 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(19)}},
   659  				{Time: 31 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(100)}},
   660  				{Time: 5 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{int64(10)}},
   661  				{Time: 53 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{int64(5)}},
   662  				{Time: 53 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{int64(4)}},
   663  			},
   664  		},
   665  		{
   666  			name: "Top_NoTags_Unsigned",
   667  			q:    `SELECT top(value, 2) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(30s), host fill(none)`,
   668  			typ:  influxql.Unsigned,
   669  			itrs: []query.Iterator{
   670  				&UnsignedIterator{Points: []query.UnsignedPoint{
   671  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
   672  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3},
   673  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100},
   674  				}},
   675  				&UnsignedIterator{Points: []query.UnsignedPoint{
   676  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
   677  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1},
   678  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2},
   679  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 3},
   680  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4},
   681  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5},
   682  				}},
   683  				&UnsignedIterator{Points: []query.UnsignedPoint{
   684  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
   685  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
   686  				}},
   687  			},
   688  			rows: []query.Row{
   689  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(20)}},
   690  				{Time: 9 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(19)}},
   691  				{Time: 31 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(100)}},
   692  				{Time: 5 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{uint64(10)}},
   693  				{Time: 53 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{uint64(5)}},
   694  				{Time: 53 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{uint64(4)}},
   695  			},
   696  		},
   697  		{
   698  			name: "Top_Tags_Float",
   699  			q:    `SELECT top(value::float, host::tag, 2) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(30s) fill(none)`,
   700  			typ:  influxql.Float,
   701  			expr: `max(value::float)`,
   702  			itrs: []query.Iterator{
   703  				&FloatIterator{Points: []query.FloatPoint{
   704  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20, Aux: []interface{}{"A"}},
   705  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3, Aux: []interface{}{"A"}},
   706  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100, Aux: []interface{}{"A"}},
   707  				}},
   708  				&FloatIterator{Points: []query.FloatPoint{
   709  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10, Aux: []interface{}{"B"}},
   710  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1, Aux: []interface{}{"B"}},
   711  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2, Aux: []interface{}{"B"}},
   712  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 3, Aux: []interface{}{"B"}},
   713  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4, Aux: []interface{}{"B"}},
   714  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5, Aux: []interface{}{"B"}},
   715  				}},
   716  				&FloatIterator{Points: []query.FloatPoint{
   717  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19, Aux: []interface{}{"A"}},
   718  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2, Aux: []interface{}{"A"}},
   719  				}},
   720  			},
   721  			rows: []query.Row{
   722  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(20), "A"}},
   723  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(10), "B"}},
   724  				{Time: 31 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(100), "A"}},
   725  				{Time: 53 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(5), "B"}},
   726  			},
   727  		},
   728  		{
   729  			name: "Top_Tags_Integer",
   730  			q:    `SELECT top(value::integer, host::tag, 2) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(30s) fill(none)`,
   731  			typ:  influxql.Integer,
   732  			expr: `max(value::integer)`,
   733  			itrs: []query.Iterator{
   734  				&IntegerIterator{Points: []query.IntegerPoint{
   735  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20, Aux: []interface{}{"A"}},
   736  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3, Aux: []interface{}{"A"}},
   737  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100, Aux: []interface{}{"A"}},
   738  				}},
   739  				&IntegerIterator{Points: []query.IntegerPoint{
   740  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10, Aux: []interface{}{"B"}},
   741  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1, Aux: []interface{}{"B"}},
   742  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2, Aux: []interface{}{"B"}},
   743  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 3, Aux: []interface{}{"B"}},
   744  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4, Aux: []interface{}{"B"}},
   745  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5, Aux: []interface{}{"B"}},
   746  				}},
   747  				&IntegerIterator{Points: []query.IntegerPoint{
   748  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19, Aux: []interface{}{"A"}},
   749  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2, Aux: []interface{}{"A"}},
   750  				}},
   751  			},
   752  			rows: []query.Row{
   753  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(20), "A"}},
   754  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(10), "B"}},
   755  				{Time: 31 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(100), "A"}},
   756  				{Time: 53 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(5), "B"}},
   757  			},
   758  		},
   759  		{
   760  			name: "Top_Tags_Unsigned",
   761  			q:    `SELECT top(value::Unsigned, host::tag, 2) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(30s) fill(none)`,
   762  			typ:  influxql.Unsigned,
   763  			expr: `max(value::Unsigned)`,
   764  			itrs: []query.Iterator{
   765  				&UnsignedIterator{Points: []query.UnsignedPoint{
   766  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20, Aux: []interface{}{"A"}},
   767  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3, Aux: []interface{}{"A"}},
   768  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100, Aux: []interface{}{"A"}},
   769  				}},
   770  				&UnsignedIterator{Points: []query.UnsignedPoint{
   771  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10, Aux: []interface{}{"B"}},
   772  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1, Aux: []interface{}{"B"}},
   773  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2, Aux: []interface{}{"B"}},
   774  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 3, Aux: []interface{}{"B"}},
   775  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4, Aux: []interface{}{"B"}},
   776  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5, Aux: []interface{}{"B"}},
   777  				}},
   778  				&UnsignedIterator{Points: []query.UnsignedPoint{
   779  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19, Aux: []interface{}{"A"}},
   780  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2, Aux: []interface{}{"A"}},
   781  				}},
   782  			},
   783  			rows: []query.Row{
   784  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(20), "A"}},
   785  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(10), "B"}},
   786  				{Time: 31 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(100), "A"}},
   787  				{Time: 53 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(5), "B"}},
   788  			},
   789  		},
   790  		{
   791  			name: "Top_GroupByTags_Float",
   792  			q:    `SELECT top(value::float, host::tag, 1) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY region, time(30s) fill(none)`,
   793  			typ:  influxql.Float,
   794  			expr: `max(value::float)`,
   795  			itrs: []query.Iterator{
   796  				&FloatIterator{Points: []query.FloatPoint{
   797  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20, Aux: []interface{}{"A"}},
   798  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3, Aux: []interface{}{"A"}},
   799  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100, Aux: []interface{}{"A"}},
   800  				}},
   801  				&FloatIterator{Points: []query.FloatPoint{
   802  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10, Aux: []interface{}{"B"}},
   803  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1, Aux: []interface{}{"B"}},
   804  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2, Aux: []interface{}{"B"}},
   805  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 3, Aux: []interface{}{"B"}},
   806  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4, Aux: []interface{}{"B"}},
   807  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5, Aux: []interface{}{"B"}},
   808  				}},
   809  				&FloatIterator{Points: []query.FloatPoint{
   810  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19, Aux: []interface{}{"A"}},
   811  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2, Aux: []interface{}{"A"}},
   812  				}},
   813  			},
   814  			rows: []query.Row{
   815  				{Time: 9 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("region=east")}, Values: []interface{}{float64(19), "A"}},
   816  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("region=west")}, Values: []interface{}{float64(20), "A"}},
   817  				{Time: 31 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("region=west")}, Values: []interface{}{float64(100), "A"}},
   818  			},
   819  		},
   820  		{
   821  			name: "Top_GroupByTags_Integer",
   822  			q:    `SELECT top(value::integer, host::tag, 1) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY region, time(30s) fill(none)`,
   823  			typ:  influxql.Integer,
   824  			itrs: []query.Iterator{
   825  				&IntegerIterator{Points: []query.IntegerPoint{
   826  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20, Aux: []interface{}{"A"}},
   827  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3, Aux: []interface{}{"A"}},
   828  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100, Aux: []interface{}{"A"}},
   829  				}},
   830  				&IntegerIterator{Points: []query.IntegerPoint{
   831  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10, Aux: []interface{}{"B"}},
   832  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1, Aux: []interface{}{"B"}},
   833  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2, Aux: []interface{}{"B"}},
   834  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 3, Aux: []interface{}{"B"}},
   835  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4, Aux: []interface{}{"B"}},
   836  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5, Aux: []interface{}{"B"}},
   837  				}},
   838  				&IntegerIterator{Points: []query.IntegerPoint{
   839  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19, Aux: []interface{}{"A"}},
   840  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2, Aux: []interface{}{"A"}},
   841  				}},
   842  			},
   843  			rows: []query.Row{
   844  				{Time: 9 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("region=east")}, Values: []interface{}{int64(19), "A"}},
   845  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("region=west")}, Values: []interface{}{int64(20), "A"}},
   846  				{Time: 31 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("region=west")}, Values: []interface{}{int64(100), "A"}},
   847  			},
   848  		},
   849  		{
   850  			name: "Top_GroupByTags_Unsigned",
   851  			q:    `SELECT top(value::Unsigned, host::tag, 1) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY region, time(30s) fill(none)`,
   852  			typ:  influxql.Unsigned,
   853  			itrs: []query.Iterator{
   854  				&UnsignedIterator{Points: []query.UnsignedPoint{
   855  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20, Aux: []interface{}{"A"}},
   856  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3, Aux: []interface{}{"A"}},
   857  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100, Aux: []interface{}{"A"}},
   858  				}},
   859  				&UnsignedIterator{Points: []query.UnsignedPoint{
   860  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10, Aux: []interface{}{"B"}},
   861  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1, Aux: []interface{}{"B"}},
   862  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2, Aux: []interface{}{"B"}},
   863  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 3, Aux: []interface{}{"B"}},
   864  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4, Aux: []interface{}{"B"}},
   865  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5, Aux: []interface{}{"B"}},
   866  				}},
   867  				&UnsignedIterator{Points: []query.UnsignedPoint{
   868  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19, Aux: []interface{}{"A"}},
   869  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2, Aux: []interface{}{"A"}},
   870  				}},
   871  			},
   872  			rows: []query.Row{
   873  				{Time: 9 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("region=east")}, Values: []interface{}{uint64(19), "A"}},
   874  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("region=west")}, Values: []interface{}{uint64(20), "A"}},
   875  				{Time: 31 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("region=west")}, Values: []interface{}{uint64(100), "A"}},
   876  			},
   877  		},
   878  		{
   879  			name: "Top_AuxFields_Float",
   880  			q:    `SELECT top(p1, 2), p2, p3 FROM cpu`,
   881  			fields: map[string]influxql.DataType{
   882  				"p1": influxql.Float,
   883  				"p2": influxql.Float,
   884  				"p3": influxql.String,
   885  			},
   886  			itrs: []query.Iterator{
   887  				&FloatIterator{Points: []query.FloatPoint{
   888  					{Name: "cpu", Time: 0 * Second, Value: 1, Aux: []interface{}{float64(2), "aaa"}},
   889  					{Name: "cpu", Time: 1 * Second, Value: 2, Aux: []interface{}{float64(3), "bbb"}},
   890  					{Name: "cpu", Time: 2 * Second, Value: 3, Aux: []interface{}{float64(4), "ccc"}},
   891  					{Name: "cpu", Time: 3 * Second, Value: 4, Aux: []interface{}{float64(5), "ddd"}},
   892  				}},
   893  			},
   894  			rows: []query.Row{
   895  				{Time: 2 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(3), float64(4), "ccc"}},
   896  				{Time: 3 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(4), float64(5), "ddd"}},
   897  			},
   898  		},
   899  		{
   900  			name: "Top_AuxFields_Integer",
   901  			q:    `SELECT top(p1, 2), p2, p3 FROM cpu`,
   902  			fields: map[string]influxql.DataType{
   903  				"p1": influxql.Integer,
   904  				"p2": influxql.Integer,
   905  				"p3": influxql.String,
   906  			},
   907  			itrs: []query.Iterator{
   908  				&IntegerIterator{Points: []query.IntegerPoint{
   909  					{Name: "cpu", Time: 0 * Second, Value: 1, Aux: []interface{}{int64(2), "aaa"}},
   910  					{Name: "cpu", Time: 1 * Second, Value: 2, Aux: []interface{}{int64(3), "bbb"}},
   911  					{Name: "cpu", Time: 2 * Second, Value: 3, Aux: []interface{}{int64(4), "ccc"}},
   912  					{Name: "cpu", Time: 3 * Second, Value: 4, Aux: []interface{}{int64(5), "ddd"}},
   913  				}},
   914  			},
   915  			rows: []query.Row{
   916  				{Time: 2 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(3), int64(4), "ccc"}},
   917  				{Time: 3 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(4), int64(5), "ddd"}},
   918  			},
   919  		},
   920  		{
   921  			name: "Top_AuxFields_Unsigned",
   922  			q:    `SELECT top(p1, 2), p2, p3 FROM cpu`,
   923  			fields: map[string]influxql.DataType{
   924  				"p1": influxql.Unsigned,
   925  				"p2": influxql.Unsigned,
   926  				"p3": influxql.String,
   927  			},
   928  			itrs: []query.Iterator{
   929  				&UnsignedIterator{Points: []query.UnsignedPoint{
   930  					{Name: "cpu", Time: 0 * Second, Value: 1, Aux: []interface{}{uint64(2), "aaa"}},
   931  					{Name: "cpu", Time: 1 * Second, Value: 2, Aux: []interface{}{uint64(3), "bbb"}},
   932  					{Name: "cpu", Time: 2 * Second, Value: 3, Aux: []interface{}{uint64(4), "ccc"}},
   933  					{Name: "cpu", Time: 3 * Second, Value: 4, Aux: []interface{}{uint64(5), "ddd"}},
   934  				}},
   935  			},
   936  			rows: []query.Row{
   937  				{Time: 2 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(3), uint64(4), "ccc"}},
   938  				{Time: 3 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(4), uint64(5), "ddd"}},
   939  			},
   940  		},
   941  		{
   942  			name: "Bottom_NoTags_Float",
   943  			q:    `SELECT bottom(value::float, 2) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(30s), host fill(none)`,
   944  			typ:  influxql.Float,
   945  			itrs: []query.Iterator{
   946  				&FloatIterator{Points: []query.FloatPoint{
   947  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
   948  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3},
   949  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100},
   950  				}},
   951  				&FloatIterator{Points: []query.FloatPoint{
   952  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
   953  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1},
   954  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2},
   955  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 3},
   956  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4},
   957  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5},
   958  				}},
   959  				&FloatIterator{Points: []query.FloatPoint{
   960  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
   961  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
   962  				}},
   963  			},
   964  			rows: []query.Row{
   965  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(2)}},
   966  				{Time: 11 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(3)}},
   967  				{Time: 31 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(100)}},
   968  				{Time: 5 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(10)}},
   969  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(1)}},
   970  				{Time: 51 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(2)}},
   971  			},
   972  		},
   973  		{
   974  			name: "Bottom_NoTags_Integer",
   975  			q:    `SELECT bottom(value::integer, 2) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(30s), host fill(none)`,
   976  			typ:  influxql.Integer,
   977  			itrs: []query.Iterator{
   978  				&IntegerIterator{Points: []query.IntegerPoint{
   979  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
   980  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3},
   981  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100},
   982  				}},
   983  				&IntegerIterator{Points: []query.IntegerPoint{
   984  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
   985  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1},
   986  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2},
   987  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 3},
   988  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4},
   989  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5},
   990  				}},
   991  				&IntegerIterator{Points: []query.IntegerPoint{
   992  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
   993  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
   994  				}},
   995  			},
   996  			rows: []query.Row{
   997  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(2)}},
   998  				{Time: 11 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(3)}},
   999  				{Time: 31 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(100)}},
  1000  				{Time: 5 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{int64(10)}},
  1001  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{int64(1)}},
  1002  				{Time: 51 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{int64(2)}},
  1003  			},
  1004  		},
  1005  		{
  1006  			name: "Bottom_NoTags_Unsigned",
  1007  			q:    `SELECT bottom(value::Unsigned, 2) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(30s), host fill(none)`,
  1008  			typ:  influxql.Unsigned,
  1009  			itrs: []query.Iterator{
  1010  				&UnsignedIterator{Points: []query.UnsignedPoint{
  1011  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
  1012  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3},
  1013  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100},
  1014  				}},
  1015  				&UnsignedIterator{Points: []query.UnsignedPoint{
  1016  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
  1017  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1},
  1018  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2},
  1019  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 3},
  1020  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4},
  1021  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5},
  1022  				}},
  1023  				&UnsignedIterator{Points: []query.UnsignedPoint{
  1024  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
  1025  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
  1026  				}},
  1027  			},
  1028  			rows: []query.Row{
  1029  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(2)}},
  1030  				{Time: 11 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(3)}},
  1031  				{Time: 31 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(100)}},
  1032  				{Time: 5 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{uint64(10)}},
  1033  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{uint64(1)}},
  1034  				{Time: 51 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{uint64(2)}},
  1035  			},
  1036  		},
  1037  		{
  1038  			name: "Bottom_Tags_Float",
  1039  			q:    `SELECT bottom(value::float, host::tag, 2) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(30s) fill(none)`,
  1040  			typ:  influxql.Float,
  1041  			expr: `min(value::float)`,
  1042  			itrs: []query.Iterator{
  1043  				&FloatIterator{Points: []query.FloatPoint{
  1044  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20, Aux: []interface{}{"A"}},
  1045  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3, Aux: []interface{}{"A"}},
  1046  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100, Aux: []interface{}{"A"}},
  1047  				}},
  1048  				&FloatIterator{Points: []query.FloatPoint{
  1049  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10, Aux: []interface{}{"B"}},
  1050  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1, Aux: []interface{}{"B"}},
  1051  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2, Aux: []interface{}{"B"}},
  1052  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 3, Aux: []interface{}{"B"}},
  1053  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4, Aux: []interface{}{"B"}},
  1054  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5, Aux: []interface{}{"B"}},
  1055  				}},
  1056  				&FloatIterator{Points: []query.FloatPoint{
  1057  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19, Aux: []interface{}{"A"}},
  1058  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2, Aux: []interface{}{"A"}},
  1059  				}},
  1060  			},
  1061  			rows: []query.Row{
  1062  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(10), "B"}},
  1063  				{Time: 10 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(2), "A"}},
  1064  				{Time: 31 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(100), "A"}},
  1065  				{Time: 50 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(1), "B"}},
  1066  			},
  1067  		},
  1068  		{
  1069  			name: "Bottom_Tags_Integer",
  1070  			q:    `SELECT bottom(value::integer, host::tag, 2) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(30s) fill(none)`,
  1071  			typ:  influxql.Integer,
  1072  			itrs: []query.Iterator{
  1073  				&IntegerIterator{Points: []query.IntegerPoint{
  1074  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20, Aux: []interface{}{"A"}},
  1075  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3, Aux: []interface{}{"A"}},
  1076  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100, Aux: []interface{}{"A"}},
  1077  				}},
  1078  				&IntegerIterator{Points: []query.IntegerPoint{
  1079  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10, Aux: []interface{}{"B"}},
  1080  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1, Aux: []interface{}{"B"}},
  1081  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2, Aux: []interface{}{"B"}},
  1082  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 3, Aux: []interface{}{"B"}},
  1083  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4, Aux: []interface{}{"B"}},
  1084  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5, Aux: []interface{}{"B"}},
  1085  				}},
  1086  				&IntegerIterator{Points: []query.IntegerPoint{
  1087  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19, Aux: []interface{}{"A"}},
  1088  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2, Aux: []interface{}{"A"}},
  1089  				}},
  1090  			},
  1091  			rows: []query.Row{
  1092  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(10), "B"}},
  1093  				{Time: 10 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(2), "A"}},
  1094  				{Time: 31 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(100), "A"}},
  1095  				{Time: 50 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(1), "B"}},
  1096  			},
  1097  		},
  1098  		{
  1099  			name: "Bottom_Tags_Unsigned",
  1100  			q:    `SELECT bottom(value::Unsigned, host::tag, 2) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(30s) fill(none)`,
  1101  			typ:  influxql.Unsigned,
  1102  			itrs: []query.Iterator{
  1103  				&UnsignedIterator{Points: []query.UnsignedPoint{
  1104  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20, Aux: []interface{}{"A"}},
  1105  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3, Aux: []interface{}{"A"}},
  1106  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100, Aux: []interface{}{"A"}},
  1107  				}},
  1108  				&UnsignedIterator{Points: []query.UnsignedPoint{
  1109  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10, Aux: []interface{}{"B"}},
  1110  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1, Aux: []interface{}{"B"}},
  1111  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2, Aux: []interface{}{"B"}},
  1112  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 3, Aux: []interface{}{"B"}},
  1113  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4, Aux: []interface{}{"B"}},
  1114  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5, Aux: []interface{}{"B"}},
  1115  				}},
  1116  				&UnsignedIterator{Points: []query.UnsignedPoint{
  1117  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19, Aux: []interface{}{"A"}},
  1118  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2, Aux: []interface{}{"A"}},
  1119  				}},
  1120  			},
  1121  			rows: []query.Row{
  1122  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(10), "B"}},
  1123  				{Time: 10 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(2), "A"}},
  1124  				{Time: 31 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(100), "A"}},
  1125  				{Time: 50 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(1), "B"}},
  1126  			},
  1127  		},
  1128  		{
  1129  			name: "Bottom_GroupByTags_Float",
  1130  			q:    `SELECT bottom(value::float, host::tag, 1) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY region, time(30s) fill(none)`,
  1131  			typ:  influxql.Float,
  1132  			expr: `min(value::float)`,
  1133  			itrs: []query.Iterator{
  1134  				&FloatIterator{Points: []query.FloatPoint{
  1135  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20, Aux: []interface{}{"A"}},
  1136  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3, Aux: []interface{}{"A"}},
  1137  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100, Aux: []interface{}{"A"}},
  1138  				}},
  1139  				&FloatIterator{Points: []query.FloatPoint{
  1140  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10, Aux: []interface{}{"B"}},
  1141  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1, Aux: []interface{}{"B"}},
  1142  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2, Aux: []interface{}{"B"}},
  1143  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 3, Aux: []interface{}{"B"}},
  1144  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4, Aux: []interface{}{"B"}},
  1145  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5, Aux: []interface{}{"B"}},
  1146  				}},
  1147  				&FloatIterator{Points: []query.FloatPoint{
  1148  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19, Aux: []interface{}{"A"}},
  1149  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2, Aux: []interface{}{"A"}},
  1150  				}},
  1151  			},
  1152  			rows: []query.Row{
  1153  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("region=east")}, Values: []interface{}{float64(2), "A"}},
  1154  				{Time: 11 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("region=west")}, Values: []interface{}{float64(3), "A"}},
  1155  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("region=west")}, Values: []interface{}{float64(1), "B"}},
  1156  			},
  1157  		},
  1158  		{
  1159  			name: "Bottom_GroupByTags_Integer",
  1160  			q:    `SELECT bottom(value::float, host::tag, 1) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY region, time(30s) fill(none)`,
  1161  			typ:  influxql.Integer,
  1162  			expr: `min(value::float)`,
  1163  			itrs: []query.Iterator{
  1164  				&IntegerIterator{Points: []query.IntegerPoint{
  1165  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20, Aux: []interface{}{"A"}},
  1166  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3, Aux: []interface{}{"A"}},
  1167  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100, Aux: []interface{}{"A"}},
  1168  				}},
  1169  				&IntegerIterator{Points: []query.IntegerPoint{
  1170  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10, Aux: []interface{}{"B"}},
  1171  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1, Aux: []interface{}{"B"}},
  1172  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2, Aux: []interface{}{"B"}},
  1173  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 3, Aux: []interface{}{"B"}},
  1174  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4, Aux: []interface{}{"B"}},
  1175  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5, Aux: []interface{}{"B"}},
  1176  				}},
  1177  				&IntegerIterator{Points: []query.IntegerPoint{
  1178  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19, Aux: []interface{}{"A"}},
  1179  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2, Aux: []interface{}{"A"}},
  1180  				}},
  1181  			},
  1182  			rows: []query.Row{
  1183  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("region=east")}, Values: []interface{}{int64(2), "A"}},
  1184  				{Time: 11 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("region=west")}, Values: []interface{}{int64(3), "A"}},
  1185  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("region=west")}, Values: []interface{}{int64(1), "B"}},
  1186  			},
  1187  		},
  1188  		{
  1189  			name: "Bottom_GroupByTags_Unsigned",
  1190  			q:    `SELECT bottom(value::float, host::tag, 1) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY region, time(30s) fill(none)`,
  1191  			typ:  influxql.Unsigned,
  1192  			expr: `min(value::float)`,
  1193  			itrs: []query.Iterator{
  1194  				&UnsignedIterator{Points: []query.UnsignedPoint{
  1195  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20, Aux: []interface{}{"A"}},
  1196  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3, Aux: []interface{}{"A"}},
  1197  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100, Aux: []interface{}{"A"}},
  1198  				}},
  1199  				&UnsignedIterator{Points: []query.UnsignedPoint{
  1200  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10, Aux: []interface{}{"B"}},
  1201  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1, Aux: []interface{}{"B"}},
  1202  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2, Aux: []interface{}{"B"}},
  1203  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 3, Aux: []interface{}{"B"}},
  1204  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4, Aux: []interface{}{"B"}},
  1205  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5, Aux: []interface{}{"B"}},
  1206  				}},
  1207  				&UnsignedIterator{Points: []query.UnsignedPoint{
  1208  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19, Aux: []interface{}{"A"}},
  1209  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2, Aux: []interface{}{"A"}},
  1210  				}},
  1211  			},
  1212  			rows: []query.Row{
  1213  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("region=east")}, Values: []interface{}{uint64(2), "A"}},
  1214  				{Time: 11 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("region=west")}, Values: []interface{}{uint64(3), "A"}},
  1215  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("region=west")}, Values: []interface{}{uint64(1), "B"}},
  1216  			},
  1217  		},
  1218  		{
  1219  			name: "Bottom_AuxFields_Float",
  1220  			q:    `SELECT bottom(p1, 2), p2, p3 FROM cpu`,
  1221  			fields: map[string]influxql.DataType{
  1222  				"p1": influxql.Float,
  1223  				"p2": influxql.Float,
  1224  				"p3": influxql.String,
  1225  			},
  1226  			itrs: []query.Iterator{
  1227  				&FloatIterator{Points: []query.FloatPoint{
  1228  					{Name: "cpu", Time: 0 * Second, Value: 1, Aux: []interface{}{float64(2), "aaa"}},
  1229  					{Name: "cpu", Time: 1 * Second, Value: 2, Aux: []interface{}{float64(3), "bbb"}},
  1230  					{Name: "cpu", Time: 2 * Second, Value: 3, Aux: []interface{}{float64(4), "ccc"}},
  1231  					{Name: "cpu", Time: 3 * Second, Value: 4, Aux: []interface{}{float64(5), "ddd"}},
  1232  				}},
  1233  			},
  1234  			rows: []query.Row{
  1235  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(1), float64(2), "aaa"}},
  1236  				{Time: 1 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(2), float64(3), "bbb"}},
  1237  			},
  1238  		},
  1239  		{
  1240  			name: "Bottom_AuxFields_Integer",
  1241  			q:    `SELECT bottom(p1, 2), p2, p3 FROM cpu`,
  1242  			fields: map[string]influxql.DataType{
  1243  				"p1": influxql.Integer,
  1244  				"p2": influxql.Integer,
  1245  				"p3": influxql.String,
  1246  			},
  1247  			itrs: []query.Iterator{
  1248  				&IntegerIterator{Points: []query.IntegerPoint{
  1249  					{Name: "cpu", Time: 0 * Second, Value: 1, Aux: []interface{}{int64(2), "aaa"}},
  1250  					{Name: "cpu", Time: 1 * Second, Value: 2, Aux: []interface{}{int64(3), "bbb"}},
  1251  					{Name: "cpu", Time: 2 * Second, Value: 3, Aux: []interface{}{int64(4), "ccc"}},
  1252  					{Name: "cpu", Time: 3 * Second, Value: 4, Aux: []interface{}{int64(5), "ddd"}},
  1253  				}},
  1254  			},
  1255  			rows: []query.Row{
  1256  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(1), int64(2), "aaa"}},
  1257  				{Time: 1 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(2), int64(3), "bbb"}},
  1258  			},
  1259  		},
  1260  		{
  1261  			name: "Bottom_AuxFields_Unsigned",
  1262  			q:    `SELECT bottom(p1, 2), p2, p3 FROM cpu`,
  1263  			fields: map[string]influxql.DataType{
  1264  				"p1": influxql.Unsigned,
  1265  				"p2": influxql.Unsigned,
  1266  				"p3": influxql.String,
  1267  			},
  1268  			itrs: []query.Iterator{
  1269  				&UnsignedIterator{Points: []query.UnsignedPoint{
  1270  					{Name: "cpu", Time: 0 * Second, Value: 1, Aux: []interface{}{uint64(2), "aaa"}},
  1271  					{Name: "cpu", Time: 1 * Second, Value: 2, Aux: []interface{}{uint64(3), "bbb"}},
  1272  					{Name: "cpu", Time: 2 * Second, Value: 3, Aux: []interface{}{uint64(4), "ccc"}},
  1273  					{Name: "cpu", Time: 3 * Second, Value: 4, Aux: []interface{}{uint64(5), "ddd"}},
  1274  				}},
  1275  			},
  1276  			rows: []query.Row{
  1277  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(1), uint64(2), "aaa"}},
  1278  				{Time: 1 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(2), uint64(3), "bbb"}},
  1279  			},
  1280  		},
  1281  		{
  1282  			name: "Fill_Null_Float",
  1283  			q:    `SELECT mean(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:01:00Z' GROUP BY host, time(10s) fill(null)`,
  1284  			typ:  influxql.Float,
  1285  			expr: `mean(value::float)`,
  1286  			itrs: []query.Iterator{
  1287  				&FloatIterator{Points: []query.FloatPoint{
  1288  					{Name: "cpu", Tags: ParseTags("host=A"), Time: 12 * Second, Value: 2},
  1289  				}},
  1290  			},
  1291  			rows: []query.Row{
  1292  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1293  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(2)}},
  1294  				{Time: 20 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1295  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1296  				{Time: 40 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1297  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1298  			},
  1299  		},
  1300  		{
  1301  			name: "Fill_Number_Float",
  1302  			q:    `SELECT mean(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:01:00Z' GROUP BY host, time(10s) fill(1)`,
  1303  			typ:  influxql.Float,
  1304  			expr: `mean(value::float)`,
  1305  			itrs: []query.Iterator{
  1306  				&FloatIterator{Points: []query.FloatPoint{
  1307  					{Name: "cpu", Tags: ParseTags("host=A"), Time: 12 * Second, Value: 2},
  1308  				}},
  1309  			},
  1310  			rows: []query.Row{
  1311  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(1)}},
  1312  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(2)}},
  1313  				{Time: 20 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(1)}},
  1314  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(1)}},
  1315  				{Time: 40 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(1)}},
  1316  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(1)}},
  1317  			},
  1318  		},
  1319  		{
  1320  			name: "Fill_Previous_Float",
  1321  			q:    `SELECT mean(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:01:00Z' GROUP BY host, time(10s) fill(previous)`,
  1322  			typ:  influxql.Float,
  1323  			expr: `mean(value::float)`,
  1324  			itrs: []query.Iterator{
  1325  				&FloatIterator{Points: []query.FloatPoint{
  1326  					{Name: "cpu", Tags: ParseTags("host=A"), Time: 12 * Second, Value: 2},
  1327  				}},
  1328  			},
  1329  			rows: []query.Row{
  1330  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1331  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(2)}},
  1332  				{Time: 20 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(2)}},
  1333  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(2)}},
  1334  				{Time: 40 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(2)}},
  1335  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(2)}},
  1336  			},
  1337  		},
  1338  		{
  1339  			name: "Fill_Previous_Float_Two_Series",
  1340  			q:    `SELECT last(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:01:00Z' GROUP BY host, time(10s) fill(previous)`,
  1341  			typ:  influxql.Float,
  1342  			expr: `last(value::float)`,
  1343  			itrs: []query.Iterator{
  1344  				&FloatIterator{Points: []query.FloatPoint{
  1345  					{Name: "cpu", Tags: ParseTags("host=A"), Time: 30 * Second, Value: 20},
  1346  					{Name: "cpu", Tags: ParseTags("host=A"), Time: 40 * Second, Value: 30},
  1347  					{Name: "cpu", Tags: ParseTags("host=B"), Time: 30 * Second, Value: 1},
  1348  					{Name: "cpu", Tags: ParseTags("host=B"), Time: 40 * Second, Value: 2},
  1349  				}},
  1350  			},
  1351  			rows: []query.Row{
  1352  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1353  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1354  				{Time: 20 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1355  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(20)}},
  1356  				{Time: 40 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(30)}},
  1357  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(30)}},
  1358  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{nil}},
  1359  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{nil}},
  1360  				{Time: 20 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{nil}},
  1361  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(1)}},
  1362  				{Time: 40 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(2)}},
  1363  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(2)}},
  1364  			},
  1365  		},
  1366  		{
  1367  			name: "Fill_Linear_Float_One",
  1368  			q:    `SELECT mean(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:01:00Z' GROUP BY host, time(10s) fill(linear)`,
  1369  			typ:  influxql.Float,
  1370  			expr: `mean(value::float)`,
  1371  			itrs: []query.Iterator{
  1372  				&FloatIterator{Points: []query.FloatPoint{
  1373  					{Name: "cpu", Tags: ParseTags("host=A"), Time: 12 * Second, Value: 2},
  1374  					{Name: "cpu", Tags: ParseTags("host=A"), Time: 32 * Second, Value: 4},
  1375  				}},
  1376  			},
  1377  			rows: []query.Row{
  1378  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1379  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(2)}},
  1380  				{Time: 20 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(3)}},
  1381  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(4)}},
  1382  				{Time: 40 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1383  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1384  			},
  1385  		},
  1386  		{
  1387  			name: "Fill_Linear_Float_Many",
  1388  			q:    `SELECT mean(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:01:00Z' GROUP BY host, time(10s) fill(linear)`,
  1389  			typ:  influxql.Float,
  1390  			expr: `mean(value::float)`,
  1391  			itrs: []query.Iterator{
  1392  				&FloatIterator{Points: []query.FloatPoint{
  1393  					{Name: "cpu", Tags: ParseTags("host=A"), Time: 12 * Second, Value: 2},
  1394  					{Name: "cpu", Tags: ParseTags("host=A"), Time: 62 * Second, Value: 7},
  1395  				}},
  1396  			},
  1397  			rows: []query.Row{
  1398  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1399  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(2)}},
  1400  				{Time: 20 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(3)}},
  1401  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(4)}},
  1402  				{Time: 40 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(5)}},
  1403  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(6)}},
  1404  				{Time: 60 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(7)}},
  1405  			},
  1406  		},
  1407  		{
  1408  			name: "Fill_Linear_Float_MultipleSeries",
  1409  			q:    `SELECT mean(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:01:00Z' GROUP BY host, time(10s) fill(linear)`,
  1410  			typ:  influxql.Float,
  1411  			expr: `mean(value::float)`,
  1412  			itrs: []query.Iterator{
  1413  				&FloatIterator{Points: []query.FloatPoint{
  1414  					{Name: "cpu", Tags: ParseTags("host=A"), Time: 12 * Second, Value: 2},
  1415  					{Name: "cpu", Tags: ParseTags("host=B"), Time: 32 * Second, Value: 4},
  1416  				}},
  1417  			},
  1418  			rows: []query.Row{
  1419  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1420  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(2)}},
  1421  				{Time: 20 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1422  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1423  				{Time: 40 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1424  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1425  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{nil}},
  1426  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{nil}},
  1427  				{Time: 20 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{nil}},
  1428  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(4)}},
  1429  				{Time: 40 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{nil}},
  1430  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{nil}},
  1431  			},
  1432  		},
  1433  		{
  1434  			name: "Fill_Linear_Integer_One",
  1435  			q:    `SELECT max(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:01:00Z' GROUP BY host, time(10s) fill(linear)`,
  1436  			typ:  influxql.Integer,
  1437  			expr: `max(value::integer)`,
  1438  			itrs: []query.Iterator{
  1439  				&IntegerIterator{Points: []query.IntegerPoint{
  1440  					{Name: "cpu", Tags: ParseTags("host=A"), Time: 12 * Second, Value: 1},
  1441  					{Name: "cpu", Tags: ParseTags("host=A"), Time: 32 * Second, Value: 4},
  1442  				}},
  1443  			},
  1444  			rows: []query.Row{
  1445  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1446  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(1)}},
  1447  				{Time: 20 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(2)}},
  1448  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(4)}},
  1449  				{Time: 40 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1450  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1451  			},
  1452  		},
  1453  		{
  1454  			name: "Fill_Linear_Integer_Many",
  1455  			q:    `SELECT max(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:01:20Z' GROUP BY host, time(10s) fill(linear)`,
  1456  			typ:  influxql.Integer,
  1457  			expr: `max(value::integer)`,
  1458  			itrs: []query.Iterator{
  1459  				&IntegerIterator{Points: []query.IntegerPoint{
  1460  					{Name: "cpu", Tags: ParseTags("host=A"), Time: 12 * Second, Value: 1},
  1461  					{Name: "cpu", Tags: ParseTags("host=A"), Time: 72 * Second, Value: 10},
  1462  				}},
  1463  			},
  1464  			rows: []query.Row{
  1465  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1466  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(1)}},
  1467  				{Time: 20 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(2)}},
  1468  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(4)}},
  1469  				{Time: 40 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(5)}},
  1470  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(7)}},
  1471  				{Time: 60 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(8)}},
  1472  				{Time: 70 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(10)}},
  1473  			},
  1474  		},
  1475  		{
  1476  			name: "Fill_Linear_Integer_MultipleSeries",
  1477  			q:    `SELECT max(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:01:00Z' GROUP BY host, time(10s) fill(linear)`,
  1478  			typ:  influxql.Integer,
  1479  			expr: `max(value::integer)`,
  1480  			itrs: []query.Iterator{
  1481  				&IntegerIterator{Points: []query.IntegerPoint{
  1482  					{Name: "cpu", Tags: ParseTags("host=A"), Time: 12 * Second, Value: 2},
  1483  					{Name: "cpu", Tags: ParseTags("host=B"), Time: 32 * Second, Value: 4},
  1484  				}},
  1485  			},
  1486  			rows: []query.Row{
  1487  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1488  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(2)}},
  1489  				{Time: 20 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1490  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1491  				{Time: 40 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1492  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1493  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{nil}},
  1494  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{nil}},
  1495  				{Time: 20 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{nil}},
  1496  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{int64(4)}},
  1497  				{Time: 40 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{nil}},
  1498  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{nil}},
  1499  			},
  1500  		},
  1501  		{
  1502  			name: "Fill_Linear_Unsigned_One",
  1503  			q:    `SELECT max(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:01:00Z' GROUP BY host, time(10s) fill(linear)`,
  1504  			typ:  influxql.Unsigned,
  1505  			expr: `max(value::Unsigned)`,
  1506  			itrs: []query.Iterator{
  1507  				&UnsignedIterator{Points: []query.UnsignedPoint{
  1508  					{Name: "cpu", Tags: ParseTags("host=A"), Time: 12 * Second, Value: 1},
  1509  					{Name: "cpu", Tags: ParseTags("host=A"), Time: 32 * Second, Value: 4},
  1510  				}},
  1511  			},
  1512  			rows: []query.Row{
  1513  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1514  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(1)}},
  1515  				{Time: 20 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(2)}},
  1516  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(4)}},
  1517  				{Time: 40 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1518  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1519  			},
  1520  		},
  1521  		{
  1522  			name: "Fill_Linear_Unsigned_Many",
  1523  			q:    `SELECT max(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:01:20Z' GROUP BY host, time(10s) fill(linear)`,
  1524  			typ:  influxql.Unsigned,
  1525  			expr: `max(value::Unsigned)`,
  1526  			itrs: []query.Iterator{
  1527  				&UnsignedIterator{Points: []query.UnsignedPoint{
  1528  					{Name: "cpu", Tags: ParseTags("host=A"), Time: 12 * Second, Value: 1},
  1529  					{Name: "cpu", Tags: ParseTags("host=A"), Time: 72 * Second, Value: 10},
  1530  				}},
  1531  			},
  1532  			rows: []query.Row{
  1533  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1534  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(1)}},
  1535  				{Time: 20 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(2)}},
  1536  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(4)}},
  1537  				{Time: 40 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(5)}},
  1538  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(7)}},
  1539  				{Time: 60 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(8)}},
  1540  				{Time: 70 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(10)}},
  1541  			},
  1542  		},
  1543  		{
  1544  			name: "Fill_Linear_Unsigned_MultipleSeries",
  1545  			q:    `SELECT max(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:01:00Z' GROUP BY host, time(10s) fill(linear)`,
  1546  			typ:  influxql.Unsigned,
  1547  			expr: `max(value::Unsigned)`,
  1548  			itrs: []query.Iterator{
  1549  				&UnsignedIterator{Points: []query.UnsignedPoint{
  1550  					{Name: "cpu", Tags: ParseTags("host=A"), Time: 12 * Second, Value: 2},
  1551  					{Name: "cpu", Tags: ParseTags("host=B"), Time: 32 * Second, Value: 4},
  1552  				}},
  1553  			},
  1554  			rows: []query.Row{
  1555  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1556  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(2)}},
  1557  				{Time: 20 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1558  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1559  				{Time: 40 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1560  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{nil}},
  1561  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{nil}},
  1562  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{nil}},
  1563  				{Time: 20 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{nil}},
  1564  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{uint64(4)}},
  1565  				{Time: 40 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{nil}},
  1566  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{nil}},
  1567  			},
  1568  		},
  1569  		{
  1570  			name: "Stddev_Float",
  1571  			q:    `SELECT stddev(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
  1572  			typ:  influxql.Float,
  1573  			itrs: []query.Iterator{
  1574  				&FloatIterator{Points: []query.FloatPoint{
  1575  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
  1576  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3},
  1577  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100},
  1578  				}},
  1579  				&FloatIterator{Points: []query.FloatPoint{
  1580  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
  1581  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1},
  1582  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2},
  1583  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 3},
  1584  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4},
  1585  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5},
  1586  				}},
  1587  				&FloatIterator{Points: []query.FloatPoint{
  1588  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
  1589  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
  1590  				}},
  1591  			},
  1592  			rows: []query.Row{
  1593  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{0.7071067811865476}},
  1594  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{0.7071067811865476}},
  1595  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{query.NullFloat}},
  1596  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{query.NullFloat}},
  1597  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{1.5811388300841898}},
  1598  			},
  1599  		},
  1600  		{
  1601  			name: "Stddev_Integer",
  1602  			q:    `SELECT stddev(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
  1603  			typ:  influxql.Integer,
  1604  			itrs: []query.Iterator{
  1605  				&IntegerIterator{Points: []query.IntegerPoint{
  1606  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
  1607  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3},
  1608  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100},
  1609  				}},
  1610  				&IntegerIterator{Points: []query.IntegerPoint{
  1611  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
  1612  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1},
  1613  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2},
  1614  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 3},
  1615  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4},
  1616  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5},
  1617  				}},
  1618  				&IntegerIterator{Points: []query.IntegerPoint{
  1619  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
  1620  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
  1621  				}},
  1622  			},
  1623  			rows: []query.Row{
  1624  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{0.7071067811865476}},
  1625  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{0.7071067811865476}},
  1626  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{query.NullFloat}},
  1627  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{query.NullFloat}},
  1628  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{1.5811388300841898}},
  1629  			},
  1630  		},
  1631  		{
  1632  			name: "Stddev_Unsigned",
  1633  			q:    `SELECT stddev(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
  1634  			typ:  influxql.Unsigned,
  1635  			itrs: []query.Iterator{
  1636  				&UnsignedIterator{Points: []query.UnsignedPoint{
  1637  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
  1638  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3},
  1639  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100},
  1640  				}},
  1641  				&UnsignedIterator{Points: []query.UnsignedPoint{
  1642  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
  1643  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1},
  1644  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2},
  1645  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 3},
  1646  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4},
  1647  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5},
  1648  				}},
  1649  				&UnsignedIterator{Points: []query.UnsignedPoint{
  1650  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
  1651  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
  1652  				}},
  1653  			},
  1654  			rows: []query.Row{
  1655  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{0.7071067811865476}},
  1656  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{0.7071067811865476}},
  1657  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{query.NullFloat}},
  1658  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{query.NullFloat}},
  1659  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{1.5811388300841898}},
  1660  			},
  1661  		},
  1662  		{
  1663  			name: "Spread_Float",
  1664  			q:    `SELECT spread(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
  1665  			typ:  influxql.Float,
  1666  			itrs: []query.Iterator{
  1667  				&FloatIterator{Points: []query.FloatPoint{
  1668  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
  1669  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3},
  1670  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100},
  1671  				}},
  1672  				&FloatIterator{Points: []query.FloatPoint{
  1673  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
  1674  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1},
  1675  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2},
  1676  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 3},
  1677  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4},
  1678  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5},
  1679  				}},
  1680  				&FloatIterator{Points: []query.FloatPoint{
  1681  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
  1682  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
  1683  				}},
  1684  			},
  1685  			rows: []query.Row{
  1686  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(1)}},
  1687  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(1)}},
  1688  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(0)}},
  1689  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(0)}},
  1690  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(4)}},
  1691  			},
  1692  		},
  1693  		{
  1694  			name: "Spread_Integer",
  1695  			q:    `SELECT spread(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
  1696  			typ:  influxql.Integer,
  1697  			itrs: []query.Iterator{
  1698  				&IntegerIterator{Points: []query.IntegerPoint{
  1699  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
  1700  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3},
  1701  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100},
  1702  				}},
  1703  				&IntegerIterator{Points: []query.IntegerPoint{
  1704  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
  1705  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1},
  1706  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2},
  1707  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 3},
  1708  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4},
  1709  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5},
  1710  				}},
  1711  				&IntegerIterator{Points: []query.IntegerPoint{
  1712  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
  1713  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
  1714  				}},
  1715  			},
  1716  			rows: []query.Row{
  1717  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(1)}},
  1718  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(1)}},
  1719  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(0)}},
  1720  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{int64(0)}},
  1721  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{int64(4)}},
  1722  			},
  1723  		},
  1724  		{
  1725  			name: "Spread_Unsigned",
  1726  			q:    `SELECT spread(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
  1727  			typ:  influxql.Unsigned,
  1728  			itrs: []query.Iterator{
  1729  				&UnsignedIterator{Points: []query.UnsignedPoint{
  1730  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
  1731  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3},
  1732  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100},
  1733  				}},
  1734  				&UnsignedIterator{Points: []query.UnsignedPoint{
  1735  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
  1736  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 1},
  1737  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 2},
  1738  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 3},
  1739  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 4},
  1740  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 5},
  1741  				}},
  1742  				&UnsignedIterator{Points: []query.UnsignedPoint{
  1743  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
  1744  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
  1745  				}},
  1746  			},
  1747  			rows: []query.Row{
  1748  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(1)}},
  1749  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(1)}},
  1750  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(0)}},
  1751  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{uint64(0)}},
  1752  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{uint64(4)}},
  1753  			},
  1754  		},
  1755  		{
  1756  			name: "Percentile_Float",
  1757  			q:    `SELECT percentile(value, 90) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
  1758  			typ:  influxql.Float,
  1759  			itrs: []query.Iterator{
  1760  				&FloatIterator{Points: []query.FloatPoint{
  1761  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
  1762  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3},
  1763  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100},
  1764  				}},
  1765  				&FloatIterator{Points: []query.FloatPoint{
  1766  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
  1767  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 10},
  1768  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 9},
  1769  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 8},
  1770  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 7},
  1771  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 54 * Second, Value: 6},
  1772  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 55 * Second, Value: 5},
  1773  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 56 * Second, Value: 4},
  1774  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 57 * Second, Value: 3},
  1775  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 58 * Second, Value: 2},
  1776  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 59 * Second, Value: 1},
  1777  				}},
  1778  				&FloatIterator{Points: []query.FloatPoint{
  1779  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
  1780  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
  1781  				}},
  1782  			},
  1783  			rows: []query.Row{
  1784  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(20)}},
  1785  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(3)}},
  1786  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(100)}},
  1787  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(10)}},
  1788  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(9)}},
  1789  			},
  1790  		},
  1791  		{
  1792  			name: "Percentile_Integer",
  1793  			q:    `SELECT percentile(value, 90) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
  1794  			typ:  influxql.Integer,
  1795  			itrs: []query.Iterator{
  1796  				&IntegerIterator{Points: []query.IntegerPoint{
  1797  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
  1798  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3},
  1799  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100},
  1800  				}},
  1801  				&IntegerIterator{Points: []query.IntegerPoint{
  1802  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
  1803  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 10},
  1804  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 9},
  1805  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 8},
  1806  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 7},
  1807  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 54 * Second, Value: 6},
  1808  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 55 * Second, Value: 5},
  1809  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 56 * Second, Value: 4},
  1810  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 57 * Second, Value: 3},
  1811  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 58 * Second, Value: 2},
  1812  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 59 * Second, Value: 1},
  1813  				}},
  1814  				&IntegerIterator{Points: []query.IntegerPoint{
  1815  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
  1816  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
  1817  				}},
  1818  			},
  1819  			rows: []query.Row{
  1820  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(20)}},
  1821  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(3)}},
  1822  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(100)}},
  1823  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{int64(10)}},
  1824  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{int64(9)}},
  1825  			},
  1826  		},
  1827  		{
  1828  			name: "Percentile_Unsigned",
  1829  			q:    `SELECT percentile(value, 90) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
  1830  			typ:  influxql.Unsigned,
  1831  			itrs: []query.Iterator{
  1832  				&UnsignedIterator{Points: []query.UnsignedPoint{
  1833  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
  1834  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3},
  1835  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100},
  1836  				}},
  1837  				&UnsignedIterator{Points: []query.UnsignedPoint{
  1838  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
  1839  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 50 * Second, Value: 10},
  1840  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 51 * Second, Value: 9},
  1841  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 52 * Second, Value: 8},
  1842  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 53 * Second, Value: 7},
  1843  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 54 * Second, Value: 6},
  1844  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 55 * Second, Value: 5},
  1845  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 56 * Second, Value: 4},
  1846  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 57 * Second, Value: 3},
  1847  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 58 * Second, Value: 2},
  1848  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 59 * Second, Value: 1},
  1849  				}},
  1850  				&UnsignedIterator{Points: []query.UnsignedPoint{
  1851  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
  1852  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
  1853  				}},
  1854  			},
  1855  			rows: []query.Row{
  1856  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(20)}},
  1857  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(3)}},
  1858  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(100)}},
  1859  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{uint64(10)}},
  1860  				{Time: 50 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{uint64(9)}},
  1861  			},
  1862  		},
  1863  		{
  1864  			name: "Sample_Float",
  1865  			q:    `SELECT sample(value, 2) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
  1866  			typ:  influxql.Float,
  1867  			itrs: []query.Iterator{
  1868  				&FloatIterator{Points: []query.FloatPoint{
  1869  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
  1870  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 5 * Second, Value: 10},
  1871  				}},
  1872  				&FloatIterator{Points: []query.FloatPoint{
  1873  					{Name: "cpu", Tags: ParseTags("region=east,host=B"), Time: 10 * Second, Value: 19},
  1874  					{Name: "cpu", Tags: ParseTags("region=east,host=B"), Time: 15 * Second, Value: 2},
  1875  				}},
  1876  			},
  1877  			rows: []query.Row{
  1878  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(20)}},
  1879  				{Time: 5 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(10)}},
  1880  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(19)}},
  1881  				{Time: 15 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(2)}},
  1882  			},
  1883  		},
  1884  		{
  1885  			name: "Sample_Integer",
  1886  			q:    `SELECT sample(value, 2) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
  1887  			typ:  influxql.Integer,
  1888  			itrs: []query.Iterator{
  1889  				&IntegerIterator{Points: []query.IntegerPoint{
  1890  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
  1891  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 5 * Second, Value: 10},
  1892  				}},
  1893  				&IntegerIterator{Points: []query.IntegerPoint{
  1894  					{Name: "cpu", Tags: ParseTags("region=east,host=B"), Time: 10 * Second, Value: 19},
  1895  					{Name: "cpu", Tags: ParseTags("region=east,host=B"), Time: 15 * Second, Value: 2},
  1896  				}},
  1897  			},
  1898  			rows: []query.Row{
  1899  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(20)}},
  1900  				{Time: 5 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{int64(10)}},
  1901  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{int64(19)}},
  1902  				{Time: 15 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{int64(2)}},
  1903  			},
  1904  		},
  1905  		{
  1906  			name: "Sample_Unsigned",
  1907  			q:    `SELECT sample(value, 2) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
  1908  			typ:  influxql.Unsigned,
  1909  			itrs: []query.Iterator{
  1910  				&UnsignedIterator{Points: []query.UnsignedPoint{
  1911  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
  1912  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 5 * Second, Value: 10},
  1913  				}},
  1914  				&UnsignedIterator{Points: []query.UnsignedPoint{
  1915  					{Name: "cpu", Tags: ParseTags("region=east,host=B"), Time: 10 * Second, Value: 19},
  1916  					{Name: "cpu", Tags: ParseTags("region=east,host=B"), Time: 15 * Second, Value: 2},
  1917  				}},
  1918  			},
  1919  			rows: []query.Row{
  1920  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(20)}},
  1921  				{Time: 5 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{uint64(10)}},
  1922  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{uint64(19)}},
  1923  				{Time: 15 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{uint64(2)}},
  1924  			},
  1925  		},
  1926  		{
  1927  			name: "Sample_String",
  1928  			q:    `SELECT sample(value, 2) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
  1929  			typ:  influxql.String,
  1930  			itrs: []query.Iterator{
  1931  				&StringIterator{Points: []query.StringPoint{
  1932  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: "a"},
  1933  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 5 * Second, Value: "b"},
  1934  				}},
  1935  				&StringIterator{Points: []query.StringPoint{
  1936  					{Name: "cpu", Tags: ParseTags("region=east,host=B"), Time: 10 * Second, Value: "c"},
  1937  					{Name: "cpu", Tags: ParseTags("region=east,host=B"), Time: 15 * Second, Value: "d"},
  1938  				}},
  1939  			},
  1940  			rows: []query.Row{
  1941  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{"a"}},
  1942  				{Time: 5 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{"b"}},
  1943  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{"c"}},
  1944  				{Time: 15 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{"d"}},
  1945  			},
  1946  		},
  1947  		{
  1948  			name: "Sample_Boolean",
  1949  			q:    `SELECT sample(value, 2) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
  1950  			typ:  influxql.Boolean,
  1951  			itrs: []query.Iterator{
  1952  				&BooleanIterator{Points: []query.BooleanPoint{
  1953  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: true},
  1954  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 5 * Second, Value: false},
  1955  				}},
  1956  				&BooleanIterator{Points: []query.BooleanPoint{
  1957  					{Name: "cpu", Tags: ParseTags("region=east,host=B"), Time: 10 * Second, Value: false},
  1958  					{Name: "cpu", Tags: ParseTags("region=east,host=B"), Time: 15 * Second, Value: true},
  1959  				}},
  1960  			},
  1961  			rows: []query.Row{
  1962  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{true}},
  1963  				{Time: 5 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{false}},
  1964  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{false}},
  1965  				{Time: 15 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{true}},
  1966  			},
  1967  		},
  1968  		//{
  1969  		//	name: "Raw",
  1970  		//	q:    `SELECT v1::float, v2::float FROM cpu`,
  1971  		//	itrs: []query.Iterator{
  1972  		//		&FloatIterator{Points: []query.FloatPoint{
  1973  		//			{Time: 0, Aux: []interface{}{float64(1), nil}},
  1974  		//			{Time: 1, Aux: []interface{}{nil, float64(2)}},
  1975  		//			{Time: 5, Aux: []interface{}{float64(3), float64(4)}},
  1976  		//		}},
  1977  		//	},
  1978  		//	points: [][]query.Point{
  1979  		//		{
  1980  		//			&query.FloatPoint{Time: 0, Value: 1},
  1981  		//			&query.FloatPoint{Time: 0, Nil: true},
  1982  		//		},
  1983  		//		{
  1984  		//			&query.FloatPoint{Time: 1, Nil: true},
  1985  		//			&query.FloatPoint{Time: 1, Value: 2},
  1986  		//		},
  1987  		//		{
  1988  		//			&query.FloatPoint{Time: 5, Value: 3},
  1989  		//			&query.FloatPoint{Time: 5, Value: 4},
  1990  		//		},
  1991  		//	},
  1992  		//},
  1993  		{
  1994  			name: "ParenExpr_Min",
  1995  			q:    `SELECT (min(value)) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
  1996  			typ:  influxql.Float,
  1997  			expr: `min(value::float)`,
  1998  			itrs: []query.Iterator{
  1999  				&FloatIterator{Points: []query.FloatPoint{
  2000  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
  2001  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3},
  2002  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100},
  2003  				}},
  2004  				&FloatIterator{Points: []query.FloatPoint{
  2005  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
  2006  				}},
  2007  				&FloatIterator{Points: []query.FloatPoint{
  2008  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
  2009  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
  2010  				}},
  2011  			},
  2012  			rows: []query.Row{
  2013  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(19)}},
  2014  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(2)}},
  2015  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(100)}},
  2016  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(10)}},
  2017  			},
  2018  		},
  2019  		{
  2020  			name: "ParenExpr_Distinct",
  2021  			q:    `SELECT (distinct(value)) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
  2022  			typ:  influxql.Float,
  2023  			itrs: []query.Iterator{
  2024  				&FloatIterator{Points: []query.FloatPoint{
  2025  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
  2026  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 1 * Second, Value: 19},
  2027  				}},
  2028  				&FloatIterator{Points: []query.FloatPoint{
  2029  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
  2030  				}},
  2031  				&FloatIterator{Points: []query.FloatPoint{
  2032  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
  2033  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
  2034  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 11 * Second, Value: 2},
  2035  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 12 * Second, Value: 2},
  2036  				}},
  2037  			},
  2038  			rows: []query.Row{
  2039  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(20)}},
  2040  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(19)}},
  2041  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(2)}},
  2042  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(10)}},
  2043  			},
  2044  		},
  2045  		{
  2046  			name: "Derivative_Float",
  2047  			q:    `SELECT derivative(value, 1s) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2048  			typ:  influxql.Float,
  2049  			itrs: []query.Iterator{
  2050  				&FloatIterator{Points: []query.FloatPoint{
  2051  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2052  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2053  					{Name: "cpu", Time: 8 * Second, Value: 19},
  2054  					{Name: "cpu", Time: 12 * Second, Value: 3},
  2055  				}},
  2056  			},
  2057  			rows: []query.Row{
  2058  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-2.5)}},
  2059  				{Time: 8 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(2.25)}},
  2060  				{Time: 12 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-4)}},
  2061  			},
  2062  		},
  2063  		{
  2064  			name: "Derivative_Integer",
  2065  			q:    `SELECT derivative(value, 1s) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2066  			typ:  influxql.Integer,
  2067  			itrs: []query.Iterator{
  2068  				&IntegerIterator{Points: []query.IntegerPoint{
  2069  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2070  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2071  					{Name: "cpu", Time: 8 * Second, Value: 19},
  2072  					{Name: "cpu", Time: 12 * Second, Value: 3},
  2073  				}},
  2074  			},
  2075  			rows: []query.Row{
  2076  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-2.5)}},
  2077  				{Time: 8 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(2.25)}},
  2078  				{Time: 12 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-4)}},
  2079  			},
  2080  		},
  2081  		{
  2082  			name: "Derivative_Unsigned",
  2083  			q:    `SELECT derivative(value, 1s) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2084  			typ:  influxql.Unsigned,
  2085  			itrs: []query.Iterator{
  2086  				&UnsignedIterator{Points: []query.UnsignedPoint{
  2087  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2088  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2089  					{Name: "cpu", Time: 8 * Second, Value: 19},
  2090  					{Name: "cpu", Time: 12 * Second, Value: 3},
  2091  				}},
  2092  			},
  2093  			rows: []query.Row{
  2094  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-2.5)}},
  2095  				{Time: 8 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(2.25)}},
  2096  				{Time: 12 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-4)}},
  2097  			},
  2098  		},
  2099  		{
  2100  			name: "Derivative_Desc_Float",
  2101  			q:    `SELECT derivative(value, 1s) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z' ORDER BY desc`,
  2102  			typ:  influxql.Float,
  2103  			itrs: []query.Iterator{
  2104  				&FloatIterator{Points: []query.FloatPoint{
  2105  					{Name: "cpu", Time: 12 * Second, Value: 3},
  2106  					{Name: "cpu", Time: 8 * Second, Value: 19},
  2107  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2108  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2109  				}},
  2110  			},
  2111  			rows: []query.Row{
  2112  				{Time: 8 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(4)}},
  2113  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-2.25)}},
  2114  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(2.5)}},
  2115  			},
  2116  		},
  2117  		{
  2118  			name: "Derivative_Desc_Integer",
  2119  			q:    `SELECT derivative(value, 1s) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z' ORDER BY desc`,
  2120  			typ:  influxql.Integer,
  2121  			itrs: []query.Iterator{
  2122  				&IntegerIterator{Points: []query.IntegerPoint{
  2123  					{Name: "cpu", Time: 12 * Second, Value: 3},
  2124  					{Name: "cpu", Time: 8 * Second, Value: 19},
  2125  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2126  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2127  				}},
  2128  			},
  2129  			rows: []query.Row{
  2130  				{Time: 8 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(4)}},
  2131  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-2.25)}},
  2132  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(2.5)}},
  2133  			},
  2134  		},
  2135  		{
  2136  			name: "Derivative_Desc_Unsigned",
  2137  			q:    `SELECT derivative(value, 1s) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z' ORDER BY desc`,
  2138  			typ:  influxql.Unsigned,
  2139  			itrs: []query.Iterator{
  2140  				&UnsignedIterator{Points: []query.UnsignedPoint{
  2141  					{Name: "cpu", Time: 12 * Second, Value: 3},
  2142  					{Name: "cpu", Time: 8 * Second, Value: 19},
  2143  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2144  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2145  				}},
  2146  			},
  2147  			rows: []query.Row{
  2148  				{Time: 8 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(4)}},
  2149  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-2.25)}},
  2150  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(2.5)}},
  2151  			},
  2152  		},
  2153  		{
  2154  			name: "Derivative_Duplicate_Float",
  2155  			q:    `SELECT derivative(value, 1s) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2156  			typ:  influxql.Float,
  2157  			itrs: []query.Iterator{
  2158  				&FloatIterator{Points: []query.FloatPoint{
  2159  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2160  					{Name: "cpu", Time: 0 * Second, Value: 19},
  2161  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2162  					{Name: "cpu", Time: 4 * Second, Value: 3},
  2163  				}},
  2164  			},
  2165  			rows: []query.Row{
  2166  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-2.5)}},
  2167  			},
  2168  		},
  2169  		{
  2170  			name: "Derivative_Duplicate_Integer",
  2171  			q:    `SELECT derivative(value, 1s) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2172  			typ:  influxql.Integer,
  2173  			itrs: []query.Iterator{
  2174  				&IntegerIterator{Points: []query.IntegerPoint{
  2175  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2176  					{Name: "cpu", Time: 0 * Second, Value: 19},
  2177  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2178  					{Name: "cpu", Time: 4 * Second, Value: 3},
  2179  				}},
  2180  			},
  2181  			rows: []query.Row{
  2182  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-2.5)}},
  2183  			},
  2184  		},
  2185  		{
  2186  			name: "Derivative_Duplicate_Unsigned",
  2187  			q:    `SELECT derivative(value, 1s) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2188  			typ:  influxql.Unsigned,
  2189  			itrs: []query.Iterator{
  2190  				&UnsignedIterator{Points: []query.UnsignedPoint{
  2191  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2192  					{Name: "cpu", Time: 0 * Second, Value: 19},
  2193  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2194  					{Name: "cpu", Time: 4 * Second, Value: 3},
  2195  				}},
  2196  			},
  2197  			rows: []query.Row{
  2198  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-2.5)}},
  2199  			},
  2200  		},
  2201  		{
  2202  			name: "Difference_Float",
  2203  			q:    `SELECT difference(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2204  			typ:  influxql.Float,
  2205  			itrs: []query.Iterator{
  2206  				&FloatIterator{Points: []query.FloatPoint{
  2207  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2208  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2209  					{Name: "cpu", Time: 8 * Second, Value: 19},
  2210  					{Name: "cpu", Time: 12 * Second, Value: 3},
  2211  				}},
  2212  			},
  2213  			rows: []query.Row{
  2214  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-10)}},
  2215  				{Time: 8 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(9)}},
  2216  				{Time: 12 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-16)}},
  2217  			},
  2218  		},
  2219  		{
  2220  			name: "Difference_Integer",
  2221  			q:    `SELECT difference(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2222  			typ:  influxql.Integer,
  2223  			itrs: []query.Iterator{
  2224  				&IntegerIterator{Points: []query.IntegerPoint{
  2225  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2226  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2227  					{Name: "cpu", Time: 8 * Second, Value: 19},
  2228  					{Name: "cpu", Time: 12 * Second, Value: 3},
  2229  				}},
  2230  			},
  2231  			rows: []query.Row{
  2232  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(-10)}},
  2233  				{Time: 8 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(9)}},
  2234  				{Time: 12 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(-16)}},
  2235  			},
  2236  		},
  2237  		{
  2238  			name: "Difference_Unsigned",
  2239  			q:    `SELECT difference(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2240  			typ:  influxql.Unsigned,
  2241  			itrs: []query.Iterator{
  2242  				&UnsignedIterator{Points: []query.UnsignedPoint{
  2243  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2244  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2245  					{Name: "cpu", Time: 8 * Second, Value: 19},
  2246  					{Name: "cpu", Time: 12 * Second, Value: 3},
  2247  				}},
  2248  			},
  2249  			rows: []query.Row{
  2250  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(18446744073709551606)}},
  2251  				{Time: 8 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(9)}},
  2252  				{Time: 12 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(18446744073709551600)}},
  2253  			},
  2254  		},
  2255  		{
  2256  			name: "Difference_Duplicate_Float",
  2257  			q:    `SELECT difference(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2258  			typ:  influxql.Float,
  2259  			itrs: []query.Iterator{
  2260  				&FloatIterator{Points: []query.FloatPoint{
  2261  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2262  					{Name: "cpu", Time: 0 * Second, Value: 19},
  2263  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2264  					{Name: "cpu", Time: 4 * Second, Value: 3},
  2265  				}},
  2266  			},
  2267  			rows: []query.Row{
  2268  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-10)}},
  2269  			},
  2270  		},
  2271  		{
  2272  			name: "Difference_Duplicate_Integer",
  2273  			q:    `SELECT difference(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2274  			typ:  influxql.Integer,
  2275  			itrs: []query.Iterator{
  2276  				&IntegerIterator{Points: []query.IntegerPoint{
  2277  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2278  					{Name: "cpu", Time: 0 * Second, Value: 19},
  2279  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2280  					{Name: "cpu", Time: 4 * Second, Value: 3},
  2281  				}},
  2282  			},
  2283  			rows: []query.Row{
  2284  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(-10)}},
  2285  			},
  2286  		},
  2287  		{
  2288  			name: "Difference_Duplicate_Unsigned",
  2289  			q:    `SELECT difference(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2290  			typ:  influxql.Unsigned,
  2291  			itrs: []query.Iterator{
  2292  				&UnsignedIterator{Points: []query.UnsignedPoint{
  2293  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2294  					{Name: "cpu", Time: 0 * Second, Value: 19},
  2295  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2296  					{Name: "cpu", Time: 4 * Second, Value: 3},
  2297  				}},
  2298  			},
  2299  			rows: []query.Row{
  2300  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(18446744073709551606)}},
  2301  			},
  2302  		},
  2303  		{
  2304  			name: "Non_Negative_Difference_Float",
  2305  			q:    `SELECT non_negative_difference(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2306  			typ:  influxql.Float,
  2307  			itrs: []query.Iterator{
  2308  				&FloatIterator{Points: []query.FloatPoint{
  2309  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2310  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2311  					{Name: "cpu", Time: 8 * Second, Value: 29},
  2312  					{Name: "cpu", Time: 12 * Second, Value: 3},
  2313  					{Name: "cpu", Time: 16 * Second, Value: 39},
  2314  				}},
  2315  			},
  2316  			rows: []query.Row{
  2317  				{Time: 8 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(19)}},
  2318  				{Time: 16 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(36)}},
  2319  			},
  2320  		},
  2321  		{
  2322  			name: "Non_Negative_Difference_Integer",
  2323  			q:    `SELECT non_negative_difference(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2324  			typ:  influxql.Integer,
  2325  			itrs: []query.Iterator{
  2326  				&IntegerIterator{Points: []query.IntegerPoint{
  2327  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2328  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2329  					{Name: "cpu", Time: 8 * Second, Value: 21},
  2330  					{Name: "cpu", Time: 12 * Second, Value: 3},
  2331  				}},
  2332  			},
  2333  			rows: []query.Row{
  2334  				{Time: 8 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(11)}},
  2335  			},
  2336  		},
  2337  		{
  2338  			name: "Non_Negative_Difference_Unsigned",
  2339  			q:    `SELECT non_negative_difference(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2340  			typ:  influxql.Unsigned,
  2341  			itrs: []query.Iterator{
  2342  				&UnsignedIterator{Points: []query.UnsignedPoint{
  2343  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2344  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2345  					{Name: "cpu", Time: 8 * Second, Value: 21},
  2346  					{Name: "cpu", Time: 12 * Second, Value: 3},
  2347  				}},
  2348  			},
  2349  			rows: []query.Row{
  2350  				{Time: 8 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(11)}},
  2351  			},
  2352  		},
  2353  		{
  2354  			name: "Non_Negative_Difference_Duplicate_Float",
  2355  			q:    `SELECT non_negative_difference(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2356  			typ:  influxql.Float,
  2357  			itrs: []query.Iterator{
  2358  				&FloatIterator{Points: []query.FloatPoint{
  2359  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2360  					{Name: "cpu", Time: 0 * Second, Value: 19},
  2361  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2362  					{Name: "cpu", Time: 4 * Second, Value: 3},
  2363  					{Name: "cpu", Time: 8 * Second, Value: 30},
  2364  					{Name: "cpu", Time: 8 * Second, Value: 19},
  2365  					{Name: "cpu", Time: 12 * Second, Value: 10},
  2366  					{Name: "cpu", Time: 12 * Second, Value: 3},
  2367  					{Name: "cpu", Time: 16 * Second, Value: 40},
  2368  					{Name: "cpu", Time: 16 * Second, Value: 3},
  2369  				}},
  2370  			},
  2371  			rows: []query.Row{
  2372  				{Time: 8 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(20)}},
  2373  				{Time: 16 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(30)}},
  2374  			},
  2375  		},
  2376  		{
  2377  			name: "Non_Negative_Difference_Duplicate_Integer",
  2378  			q:    `SELECT non_negative_difference(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2379  			typ:  influxql.Integer,
  2380  			itrs: []query.Iterator{
  2381  				&IntegerIterator{Points: []query.IntegerPoint{
  2382  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2383  					{Name: "cpu", Time: 0 * Second, Value: 19},
  2384  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2385  					{Name: "cpu", Time: 4 * Second, Value: 3},
  2386  					{Name: "cpu", Time: 8 * Second, Value: 30},
  2387  					{Name: "cpu", Time: 8 * Second, Value: 19},
  2388  					{Name: "cpu", Time: 12 * Second, Value: 10},
  2389  					{Name: "cpu", Time: 12 * Second, Value: 3},
  2390  					{Name: "cpu", Time: 16 * Second, Value: 40},
  2391  					{Name: "cpu", Time: 16 * Second, Value: 3},
  2392  				}},
  2393  			},
  2394  			rows: []query.Row{
  2395  				{Time: 8 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(20)}},
  2396  				{Time: 16 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(30)}},
  2397  			},
  2398  		},
  2399  		{
  2400  			name: "Non_Negative_Difference_Duplicate_Unsigned",
  2401  			q:    `SELECT non_negative_difference(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2402  			typ:  influxql.Unsigned,
  2403  			itrs: []query.Iterator{
  2404  				&UnsignedIterator{Points: []query.UnsignedPoint{
  2405  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2406  					{Name: "cpu", Time: 0 * Second, Value: 19},
  2407  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2408  					{Name: "cpu", Time: 4 * Second, Value: 3},
  2409  					{Name: "cpu", Time: 8 * Second, Value: 30},
  2410  					{Name: "cpu", Time: 8 * Second, Value: 19},
  2411  					{Name: "cpu", Time: 12 * Second, Value: 10},
  2412  					{Name: "cpu", Time: 12 * Second, Value: 3},
  2413  					{Name: "cpu", Time: 16 * Second, Value: 40},
  2414  					{Name: "cpu", Time: 16 * Second, Value: 3},
  2415  				}},
  2416  			},
  2417  			rows: []query.Row{
  2418  				{Time: 8 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(20)}},
  2419  				{Time: 16 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(30)}},
  2420  			},
  2421  		},
  2422  		{
  2423  			name: "Elapsed_Float",
  2424  			q:    `SELECT elapsed(value, 1s) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2425  			typ:  influxql.Float,
  2426  			itrs: []query.Iterator{
  2427  				&FloatIterator{Points: []query.FloatPoint{
  2428  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2429  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2430  					{Name: "cpu", Time: 8 * Second, Value: 19},
  2431  					{Name: "cpu", Time: 11 * Second, Value: 3},
  2432  				}},
  2433  			},
  2434  			rows: []query.Row{
  2435  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(4)}},
  2436  				{Time: 8 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(4)}},
  2437  				{Time: 11 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(3)}},
  2438  			},
  2439  		},
  2440  		{
  2441  			name: "Elapsed_Integer",
  2442  			q:    `SELECT elapsed(value, 1s) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2443  			typ:  influxql.Integer,
  2444  			itrs: []query.Iterator{
  2445  				&IntegerIterator{Points: []query.IntegerPoint{
  2446  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2447  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2448  					{Name: "cpu", Time: 8 * Second, Value: 19},
  2449  					{Name: "cpu", Time: 11 * Second, Value: 3},
  2450  				}},
  2451  			},
  2452  			rows: []query.Row{
  2453  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(4)}},
  2454  				{Time: 8 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(4)}},
  2455  				{Time: 11 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(3)}},
  2456  			},
  2457  		},
  2458  		{
  2459  			name: "Elapsed_Unsigned",
  2460  			q:    `SELECT elapsed(value, 1s) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2461  			typ:  influxql.Unsigned,
  2462  			itrs: []query.Iterator{
  2463  				&UnsignedIterator{Points: []query.UnsignedPoint{
  2464  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2465  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2466  					{Name: "cpu", Time: 8 * Second, Value: 19},
  2467  					{Name: "cpu", Time: 11 * Second, Value: 3},
  2468  				}},
  2469  			},
  2470  			rows: []query.Row{
  2471  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(4)}},
  2472  				{Time: 8 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(4)}},
  2473  				{Time: 11 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(3)}},
  2474  			},
  2475  		},
  2476  		{
  2477  			name: "Elapsed_String",
  2478  			q:    `SELECT elapsed(value, 1s) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2479  			typ:  influxql.String,
  2480  			itrs: []query.Iterator{
  2481  				&StringIterator{Points: []query.StringPoint{
  2482  					{Name: "cpu", Time: 0 * Second, Value: "a"},
  2483  					{Name: "cpu", Time: 4 * Second, Value: "b"},
  2484  					{Name: "cpu", Time: 8 * Second, Value: "c"},
  2485  					{Name: "cpu", Time: 11 * Second, Value: "d"},
  2486  				}},
  2487  			},
  2488  			rows: []query.Row{
  2489  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(4)}},
  2490  				{Time: 8 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(4)}},
  2491  				{Time: 11 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(3)}},
  2492  			},
  2493  		},
  2494  		{
  2495  			name: "Elapsed_Boolean",
  2496  			q:    `SELECT elapsed(value, 1s) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2497  			typ:  influxql.Boolean,
  2498  			itrs: []query.Iterator{
  2499  				&BooleanIterator{Points: []query.BooleanPoint{
  2500  					{Name: "cpu", Time: 0 * Second, Value: true},
  2501  					{Name: "cpu", Time: 4 * Second, Value: false},
  2502  					{Name: "cpu", Time: 8 * Second, Value: false},
  2503  					{Name: "cpu", Time: 11 * Second, Value: true},
  2504  				}},
  2505  			},
  2506  			rows: []query.Row{
  2507  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(4)}},
  2508  				{Time: 8 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(4)}},
  2509  				{Time: 11 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(3)}},
  2510  			},
  2511  		},
  2512  		{
  2513  			name: "Integral_Float",
  2514  			q:    `SELECT integral(value) FROM cpu`,
  2515  			typ:  influxql.Float,
  2516  			itrs: []query.Iterator{
  2517  				&FloatIterator{Points: []query.FloatPoint{
  2518  					{Name: "cpu", Time: 10 * Second, Value: 20},
  2519  					{Name: "cpu", Time: 15 * Second, Value: 10},
  2520  					{Name: "cpu", Time: 20 * Second, Value: 0},
  2521  					{Name: "cpu", Time: 30 * Second, Value: -10},
  2522  				}},
  2523  			},
  2524  			rows: []query.Row{
  2525  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(50)}},
  2526  			},
  2527  		},
  2528  		{
  2529  			name: "Integral_Duplicate_Float",
  2530  			q:    `SELECT integral(value) FROM cpu`,
  2531  			typ:  influxql.Float,
  2532  			itrs: []query.Iterator{
  2533  				&FloatIterator{Points: []query.FloatPoint{
  2534  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2535  					{Name: "cpu", Time: 5 * Second, Value: 10},
  2536  					{Name: "cpu", Time: 5 * Second, Value: 30},
  2537  					{Name: "cpu", Time: 10 * Second, Value: 40},
  2538  				}},
  2539  			},
  2540  			rows: []query.Row{
  2541  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(250)}},
  2542  			},
  2543  		},
  2544  		{
  2545  			name: "Integral_Float_GroupByTime",
  2546  			q:    `SELECT integral(value) FROM cpu WHERE time > 0s AND time < 60s GROUP BY time(20s)`,
  2547  			typ:  influxql.Float,
  2548  			itrs: []query.Iterator{
  2549  				&FloatIterator{Points: []query.FloatPoint{
  2550  					{Name: "cpu", Time: 10 * Second, Value: 20},
  2551  					{Name: "cpu", Time: 15 * Second, Value: 10},
  2552  					{Name: "cpu", Time: 20 * Second, Value: 0},
  2553  					{Name: "cpu", Time: 30 * Second, Value: -10},
  2554  				}},
  2555  			},
  2556  			rows: []query.Row{
  2557  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(100)}},
  2558  				{Time: 20 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-50)}},
  2559  			},
  2560  		},
  2561  		{
  2562  			name: "Integral_Float_InterpolateGroupByTime",
  2563  			q:    `SELECT integral(value) FROM cpu WHERE time > 0s AND time < 60s GROUP BY time(20s)`,
  2564  			typ:  influxql.Float,
  2565  			itrs: []query.Iterator{
  2566  				&FloatIterator{Points: []query.FloatPoint{
  2567  					{Name: "cpu", Time: 10 * Second, Value: 20},
  2568  					{Name: "cpu", Time: 15 * Second, Value: 10},
  2569  					{Name: "cpu", Time: 25 * Second, Value: 0},
  2570  					{Name: "cpu", Time: 30 * Second, Value: -10},
  2571  				}},
  2572  			},
  2573  			rows: []query.Row{
  2574  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(112.5)}},
  2575  				{Time: 20 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-12.5)}},
  2576  			},
  2577  		},
  2578  		{
  2579  			name: "Integral_Integer",
  2580  			q:    `SELECT integral(value) FROM cpu`,
  2581  			typ:  influxql.Integer,
  2582  			itrs: []query.Iterator{
  2583  				&IntegerIterator{Points: []query.IntegerPoint{
  2584  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2585  					{Name: "cpu", Time: 5 * Second, Value: 10},
  2586  					{Name: "cpu", Time: 10 * Second, Value: 0},
  2587  					{Name: "cpu", Time: 20 * Second, Value: -10},
  2588  				}},
  2589  			},
  2590  			rows: []query.Row{
  2591  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(50)}},
  2592  			},
  2593  		},
  2594  		{
  2595  			name: "Integral_Duplicate_Integer",
  2596  			q:    `SELECT integral(value, 2s) FROM cpu`,
  2597  			typ:  influxql.Integer,
  2598  			itrs: []query.Iterator{
  2599  				&IntegerIterator{Points: []query.IntegerPoint{
  2600  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2601  					{Name: "cpu", Time: 5 * Second, Value: 10},
  2602  					{Name: "cpu", Time: 5 * Second, Value: 30},
  2603  					{Name: "cpu", Time: 10 * Second, Value: 40},
  2604  				}},
  2605  			},
  2606  			rows: []query.Row{
  2607  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(125)}},
  2608  			},
  2609  		},
  2610  		{
  2611  			name: "Integral_Unsigned",
  2612  			q:    `SELECT integral(value) FROM cpu`,
  2613  			typ:  influxql.Unsigned,
  2614  			itrs: []query.Iterator{
  2615  				&UnsignedIterator{Points: []query.UnsignedPoint{
  2616  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2617  					{Name: "cpu", Time: 5 * Second, Value: 10},
  2618  					{Name: "cpu", Time: 10 * Second, Value: 0},
  2619  				}},
  2620  			},
  2621  			rows: []query.Row{
  2622  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(100)}},
  2623  			},
  2624  		},
  2625  		{
  2626  			name: "Integral_Duplicate_Unsigned",
  2627  			q:    `SELECT integral(value, 2s) FROM cpu`,
  2628  			typ:  influxql.Unsigned,
  2629  			itrs: []query.Iterator{
  2630  				&UnsignedIterator{Points: []query.UnsignedPoint{
  2631  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2632  					{Name: "cpu", Time: 5 * Second, Value: 10},
  2633  					{Name: "cpu", Time: 5 * Second, Value: 30},
  2634  					{Name: "cpu", Time: 10 * Second, Value: 40},
  2635  				}},
  2636  			},
  2637  			rows: []query.Row{
  2638  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(125)}},
  2639  			},
  2640  		},
  2641  		{
  2642  			name: "MovingAverage_Float",
  2643  			q:    `SELECT moving_average(value, 2) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2644  			typ:  influxql.Float,
  2645  			itrs: []query.Iterator{
  2646  				&FloatIterator{Points: []query.FloatPoint{
  2647  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2648  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2649  					{Name: "cpu", Time: 8 * Second, Value: 19},
  2650  					{Name: "cpu", Time: 12 * Second, Value: 3},
  2651  				}},
  2652  			},
  2653  			rows: []query.Row{
  2654  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(15)}},
  2655  				{Time: 8 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(14.5)}},
  2656  				{Time: 12 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(11)}},
  2657  			},
  2658  		},
  2659  		{
  2660  			name: "MovingAverage_Integer",
  2661  			q:    `SELECT moving_average(value, 2) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2662  			typ:  influxql.Integer,
  2663  			itrs: []query.Iterator{
  2664  				&IntegerIterator{Points: []query.IntegerPoint{
  2665  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2666  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2667  					{Name: "cpu", Time: 8 * Second, Value: 19},
  2668  					{Name: "cpu", Time: 12 * Second, Value: 3},
  2669  				}},
  2670  			},
  2671  			rows: []query.Row{
  2672  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(15)}},
  2673  				{Time: 8 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(14.5)}},
  2674  				{Time: 12 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(11)}},
  2675  			},
  2676  		},
  2677  		{
  2678  			name: "MovingAverage_Unsigned",
  2679  			q:    `SELECT moving_average(value, 2) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2680  			typ:  influxql.Unsigned,
  2681  			itrs: []query.Iterator{
  2682  				&UnsignedIterator{Points: []query.UnsignedPoint{
  2683  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2684  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2685  					{Name: "cpu", Time: 8 * Second, Value: 19},
  2686  					{Name: "cpu", Time: 12 * Second, Value: 3},
  2687  				}},
  2688  			},
  2689  			rows: []query.Row{
  2690  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(15)}},
  2691  				{Time: 8 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(14.5)}},
  2692  				{Time: 12 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(11)}},
  2693  			},
  2694  		},
  2695  		{
  2696  			name: "CumulativeSum_Float",
  2697  			q:    `SELECT cumulative_sum(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2698  			typ:  influxql.Float,
  2699  			itrs: []query.Iterator{
  2700  				&FloatIterator{Points: []query.FloatPoint{
  2701  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2702  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2703  					{Name: "cpu", Time: 8 * Second, Value: 19},
  2704  					{Name: "cpu", Time: 12 * Second, Value: 3},
  2705  				}},
  2706  			},
  2707  			rows: []query.Row{
  2708  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(20)}},
  2709  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(30)}},
  2710  				{Time: 8 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(49)}},
  2711  				{Time: 12 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(52)}},
  2712  			},
  2713  		},
  2714  		{
  2715  			name: "CumulativeSum_Integer",
  2716  			q:    `SELECT cumulative_sum(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2717  			typ:  influxql.Integer,
  2718  			itrs: []query.Iterator{
  2719  				&IntegerIterator{Points: []query.IntegerPoint{
  2720  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2721  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2722  					{Name: "cpu", Time: 8 * Second, Value: 19},
  2723  					{Name: "cpu", Time: 12 * Second, Value: 3},
  2724  				}},
  2725  			},
  2726  			rows: []query.Row{
  2727  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(20)}},
  2728  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(30)}},
  2729  				{Time: 8 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(49)}},
  2730  				{Time: 12 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(52)}},
  2731  			},
  2732  		},
  2733  		{
  2734  			name: "CumulativeSum_Unsigned",
  2735  			q:    `SELECT cumulative_sum(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2736  			typ:  influxql.Unsigned,
  2737  			itrs: []query.Iterator{
  2738  				&UnsignedIterator{Points: []query.UnsignedPoint{
  2739  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2740  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2741  					{Name: "cpu", Time: 8 * Second, Value: 19},
  2742  					{Name: "cpu", Time: 12 * Second, Value: 3},
  2743  				}},
  2744  			},
  2745  			rows: []query.Row{
  2746  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(20)}},
  2747  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(30)}},
  2748  				{Time: 8 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(49)}},
  2749  				{Time: 12 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(52)}},
  2750  			},
  2751  		},
  2752  		{
  2753  			name: "CumulativeSum_Duplicate_Float",
  2754  			q:    `SELECT cumulative_sum(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2755  			typ:  influxql.Float,
  2756  			itrs: []query.Iterator{
  2757  				&FloatIterator{Points: []query.FloatPoint{
  2758  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2759  					{Name: "cpu", Time: 0 * Second, Value: 19},
  2760  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2761  					{Name: "cpu", Time: 4 * Second, Value: 3},
  2762  				}},
  2763  			},
  2764  			rows: []query.Row{
  2765  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(20)}},
  2766  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(39)}},
  2767  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(49)}},
  2768  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(52)}},
  2769  			},
  2770  		},
  2771  		{
  2772  			name: "CumulativeSum_Duplicate_Integer",
  2773  			q:    `SELECT cumulative_sum(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2774  			typ:  influxql.Integer,
  2775  			itrs: []query.Iterator{
  2776  				&IntegerIterator{Points: []query.IntegerPoint{
  2777  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2778  					{Name: "cpu", Time: 0 * Second, Value: 19},
  2779  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2780  					{Name: "cpu", Time: 4 * Second, Value: 3},
  2781  				}},
  2782  			},
  2783  			rows: []query.Row{
  2784  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(20)}},
  2785  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(39)}},
  2786  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(49)}},
  2787  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(52)}},
  2788  			},
  2789  		},
  2790  		{
  2791  			name: "CumulativeSum_Duplicate_Unsigned",
  2792  			q:    `SELECT cumulative_sum(value) FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-01T00:00:16Z'`,
  2793  			typ:  influxql.Unsigned,
  2794  			itrs: []query.Iterator{
  2795  				&UnsignedIterator{Points: []query.UnsignedPoint{
  2796  					{Name: "cpu", Time: 0 * Second, Value: 20},
  2797  					{Name: "cpu", Time: 0 * Second, Value: 19},
  2798  					{Name: "cpu", Time: 4 * Second, Value: 10},
  2799  					{Name: "cpu", Time: 4 * Second, Value: 3},
  2800  				}},
  2801  			},
  2802  			rows: []query.Row{
  2803  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(20)}},
  2804  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(39)}},
  2805  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(49)}},
  2806  				{Time: 4 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(52)}},
  2807  			},
  2808  		},
  2809  		{
  2810  			name: "HoltWinters_GroupBy_Agg",
  2811  			q:    `SELECT holt_winters(mean(value), 2, 2) FROM cpu WHERE time >= '1970-01-01T00:00:10Z' AND time < '1970-01-01T00:00:20Z' GROUP BY time(2s)`,
  2812  			typ:  influxql.Float,
  2813  			expr: `mean(value::float)`,
  2814  			itrs: []query.Iterator{
  2815  				&FloatIterator{Points: []query.FloatPoint{
  2816  					{Name: "cpu", Time: 10 * Second, Value: 4},
  2817  					{Name: "cpu", Time: 11 * Second, Value: 6},
  2818  
  2819  					{Name: "cpu", Time: 12 * Second, Value: 9},
  2820  					{Name: "cpu", Time: 13 * Second, Value: 11},
  2821  
  2822  					{Name: "cpu", Time: 14 * Second, Value: 5},
  2823  					{Name: "cpu", Time: 15 * Second, Value: 7},
  2824  
  2825  					{Name: "cpu", Time: 16 * Second, Value: 10},
  2826  					{Name: "cpu", Time: 17 * Second, Value: 12},
  2827  
  2828  					{Name: "cpu", Time: 18 * Second, Value: 6},
  2829  					{Name: "cpu", Time: 19 * Second, Value: 8},
  2830  				}},
  2831  			},
  2832  			rows: []query.Row{
  2833  				{Time: 20 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{11.960623419918432}},
  2834  				{Time: 22 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{7.953140268154609}},
  2835  			},
  2836  			onlyArch: "amd64",
  2837  		},
  2838  		{
  2839  			name: "DuplicateSelectors",
  2840  			q:    `SELECT min(value) * 2, min(value) / 2 FROM cpu WHERE time >= '1970-01-01T00:00:00Z' AND time < '1970-01-02T00:00:00Z' GROUP BY time(10s), host fill(none)`,
  2841  			typ:  influxql.Float,
  2842  			expr: `min(value::float)`,
  2843  			itrs: []query.Iterator{
  2844  				&FloatIterator{Points: []query.FloatPoint{
  2845  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 0 * Second, Value: 20},
  2846  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 11 * Second, Value: 3},
  2847  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 31 * Second, Value: 100},
  2848  				}},
  2849  				&FloatIterator{Points: []query.FloatPoint{
  2850  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 9 * Second, Value: 19},
  2851  					{Name: "cpu", Tags: ParseTags("region=east,host=A"), Time: 10 * Second, Value: 2},
  2852  				}},
  2853  				&FloatIterator{Points: []query.FloatPoint{
  2854  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 5 * Second, Value: 10},
  2855  				}},
  2856  			},
  2857  			rows: []query.Row{
  2858  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(38), float64(19) / 2}},
  2859  				{Time: 10 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(4), float64(1)}},
  2860  				{Time: 30 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=A")}, Values: []interface{}{float64(200), float64(50)}},
  2861  				{Time: 0 * Second, Series: query.Series{Name: "cpu", Tags: ParseTags("host=B")}, Values: []interface{}{float64(20), float64(5)}},
  2862  			},
  2863  		},
  2864  		{
  2865  			name: "GroupByOffset",
  2866  			q:    `SELECT mean(value) FROM cpu WHERE time >= now() - 2m AND time < now() GROUP BY time(1m, now())`,
  2867  			typ:  influxql.Float,
  2868  			expr: `mean(value::float)`,
  2869  			itrs: []query.Iterator{
  2870  				&FloatIterator{Points: []query.FloatPoint{
  2871  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 34 * Second, Value: 20},
  2872  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 57 * Second, Value: 3},
  2873  					{Name: "cpu", Tags: ParseTags("region=west,host=A"), Time: 92 * Second, Value: 100},
  2874  				}},
  2875  				&FloatIterator{Points: []query.FloatPoint{
  2876  					{Name: "cpu", Tags: ParseTags("region=west,host=B"), Time: 45 * Second, Value: 10},
  2877  				}},
  2878  			},
  2879  			rows: []query.Row{
  2880  				{Time: 30 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(11)}},
  2881  				{Time: 90 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(100)}},
  2882  			},
  2883  			now: mustParseTime("1970-01-01T00:02:30Z"),
  2884  		},
  2885  	} {
  2886  		t.Run(tt.name, func(t *testing.T) {
  2887  			if tt.onlyArch != "" && runtime.GOARCH != tt.onlyArch {
  2888  				t.Skipf("Expected outputs of %s only valid when GOARCH = %s", tt.name, tt.onlyArch)
  2889  			}
  2890  
  2891  			shardMapper := ShardMapper{
  2892  				MapShardsFn: func(_ context.Context, sources influxql.Sources, _ influxql.TimeRange) query.ShardGroup {
  2893  					var fields map[string]influxql.DataType
  2894  					if tt.typ != influxql.Unknown {
  2895  						fields = map[string]influxql.DataType{"value": tt.typ}
  2896  					} else {
  2897  						fields = tt.fields
  2898  					}
  2899  					return &ShardGroup{
  2900  						Fields:     fields,
  2901  						Dimensions: []string{"host", "region"},
  2902  						CreateIteratorFn: func(ctx context.Context, m *influxql.Measurement, opt query.IteratorOptions) (query.Iterator, error) {
  2903  							if m.Name != "cpu" {
  2904  								t.Fatalf("unexpected source: %s", m.Name)
  2905  							}
  2906  							if tt.expr != "" && !reflect.DeepEqual(opt.Expr, MustParseExpr(tt.expr)) {
  2907  								t.Fatalf("unexpected expr: %s", spew.Sdump(opt.Expr))
  2908  							}
  2909  
  2910  							itrs := tt.itrs
  2911  							if _, ok := opt.Expr.(*influxql.Call); ok {
  2912  								for i, itr := range itrs {
  2913  									itr, err := query.NewCallIterator(itr, opt)
  2914  									if err != nil {
  2915  										return nil, err
  2916  									}
  2917  									itrs[i] = itr
  2918  								}
  2919  							}
  2920  							return query.Iterators(itrs).Merge(opt)
  2921  						},
  2922  					}
  2923  				},
  2924  			}
  2925  
  2926  			stmt := MustParseSelectStatement(tt.q)
  2927  			stmt.OmitTime = true
  2928  			cur, err := func(stmt *influxql.SelectStatement) (query.Cursor, error) {
  2929  				c, err := query.Compile(stmt, query.CompileOptions{
  2930  					Now: tt.now,
  2931  				})
  2932  				if err != nil {
  2933  					return nil, err
  2934  				}
  2935  
  2936  				p, err := c.Prepare(context.Background(), &shardMapper, query.SelectOptions{})
  2937  				if err != nil {
  2938  					return nil, err
  2939  				}
  2940  				return p.Select(context.Background())
  2941  			}(stmt)
  2942  			if err != nil {
  2943  				if tt.err == "" {
  2944  					t.Fatal(err)
  2945  				} else if have, want := err.Error(), tt.err; have != want {
  2946  					t.Fatalf("unexpected error: have=%s want=%s", have, want)
  2947  				}
  2948  			} else if tt.err != "" {
  2949  				t.Fatal("expected error")
  2950  			} else if a, err := ReadCursor(cur); err != nil {
  2951  				t.Fatalf("unexpected point: %s", err)
  2952  			} else if diff := cmp.Diff(tt.rows, a); diff != "" {
  2953  				t.Fatalf("unexpected points:\n%s", diff)
  2954  			}
  2955  		})
  2956  	}
  2957  }
  2958  
  2959  // Ensure a SELECT with raw fields works for all types.
  2960  func TestSelect_Raw(t *testing.T) {
  2961  	shardMapper := ShardMapper{
  2962  		MapShardsFn: func(_ context.Context, sources influxql.Sources, _ influxql.TimeRange) query.ShardGroup {
  2963  			return &ShardGroup{
  2964  				Fields: map[string]influxql.DataType{
  2965  					"f": influxql.Float,
  2966  					"i": influxql.Integer,
  2967  					"u": influxql.Unsigned,
  2968  					"s": influxql.String,
  2969  					"b": influxql.Boolean,
  2970  				},
  2971  				CreateIteratorFn: func(ctx context.Context, m *influxql.Measurement, opt query.IteratorOptions) (query.Iterator, error) {
  2972  					if m.Name != "cpu" {
  2973  						t.Fatalf("unexpected source: %s", m.Name)
  2974  					}
  2975  					if !reflect.DeepEqual(opt.Aux, []influxql.VarRef{
  2976  						{Val: "b", Type: influxql.Boolean},
  2977  						{Val: "f", Type: influxql.Float},
  2978  						{Val: "i", Type: influxql.Integer},
  2979  						{Val: "s", Type: influxql.String},
  2980  						{Val: "u", Type: influxql.Unsigned},
  2981  					}) {
  2982  						t.Fatalf("unexpected auxiliary fields: %v", opt.Aux)
  2983  					}
  2984  					return &FloatIterator{Points: []query.FloatPoint{
  2985  						{Name: "cpu", Time: 0 * Second, Aux: []interface{}{
  2986  							true, float64(20), int64(20), "a", uint64(20)}},
  2987  						{Name: "cpu", Time: 5 * Second, Aux: []interface{}{
  2988  							false, float64(10), int64(10), "b", uint64(10)}},
  2989  						{Name: "cpu", Time: 9 * Second, Aux: []interface{}{
  2990  							true, float64(19), int64(19), "c", uint64(19)}},
  2991  					}}, nil
  2992  				},
  2993  			}
  2994  		},
  2995  	}
  2996  
  2997  	stmt := MustParseSelectStatement(`SELECT f, i, u, s, b FROM cpu`)
  2998  	stmt.OmitTime = true
  2999  	cur, err := query.Select(context.Background(), stmt, &shardMapper, query.SelectOptions{})
  3000  	if err != nil {
  3001  		t.Errorf("parse error: %s", err)
  3002  	} else if a, err := ReadCursor(cur); err != nil {
  3003  		t.Fatalf("unexpected error: %s", err)
  3004  	} else if diff := cmp.Diff([]query.Row{
  3005  		{
  3006  			Time: 0 * Second,
  3007  			Series: query.Series{
  3008  				Name: "cpu",
  3009  			},
  3010  			Values: []interface{}{float64(20), int64(20), uint64(20), "a", true},
  3011  		},
  3012  		{
  3013  			Time: 5 * Second,
  3014  			Series: query.Series{
  3015  				Name: "cpu",
  3016  			},
  3017  			Values: []interface{}{float64(10), int64(10), uint64(10), "b", false},
  3018  		},
  3019  		{
  3020  			Time: 9 * Second,
  3021  			Series: query.Series{
  3022  				Name: "cpu",
  3023  			},
  3024  			Values: []interface{}{float64(19), int64(19), uint64(19), "c", true},
  3025  		},
  3026  	}, a); diff != "" {
  3027  		t.Errorf("unexpected points:\n%s", diff)
  3028  	}
  3029  }
  3030  
  3031  // Ensure a SELECT binary expr queries can be executed as floats.
  3032  func TestSelect_BinaryExpr(t *testing.T) {
  3033  	shardMapper := ShardMapper{
  3034  		MapShardsFn: func(_ context.Context, sources influxql.Sources, _ influxql.TimeRange) query.ShardGroup {
  3035  			return &ShardGroup{
  3036  				Fields: map[string]influxql.DataType{
  3037  					"f": influxql.Float,
  3038  					"i": influxql.Integer,
  3039  					"u": influxql.Unsigned,
  3040  				},
  3041  				CreateIteratorFn: func(ctx context.Context, m *influxql.Measurement, opt query.IteratorOptions) (query.Iterator, error) {
  3042  					if m.Name != "cpu" {
  3043  						t.Fatalf("unexpected source: %s", m.Name)
  3044  					}
  3045  					makeAuxFields := func(value int) []interface{} {
  3046  						aux := make([]interface{}, len(opt.Aux))
  3047  						for i := range aux {
  3048  							switch opt.Aux[i].Type {
  3049  							case influxql.Float:
  3050  								aux[i] = float64(value)
  3051  							case influxql.Integer:
  3052  								aux[i] = int64(value)
  3053  							case influxql.Unsigned:
  3054  								aux[i] = uint64(value)
  3055  							}
  3056  						}
  3057  						return aux
  3058  					}
  3059  					return &FloatIterator{Points: []query.FloatPoint{
  3060  						{Name: "cpu", Time: 0 * Second, Aux: makeAuxFields(20)},
  3061  						{Name: "cpu", Time: 5 * Second, Aux: makeAuxFields(10)},
  3062  						{Name: "cpu", Time: 9 * Second, Aux: makeAuxFields(19)},
  3063  					}}, nil
  3064  				},
  3065  			}
  3066  		},
  3067  	}
  3068  
  3069  	for _, test := range []struct {
  3070  		Name      string
  3071  		Statement string
  3072  		Rows      []query.Row
  3073  		Err       string
  3074  	}{
  3075  		{
  3076  			Name:      "Float_AdditionRHS_Number",
  3077  			Statement: `SELECT f + 2.0 FROM cpu`,
  3078  			Rows: []query.Row{
  3079  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(22)}},
  3080  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(12)}},
  3081  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(21)}},
  3082  			},
  3083  		},
  3084  		{
  3085  			Name:      "Integer_AdditionRHS_Number",
  3086  			Statement: `SELECT i + 2.0 FROM cpu`,
  3087  			Rows: []query.Row{
  3088  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(22)}},
  3089  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(12)}},
  3090  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(21)}},
  3091  			},
  3092  		},
  3093  		{
  3094  			Name:      "Unsigned_AdditionRHS_Number",
  3095  			Statement: `SELECT u + 2.0 FROM cpu`,
  3096  			Rows: []query.Row{
  3097  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(22)}},
  3098  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(12)}},
  3099  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(21)}},
  3100  			},
  3101  		},
  3102  		{
  3103  			Name:      "Float_AdditionRHS_Integer",
  3104  			Statement: `SELECT f + 2 FROM cpu`,
  3105  			Rows: []query.Row{
  3106  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(22)}},
  3107  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(12)}},
  3108  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(21)}},
  3109  			},
  3110  		},
  3111  		{
  3112  			Name:      "Integer_AdditionRHS_Integer",
  3113  			Statement: `SELECT i + 2 FROM cpu`,
  3114  			Rows: []query.Row{
  3115  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(22)}},
  3116  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(12)}},
  3117  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(21)}},
  3118  			},
  3119  		},
  3120  		{
  3121  			Name:      "Unsigned_AdditionRHS_Integer",
  3122  			Statement: `SELECT u + 2 FROM cpu`,
  3123  			Rows: []query.Row{
  3124  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(22)}},
  3125  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(12)}},
  3126  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(21)}},
  3127  			},
  3128  		},
  3129  		{
  3130  			Name:      "Float_AdditionRHS_Unsigned",
  3131  			Statement: `SELECT f + 9223372036854775808 FROM cpu`,
  3132  			Rows: []query.Row{ // adding small floats to this does not change the value, this is expected
  3133  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(9223372036854775808)}},
  3134  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(9223372036854775808)}},
  3135  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(9223372036854775808)}},
  3136  			},
  3137  		},
  3138  		{
  3139  			Name:      "Integer_AdditionRHS_Unsigned",
  3140  			Statement: `SELECT i + 9223372036854775808 FROM cpu`,
  3141  			Err:       `type error: i::integer + 9223372036854775808: cannot use + with an integer and unsigned literal`,
  3142  		},
  3143  		{
  3144  			Name:      "Unsigned_AdditionRHS_Unsigned",
  3145  			Statement: `SELECT u + 9223372036854775808 FROM cpu`,
  3146  			Rows: []query.Row{
  3147  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(9223372036854775828)}},
  3148  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(9223372036854775818)}},
  3149  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(9223372036854775827)}},
  3150  			},
  3151  		},
  3152  		{
  3153  			Name:      "Float_AdditionLHS_Number",
  3154  			Statement: `SELECT 2.0 + f FROM cpu`,
  3155  			Rows: []query.Row{
  3156  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(22)}},
  3157  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(12)}},
  3158  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(21)}},
  3159  			},
  3160  		},
  3161  		{
  3162  			Name:      "Integer_AdditionLHS_Number",
  3163  			Statement: `SELECT 2.0 + i FROM cpu`,
  3164  			Rows: []query.Row{
  3165  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(22)}},
  3166  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(12)}},
  3167  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(21)}},
  3168  			},
  3169  		},
  3170  		{
  3171  			Name:      "Unsigned_AdditionLHS_Number",
  3172  			Statement: `SELECT 2.0 + u FROM cpu`,
  3173  			Rows: []query.Row{
  3174  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(22)}},
  3175  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(12)}},
  3176  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(21)}},
  3177  			},
  3178  		},
  3179  		{
  3180  			Name:      "Float_AdditionLHS_Integer",
  3181  			Statement: `SELECT 2 + f FROM cpu`,
  3182  			Rows: []query.Row{
  3183  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(22)}},
  3184  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(12)}},
  3185  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(21)}},
  3186  			},
  3187  		},
  3188  		{
  3189  			Name:      "Integer_AdditionLHS_Integer",
  3190  			Statement: `SELECT 2 + i FROM cpu`,
  3191  			Rows: []query.Row{
  3192  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(22)}},
  3193  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(12)}},
  3194  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(21)}},
  3195  			},
  3196  		},
  3197  		{
  3198  			Name:      "Unsigned_AdditionLHS_Integer",
  3199  			Statement: `SELECT 2 + u FROM cpu`,
  3200  			Rows: []query.Row{
  3201  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(22)}},
  3202  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(12)}},
  3203  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(21)}},
  3204  			},
  3205  		},
  3206  		{
  3207  			Name:      "Float_AdditionLHS_Unsigned",
  3208  			Statement: `SELECT 9223372036854775808 + f FROM cpu`,
  3209  			Rows: []query.Row{ // adding small floats to this does not change the value, this is expected
  3210  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(9223372036854775808)}},
  3211  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(9223372036854775808)}},
  3212  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(9223372036854775808)}},
  3213  			},
  3214  		},
  3215  		{
  3216  			Name:      "Integer_AdditionLHS_Unsigned",
  3217  			Statement: `SELECT 9223372036854775808 + i FROM cpu`,
  3218  			Err:       `type error: 9223372036854775808 + i::integer: cannot use + with an integer and unsigned literal`,
  3219  		},
  3220  		{
  3221  			Name:      "Unsigned_AdditionLHS_Unsigned",
  3222  			Statement: `SELECT 9223372036854775808 + u FROM cpu`,
  3223  			Rows: []query.Row{
  3224  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(9223372036854775828)}},
  3225  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(9223372036854775818)}},
  3226  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(9223372036854775827)}},
  3227  			},
  3228  		},
  3229  		{
  3230  			Name:      "Float_Add_Float",
  3231  			Statement: `SELECT f + f FROM cpu`,
  3232  			Rows: []query.Row{
  3233  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(40)}},
  3234  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(20)}},
  3235  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(38)}},
  3236  			},
  3237  		},
  3238  		{
  3239  			Name:      "Integer_Add_Integer",
  3240  			Statement: `SELECT i + i FROM cpu`,
  3241  			Rows: []query.Row{
  3242  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(40)}},
  3243  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(20)}},
  3244  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(38)}},
  3245  			},
  3246  		},
  3247  		{
  3248  			Name:      "Unsigned_Add_Unsigned",
  3249  			Statement: `SELECT u + u FROM cpu`,
  3250  			Rows: []query.Row{
  3251  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(40)}},
  3252  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(20)}},
  3253  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(38)}},
  3254  			},
  3255  		},
  3256  		{
  3257  			Name:      "Float_Add_Integer",
  3258  			Statement: `SELECT f + i FROM cpu`,
  3259  			Rows: []query.Row{
  3260  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(40)}},
  3261  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(20)}},
  3262  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(38)}},
  3263  			},
  3264  		},
  3265  		{
  3266  			Name:      "Float_Add_Unsigned",
  3267  			Statement: `SELECT f + u FROM cpu`,
  3268  			Rows: []query.Row{
  3269  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(40)}},
  3270  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(20)}},
  3271  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(38)}},
  3272  			},
  3273  		},
  3274  		{
  3275  			Name:      "Integer_Add_Unsigned",
  3276  			Statement: `SELECT i + u FROM cpu`,
  3277  			Err:       `type error: i::integer + u::unsigned: cannot use + between an integer and unsigned, an explicit cast is required`,
  3278  		},
  3279  		{
  3280  			Name:      "Float_MultiplicationRHS_Number",
  3281  			Statement: `SELECT f * 2.0 FROM cpu`,
  3282  			Rows: []query.Row{
  3283  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(40)}},
  3284  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(20)}},
  3285  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(38)}},
  3286  			},
  3287  		},
  3288  		{
  3289  			Name:      "Integer_MultiplicationRHS_Number",
  3290  			Statement: `SELECT i * 2.0 FROM cpu`,
  3291  			Rows: []query.Row{
  3292  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(40)}},
  3293  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(20)}},
  3294  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(38)}},
  3295  			},
  3296  		},
  3297  		{
  3298  			Name:      "Unsigned_MultiplicationRHS_Number",
  3299  			Statement: `SELECT u * 2.0 FROM cpu`,
  3300  			Rows: []query.Row{
  3301  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(40)}},
  3302  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(20)}},
  3303  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(38)}},
  3304  			},
  3305  		},
  3306  		{
  3307  			Name:      "Float_MultiplicationRHS_Integer",
  3308  			Statement: `SELECT f * 2 FROM cpu`,
  3309  			Rows: []query.Row{
  3310  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(40)}},
  3311  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(20)}},
  3312  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(38)}},
  3313  			},
  3314  		},
  3315  		{
  3316  			Name:      "Integer_MultiplicationRHS_Integer",
  3317  			Statement: `SELECT i * 2 FROM cpu`,
  3318  			Rows: []query.Row{
  3319  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(40)}},
  3320  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(20)}},
  3321  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(38)}},
  3322  			},
  3323  		},
  3324  		{
  3325  			Name:      "Unsigned_MultiplicationRHS_Integer",
  3326  			Statement: `SELECT u * 2 FROM cpu`,
  3327  			Rows: []query.Row{
  3328  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(40)}},
  3329  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(20)}},
  3330  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(38)}},
  3331  			},
  3332  		},
  3333  		// Skip unsigned literals for multiplication because there is inevitable
  3334  		// overflow. While it is possible to do, the behavior is considered undefined
  3335  		// and it's not a very good test because it would result in just plugging
  3336  		// the values into the computer anyway to figure out what the correct answer
  3337  		// is rather than calculating it myself and testing that I get the correct
  3338  		// value.
  3339  		{
  3340  			Name:      "Float_MultiplicationLHS_Number",
  3341  			Statement: `SELECT 2.0 * f FROM cpu`,
  3342  			Rows: []query.Row{
  3343  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(40)}},
  3344  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(20)}},
  3345  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(38)}},
  3346  			},
  3347  		},
  3348  		{
  3349  			Name:      "Integer_MultiplicationLHS_Number",
  3350  			Statement: `SELECT 2.0 * i FROM cpu`,
  3351  			Rows: []query.Row{
  3352  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(40)}},
  3353  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(20)}},
  3354  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(38)}},
  3355  			},
  3356  		},
  3357  		{
  3358  			Name:      "Unsigned_MultiplicationLHS_Number",
  3359  			Statement: `SELECT 2.0 * u FROM cpu`,
  3360  			Rows: []query.Row{
  3361  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(40)}},
  3362  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(20)}},
  3363  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(38)}},
  3364  			},
  3365  		},
  3366  		{
  3367  			Name:      "Float_MultiplicationLHS_Integer",
  3368  			Statement: `SELECT 2 * f FROM cpu`,
  3369  			Rows: []query.Row{
  3370  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(40)}},
  3371  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(20)}},
  3372  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(38)}},
  3373  			},
  3374  		},
  3375  		{
  3376  			Name:      "Integer_MultiplicationLHS_Integer",
  3377  			Statement: `SELECT 2 * i FROM cpu`,
  3378  			Rows: []query.Row{
  3379  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(40)}},
  3380  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(20)}},
  3381  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(38)}},
  3382  			},
  3383  		},
  3384  		{
  3385  			Name:      "Unsigned_MultiplicationLHS_Integer",
  3386  			Statement: `SELECT 2 * u FROM cpu`,
  3387  			Rows: []query.Row{
  3388  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(40)}},
  3389  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(20)}},
  3390  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(38)}},
  3391  			},
  3392  		},
  3393  		// Skip unsigned literals for multiplication. See above.
  3394  		{
  3395  			Name:      "Float_Multiply_Float",
  3396  			Statement: `SELECT f * f FROM cpu`,
  3397  			Rows: []query.Row{
  3398  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(400)}},
  3399  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(100)}},
  3400  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(361)}},
  3401  			},
  3402  		},
  3403  		{
  3404  			Name:      "Integer_Multiply_Integer",
  3405  			Statement: `SELECT i * i FROM cpu`,
  3406  			Rows: []query.Row{
  3407  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(400)}},
  3408  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(100)}},
  3409  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(361)}},
  3410  			},
  3411  		},
  3412  		{
  3413  			Name:      "Unsigned_Multiply_Unsigned",
  3414  			Statement: `SELECT u * u FROM cpu`,
  3415  			Rows: []query.Row{
  3416  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(400)}},
  3417  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(100)}},
  3418  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(361)}},
  3419  			},
  3420  		},
  3421  		{
  3422  			Name:      "Float_Multiply_Integer",
  3423  			Statement: `SELECT f * i FROM cpu`,
  3424  			Rows: []query.Row{
  3425  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(400)}},
  3426  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(100)}},
  3427  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(361)}},
  3428  			},
  3429  		},
  3430  		{
  3431  			Name:      "Float_Multiply_Unsigned",
  3432  			Statement: `SELECT f * u FROM cpu`,
  3433  			Rows: []query.Row{
  3434  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(400)}},
  3435  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(100)}},
  3436  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(361)}},
  3437  			},
  3438  		},
  3439  		{
  3440  			Name:      "Integer_Multiply_Unsigned",
  3441  			Statement: `SELECT i * u FROM cpu`,
  3442  			Err:       `type error: i::integer * u::unsigned: cannot use * between an integer and unsigned, an explicit cast is required`,
  3443  		},
  3444  		{
  3445  			Name:      "Float_SubtractionRHS_Number",
  3446  			Statement: `SELECT f - 2.0 FROM cpu`,
  3447  			Rows: []query.Row{
  3448  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(18)}},
  3449  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(8)}},
  3450  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(17)}},
  3451  			},
  3452  		},
  3453  		{
  3454  			Name:      "Integer_SubtractionRHS_Number",
  3455  			Statement: `SELECT i - 2.0 FROM cpu`,
  3456  			Rows: []query.Row{
  3457  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(18)}},
  3458  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(8)}},
  3459  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(17)}},
  3460  			},
  3461  		},
  3462  		{
  3463  			Name:      "Unsigned_SubtractionRHS_Number",
  3464  			Statement: `SELECT u - 2.0 FROM cpu`,
  3465  			Rows: []query.Row{
  3466  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(18)}},
  3467  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(8)}},
  3468  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(17)}},
  3469  			},
  3470  		},
  3471  		{
  3472  			Name:      "Float_SubtractionRHS_Integer",
  3473  			Statement: `SELECT f - 2 FROM cpu`,
  3474  			Rows: []query.Row{
  3475  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(18)}},
  3476  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(8)}},
  3477  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(17)}},
  3478  			},
  3479  		},
  3480  		{
  3481  			Name:      "Integer_SubtractionRHS_Integer",
  3482  			Statement: `SELECT i - 2 FROM cpu`,
  3483  			Rows: []query.Row{
  3484  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(18)}},
  3485  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(8)}},
  3486  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(17)}},
  3487  			},
  3488  		},
  3489  		{
  3490  			Name:      "Unsigned_SubtractionRHS_Integer",
  3491  			Statement: `SELECT u - 2 FROM cpu`,
  3492  			Rows: []query.Row{
  3493  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(18)}},
  3494  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(8)}},
  3495  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(17)}},
  3496  			},
  3497  		},
  3498  		{
  3499  			Name:      "Float_SubtractionRHS_Unsigned",
  3500  			Statement: `SELECT f - 9223372036854775808 FROM cpu`,
  3501  			Rows: []query.Row{ // adding small floats to this does not change the value, this is expected
  3502  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-9223372036854775808)}},
  3503  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-9223372036854775808)}},
  3504  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-9223372036854775808)}},
  3505  			},
  3506  		},
  3507  		{
  3508  			Name:      "Integer_SubtractionRHS_Unsigned",
  3509  			Statement: `SELECT i - 9223372036854775808 FROM cpu`,
  3510  			Err:       `type error: i::integer - 9223372036854775808: cannot use - with an integer and unsigned literal`,
  3511  		},
  3512  		// Skip Unsigned_SubtractionRHS_Integer because it would result in underflow.
  3513  		{
  3514  			Name:      "Float_SubtractionLHS_Number",
  3515  			Statement: `SELECT 2.0 - f FROM cpu`,
  3516  			Rows: []query.Row{
  3517  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-18)}},
  3518  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-8)}},
  3519  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-17)}},
  3520  			},
  3521  		},
  3522  		{
  3523  			Name:      "Integer_SubtractionLHS_Number",
  3524  			Statement: `SELECT 2.0 - i FROM cpu`,
  3525  			Rows: []query.Row{
  3526  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-18)}},
  3527  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-8)}},
  3528  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-17)}},
  3529  			},
  3530  		},
  3531  		{
  3532  			Name:      "Unsigned_SubtractionLHS_Number",
  3533  			Statement: `SELECT 2.0 - u FROM cpu`,
  3534  			Rows: []query.Row{
  3535  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-18)}},
  3536  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-8)}},
  3537  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-17)}},
  3538  			},
  3539  		},
  3540  		{
  3541  			Name:      "Float_SubtractionLHS_Integer",
  3542  			Statement: `SELECT 2 - f FROM cpu`,
  3543  			Rows: []query.Row{
  3544  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-18)}},
  3545  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-8)}},
  3546  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-17)}},
  3547  			},
  3548  		},
  3549  		{
  3550  			Name:      "Integer_SubtractionLHS_Integer",
  3551  			Statement: `SELECT 2 - i FROM cpu`,
  3552  			Rows: []query.Row{
  3553  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(-18)}},
  3554  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(-8)}},
  3555  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(-17)}},
  3556  			},
  3557  		},
  3558  		{
  3559  			Name:      "Unsigned_SubtractionLHS_Integer",
  3560  			Statement: `SELECT 30 - u FROM cpu`,
  3561  			Rows: []query.Row{
  3562  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(10)}},
  3563  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(20)}},
  3564  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(11)}},
  3565  			},
  3566  		},
  3567  		{
  3568  			Name:      "Float_SubtractionLHS_Unsigned",
  3569  			Statement: `SELECT 9223372036854775808 - f FROM cpu`, // subtracting small floats to this does not change the value, this is expected
  3570  			Rows: []query.Row{
  3571  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(9223372036854775828)}},
  3572  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(9223372036854775828)}},
  3573  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(9223372036854775828)}},
  3574  			},
  3575  		},
  3576  		{
  3577  			Name:      "Integer_SubtractionLHS_Unsigned",
  3578  			Statement: `SELECT 9223372036854775808 - i FROM cpu`,
  3579  			Err:       `type error: 9223372036854775808 - i::integer: cannot use - with an integer and unsigned literal`,
  3580  		},
  3581  		{
  3582  			Name:      "Unsigned_SubtractionLHS_Unsigned",
  3583  			Statement: `SELECT 9223372036854775808 - u FROM cpu`,
  3584  			Rows: []query.Row{
  3585  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(9223372036854775788)}},
  3586  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(9223372036854775798)}},
  3587  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(9223372036854775789)}},
  3588  			},
  3589  		},
  3590  		{
  3591  			Name:      "Float_Subtract_Float",
  3592  			Statement: `SELECT f - f FROM cpu`,
  3593  			Rows: []query.Row{
  3594  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(0)}},
  3595  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(0)}},
  3596  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(0)}},
  3597  			},
  3598  		},
  3599  		{
  3600  			Name:      "Integer_Subtract_Integer",
  3601  			Statement: `SELECT i - i FROM cpu`,
  3602  			Rows: []query.Row{
  3603  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(0)}},
  3604  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(0)}},
  3605  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(0)}},
  3606  			},
  3607  		},
  3608  		{
  3609  			Name:      "Unsigned_Subtract_Unsigned",
  3610  			Statement: `SELECT u - u FROM cpu`,
  3611  			Rows: []query.Row{
  3612  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(0)}},
  3613  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(0)}},
  3614  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(0)}},
  3615  			},
  3616  		},
  3617  		{
  3618  			Name:      "Float_Subtract_Integer",
  3619  			Statement: `SELECT f - i FROM cpu`,
  3620  			Rows: []query.Row{
  3621  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(0)}},
  3622  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(0)}},
  3623  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(0)}},
  3624  			},
  3625  		},
  3626  		{
  3627  			Name:      "Float_Subtract_Unsigned",
  3628  			Statement: `SELECT f - u FROM cpu`,
  3629  			Rows: []query.Row{
  3630  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(0)}},
  3631  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(0)}},
  3632  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(0)}},
  3633  			},
  3634  		},
  3635  		{
  3636  			Name:      "Integer_Subtract_Unsigned",
  3637  			Statement: `SELECT i - u FROM cpu`,
  3638  			Err:       `type error: i::integer - u::unsigned: cannot use - between an integer and unsigned, an explicit cast is required`,
  3639  		},
  3640  		{
  3641  			Name:      "Float_DivisionRHS_Number",
  3642  			Statement: `SELECT f / 2.0 FROM cpu`,
  3643  			Rows: []query.Row{
  3644  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(10)}},
  3645  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(5)}},
  3646  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(19) / 2}},
  3647  			},
  3648  		},
  3649  		{
  3650  			Name:      "Integer_DivisionRHS_Number",
  3651  			Statement: `SELECT i / 2.0 FROM cpu`,
  3652  			Rows: []query.Row{
  3653  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(10)}},
  3654  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(5)}},
  3655  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(19) / 2}},
  3656  			},
  3657  		},
  3658  		{
  3659  			Name:      "Unsigned_DivisionRHS_Number",
  3660  			Statement: `SELECT u / 2.0 FROM cpu`,
  3661  			Rows: []query.Row{
  3662  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(10)}},
  3663  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(5)}},
  3664  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(19) / 2}},
  3665  			},
  3666  		},
  3667  		{
  3668  			Name:      "Float_DivisionRHS_Integer",
  3669  			Statement: `SELECT f / 2 FROM cpu`,
  3670  			Rows: []query.Row{
  3671  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(10)}},
  3672  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(5)}},
  3673  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(19) / 2}},
  3674  			},
  3675  		},
  3676  		{
  3677  			Name:      "Integer_DivisionRHS_Integer",
  3678  			Statement: `SELECT i / 2 FROM cpu`,
  3679  			Rows: []query.Row{
  3680  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(10)}},
  3681  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(5)}},
  3682  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(19) / 2}},
  3683  			},
  3684  		},
  3685  		{
  3686  			Name:      "Unsigned_DivisionRHS_Integer",
  3687  			Statement: `SELECT u / 2 FROM cpu`,
  3688  			Rows: []query.Row{
  3689  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(10)}},
  3690  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(5)}},
  3691  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(9)}},
  3692  			},
  3693  		},
  3694  		{
  3695  			Name:      "Float_DivisionRHS_Unsigned",
  3696  			Statement: `SELECT f / 9223372036854775808 FROM cpu`,
  3697  			Rows: []query.Row{ // dividing small floats does not result in a meaningful result, this is expected
  3698  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(20) / float64(9223372036854775808)}},
  3699  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(10) / float64(9223372036854775808)}},
  3700  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(19) / float64(9223372036854775808)}},
  3701  			},
  3702  		},
  3703  		{
  3704  			Name:      "Integer_DivisionRHS_Unsigned",
  3705  			Statement: `SELECT i / 9223372036854775808 FROM cpu`,
  3706  			Err:       `type error: i::integer / 9223372036854775808: cannot use / with an integer and unsigned literal`,
  3707  		},
  3708  		{
  3709  			Name:      "Unsigned_DivisionRHS_Unsigned",
  3710  			Statement: `SELECT u / 9223372036854775808 FROM cpu`,
  3711  			Rows: []query.Row{
  3712  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(0)}},
  3713  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(0)}},
  3714  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(0)}},
  3715  			},
  3716  		},
  3717  		{
  3718  			Name:      "Float_DivisionLHS_Number",
  3719  			Statement: `SELECT 38.0 / f FROM cpu`,
  3720  			Rows: []query.Row{
  3721  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(1.9)}},
  3722  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(3.8)}},
  3723  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(2)}},
  3724  			},
  3725  		},
  3726  		{
  3727  			Name:      "Integer_DivisionLHS_Number",
  3728  			Statement: `SELECT 38.0 / i FROM cpu`,
  3729  			Rows: []query.Row{
  3730  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(1.9)}},
  3731  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(3.8)}},
  3732  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(2)}},
  3733  			},
  3734  		},
  3735  		{
  3736  			Name:      "Unsigned_DivisionLHS_Number",
  3737  			Statement: `SELECT 38.0 / u FROM cpu`,
  3738  			Rows: []query.Row{
  3739  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(1.9)}},
  3740  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(3.8)}},
  3741  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(2)}},
  3742  			},
  3743  		},
  3744  		{
  3745  			Name:      "Float_DivisionLHS_Integer",
  3746  			Statement: `SELECT 38 / f FROM cpu`,
  3747  			Rows: []query.Row{
  3748  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(1.9)}},
  3749  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(3.8)}},
  3750  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(2)}},
  3751  			},
  3752  		},
  3753  		{
  3754  			Name:      "Integer_DivisionLHS_Integer",
  3755  			Statement: `SELECT 38 / i FROM cpu`,
  3756  			Rows: []query.Row{
  3757  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(1.9)}},
  3758  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(3.8)}},
  3759  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(2)}},
  3760  			},
  3761  		},
  3762  		{
  3763  			Name:      "Unsigned_DivisionLHS_Integer",
  3764  			Statement: `SELECT 38 / u FROM cpu`,
  3765  			Rows: []query.Row{
  3766  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(1)}},
  3767  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(3)}},
  3768  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(2)}},
  3769  			},
  3770  		},
  3771  		{
  3772  			Name:      "Float_DivisionLHS_Unsigned",
  3773  			Statement: `SELECT 9223372036854775808 / f FROM cpu`,
  3774  			Rows: []query.Row{ // dividing large floats results in inaccurate outputs so these may not be correct, but that is considered normal for floating point
  3775  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(461168601842738816)}},
  3776  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(922337203685477632)}},
  3777  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(485440633518672384)}},
  3778  			},
  3779  		},
  3780  		{
  3781  			Name:      "Integer_DivisionLHS_Unsigned",
  3782  			Statement: `SELECT 9223372036854775808 / i FROM cpu`,
  3783  			Err:       `type error: 9223372036854775808 / i::integer: cannot use / with an integer and unsigned literal`,
  3784  		},
  3785  		{
  3786  			Name:      "Unsigned_DivisionLHS_Unsigned",
  3787  			Statement: `SELECT 9223372036854775808 / u FROM cpu`,
  3788  			Rows: []query.Row{
  3789  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(461168601842738790)}},
  3790  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(922337203685477580)}},
  3791  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(485440633518672410)}},
  3792  			},
  3793  		},
  3794  		{
  3795  			Name:      "Float_Divide_Float",
  3796  			Statement: `SELECT f / f FROM cpu`,
  3797  			Rows: []query.Row{
  3798  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(1)}},
  3799  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(1)}},
  3800  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(1)}},
  3801  			},
  3802  		},
  3803  		{
  3804  			Name:      "Integer_Divide_Integer",
  3805  			Statement: `SELECT i / i FROM cpu`,
  3806  			Rows: []query.Row{
  3807  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(1)}},
  3808  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(1)}},
  3809  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(1)}},
  3810  			},
  3811  		},
  3812  		{
  3813  			Name:      "Unsigned_Divide_Unsigned",
  3814  			Statement: `SELECT u / u FROM cpu`,
  3815  			Rows: []query.Row{
  3816  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(1)}},
  3817  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(1)}},
  3818  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(1)}},
  3819  			},
  3820  		},
  3821  		{
  3822  			Name:      "Float_Divide_Integer",
  3823  			Statement: `SELECT f / i FROM cpu`,
  3824  			Rows: []query.Row{
  3825  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(1)}},
  3826  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(1)}},
  3827  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(1)}},
  3828  			},
  3829  		},
  3830  		{
  3831  			Name:      "Float_Divide_Unsigned",
  3832  			Statement: `SELECT f / u FROM cpu`,
  3833  			Rows: []query.Row{
  3834  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(1)}},
  3835  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(1)}},
  3836  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(1)}},
  3837  			},
  3838  		},
  3839  		{
  3840  			Name:      "Integer_Divide_Unsigned",
  3841  			Statement: `SELECT i / u FROM cpu`,
  3842  			Err:       `type error: i::integer / u::unsigned: cannot use / between an integer and unsigned, an explicit cast is required`,
  3843  		},
  3844  		{
  3845  			Name:      "Integer_BitwiseAndRHS",
  3846  			Statement: `SELECT i & 254 FROM cpu`,
  3847  			Rows: []query.Row{
  3848  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(20)}},
  3849  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(10)}},
  3850  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(18)}},
  3851  			},
  3852  		},
  3853  		{
  3854  			Name:      "Unsigned_BitwiseAndRHS",
  3855  			Statement: `SELECT u & 254 FROM cpu`,
  3856  			Rows: []query.Row{
  3857  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(20)}},
  3858  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(10)}},
  3859  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(18)}},
  3860  			},
  3861  		},
  3862  		{
  3863  			Name:      "Integer_BitwiseOrLHS",
  3864  			Statement: `SELECT 4 | i FROM cpu`,
  3865  			Rows: []query.Row{
  3866  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(20)}},
  3867  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(14)}},
  3868  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(23)}},
  3869  			},
  3870  		},
  3871  		{
  3872  			Name:      "Unsigned_BitwiseOrLHS",
  3873  			Statement: `SELECT 4 | u FROM cpu`,
  3874  			Rows: []query.Row{
  3875  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(20)}},
  3876  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(14)}},
  3877  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(23)}},
  3878  			},
  3879  		},
  3880  		{
  3881  			Name:      "Integer_BitwiseXOr_Integer",
  3882  			Statement: `SELECT i ^ i FROM cpu`,
  3883  			Rows: []query.Row{
  3884  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(0)}},
  3885  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(0)}},
  3886  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{int64(0)}},
  3887  			},
  3888  		},
  3889  		{
  3890  			Name:      "Unsigned_BitwiseXOr_Integer",
  3891  			Statement: `SELECT u ^ u FROM cpu`,
  3892  			Rows: []query.Row{
  3893  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(0)}},
  3894  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(0)}},
  3895  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{uint64(0)}},
  3896  			},
  3897  		},
  3898  	} {
  3899  		t.Run(test.Name, func(t *testing.T) {
  3900  			stmt := MustParseSelectStatement(test.Statement)
  3901  			stmt.OmitTime = true
  3902  			cur, err := query.Select(context.Background(), stmt, &shardMapper, query.SelectOptions{})
  3903  			if err != nil {
  3904  				if have, want := err.Error(), test.Err; want != "" {
  3905  					if have != want {
  3906  						t.Errorf("%s: unexpected parse error: %s != %s", test.Name, have, want)
  3907  					}
  3908  				} else {
  3909  					t.Errorf("%s: unexpected parse error: %s", test.Name, have)
  3910  				}
  3911  			} else if test.Err != "" {
  3912  				t.Fatalf("%s: expected error", test.Name)
  3913  			} else if a, err := ReadCursor(cur); err != nil {
  3914  				t.Fatalf("%s: unexpected error: %s", test.Name, err)
  3915  			} else if diff := cmp.Diff(test.Rows, a); diff != "" {
  3916  				t.Errorf("%s: unexpected points:\n%s", test.Name, diff)
  3917  			}
  3918  		})
  3919  	}
  3920  }
  3921  
  3922  // Ensure a SELECT binary expr queries can be executed as booleans.
  3923  func TestSelect_BinaryExpr_Boolean(t *testing.T) {
  3924  	shardMapper := ShardMapper{
  3925  		MapShardsFn: func(_ context.Context, sources influxql.Sources, _ influxql.TimeRange) query.ShardGroup {
  3926  			return &ShardGroup{
  3927  				Fields: map[string]influxql.DataType{
  3928  					"one": influxql.Boolean,
  3929  					"two": influxql.Boolean,
  3930  				},
  3931  				CreateIteratorFn: func(ctx context.Context, m *influxql.Measurement, opt query.IteratorOptions) (query.Iterator, error) {
  3932  					if m.Name != "cpu" {
  3933  						t.Fatalf("unexpected source: %s", m.Name)
  3934  					}
  3935  					makeAuxFields := func(value bool) []interface{} {
  3936  						aux := make([]interface{}, len(opt.Aux))
  3937  						for i := range aux {
  3938  							aux[i] = value
  3939  						}
  3940  						return aux
  3941  					}
  3942  					return &FloatIterator{Points: []query.FloatPoint{
  3943  						{Name: "cpu", Time: 0 * Second, Aux: makeAuxFields(true)},
  3944  						{Name: "cpu", Time: 5 * Second, Aux: makeAuxFields(false)},
  3945  						{Name: "cpu", Time: 9 * Second, Aux: makeAuxFields(true)},
  3946  					}}, nil
  3947  				},
  3948  			}
  3949  		},
  3950  	}
  3951  
  3952  	for _, test := range []struct {
  3953  		Name      string
  3954  		Statement string
  3955  		Rows      []query.Row
  3956  	}{
  3957  		{
  3958  			Name:      "BinaryXOrRHS",
  3959  			Statement: `SELECT one ^ true FROM cpu`,
  3960  			Rows: []query.Row{
  3961  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{false}},
  3962  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{true}},
  3963  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{false}},
  3964  			},
  3965  		},
  3966  		{
  3967  			Name:      "BinaryOrLHS",
  3968  			Statement: `SELECT true | two FROM cpu`,
  3969  			Rows: []query.Row{
  3970  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{true}},
  3971  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{true}},
  3972  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{true}},
  3973  			},
  3974  		},
  3975  		{
  3976  			Name:      "TwoSeriesBitwiseAnd",
  3977  			Statement: `SELECT one & two FROM cpu`,
  3978  			Rows: []query.Row{
  3979  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{true}},
  3980  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{false}},
  3981  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{true}},
  3982  			},
  3983  		},
  3984  	} {
  3985  		t.Run(test.Name, func(t *testing.T) {
  3986  			stmt := MustParseSelectStatement(test.Statement)
  3987  			stmt.OmitTime = true
  3988  			cur, err := query.Select(context.Background(), stmt, &shardMapper, query.SelectOptions{})
  3989  			if err != nil {
  3990  				t.Errorf("%s: parse error: %s", test.Name, err)
  3991  			} else if a, err := ReadCursor(cur); err != nil {
  3992  				t.Fatalf("%s: unexpected error: %s", test.Name, err)
  3993  			} else if diff := cmp.Diff(test.Rows, a); diff != "" {
  3994  				t.Errorf("%s: unexpected points:\n%s", test.Name, diff)
  3995  			}
  3996  		})
  3997  	}
  3998  }
  3999  
  4000  // Ensure a SELECT binary expr with nil values can be executed.
  4001  // Nil values may be present when a field is missing from one iterator,
  4002  // but not the other.
  4003  func TestSelect_BinaryExpr_NilValues(t *testing.T) {
  4004  	shardMapper := ShardMapper{
  4005  		MapShardsFn: func(_ context.Context, sources influxql.Sources, _ influxql.TimeRange) query.ShardGroup {
  4006  			return &ShardGroup{
  4007  				Fields: map[string]influxql.DataType{
  4008  					"total": influxql.Float,
  4009  					"value": influxql.Float,
  4010  				},
  4011  				CreateIteratorFn: func(ctx context.Context, m *influxql.Measurement, opt query.IteratorOptions) (query.Iterator, error) {
  4012  					if m.Name != "cpu" {
  4013  						t.Fatalf("unexpected source: %s", m.Name)
  4014  					}
  4015  					return &FloatIterator{Points: []query.FloatPoint{
  4016  						{Name: "cpu", Time: 0 * Second, Aux: []interface{}{float64(20), nil}},
  4017  						{Name: "cpu", Time: 5 * Second, Aux: []interface{}{float64(10), float64(15)}},
  4018  						{Name: "cpu", Time: 9 * Second, Aux: []interface{}{nil, float64(5)}},
  4019  					}}, nil
  4020  				},
  4021  			}
  4022  		},
  4023  	}
  4024  
  4025  	for _, test := range []struct {
  4026  		Name      string
  4027  		Statement string
  4028  		Rows      []query.Row
  4029  	}{
  4030  		{
  4031  			Name:      "Addition",
  4032  			Statement: `SELECT total + value FROM cpu`,
  4033  			Rows: []query.Row{
  4034  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{nil}},
  4035  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(25)}},
  4036  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{nil}},
  4037  			},
  4038  		},
  4039  		{
  4040  			Name:      "Subtraction",
  4041  			Statement: `SELECT total - value FROM cpu`,
  4042  			Rows: []query.Row{
  4043  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{nil}},
  4044  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(-5)}},
  4045  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{nil}},
  4046  			},
  4047  		},
  4048  		{
  4049  			Name:      "Multiplication",
  4050  			Statement: `SELECT total * value FROM cpu`,
  4051  			Rows: []query.Row{
  4052  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{nil}},
  4053  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(150)}},
  4054  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{nil}},
  4055  			},
  4056  		},
  4057  		{
  4058  			Name:      "Division",
  4059  			Statement: `SELECT total / value FROM cpu`,
  4060  			Rows: []query.Row{
  4061  				{Time: 0 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{nil}},
  4062  				{Time: 5 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(10) / float64(15)}},
  4063  				{Time: 9 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{nil}},
  4064  			},
  4065  		},
  4066  	} {
  4067  		t.Run(test.Name, func(t *testing.T) {
  4068  			stmt := MustParseSelectStatement(test.Statement)
  4069  			stmt.OmitTime = true
  4070  			cur, err := query.Select(context.Background(), stmt, &shardMapper, query.SelectOptions{})
  4071  			if err != nil {
  4072  				t.Errorf("%s: parse error: %s", test.Name, err)
  4073  			} else if a, err := ReadCursor(cur); err != nil {
  4074  				t.Fatalf("%s: unexpected error: %s", test.Name, err)
  4075  			} else if diff := cmp.Diff(test.Rows, a); diff != "" {
  4076  				t.Errorf("%s: unexpected points:\n%s", test.Name, diff)
  4077  			}
  4078  		})
  4079  	}
  4080  }
  4081  
  4082  type ShardMapper struct {
  4083  	MapShardsFn func(ctx context.Context, sources influxql.Sources, t influxql.TimeRange) query.ShardGroup
  4084  }
  4085  
  4086  func (m *ShardMapper) MapShards(ctx context.Context, sources influxql.Sources, t influxql.TimeRange, opt query.SelectOptions) (query.ShardGroup, error) {
  4087  	shards := m.MapShardsFn(ctx, sources, t)
  4088  	return shards, nil
  4089  }
  4090  
  4091  type ShardGroup struct {
  4092  	CreateIteratorFn func(ctx context.Context, m *influxql.Measurement, opt query.IteratorOptions) (query.Iterator, error)
  4093  	Fields           map[string]influxql.DataType
  4094  	Dimensions       []string
  4095  }
  4096  
  4097  func (sh *ShardGroup) CreateIterator(ctx context.Context, m *influxql.Measurement, opt query.IteratorOptions) (query.Iterator, error) {
  4098  	return sh.CreateIteratorFn(ctx, m, opt)
  4099  }
  4100  
  4101  func (sh *ShardGroup) IteratorCost(ctx context.Context, source *influxql.Measurement, opt query.IteratorOptions) (query.IteratorCost, error) {
  4102  	return query.IteratorCost{}, nil
  4103  }
  4104  
  4105  func (sh *ShardGroup) FieldDimensions(ctx context.Context, m *influxql.Measurement) (fields map[string]influxql.DataType, dimensions map[string]struct{}, err error) {
  4106  	fields = make(map[string]influxql.DataType)
  4107  	dimensions = make(map[string]struct{})
  4108  
  4109  	for f, typ := range sh.Fields {
  4110  		fields[f] = typ
  4111  	}
  4112  	for _, d := range sh.Dimensions {
  4113  		dimensions[d] = struct{}{}
  4114  	}
  4115  	return fields, dimensions, nil
  4116  }
  4117  
  4118  func (sh *ShardGroup) MapType(ctx context.Context, measurement *influxql.Measurement, field string) influxql.DataType {
  4119  	if typ, ok := sh.Fields[field]; ok {
  4120  		return typ
  4121  	}
  4122  	for _, d := range sh.Dimensions {
  4123  		if d == field {
  4124  			return influxql.Tag
  4125  		}
  4126  	}
  4127  	return influxql.Unknown
  4128  }
  4129  
  4130  func (*ShardGroup) Close() error {
  4131  	return nil
  4132  }
  4133  
  4134  func BenchmarkSelect_Raw_1K(b *testing.B)   { benchmarkSelectRaw(b, 1000) }
  4135  func BenchmarkSelect_Raw_100K(b *testing.B) { benchmarkSelectRaw(b, 1000000) }
  4136  
  4137  func benchmarkSelectRaw(b *testing.B, pointN int) {
  4138  	benchmarkSelect(b, MustParseSelectStatement(`SELECT fval FROM cpu`), NewRawBenchmarkIteratorCreator(pointN))
  4139  }
  4140  
  4141  func benchmarkSelect(b *testing.B, stmt *influxql.SelectStatement, shardMapper query.ShardMapper) {
  4142  	b.ReportAllocs()
  4143  
  4144  	for i := 0; i < b.N; i++ {
  4145  		cur, err := query.Select(context.Background(), stmt, shardMapper, query.SelectOptions{})
  4146  		if err != nil {
  4147  			b.Fatal(err)
  4148  		}
  4149  		query.DrainCursor(cur)
  4150  	}
  4151  }
  4152  
  4153  // NewRawBenchmarkIteratorCreator returns a new mock iterator creator with generated fields.
  4154  func NewRawBenchmarkIteratorCreator(pointN int) query.ShardMapper {
  4155  	return &ShardMapper{
  4156  		MapShardsFn: func(_ context.Context, sources influxql.Sources, t influxql.TimeRange) query.ShardGroup {
  4157  			return &ShardGroup{
  4158  				Fields: map[string]influxql.DataType{
  4159  					"fval": influxql.Float,
  4160  				},
  4161  				CreateIteratorFn: func(ctx context.Context, m *influxql.Measurement, opt query.IteratorOptions) (query.Iterator, error) {
  4162  					if opt.Expr != nil {
  4163  						panic("unexpected expression")
  4164  					}
  4165  
  4166  					p := query.FloatPoint{
  4167  						Name: "cpu",
  4168  						Aux:  make([]interface{}, len(opt.Aux)),
  4169  					}
  4170  
  4171  					for i := range opt.Aux {
  4172  						switch opt.Aux[i].Val {
  4173  						case "fval":
  4174  							p.Aux[i] = float64(100)
  4175  						default:
  4176  							panic("unknown iterator expr: " + opt.Expr.String())
  4177  						}
  4178  					}
  4179  
  4180  					return &FloatPointGenerator{N: pointN, Fn: func(i int) *query.FloatPoint {
  4181  						p.Time = int64(time.Duration(i) * (10 * time.Second))
  4182  						return &p
  4183  					}}, nil
  4184  				},
  4185  			}
  4186  		},
  4187  	}
  4188  }
  4189  
  4190  func benchmarkSelectDedupe(b *testing.B, seriesN, pointsPerSeries int) {
  4191  	stmt := MustParseSelectStatement(`SELECT sval::string FROM cpu`)
  4192  	stmt.Dedupe = true
  4193  
  4194  	shardMapper := ShardMapper{
  4195  		MapShardsFn: func(_ context.Context, sources influxql.Sources, t influxql.TimeRange) query.ShardGroup {
  4196  			return &ShardGroup{
  4197  				Fields: map[string]influxql.DataType{
  4198  					"sval": influxql.String,
  4199  				},
  4200  				CreateIteratorFn: func(ctx context.Context, m *influxql.Measurement, opt query.IteratorOptions) (query.Iterator, error) {
  4201  					if opt.Expr != nil {
  4202  						panic("unexpected expression")
  4203  					}
  4204  
  4205  					p := query.FloatPoint{
  4206  						Name: "tags",
  4207  						Aux:  []interface{}{nil},
  4208  					}
  4209  
  4210  					return &FloatPointGenerator{N: seriesN * pointsPerSeries, Fn: func(i int) *query.FloatPoint {
  4211  						p.Aux[0] = fmt.Sprintf("server%d", i%seriesN)
  4212  						return &p
  4213  					}}, nil
  4214  				},
  4215  			}
  4216  		},
  4217  	}
  4218  
  4219  	b.ResetTimer()
  4220  	benchmarkSelect(b, stmt, &shardMapper)
  4221  }
  4222  
  4223  func BenchmarkSelect_Dedupe_1K(b *testing.B) { benchmarkSelectDedupe(b, 1000, 100) }
  4224  
  4225  func benchmarkSelectTop(b *testing.B, seriesN, pointsPerSeries int) {
  4226  	stmt := MustParseSelectStatement(`SELECT top(sval, 10) FROM cpu`)
  4227  
  4228  	shardMapper := ShardMapper{
  4229  		MapShardsFn: func(_ context.Context, sources influxql.Sources, t influxql.TimeRange) query.ShardGroup {
  4230  			return &ShardGroup{
  4231  				Fields: map[string]influxql.DataType{
  4232  					"sval": influxql.Float,
  4233  				},
  4234  				CreateIteratorFn: func(ctx context.Context, m *influxql.Measurement, opt query.IteratorOptions) (query.Iterator, error) {
  4235  					if m.Name != "cpu" {
  4236  						b.Fatalf("unexpected source: %s", m.Name)
  4237  					}
  4238  					if !reflect.DeepEqual(opt.Expr, MustParseExpr(`sval`)) {
  4239  						b.Fatalf("unexpected expr: %s", spew.Sdump(opt.Expr))
  4240  					}
  4241  
  4242  					p := query.FloatPoint{
  4243  						Name: "cpu",
  4244  					}
  4245  
  4246  					return &FloatPointGenerator{N: seriesN * pointsPerSeries, Fn: func(i int) *query.FloatPoint {
  4247  						p.Value = float64(rand.Int63())
  4248  						p.Time = int64(time.Duration(i) * (10 * time.Second))
  4249  						return &p
  4250  					}}, nil
  4251  				},
  4252  			}
  4253  		},
  4254  	}
  4255  
  4256  	b.ResetTimer()
  4257  	benchmarkSelect(b, stmt, &shardMapper)
  4258  }
  4259  
  4260  func BenchmarkSelect_Top_1K(b *testing.B) { benchmarkSelectTop(b, 1000, 1000) }
  4261  
  4262  // ReadCursor reads a Cursor into an array of points.
  4263  func ReadCursor(cur query.Cursor) ([]query.Row, error) {
  4264  	defer cur.Close()
  4265  
  4266  	var rows []query.Row
  4267  	for {
  4268  		var row query.Row
  4269  		if !cur.Scan(&row) {
  4270  			if err := cur.Err(); err != nil {
  4271  				return nil, err
  4272  			}
  4273  			return rows, nil
  4274  		}
  4275  		rows = append(rows, row)
  4276  	}
  4277  }