Merge pull request from influxdata/js-7621-sample-wildcard

Expand string and boolean fields when using a wildcard with sample()
pull/7632/head
Jonathan A. Sternberg 2016-11-15 16:15:52 -06:00 committed by GitHub
commit 4b9c88037f
4 changed files with 52 additions and 7 deletions

View File

@ -9,6 +9,7 @@
### Bugfixes
- [#7621](https://github.com/influxdata/influxdb/issues/7621): Expand string and boolean fields when using a wildcard with `sample()`.
## v1.1.0 [unreleased]

View File

@ -6964,3 +6964,47 @@ func TestServer_Query_ImplicitEndTime(t *testing.T) {
}
}
}
func TestServer_Query_Sample_Wildcard(t *testing.T) {
t.Parallel()
s := OpenServer(NewConfig())
defer s.Close()
if err := s.CreateDatabaseAndRetentionPolicy("db0", newRetentionPolicySpec("rp0", 1, 0), true); err != nil {
t.Fatal(err)
}
writes := []string{
fmt.Sprintf(`cpu float=1,int=1i,string="hello, world",bool=true %d`, mustParseTime(time.RFC3339Nano, "2000-01-01T00:00:00Z").UnixNano()),
}
test := NewTest("db0", "rp0")
test.writes = Writes{
&Write{data: strings.Join(writes, "\n")},
}
test.addQueries([]*Query{
&Query{
name: "sample() with wildcard",
params: url.Values{"db": []string{"db0"}},
command: `SELECT sample(*, 1) FROM cpu`,
exp: `{"results":[{"series":[{"name":"cpu","columns":["time","sample_bool","sample_float","sample_int","sample_string"],"values":[["2000-01-01T00:00:00Z",true,1,1,"hello, world"]]}]}]}`,
},
}...)
if err := test.init(s); err != nil {
t.Fatalf("test init failed: %s", err)
}
for _, query := range test.queries {
if query.skip {
t.Logf("SKIP:: %s", query.name)
continue
}
if err := query.Execute(s); err != nil {
t.Error(query.Error(err))
} else if !query.success() {
t.Error(query.failureMessage())
}
}
}

View File

@ -1178,7 +1178,7 @@ func (s *SelectStatement) RewriteFields(ic IteratorCreator) (*SelectStatement, e
// Add additional types for certain functions.
switch call.Name {
case "count", "first", "last", "distinct", "elapsed", "mode":
case "count", "first", "last", "distinct", "elapsed", "mode", "sample":
supportedTypes[String] = struct{}{}
fallthrough
case "min", "max":

View File

@ -1276,18 +1276,18 @@ func newSampleIterator(input Iterator, opt IteratorOptions, size int) (Iterator,
return fn, fn
}
return &integerReduceIntegerIterator{input: newBufIntegerIterator(input), opt: opt, create: createFn}, nil
case BooleanIterator:
createFn := func() (BooleanPointAggregator, BooleanPointEmitter) {
fn := NewBooleanSampleReducer(size)
return fn, fn
}
return &booleanReduceBooleanIterator{input: newBufBooleanIterator(input), opt: opt, create: createFn}, nil
case StringIterator:
createFn := func() (StringPointAggregator, StringPointEmitter) {
fn := NewStringSampleReducer(size)
return fn, fn
}
return &stringReduceStringIterator{input: newBufStringIterator(input), opt: opt, create: createFn}, nil
case BooleanIterator:
createFn := func() (BooleanPointAggregator, BooleanPointEmitter) {
fn := NewBooleanSampleReducer(size)
return fn, fn
}
return &booleanReduceBooleanIterator{input: newBufBooleanIterator(input), opt: opt, create: createFn}, nil
default:
return nil, fmt.Errorf("unsupported elapsed iterator type: %T", input)
}