Skip to content

Instantly share code, notes, and snippets.

@cxreg
Created August 17, 2016 18:48
Show Gist options
  • Save cxreg/4b930a5fb50dd82934e1edaecb26c1dd to your computer and use it in GitHub Desktop.
Save cxreg/4b930a5fb50dd82934e1edaecb26c1dd to your computer and use it in GitHub Desktop.
Downsampling Influxdb data while converting tags to fields
# Insert some data
> insert foo,bar=baz,biff=buzz numvalue=1,strvalue="some string"
> insert foo,bar=baz,biff=buzz numvalue=1,strvalue="some string"
> insert foo,bar=baz,biff=buzz numvalue=1,strvalue="some string"
> insert foo,bar=baz,biff=buzz numvalue=1,strvalue="some string"
> insert foo,bar=baz,biff=buzz numvalue=1,strvalue="some string"
> show series
key
foo,bar=baz,biff=buzz
> select * from foo
name: foo
---------
time bar biff numvalue strvalue
1471459200225949305 baz buzz 1 some string
1471459203143602192 baz buzz 1 some string
1471459203897832655 baz buzz 1 some string
1471459207540428892 baz buzz 1 some string
1471459209405112430 baz buzz 1 some string
# Attempt to downsample, converting tags to fields. It doesn't work!
> select mean(numvalue) as numvalue, first(strvalue) as strvalue, first(bar) as bar, first(biff) as biff from foo where time > now() - 4m group by time(1s)
name: foo
---------
time numvalue strvalue bar biff
1471459200000000000 1 some string
1471459203000000000 1 some string
1471459207000000000 1 some string
1471459209000000000 1 some string
# Convert to fields
> select * into "intermediate" from foo
name: result
------------
time written
0 5
# Now downsample. It worked!
> select mean(numvalue) as numvalue, first(strvalue) as strvalue, first(bar) as bar, first(biff) as biff from intermediate where time > now() - 4m group by time(1s)
name: intermediate
------------------
time numvalue strvalue bar biff
1471459200000000000 1 some string baz buzz
1471459203000000000 1 some string baz buzz
1471459207000000000 1 some string baz buzz
1471459209000000000 1 some string baz buzz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment