diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..e9cfb1a2d1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +vendor +.netrc +.vscode +.vs +.tern-project diff --git a/Gopkg.lock b/Gopkg.lock new file mode 100644 index 0000000000..28eee9cff2 --- /dev/null +++ b/Gopkg.lock @@ -0,0 +1,1032 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + digest = "1:72fff13e105db55c6d4b1acb69216b88d9d3009433f43d7df3488f842b0b6929" + name = "github.com/RoaringBitmap/roaring" + packages = ["."] + pruneopts = "UT" + revision = "3d677d3262197ee558b85029301eb69b8239f91a" + version = "v0.4.16" + +[[projects]] + digest = "1:c06d9e11d955af78ac3bbb26bd02e01d2f61f689e1a3bce2ef6fb683ef8a7f2d" + name = "github.com/alecthomas/kingpin" + packages = ["."] + pruneopts = "UT" + revision = "947dcec5ba9c011838740e680966fd7087a71d0d" + version = "v2.2.6" + +[[projects]] + branch = "master" + digest = "1:315c5f2f60c76d89b871c73f9bd5fe689cad96597afd50fb9992228ef80bdd34" + name = "github.com/alecthomas/template" + packages = [ + ".", + "parse", + ] + pruneopts = "UT" + revision = "a0175ee3bccc567396460bf5acd36800cb10c49c" + +[[projects]] + branch = "master" + digest = "1:c198fdc381e898e8fb62b8eb62758195091c313ad18e52a3067366e1dda2fb3c" + name = "github.com/alecthomas/units" + packages = ["."] + pruneopts = "UT" + revision = "2efee857e7cfd4f3d0138cc3cbb1b4966962b93a" + +[[projects]] + branch = "master" + digest = "1:86d119ee8a0fb122f2d0e0fbbbd5d2f65953029248743462ee3908a21ae04247" + name = "github.com/andreyvit/diff" + packages = ["."] + pruneopts = "UT" + revision = "c7f18ee00883bfd3b00e0a2bf7607827e0148ad4" + +[[projects]] + branch = "master" + digest = "1:861e7c55835e36c4bb41132ee48a4669429096cc184b634b99809822b416f66b" + name = "github.com/apex/log" + packages = [ + ".", + "handlers/cli", + ] + pruneopts = "UT" + revision = "941dea75d3ebfbdd905a5d8b7b232965c5e5c684" + +[[projects]] + digest = "1:d128bb41bb76745c62ffc652051f6800117dde46601db31d29df291fea10d0d5" + name = "github.com/aws/aws-sdk-go" + packages = [ + "aws", + "aws/awserr", + "aws/awsutil", + "aws/client", + "aws/client/metadata", + "aws/corehandlers", + "aws/credentials", + "aws/credentials/ec2rolecreds", + "aws/credentials/endpointcreds", + "aws/credentials/stscreds", + "aws/csm", + "aws/defaults", + "aws/ec2metadata", + "aws/endpoints", + "aws/request", + "aws/session", + "aws/signer/v4", + "internal/sdkio", + "internal/sdkrand", + "internal/sdkuri", + "internal/shareddefaults", + "private/protocol", + "private/protocol/eventstream", + "private/protocol/eventstream/eventstreamapi", + "private/protocol/query", + "private/protocol/query/queryutil", + "private/protocol/rest", + "private/protocol/restxml", + "private/protocol/xml/xmlutil", + "service/s3", + "service/sts", + ] + pruneopts = "UT" + revision = "3e9c4ca8d7fc8d22f0d21d50120186f73d2fdf1a" + version = "v1.15.27" + +[[projects]] + branch = "master" + digest = "1:d6afaeed1502aa28e80a4ed0981d570ad91b2579193404256ce672ed0a609e0d" + name = "github.com/beorn7/perks" + packages = ["quantile"] + pruneopts = "UT" + revision = "3a771d992973f24aa725d07868b467d1ddfceafb" + +[[projects]] + branch = "master" + digest = "1:06519a2ec1d59040eaccec40206f9d0b59dc662db2a032f974d6d6b9a2bcb839" + name = "github.com/blakesmith/ar" + packages = ["."] + pruneopts = "UT" + revision = "8bd4349a67f2533b078dbc524689d15dba0f4659" + +[[projects]] + digest = "1:a2486f94bda33b301614ff5cfce102b7eed4c923fa650c2b83dba1fcf2117466" + name = "github.com/c-bata/go-prompt" + packages = ["."] + pruneopts = "UT" + revision = "c52492ff1b386e5c0ba5271b5eaad165fab09eca" + version = "v0.2.2" + +[[projects]] + digest = "1:bf525707b4455ed126b3b091939a3693f608385c73d8dfdeb748e510bcda1338" + name = "github.com/caarlos0/ctrlc" + packages = ["."] + pruneopts = "UT" + revision = "70dc48d5d792f20f684a8f1d29bbac298f4b2ef4" + version = "v1.0.0" + +[[projects]] + branch = "master" + digest = "1:e3bb755ea84412451cdc4bd902b0985611f0e2826dad686eb17a0e5c45a62fbf" + name = "github.com/campoy/unique" + packages = ["."] + pruneopts = "UT" + revision = "88950e537e7e644cd746a3102037b5d2b723e9f5" + +[[projects]] + digest = "1:3535f00c607f3993a1a2f1cbb1b3faa3bf8903f9edc77c1386491882d3b2754c" + name = "github.com/cespare/xxhash" + packages = ["."] + pruneopts = "UT" + revision = "5c37fe3735342a2e0d01c87a907579987c8936cc" + version = "v1.0.0" + +[[projects]] + branch = "master" + digest = "1:4c4c33075b704791d6a7f09dfb55c66769e8a1dc6adf87026292d274fe8ad113" + name = "github.com/codahale/hdrhistogram" + packages = ["."] + pruneopts = "UT" + revision = "3a0bb77429bd3a61596f5e8a3172445844342120" + +[[projects]] + branch = "master" + digest = "1:b2a9da4dfb6d53e94d8bf6fbb23a9cee5fff7419167b97770b8e3b6a462f1742" + name = "github.com/dgryski/go-bits" + packages = ["."] + pruneopts = "UT" + revision = "bd8a69a71dc203aa976f9d918b428db9ac605f57" + +[[projects]] + branch = "master" + digest = "1:c57df9dedbc4d7bcb1a014b7023838b8c121a8e07de939ceee2724fb9fd392c7" + name = "github.com/dgryski/go-bitstream" + packages = ["."] + pruneopts = "UT" + revision = "3522498ce2c8ea06df73e55df58edfbfb33cfdd6" + +[[projects]] + digest = "1:865079840386857c809b72ce300be7580cb50d3d3129ce11bf9aa6ca2bc1934a" + name = "github.com/fatih/color" + packages = ["."] + pruneopts = "UT" + revision = "5b77d2a35fb0ede96d138fc9a99f5c9b6aef11b4" + version = "v1.7.0" + +[[projects]] + branch = "master" + digest = "1:981722e5ee549ef844285c2b370c19e58b7dc30bc19ba3537f3df284b551b54a" + name = "github.com/glycerine/go-unsnap-stream" + packages = ["."] + pruneopts = "UT" + revision = "9f0cb55181dd3a0a4c168d3dbc72d4aca4853126" + +[[projects]] + digest = "1:5abd6a22805b1919f6a6bca0ae58b13cef1f3412812f38569978f43ef02743d4" + name = "github.com/go-ini/ini" + packages = ["."] + pruneopts = "UT" + revision = "5cf292cae48347c2490ac1a58fe36735fb78df7e" + version = "v1.38.2" + +[[projects]] + digest = "1:a3fbe9c08358dd9dcb92092588b200f93d72a6e9a1a7876a350f6d2ed081acc3" + name = "github.com/gogo/protobuf" + packages = [ + "codec", + "gogoproto", + "proto", + "protoc-gen-gogo/descriptor", + "sortkeys", + "types", + ] + pruneopts = "UT" + revision = "636bf0302bc95575d69441b25a2603156ffdddf1" + version = "v1.1.1" + +[[projects]] + digest = "1:4c0989ca0bcd10799064318923b9bc2db6b4d6338dd75f3f2d86c3511aaaf5cf" + name = "github.com/golang/protobuf" + packages = [ + "proto", + "ptypes", + "ptypes/any", + "ptypes/duration", + "ptypes/timestamp", + ] + pruneopts = "UT" + revision = "aa810b61a9c79d51363740d207bb46cf8e620ed5" + version = "v1.2.0" + +[[projects]] + branch = "master" + digest = "1:4a0c6bb4805508a6287675fac876be2ac1182539ca8a32468d8128882e9d5009" + name = "github.com/golang/snappy" + packages = ["."] + pruneopts = "UT" + revision = "2e65f85255dbc3072edf28d6b5b8efc472979f5a" + +[[projects]] + branch = "master" + digest = "1:5601ae3024d6657d6655a043fefce0ca8924af535fe56bcd184ecd2f7cfc5335" + name = "github.com/gonum/blas" + packages = [ + ".", + "blas64", + "native", + "native/internal/math32", + ] + pruneopts = "UT" + revision = "e7c5890b24cf6f3bb173f76e1bd71e80e887e3f9" + +[[projects]] + branch = "master" + digest = "1:4d213c1faa284634054e52465bd94d72a6b4fcd792cecf6cef357bdc3c84f745" + name = "github.com/gonum/floats" + packages = ["."] + pruneopts = "UT" + revision = "7de1f4ea7ab57890bfd427af68c7994cd67975d4" + +[[projects]] + branch = "master" + digest = "1:dc7c82ea61b3c8da96b40b7c87c1c26b41f735f516babec25ebe826acf359b43" + name = "github.com/gonum/internal" + packages = [ + "asm/f32", + "asm/f64", + ] + pruneopts = "UT" + revision = "fda53f8d25717c07e2dac25758075a182bd74235" + +[[projects]] + branch = "master" + digest = "1:2854c77b7dbe7f340e37d3b01c07f9da33b5ff7d21c915f195b4a0ae9f37d6f5" + name = "github.com/gonum/lapack" + packages = [ + ".", + "lapack64", + "native", + ] + pruneopts = "UT" + revision = "f0b8b25edeceafb3a2752941c7bf0cda962df112" + +[[projects]] + branch = "master" + digest = "1:fb0e34cdca23afa879f1d81cc9f514b8d9c34b84e83af9c642bb771d2583ed38" + name = "github.com/gonum/mathext" + packages = [ + ".", + "internal/amos", + "internal/cephes", + "internal/gonum", + ] + pruneopts = "UT" + revision = "3ffefb3e36fc77021b605da090e6571103cb6ef3" + +[[projects]] + branch = "master" + digest = "1:d28c2bfc6b59b522a166106a3a4b04ca55fd2171ffd7a1ea0a6edb5f4e5c4b40" + name = "github.com/gonum/matrix" + packages = [ + ".", + "mat64", + ] + pruneopts = "UT" + revision = "a41cc49d4c29f7451775f4379a5cc6ec6239dfab" + +[[projects]] + branch = "master" + digest = "1:bf0e5a82e5f51b7bbcdb3fa176368766dfb7e004846fb2cad398ea74e9239099" + name = "github.com/gonum/stat" + packages = [ + ".", + "distuv", + ] + pruneopts = "UT" + revision = "ec9c8a1062f4be6c6ad671f0f5dba12d4a76826d" + +[[projects]] + digest = "1:d2754cafcab0d22c13541618a8029a70a8959eb3525ff201fe971637e2274cd0" + name = "github.com/google/go-cmp" + packages = [ + "cmp", + "cmp/cmpopts", + "cmp/internal/diff", + "cmp/internal/function", + "cmp/internal/value", + ] + pruneopts = "UT" + revision = "3af367b6b30c263d47e8895973edcca9a49cf029" + version = "v0.2.0" + +[[projects]] + branch = "master" + digest = "1:f273c6b478d735f30d6756a7cce5ed296494fd654fb3c8f891714a597ed0a4db" + name = "github.com/google/go-github" + packages = ["github"] + pruneopts = "UT" + revision = "7a180b5eed10c86fc54bcc274753eb35717931db" + +[[projects]] + branch = "master" + digest = "1:a63cff6b5d8b95638bfe300385d93b2a6d9d687734b863da8e09dc834510a690" + name = "github.com/google/go-querystring" + packages = ["query"] + pruneopts = "UT" + revision = "53e6ce116135b80d037921a7fdd5138cf32d7a8a" + +[[projects]] + digest = "1:6f95db9a2709519edc486a797638bcc34b58641fa57337d4e7ab26b0ea22cf9c" + name = "github.com/goreleaser/goreleaser" + packages = [ + ".", + "internal/artifact", + "internal/builders/golang", + "internal/client", + "internal/git", + "internal/http", + "internal/linux", + "internal/pipeline", + "internal/pipeline/archive", + "internal/pipeline/artifactory", + "internal/pipeline/before", + "internal/pipeline/brew", + "internal/pipeline/build", + "internal/pipeline/changelog", + "internal/pipeline/checksums", + "internal/pipeline/defaults", + "internal/pipeline/dist", + "internal/pipeline/docker", + "internal/pipeline/effectiveconfig", + "internal/pipeline/env", + "internal/pipeline/git", + "internal/pipeline/nfpm", + "internal/pipeline/project", + "internal/pipeline/put", + "internal/pipeline/release", + "internal/pipeline/s3", + "internal/pipeline/scoop", + "internal/pipeline/sign", + "internal/pipeline/snapcraft", + "internal/pipeline/snapshot", + "internal/semerrgroup", + "internal/tmpl", + "pkg/archive", + "pkg/archive/tar", + "pkg/archive/zip", + "pkg/build", + "pkg/config", + "pkg/context", + ] + pruneopts = "UT" + revision = "93a0055d036200749a25b5a3454737b0de6af2d3" + version = "v0.84.0" + +[[projects]] + digest = "1:555e46bfe479a0c08e69f57cbce309be0c5fb2f8bc203dc0be6132758a8dd158" + name = "github.com/goreleaser/nfpm" + packages = [ + ".", + "deb", + "glob", + "rpm", + ] + pruneopts = "UT" + revision = "923d6a7473bfdbe7a583b7f3df1f3f780b1b73ab" + version = "v0.9.3" + +[[projects]] + branch = "master" + digest = "1:1a1206efd03a54d336dce7bb8719e74f2f8932f661cb9f57d5813a1d99c083d8" + name = "github.com/grpc-ecosystem/grpc-opentracing" + packages = ["go/otgrpc"] + pruneopts = "UT" + revision = "8e809c8a86450a29b90dcc9efbf062d0fe6d9746" + +[[projects]] + digest = "1:8eb1de8112c9924d59bf1d3e5c26f5eaa2bfc2a5fcbb92dc1c2e4546d695f277" + name = "github.com/imdario/mergo" + packages = ["."] + pruneopts = "UT" + revision = "9f23e2d6bd2a77f959b2bf6acdbefd708a83a4a4" + version = "v0.3.6" + +[[projects]] + digest = "1:7f8f4a78c76411293f90a142c546ba068e6de73d8d146bfcba42da2a14d867de" + name = "github.com/influxdata/influxdb" + packages = [ + ".", + "logger", + "models", + "monitor/diagnostics", + "pkg/binaryutil", + "pkg/bits", + "pkg/bloom", + "pkg/bytesutil", + "pkg/escape", + "pkg/estimator", + "pkg/estimator/hll", + "pkg/file", + "pkg/limiter", + "pkg/metrics", + "pkg/mmap", + "pkg/pool", + "pkg/rhh", + "pkg/slices", + "pkg/snowflake", + "pkg/tar", + "pkg/tracing", + "pkg/tracing/fields", + "pkg/tracing/labels", + "pkg/tracing/wire", + "query", + "query/internal", + "query/neldermead", + "services/meta", + "services/meta/internal", + "services/storage", + "toml", + "tsdb", + "tsdb/engine/tsm1", + "tsdb/index", + "tsdb/index/inmem", + "tsdb/index/tsi1", + "tsdb/internal", + ] + pruneopts = "UT" + revision = "4e4e00bc5ab85a3ff5e988c91020cf0399a87026" + version = "v1.5.4" + +[[projects]] + branch = "master" + digest = "1:4355f386eeeb63e23bfc80ba179f44f2d78c1a9f3146936a87165bd9f6a14dca" + name = "github.com/influxdata/influxql" + packages = [ + ".", + "internal", + ] + pruneopts = "UT" + revision = "a7267bff5327e316e54c54342b0bc9598753e3d5" + +[[projects]] + branch = "master" + digest = "1:ce365a2909a7ef5c9f9ca3059ba235318977065f1941589246fd111f71c0c62a" + name = "github.com/influxdata/line-protocol" + packages = ["."] + pruneopts = "UT" + revision = "32c6aa80de5eb09d190ad284a8214a531c6bce57" + +[[projects]] + branch = "master" + digest = "1:34def0636ad5ada60c9396ca249e1c5a79a69ade32460ebb5dea18cbde304063" + name = "github.com/influxdata/platform" + packages = [ + ".", + "kit/errors", + "mock", + ] + pruneopts = "UT" + revision = "9a469fd8ad02121b0d6c5b6eaa08a47f26a56af8" + +[[projects]] + branch = "master" + digest = "1:b07e7ba2bb99a70ce3318ea387a62666371c1ab4f9bfcae192a59e3f4b8ffa56" + name = "github.com/influxdata/tdigest" + packages = ["."] + pruneopts = "UT" + revision = "a7d76c6f093a59b94a01c6c2b8429122d444a8cc" + +[[projects]] + branch = "master" + digest = "1:727a6ac822715bca1eb05fd6a3824d7aea05f4f6d6c0994d8200a61f7669b7bc" + name = "github.com/influxdata/yamux" + packages = ["."] + pruneopts = "UT" + revision = "1f58ded512de5feabbe30b60c7d33a7a896c5f16" + +[[projects]] + digest = "1:4e744aba524a6af529d5cb15126a043cc6aa08eec7da8d9c8152b719e4115d03" + name = "github.com/influxdata/yarpc" + packages = [ + ".", + "codes", + "status", + "yarpcproto", + ] + pruneopts = "UT" + revision = "b13d74d757bf9ea3e5574a491eb6646bdc4e2a04" + version = "v0.0.1" + +[[projects]] + digest = "1:e22af8c7518e1eab6f2eab2b7d7558927f816262586cd6ed9f349c97a6c285c4" + name = "github.com/jmespath/go-jmespath" + packages = ["."] + pruneopts = "UT" + revision = "0b12d6b5" + +[[projects]] + digest = "1:01ebdcf56ff77c8e0b7a29853f503180f674235478fbecebd3f17e96aee99352" + name = "github.com/jsternberg/zap-logfmt" + packages = ["."] + pruneopts = "UT" + revision = "ef1948cade6f9592fac3f57654e3ddfc4986bb52" + version = "v1.2.0" + +[[projects]] + branch = "master" + digest = "1:b0a450ba626dd247151de6209d6e4a7f8156af1ebc1169186e641814d548ed16" + name = "github.com/jwilder/encoding" + packages = ["simple8b"] + pruneopts = "UT" + revision = "b4e1701a28efcc637d9afcca7d38e495fe909a09" + +[[projects]] + digest = "1:d833c2b46766fc09d7d0e453ae928ae0b1288e59e12449285f943d02d6a95533" + name = "github.com/kevinburke/go-bindata" + packages = ["."] + pruneopts = "NT" + revision = "06af60a4461b70d84a2b173d92f9f425d78baf55" + version = "v3.11.0" + +[[projects]] + digest = "1:55388fd080150b9a072912f97b1f5891eb0b50df43401f8b75fb4273d3fec9fc" + name = "github.com/masterminds/semver" + packages = ["."] + pruneopts = "UT" + revision = "c7af12943936e8c39859482e61f0574c2fd7fc75" + version = "v1.4.2" + +[[projects]] + digest = "1:c658e84ad3916da105a761660dcaeb01e63416c8ec7bc62256a9b411a05fcd67" + name = "github.com/mattn/go-colorable" + packages = ["."] + pruneopts = "UT" + revision = "167de6bfdfba052fa6b2d3664c8f5272e23c9072" + version = "v0.0.9" + +[[projects]] + digest = "1:0981502f9816113c9c8c4ac301583841855c8cf4da8c72f696b3ebedf6d0e4e5" + name = "github.com/mattn/go-isatty" + packages = ["."] + pruneopts = "UT" + revision = "6ca4dbf54d38eea1a992b3c722a76a5d1c4cb25c" + version = "v0.0.4" + +[[projects]] + branch = "master" + digest = "1:cdb899c199f907ac9fb50495ec71212c95cb5b0e0a8ee0800da0238036091033" + name = "github.com/mattn/go-runewidth" + packages = ["."] + pruneopts = "UT" + revision = "ce7b0b5c7b45a81508558cd1dba6bb1e4ddb51bb" + +[[projects]] + branch = "master" + digest = "1:d775613e6db40f54d34cc8b319ee5c2df56752f9f5e55e2f6004d11684bdc8fd" + name = "github.com/mattn/go-tty" + packages = ["."] + pruneopts = "UT" + revision = "931426f7535ac39720c8909d70ece5a41a2502a6" + +[[projects]] + branch = "master" + digest = "1:36aebe90a13cf9128280ac834399b8bebf83685283c78df279d61c46bb2a8d83" + name = "github.com/mattn/go-zglob" + packages = [ + ".", + "fastwalk", + ] + pruneopts = "UT" + revision = "2ea3427bfa539cca900ca2768d8663ecc8a708c1" + +[[projects]] + digest = "1:ff5ebae34cfbf047d505ee150de27e60570e8c394b3b8fdbb720ff6ac71985fc" + name = "github.com/matttproud/golang_protobuf_extensions" + packages = ["pbutil"] + pruneopts = "UT" + revision = "c12348ce28de40eed0136aa2b644d0ee0650e56c" + version = "v1.0.1" + +[[projects]] + branch = "master" + digest = "1:78bbb1ba5b7c3f2ed0ea1eab57bdd3859aec7e177811563edc41198a760b06af" + name = "github.com/mitchellh/go-homedir" + packages = ["."] + pruneopts = "UT" + revision = "ae18d6b8b3205b561c79e8e5f69bff09736185f4" + +[[projects]] + branch = "master" + digest = "1:81cd8e8d77ba297778b1e7b31e767f1aef0a8b34b2f853c96011281d38414035" + name = "github.com/mna/pigeon" + packages = [ + ".", + "ast", + "builder", + ] + pruneopts = "UT" + revision = "bb0192cfc2ae6ff30b9726618594b42ef2562da5" + +[[projects]] + branch = "master" + digest = "1:c22fdadfe2de0e1df75987cac34f1c721157dc24f180c76b4ef66a3c9637a799" + name = "github.com/mschoch/smat" + packages = ["."] + pruneopts = "UT" + revision = "90eadee771aeab36e8bf796039b8c261bebebe4f" + +[[projects]] + digest = "1:450b7623b185031f3a456801155c8320209f75d0d4c4e633c6b1e59d44d6e392" + name = "github.com/opentracing/opentracing-go" + packages = [ + ".", + "ext", + "log", + ] + pruneopts = "UT" + revision = "1949ddbfd147afd4d964a9f00b24eb291e0e7c38" + version = "v1.0.2" + +[[projects]] + digest = "1:5e73b34a27d827212102605789de00bd411b2e434812133c83935fe9897c75e1" + name = "github.com/philhofer/fwd" + packages = ["."] + pruneopts = "UT" + revision = "bb6d471dc95d4fe11e432687f8b70ff496cf3136" + version = "v1.0.0" + +[[projects]] + digest = "1:40e195917a951a8bf867cd05de2a46aaf1806c50cf92eebf4c16f78cd196f747" + name = "github.com/pkg/errors" + packages = ["."] + pruneopts = "UT" + revision = "645ef00459ed84a119197bfb8d8205042c6df63d" + version = "v0.8.0" + +[[projects]] + branch = "master" + digest = "1:4f43b3c1b7e44980a5f3c593f8bf0e18844dc44f451a071c93e77e28cf990db6" + name = "github.com/pkg/term" + packages = ["termios"] + pruneopts = "UT" + revision = "bffc007b7fd5a70e20e28f5b7649bb84671ef436" + +[[projects]] + digest = "1:d2df7a5cebe72c567295c018cc3f9205bc6fc72d9564c683cb4b8db4a3e8d6a8" + name = "github.com/prometheus/client_golang" + packages = ["prometheus"] + pruneopts = "UT" + revision = "661e31bf844dfca9aeba15f27ea8aa0d485ad212" + +[[projects]] + branch = "master" + digest = "1:2d5cd61daa5565187e1d96bae64dbbc6080dacf741448e9629c64fd93203b0d4" + name = "github.com/prometheus/client_model" + packages = ["go"] + pruneopts = "UT" + revision = "5c3871d89910bfb32f5fcab2aa4b9ec68e65a99f" + +[[projects]] + branch = "master" + digest = "1:63b68062b8968092eb86bedc4e68894bd096ea6b24920faca8b9dcf451f54bb5" + name = "github.com/prometheus/common" + packages = [ + "expfmt", + "internal/bitbucket.org/ww/goautoneg", + "model", + ] + pruneopts = "UT" + revision = "c7de2306084e37d54b8be01f3541a8464345e9a5" + +[[projects]] + branch = "master" + digest = "1:8c49953a1414305f2ff5465147ee576dd705487c35b15918fcd4efdc0cb7a290" + name = "github.com/prometheus/procfs" + packages = [ + ".", + "internal/util", + "nfs", + "xfs", + ] + pruneopts = "UT" + revision = "05ee40e3a273f7245e8777337fc7b46e533a9a92" + +[[projects]] + digest = "1:274f67cb6fed9588ea2521ecdac05a6d62a8c51c074c1fccc6a49a40ba80e925" + name = "github.com/satori/go.uuid" + packages = ["."] + pruneopts = "UT" + revision = "f58768cc1a7a7e77a3bd49e98cdd21419399b6a3" + version = "v1.2.0" + +[[projects]] + branch = "master" + digest = "1:7f081bc4c81e3e69f4d3b4a87e1b23f2a395e9804f06895c52f8f4157af7a35a" + name = "github.com/segmentio/kafka-go" + packages = ["."] + pruneopts = "UT" + revision = "48c37f796910d8154479aaa04ade5843ae4f55d0" + +[[projects]] + digest = "1:d917313f309bda80d27274d53985bc65651f81a5b66b820749ac7f8ef061fd04" + name = "github.com/sergi/go-diff" + packages = ["diffmatchpatch"] + pruneopts = "UT" + revision = "1744e2970ca51c86172c8190fadad617561ed6e7" + version = "v1.0.0" + +[[projects]] + digest = "1:eaa6698f44de8f2977e93c9b946e60a8af75f565058658aad2df8032b55c84e5" + name = "github.com/tinylib/msgp" + packages = ["msgp"] + pruneopts = "UT" + revision = "b2b6a672cf1e5b90748f79b8b81fc8c5cf0571a1" + version = "1.0.2" + +[[projects]] + digest = "1:104a2d7446f4628e4663d7c029b18da1aad4313735de775f37b6e7720b1d0aa7" + name = "github.com/uber/jaeger-client-go" + packages = [ + ".", + "config", + "internal/baggage", + "internal/baggage/remote", + "internal/spanlog", + "internal/throttler", + "internal/throttler/remote", + "log", + "rpcmetrics", + "thrift", + "thrift-gen/agent", + "thrift-gen/baggage", + "thrift-gen/jaeger", + "thrift-gen/sampling", + "thrift-gen/zipkincore", + "utils", + ] + pruneopts = "UT" + revision = "b043381d944715b469fd6b37addfd30145ca1758" + version = "v2.14.0" + +[[projects]] + digest = "1:0f09db8429e19d57c8346ad76fbbc679341fa86073d3b8fb5ac919f0357d8f4c" + name = "github.com/uber/jaeger-lib" + packages = ["metrics"] + pruneopts = "UT" + revision = "ed3a127ec5fef7ae9ea95b01b542c47fbd999ce5" + version = "v1.5.0" + +[[projects]] + digest = "1:211f9cf21d532e2da93a420426d714af492743f4c602389cb0cd14ec8eebe256" + name = "github.com/willf/bitset" + packages = ["."] + pruneopts = "UT" + revision = "e553b05586428962bf7058d1044519d87ca72d74" + version = "v1.1.9" + +[[projects]] + branch = "master" + digest = "1:530b61e812573f3600e7c23b1c63ce685217482389bfd85e4b7bfd21692c2f70" + name = "github.com/xlab/treeprint" + packages = ["."] + pruneopts = "UT" + revision = "d6fb6747feb6e7cfdc44682a024bddf87ef07ec2" + +[[projects]] + digest = "1:3c1a69cdae3501bf75e76d0d86dc6f2b0a7421bc205c0cb7b96b19eed464a34d" + name = "go.uber.org/atomic" + packages = ["."] + pruneopts = "UT" + revision = "1ea20fb1cbb1cc08cbd0d913a96dead89aa18289" + version = "v1.3.2" + +[[projects]] + digest = "1:60bf2a5e347af463c42ed31a493d817f8a72f102543060ed992754e689805d1a" + name = "go.uber.org/multierr" + packages = ["."] + pruneopts = "UT" + revision = "3c4937480c32f4c13a875a1829af76c98ca3d40a" + version = "v1.1.0" + +[[projects]] + digest = "1:d0786a018883b4b84c06e8b5d75b6f2797a4b8e489f860c587f57a43a7459108" + name = "go.uber.org/zap" + packages = [ + ".", + "buffer", + "internal/bufferpool", + "internal/color", + "internal/exit", + "internal/ztest", + "zapcore", + "zaptest", + ] + pruneopts = "UT" + revision = "ff33455a0e382e8a81d14dd7c922020b6b5e7982" + version = "v1.9.1" + +[[projects]] + branch = "master" + digest = "1:1ecf2a49df33be51e757d0033d5d51d5f784f35f68e5a38f797b2d3f03357d71" + name = "golang.org/x/crypto" + packages = [ + "bcrypt", + "blowfish", + ] + pruneopts = "UT" + revision = "0709b304e793a5edb4a2c0145f281ecdc20838a4" + +[[projects]] + branch = "master" + digest = "1:1c14517b2f106c61d75006199b46a46576058661d469658cb0f90739919641d2" + name = "golang.org/x/net" + packages = [ + "context", + "context/ctxhttp", + "http/httpguts", + "http2", + "http2/hpack", + "idna", + "internal/timeseries", + "trace", + ] + pruneopts = "UT" + revision = "8a410e7b638dca158bf9e766925842f6651ff828" + +[[projects]] + branch = "master" + digest = "1:363b547c971a2b07474c598b6e9ebcb238d556d8a27f37b3895ad20cd50e7281" + name = "golang.org/x/oauth2" + packages = [ + ".", + "internal", + ] + pruneopts = "UT" + revision = "d2e6202438beef2727060aa7cabdd924d92ebfd9" + +[[projects]] + branch = "master" + digest = "1:39ebcc2b11457b703ae9ee2e8cca0f68df21969c6102cb3b705f76cca0ea0239" + name = "golang.org/x/sync" + packages = ["errgroup"] + pruneopts = "UT" + revision = "1d60e4601c6fd243af51cc01ddf169918a5407ca" + +[[projects]] + branch = "master" + digest = "1:a9e9a5da9c877870b0feb5975c1e30dddb236562f912e9e9b0515ac9465f951b" + name = "golang.org/x/sys" + packages = ["unix"] + pruneopts = "UT" + revision = "ebe1bf3edb3325c393447059974de898d5133eb8" + +[[projects]] + digest = "1:a2ab62866c75542dd18d2b069fec854577a20211d7c0ea6ae746072a1dccdd18" + name = "golang.org/x/text" + packages = [ + "collate", + "collate/build", + "internal/colltab", + "internal/gen", + "internal/tag", + "internal/triegen", + "internal/ucd", + "language", + "secure/bidirule", + "transform", + "unicode/bidi", + "unicode/cldr", + "unicode/norm", + "unicode/rangetable", + ] + pruneopts = "UT" + revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0" + version = "v0.3.0" + +[[projects]] + branch = "master" + digest = "1:c9e7a4b4d47c0ed205d257648b0e5b0440880cb728506e318f8ac7cd36270bc4" + name = "golang.org/x/time" + packages = ["rate"] + pruneopts = "UT" + revision = "fbb02b2291d28baffd63558aa44b4b56f178d650" + +[[projects]] + branch = "master" + digest = "1:a05bd2d296bc727082abcb63ff52615b4dcc6219d8b61e99fd83d605dc779a18" + name = "golang.org/x/tools" + packages = [ + "go/ast/astutil", + "imports", + "internal/fastwalk", + ] + pruneopts = "UT" + revision = "0aa4b8830f481fed77b73cf7cea2bc3129e05148" + +[[projects]] + digest = "1:328b5e4f197d928c444a51a75385f4b978915c0e75521f0ad6a3db976c97a7d3" + name = "google.golang.org/appengine" + packages = [ + "internal", + "internal/base", + "internal/datastore", + "internal/log", + "internal/remote_api", + "internal/urlfetch", + "urlfetch", + ] + pruneopts = "UT" + revision = "b1f26356af11148e710935ed1ac8a7f5702c7612" + version = "v1.1.0" + +[[projects]] + branch = "master" + digest = "1:077c1c599507b3b3e9156d17d36e1e61928ee9b53a5b420f10f28ebd4a0b275c" + name = "google.golang.org/genproto" + packages = ["googleapis/rpc/status"] + pruneopts = "UT" + revision = "11092d34479b07829b72e10713b159248caf5dad" + +[[projects]] + digest = "1:3dd7996ce6bf52dec6a2f69fa43e7c4cefea1d4dfa3c8ab7a5f8a9f7434e239d" + name = "google.golang.org/grpc" + packages = [ + ".", + "balancer", + "balancer/base", + "balancer/roundrobin", + "codes", + "connectivity", + "credentials", + "encoding", + "encoding/proto", + "grpclog", + "internal", + "internal/backoff", + "internal/channelz", + "internal/envconfig", + "internal/grpcrand", + "internal/transport", + "keepalive", + "metadata", + "naming", + "peer", + "resolver", + "resolver/dns", + "resolver/passthrough", + "stats", + "status", + "tap", + ] + pruneopts = "UT" + revision = "32fb0ac620c32ba40a4626ddf94d90d12cce3455" + version = "v1.14.0" + +[[projects]] + branch = "v2" + digest = "1:342378ac4dcb378a5448dd723f0784ae519383532f5e70ade24132c4c8693202" + name = "gopkg.in/yaml.v2" + packages = ["."] + pruneopts = "UT" + revision = "5420a8b6744d3b0345ab293f6fcba19c978f1183" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + input-imports = [ + "github.com/andreyvit/diff", + "github.com/c-bata/go-prompt", + "github.com/cespare/xxhash", + "github.com/gogo/protobuf/types", + "github.com/gonum/stat/distuv", + "github.com/google/go-cmp/cmp", + "github.com/google/go-cmp/cmp/cmpopts", + "github.com/goreleaser/goreleaser", + "github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc", + "github.com/influxdata/influxdb/services/storage", + "github.com/influxdata/line-protocol", + "github.com/influxdata/platform", + "github.com/influxdata/platform/kit/errors", + "github.com/influxdata/platform/mock", + "github.com/influxdata/tdigest", + "github.com/kevinburke/go-bindata", + "github.com/mna/pigeon", + "github.com/opentracing/opentracing-go", + "github.com/pkg/errors", + "github.com/prometheus/client_golang/prometheus", + "github.com/prometheus/client_model/go", + "github.com/satori/go.uuid", + "github.com/segmentio/kafka-go", + "github.com/uber/jaeger-client-go/config", + "github.com/uber/jaeger-client-go/log", + "github.com/uber/jaeger-lib/metrics", + "go.uber.org/zap", + "go.uber.org/zap/zapcore", + "go.uber.org/zap/zaptest", + "golang.org/x/text/unicode/norm", + "google.golang.org/grpc", + ] + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml new file mode 100644 index 0000000000..83240532d9 --- /dev/null +++ b/Gopkg.toml @@ -0,0 +1,88 @@ +# Gopkg.toml example +# +# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html +# for detailed Gopkg.toml documentation. +# +# required = ["github.com/user/thing/cmd/thing"] +# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] +# +# [[constraint]] +# name = "github.com/user/project" +# version = "1.0.0" +# +# [[constraint]] +# name = "github.com/user/project2" +# branch = "dev" +# source = "github.com/myfork/project2" +# +# [[override]] +# name = "github.com/x/y" +# version = "2.4.0" +# +# [prune] +# non-go = false +# go-tests = true +# unused-packages = true + + +required = [ + # Pigeon is the command used to generate the Flux parser from the PEG description + "github.com/mna/pigeon", + # goreleaser is a utility to build and upload to S3 + "github.com/goreleaser/goreleaser", + "github.com/kevinburke/go-bindata" +] + + +[[constraint]] + name = "github.com/goreleaser/goreleaser" + version = "0.84.0" + +[[constraint]] + name = "github.com/kevinburke/go-bindata" + version = "3.11.0" + +[[constraint]] + name = "github.com/google/go-cmp" + version = "0.2.0" + +[[constraint]] + name = "github.com/influxdata/tdigest" + branch = "master" + +# Pigeon hasn't made official releases for a while, we need to use master for now. +# We plan to replace pigeon with a hand written parser, as such this dependency is short lived. +[[override]] + branch = "master" + name = "github.com/mna/pigeon" + +# Prometheus are currently pre v1.0, so the API is changing considerably. +# The latest release (0.8) predates exported API requirements. +[[constraint]] + name = "github.com/prometheus/client_golang" + revision = "661e31bf844dfca9aeba15f27ea8aa0d485ad212" + +[[constraint]] + name = "go.uber.org/zap" + version = "1.8.0" + +[prune] + go-tests = true + unused-packages = true + + [[prune.project]] + name = "github.com/kevinburke/go-bindata" + non-go = true + unused-packages = false + +[[constraint]] + branch = "master" + name = "github.com/andreyvit/diff" + +[[constraint]] + branch = "master" + name = "github.com/gonum/stat" + +[[constraint]] + name = "github.com/google/go-github" + branch = "master" diff --git a/ast/asttest/cmpgen/main.go b/ast/asttest/cmpgen/main.go index 919e742672..016bfaee90 100644 --- a/ast/asttest/cmpgen/main.go +++ b/ast/asttest/cmpgen/main.go @@ -21,7 +21,7 @@ func main() { } defer f.Close() - pkg, err := importer.For("source", nil).Import("github.com/influxdata/platform/query/ast") + pkg, err := importer.For("source", nil).Import("github.com/influxdata/flux/ast") if err != nil { log.Fatal(err) } @@ -35,7 +35,7 @@ func main() { fmt.Fprintln(f, `import (`) fmt.Fprintln(f, ` "github.com/google/go-cmp/cmp"`) fmt.Fprintln(f, ` "github.com/google/go-cmp/cmp/cmpopts"`) - fmt.Fprintln(f, ` "github.com/influxdata/platform/query/ast"`) + fmt.Fprintln(f, ` "github.com/influxdata/flux/ast"`) fmt.Fprintln(f, `)`) fmt.Fprintln(f) fmt.Fprintln(f, `var IgnoreBaseNodeOptions = []cmp.Option{`) diff --git a/ast/asttest/cmpopts.go b/ast/asttest/cmpopts.go index 40304d46cc..e6437d9ed4 100644 --- a/ast/asttest/cmpopts.go +++ b/ast/asttest/cmpopts.go @@ -5,7 +5,7 @@ package asttest import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/influxdata/platform/query/ast" + "github.com/influxdata/flux/ast" ) var IgnoreBaseNodeOptions = []cmp.Option{ diff --git a/ast/json_test.go b/ast/json_test.go index 9f92886e85..882b3f88ef 100644 --- a/ast/json_test.go +++ b/ast/json_test.go @@ -8,8 +8,8 @@ import ( "time" "github.com/google/go-cmp/cmp" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/ast/asttest" + "github.com/influxdata/flux/ast" + "github.com/influxdata/flux/ast/asttest" ) func TestJSONMarshal(t *testing.T) { diff --git a/bounds.go b/bounds.go index dabeb88243..a7a27d52fa 100644 --- a/bounds.go +++ b/bounds.go @@ -1,4 +1,4 @@ -package query +package flux import "time" diff --git a/bounds_test.go b/bounds_test.go index d5cc4e9cbb..e80e271621 100644 --- a/bounds_test.go +++ b/bounds_test.go @@ -1,54 +1,54 @@ -package query_test +package flux_test import ( "testing" "time" - "github.com/influxdata/platform/query" + "github.com/influxdata/flux" ) -var EmptyBounds = query.Bounds{ - Start: query.Now, - Stop: query.Now, +var EmptyBounds = flux.Bounds{ + Start: flux.Now, + Stop: flux.Now, } func TestBounds_HasZero(t *testing.T) { tests := []struct { name string now time.Time - bounds query.Bounds + bounds flux.Bounds want bool }{ { name: "single zero", now: time.Date(2018, time.August, 14, 11, 0, 0, 0, time.UTC), - bounds: query.Bounds{ - Start: query.Time{ + bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: -1 * time.Hour, }, - Stop: query.Time{}, + Stop: flux.Time{}, }, want: true, }, { name: "both zero", now: time.Date(2018, time.August, 14, 11, 0, 0, 0, time.UTC), - bounds: query.Bounds{ - Start: query.Time{}, - Stop: query.Time{}, + bounds: flux.Bounds{ + Start: flux.Time{}, + Stop: flux.Time{}, }, want: true, }, { name: "both non-zero", now: time.Date(2018, time.August, 14, 11, 0, 0, 0, time.UTC), - bounds: query.Bounds{ - Start: query.Time{ + bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: -1 * time.Hour, }, - Stop: query.Now, + Stop: flux.Now, }, want: false, }, @@ -68,24 +68,24 @@ func TestBounds_IsEmpty(t *testing.T) { tests := []struct { name string now time.Time - bounds query.Bounds + bounds flux.Bounds want bool }{ { name: "empty bounds / start == stop", now: time.Date(2018, time.August, 14, 11, 0, 0, 0, time.UTC), - bounds: query.Bounds{ - Start: query.Now, - Stop: query.Now, + bounds: flux.Bounds{ + Start: flux.Now, + Stop: flux.Now, }, want: true, }, { name: "empty bounds / absolute now == relative now", now: time.Date(2018, time.August, 14, 11, 0, 0, 0, time.UTC), - bounds: query.Bounds{ - Start: query.Now, - Stop: query.Time{ + bounds: flux.Bounds{ + Start: flux.Now, + Stop: flux.Time{ Absolute: time.Date(2018, time.August, 14, 11, 0, 0, 0, time.UTC), }, }, @@ -94,24 +94,24 @@ func TestBounds_IsEmpty(t *testing.T) { { name: "start > stop", now: time.Date(2018, time.August, 14, 11, 0, 0, 0, time.UTC), - bounds: query.Bounds{ - Start: query.Time{ + bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: time.Hour, }, - Stop: query.Now, + Stop: flux.Now, }, want: true, }, { name: "start < stop", now: time.Date(2018, time.August, 14, 11, 0, 0, 0, time.UTC), - bounds: query.Bounds{ - Start: query.Time{ + bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: -1 * time.Hour, }, - Stop: query.Now, + Stop: flux.Now, }, want: false, }, diff --git a/bridges.go b/bridges.go index c12370307c..6ed59c6385 100644 --- a/bridges.go +++ b/bridges.go @@ -1,4 +1,4 @@ -package query +package flux import ( "context" diff --git a/builtin/builtin.go b/builtin/builtin.go index 00aad5a7e8..6b4875d39b 100644 --- a/builtin/builtin.go +++ b/builtin/builtin.go @@ -4,11 +4,11 @@ package builtin import ( - "github.com/influxdata/platform/query" - _ "github.com/influxdata/platform/query/functions" // Import the built-in functions - _ "github.com/influxdata/platform/query/options" // Import the built-in options + "github.com/influxdata/flux" + _ "github.com/influxdata/flux/functions" // Import the built-in functions + _ "github.com/influxdata/flux/options" // Import the built-in options ) func init() { - query.FinalizeBuiltIns() + flux.FinalizeBuiltIns() } diff --git a/compile.go b/compile.go index 11009a35ba..156885ba8f 100644 --- a/compile.go +++ b/compile.go @@ -1,4 +1,4 @@ -package query +package flux import ( "context" @@ -7,10 +7,10 @@ import ( "regexp" "time" - "github.com/influxdata/platform/query/interpreter" - "github.com/influxdata/platform/query/parser" - "github.com/influxdata/platform/query/semantic" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux/interpreter" + "github.com/influxdata/flux/parser" + "github.com/influxdata/flux/semantic" + "github.com/influxdata/flux/values" opentracing "github.com/opentracing/opentracing-go" "github.com/pkg/errors" ) diff --git a/compiler.go b/compiler.go index 9b588a921b..bfb5afed19 100644 --- a/compiler.go +++ b/compiler.go @@ -1,4 +1,4 @@ -package query +package flux import ( "context" diff --git a/compiler/compiler.go b/compiler/compiler.go index d81393dd48..25af14568f 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -4,8 +4,8 @@ import ( "errors" "fmt" - "github.com/influxdata/platform/query/semantic" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux/semantic" + "github.com/influxdata/flux/values" ) func Compile(f *semantic.FunctionExpression, inTypes map[string]semantic.Type, builtinScope Scope, builtinDeclarations semantic.DeclarationScope) (Func, error) { diff --git a/compiler/compiler_test.go b/compiler/compiler_test.go index 6049209700..78225570ff 100644 --- a/compiler/compiler_test.go +++ b/compiler/compiler_test.go @@ -5,11 +5,11 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/compiler" - "github.com/influxdata/platform/query/semantic" - "github.com/influxdata/platform/query/semantic/semantictest" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux/ast" + "github.com/influxdata/flux/compiler" + "github.com/influxdata/flux/semantic" + "github.com/influxdata/flux/semantic/semantictest" + "github.com/influxdata/flux/values" ) var CmpOptions []cmp.Option diff --git a/compiler/runtime.go b/compiler/runtime.go index 42e467a4aa..7240d5c968 100644 --- a/compiler/runtime.go +++ b/compiler/runtime.go @@ -4,9 +4,9 @@ import ( "fmt" "regexp" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/semantic" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux/ast" + "github.com/influxdata/flux/semantic" + "github.com/influxdata/flux/values" ) type Evaluator interface { diff --git a/complete/complete.go b/complete/complete.go index 610a4daf91..ecf7b3c139 100644 --- a/complete/complete.go +++ b/complete/complete.go @@ -6,9 +6,9 @@ import ( "fmt" "sort" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/interpreter" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux" + "github.com/influxdata/flux/interpreter" + "github.com/influxdata/flux/semantic" ) type functionType interface { @@ -98,7 +98,7 @@ func (c Completer) FunctionSuggestion(name string) (FunctionSuggestion, error) { // DefaultCompleter creates a completer with builtin scope and declarations. func DefaultCompleter() Completer { - scope, declarations := query.BuiltIns() + scope, declarations := flux.BuiltIns() interpScope := interpreter.NewScopeWithValues(scope) return NewCompleter(interpScope, declarations) } diff --git a/complete/complete_test.go b/complete/complete_test.go index 02e1f3c44e..46f053369d 100644 --- a/complete/complete_test.go +++ b/complete/complete_test.go @@ -4,10 +4,10 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/influxdata/platform/query/complete" - "github.com/influxdata/platform/query/interpreter" - "github.com/influxdata/platform/query/semantic" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux/complete" + "github.com/influxdata/flux/interpreter" + "github.com/influxdata/flux/semantic" + "github.com/influxdata/flux/values" ) func TestNames(t *testing.T) { diff --git a/control/controller.go b/control/controller.go index d24d07709a..c16a9b26e4 100644 --- a/control/controller.go +++ b/control/controller.go @@ -28,10 +28,10 @@ import ( "sync" "time" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/plan" "github.com/influxdata/platform" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/plan" opentracing "github.com/opentracing/opentracing-go" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" @@ -99,7 +99,7 @@ func New(c Config) *Controller { // Query submits a query for execution returning immediately. // Done must be called on any returned Query objects. -func (c *Controller) Query(ctx context.Context, req *query.Request) (query.Query, error) { +func (c *Controller) Query(ctx context.Context, req *flux.Request) (flux.Query, error) { q := c.createQuery(ctx, req.OrganizationID) if err := c.compileQuery(q, req.Compiler); err != nil { q.parentSpan.Finish() @@ -124,7 +124,7 @@ func (c *Controller) createQuery(ctx context.Context, orgID platform.ID) *Query c.metrics.allDur.WithLabelValues(labelValues...), c.metrics.all.WithLabelValues(labelValues...), ) - ready := make(chan map[string]query.Result, 1) + ready := make(chan map[string]flux.Result, 1) return &Query{ id: id, orgID: orgID, @@ -139,7 +139,7 @@ func (c *Controller) createQuery(ctx context.Context, orgID platform.ID) *Query } } -func (c *Controller) compileQuery(q *Query, compiler query.Compiler) error { +func (c *Controller) compileQuery(q *Query, compiler flux.Compiler) error { if !q.tryCompile() { return errors.New("failed to transition query to compiling state") } @@ -160,7 +160,7 @@ func (c *Controller) compileQuery(q *Query, compiler query.Compiler) error { func (c *Controller) enqueueQuery(q *Query) error { if c.verbose { - log.Println("query", query.Formatted(&q.spec, query.FmtJSON)) + log.Println("query", flux.Formatted(&q.spec, flux.FmtJSON)) } if !q.tryQueue() { return errors.New("failed to transition query to queueing state") @@ -344,12 +344,12 @@ type Query struct { c *Controller - spec query.Spec + spec flux.Spec now time.Time err error - ready chan map[string]query.Result + ready chan map[string]flux.Result mu sync.Mutex state State @@ -387,7 +387,7 @@ func (q *Query) OrganizationID() platform.ID { return q.orgID } -func (q *Query) Spec() *query.Spec { +func (q *Query) Spec() *flux.Spec { return &q.spec } @@ -422,7 +422,7 @@ func (q *Query) Cancel() { // Ready returns a channel that will deliver the query results. // Its possible that the channel is closed before any results arrive, in which case the query should be // inspected for an error using Err(). -func (q *Query) Ready() <-chan map[string]query.Result { +func (q *Query) Ready() <-chan map[string]flux.Result { return q.ready } @@ -469,11 +469,11 @@ func (q *Query) Done() { // Statistics reports the statisitcs for the query. // The statisitcs are not complete until the query is finished. -func (q *Query) Statistics() query.Statistics { +func (q *Query) Statistics() flux.Statistics { q.mu.Lock() defer q.mu.Unlock() - stats := query.Statistics{} + stats := flux.Statistics{} stats.TotalDuration = q.parentSpan.Duration if q.compileSpan != nil { stats.CompileDuration = q.compileSpan.Duration @@ -532,7 +532,7 @@ func (q *Query) setErr(err error) { q.state = Errored } -func (q *Query) setResults(r map[string]query.Result) { +func (q *Query) setResults(r map[string]flux.Result) { q.mu.Lock() if q.state == Executing { q.ready <- r diff --git a/control/controller_test.go b/control/controller_test.go index 82c3fc438c..4dcbfa7481 100644 --- a/control/controller_test.go +++ b/control/controller_test.go @@ -5,12 +5,12 @@ import ( "testing" "time" + "github.com/influxdata/flux" + _ "github.com/influxdata/flux/builtin" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/mock" + "github.com/influxdata/flux/plan" "github.com/influxdata/platform" - "github.com/influxdata/platform/query" - _ "github.com/influxdata/platform/query/builtin" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/mock" - "github.com/influxdata/platform/query/plan" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" dto "github.com/prometheus/client_model/go" @@ -20,20 +20,20 @@ var mockCompiler *mock.Compiler func init() { mockCompiler = new(mock.Compiler) - mockCompiler.CompileFn = func(ctx context.Context) (*query.Spec, error) { - return query.Compile(ctx, `from(bucket: "telegraf") |> range(start: -5m) |> mean()`, time.Now()) + mockCompiler.CompileFn = func(ctx context.Context) (*flux.Spec, error) { + return flux.Compile(ctx, `from(bucket: "telegraf") |> range(start: -5m) |> mean()`, time.Now()) } } func TestController_CompileQuery_Failure(t *testing.T) { compiler := &mock.Compiler{ - CompileFn: func(ctx context.Context) (*query.Spec, error) { + CompileFn: func(ctx context.Context) (*flux.Spec, error) { return nil, errors.New("expected") }, } ctrl := New(Config{}) - req := &query.Request{ + req := &flux.Request{ OrganizationID: platform.ID("a"), Compiler: compiler, } @@ -61,17 +61,17 @@ func TestController_CompileQuery_Failure(t *testing.T) { func TestController_EnqueueQuery_Failure(t *testing.T) { compiler := &mock.Compiler{ - CompileFn: func(ctx context.Context) (*query.Spec, error) { + CompileFn: func(ctx context.Context) (*flux.Spec, error) { // This returns an invalid spec so that enqueueing the query fails. // TODO(jsternberg): We should probably move the validation step to compilation // instead as it makes more sense. In that case, we would still need to verify // that enqueueing the query was successful in some way. - return &query.Spec{}, nil + return &flux.Spec{}, nil }, } ctrl := New(Config{}) - req := &query.Request{ + req := &flux.Request{ OrganizationID: platform.ID("a"), Compiler: compiler, } @@ -104,13 +104,13 @@ func TestController_EnqueueQuery_Failure(t *testing.T) { func TestController_ExecuteQuery_Failure(t *testing.T) { executor := mock.NewExecutor() - executor.ExecuteFn = func(context.Context, platform.ID, *plan.PlanSpec, *execute.Allocator) (map[string]query.Result, error) { + executor.ExecuteFn = func(context.Context, platform.ID, *plan.PlanSpec, *execute.Allocator) (map[string]flux.Result, error) { return nil, errors.New("expected") } ctrl := New(Config{}) ctrl.executor = executor - req := &query.Request{ + req := &flux.Request{ OrganizationID: platform.ID("a"), Compiler: mockCompiler, } @@ -151,14 +151,14 @@ func TestController_ExecuteQuery_Failure(t *testing.T) { func TestController_CancelQuery(t *testing.T) { executor := mock.NewExecutor() - executor.ExecuteFn = func(context.Context, platform.ID, *plan.PlanSpec, *execute.Allocator) (map[string]query.Result, error) { + executor.ExecuteFn = func(context.Context, platform.ID, *plan.PlanSpec, *execute.Allocator) (map[string]flux.Result, error) { // Return an empty result. - return map[string]query.Result{}, nil + return map[string]flux.Result{}, nil } ctrl := New(Config{}) ctrl.executor = executor - req := &query.Request{ + req := &flux.Request{ OrganizationID: platform.ID("a"), Compiler: mockCompiler, } @@ -198,14 +198,14 @@ func TestController_BlockedExecutor(t *testing.T) { done := make(chan struct{}) executor := mock.NewExecutor() - executor.ExecuteFn = func(context.Context, platform.ID, *plan.PlanSpec, *execute.Allocator) (map[string]query.Result, error) { + executor.ExecuteFn = func(context.Context, platform.ID, *plan.PlanSpec, *execute.Allocator) (map[string]flux.Result, error) { <-done return nil, nil } ctrl := New(Config{}) ctrl.executor = executor - req := &query.Request{ + req := &flux.Request{ OrganizationID: platform.ID("a"), Compiler: mockCompiler, } diff --git a/csv/dialect.go b/csv/dialect.go index 7670f7c6d4..97c04aa024 100644 --- a/csv/dialect.go +++ b/csv/dialect.go @@ -3,14 +3,14 @@ package csv import ( "net/http" - "github.com/influxdata/platform/query" + "github.com/influxdata/flux" ) const DialectType = "csv" // AddDialectMappings adds the influxql specific dialect mappings. -func AddDialectMappings(mappings query.DialectMappings) error { - return mappings.Add(DialectType, func() query.Dialect { +func AddDialectMappings(mappings flux.DialectMappings) error { + return mappings.Add(DialectType, func() flux.Dialect { return &Dialect{ ResultEncoderConfig: DefaultEncoderConfig(), } @@ -27,10 +27,10 @@ func (d Dialect) SetHeaders(w http.ResponseWriter) { w.Header().Set("Transfer-Encoding", "chunked") } -func (d Dialect) Encoder() query.MultiResultEncoder { +func (d Dialect) Encoder() flux.MultiResultEncoder { return NewMultiResultEncoder(d.ResultEncoderConfig) } -func (d Dialect) DialectType() query.DialectType { +func (d Dialect) DialectType() flux.DialectType { return DialectType } diff --git a/csv/result.go b/csv/result.go index ebd063a66f..cd61f1cdda 100644 --- a/csv/result.go +++ b/csv/result.go @@ -12,10 +12,10 @@ import ( "time" "unicode/utf8" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/iocounter" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/iocounter" + "github.com/influxdata/flux/values" "github.com/pkg/errors" ) @@ -71,7 +71,7 @@ type ResultDecoderConfig struct { MaxBufferCount int } -func (d *ResultDecoder) Decode(r io.Reader) (query.Result, error) { +func (d *ResultDecoder) Decode(r io.Reader) (flux.Result, error) { return newResultDecoder(r, d.c, nil) } @@ -92,7 +92,7 @@ func NewMultiResultDecoder(c ResultDecoderConfig) *MultiResultDecoder { } } -func (d *MultiResultDecoder) Decode(r io.ReadCloser) (query.ResultIterator, error) { +func (d *MultiResultDecoder) Decode(r io.ReadCloser) (flux.ResultIterator, error) { return &resultIterator{ c: d.c, r: r, @@ -130,7 +130,7 @@ func (r *resultIterator) More() bool { return false } -func (r *resultIterator) Next() query.Result { +func (r *resultIterator) Next() flux.Result { return r.next } @@ -195,7 +195,7 @@ func (r *resultDecoder) Name() string { return r.id } -func (r *resultDecoder) Tables() query.TableIterator { +func (r *resultDecoder) Tables() flux.TableIterator { return r } @@ -203,7 +203,7 @@ func (r *resultDecoder) Abort(error) { panic("not implemented") } -func (r *resultDecoder) Do(f func(query.Table) error) error { +func (r *resultDecoder) Do(f func(flux.Table) error) error { var extraLine []string var meta tableMetadata newMeta := true @@ -353,7 +353,7 @@ func readMetadata(r *csv.Reader, c ResultDecoderConfig, extraLine []string) (tab } cols[j].ColMeta.Label = label cols[j].ColMeta.Type = t - if t == query.TTime { + if t == flux.TTime { switch desc { case "RFC3339": cols[j].fmt = time.RFC3339 @@ -393,7 +393,7 @@ type tableDecoder struct { initialized bool id string - key query.GroupKey + key flux.GroupKey cols []colMeta builder *execute.ColListTableBuilder @@ -430,7 +430,7 @@ func newTable( return b, nil } -func (d *tableDecoder) Do(f func(query.ColReader) error) (err error) { +func (d *tableDecoder) Do(f func(flux.ColReader) error) (err error) { // Send off first batch from first advance call. err = f(d.builder.RawTable()) if err != nil { @@ -525,7 +525,7 @@ func (d *tableDecoder) init(line []string) error { if len(line) != 0 { record = line[recordStartIdx:] } - keyCols := make([]query.ColMeta, 0, len(d.meta.Cols)) + keyCols := make([]flux.ColMeta, 0, len(d.meta.Cols)) keyValues := make([]values.Value, 0, len(d.meta.Cols)) for j, c := range d.meta.Cols { if d.meta.Groups[j] { @@ -560,22 +560,22 @@ func (d *tableDecoder) appendRecord(record []string) error { for j, c := range d.meta.Cols { if record[j] == "" && d.meta.Defaults[j] != nil { switch c.Type { - case query.TBool: + case flux.TBool: v := d.meta.Defaults[j].Bool() d.builder.AppendBool(j, v) - case query.TInt: + case flux.TInt: v := d.meta.Defaults[j].Int() d.builder.AppendInt(j, v) - case query.TUInt: + case flux.TUInt: v := d.meta.Defaults[j].UInt() d.builder.AppendUInt(j, v) - case query.TFloat: + case flux.TFloat: v := d.meta.Defaults[j].Float() d.builder.AppendFloat(j, v) - case query.TString: + case flux.TString: v := d.meta.Defaults[j].Str() d.builder.AppendString(j, v) - case query.TTime: + case flux.TTime: v := d.meta.Defaults[j].Time() d.builder.AppendTime(j, v) default: @@ -596,16 +596,16 @@ func (d *tableDecoder) Empty() bool { func (d *tableDecoder) RefCount(n int) {} -func (d *tableDecoder) Key() query.GroupKey { +func (d *tableDecoder) Key() flux.GroupKey { return d.builder.Key() } -func (d *tableDecoder) Cols() []query.ColMeta { +func (d *tableDecoder) Cols() []flux.ColMeta { return d.builder.Cols() } type colMeta struct { - query.ColMeta + flux.ColMeta fmt string } @@ -715,13 +715,13 @@ func wrapEncodingError(err error) error { return errors.Wrap(newCSVEncoderError(err.Error()), "csv encoder error") } -func (e *ResultEncoder) Encode(w io.Writer, result query.Result) (int64, error) { +func (e *ResultEncoder) Encode(w io.Writer, result flux.Result) (int64, error) { tableID := 0 tableIDStr := "0" metaCols := []colMeta{ - {ColMeta: query.ColMeta{Label: "", Type: query.TInvalid}}, - {ColMeta: query.ColMeta{Label: resultLabel, Type: query.TString}}, - {ColMeta: query.ColMeta{Label: tableLabel, Type: query.TInt}}, + {ColMeta: flux.ColMeta{Label: "", Type: flux.TInvalid}}, + {ColMeta: flux.ColMeta{Label: resultLabel, Type: flux.TString}}, + {ColMeta: flux.ColMeta{Label: tableLabel, Type: flux.TInt}}, } writeCounter := &iocounter.Writer{Writer: w} writer := e.csvWriter(writeCounter) @@ -729,13 +729,13 @@ func (e *ResultEncoder) Encode(w io.Writer, result query.Result) (int64, error) var lastCols []colMeta var lastEmpty bool - err := result.Tables().Do(func(tbl query.Table) error { + err := result.Tables().Do(func(tbl flux.Table) error { e.written = true // Update cols with table cols cols := metaCols for _, c := range tbl.Cols() { cm := colMeta{ColMeta: c} - if c.Type == query.TTime { + if c.Type == flux.TTime { cm.fmt = time.RFC3339Nano } cols = append(cols, cm) @@ -771,7 +771,7 @@ func (e *ResultEncoder) Encode(w io.Writer, result query.Result) (int64, error) } } - err := tbl.Do(func(cr query.ColReader) error { + err := tbl.Do(func(cr flux.ColReader) error { record := row[recordStartIdx:] l := cr.Len() for i := 0; i < l; i++ { @@ -819,7 +819,7 @@ func (e *ResultEncoder) EncodeError(w io.Writer, err error) error { return writer.Error() } -func writeSchema(writer *csv.Writer, c *ResultEncoderConfig, row []string, cols []colMeta, useKeyDefaults bool, key query.GroupKey, resultName, tableID string) error { +func writeSchema(writer *csv.Writer, c *ResultEncoderConfig, row []string, cols []colMeta, useKeyDefaults bool, key flux.GroupKey, resultName, tableID string) error { defaults := make([]string, len(row)) for j, c := range cols { switch j { @@ -864,7 +864,7 @@ func writeSchema(writer *csv.Writer, c *ResultEncoderConfig, row []string, cols return writer.Error() } -func writeAnnotations(writer *csv.Writer, annotations []string, row, defaults []string, cols []colMeta, key query.GroupKey) error { +func writeAnnotations(writer *csv.Writer, annotations []string, row, defaults []string, cols []colMeta, key flux.GroupKey) error { for _, annotation := range annotations { switch annotation { case datatypeAnnotation: @@ -893,17 +893,17 @@ func writeDatatypes(writer *csv.Writer, row []string, cols []colMeta) error { continue } switch c.Type { - case query.TBool: + case flux.TBool: row[j] = boolDatatype - case query.TInt: + case flux.TInt: row[j] = intDatatype - case query.TUInt: + case flux.TUInt: row[j] = uintDatatype - case query.TFloat: + case flux.TFloat: row[j] = floatDatatype - case query.TString: + case flux.TString: row[j] = stringDatatype - case query.TTime: + case flux.TTime: row[j] = timeDataTypeWithFmt default: return fmt.Errorf("unknown column type %v", c.Type) @@ -912,7 +912,7 @@ func writeDatatypes(writer *csv.Writer, row []string, cols []colMeta) error { return writer.Write(row) } -func writeGroups(writer *csv.Writer, row []string, cols []colMeta, key query.GroupKey) error { +func writeGroups(writer *csv.Writer, row []string, cols []colMeta, key flux.GroupKey) error { for j, c := range cols { if j == annotationIdx { row[j] = commentPrefix + groupAnnotation @@ -938,33 +938,33 @@ func writeDefaults(writer *csv.Writer, row, defaults []string) error { func decodeValue(value string, c colMeta) (values.Value, error) { var val values.Value switch c.Type { - case query.TBool: + case flux.TBool: v, err := strconv.ParseBool(value) if err != nil { return nil, err } val = values.NewBoolValue(v) - case query.TInt: + case flux.TInt: v, err := strconv.ParseInt(value, 10, 64) if err != nil { return nil, err } val = values.NewIntValue(v) - case query.TUInt: + case flux.TUInt: v, err := strconv.ParseUint(value, 10, 64) if err != nil { return nil, err } val = values.NewUIntValue(v) - case query.TFloat: + case flux.TFloat: v, err := strconv.ParseFloat(value, 64) if err != nil { return nil, err } val = values.NewFloatValue(v) - case query.TString: + case flux.TString: val = values.NewStringValue(value) - case query.TTime: + case flux.TTime: v, err := decodeTime(value, c.fmt) if err != nil { return nil, err @@ -978,33 +978,33 @@ func decodeValue(value string, c colMeta) (values.Value, error) { func decodeValueInto(j int, c colMeta, value string, builder execute.TableBuilder) error { switch c.Type { - case query.TBool: + case flux.TBool: v, err := strconv.ParseBool(value) if err != nil { return err } builder.AppendBool(j, v) - case query.TInt: + case flux.TInt: v, err := strconv.ParseInt(value, 10, 64) if err != nil { return err } builder.AppendInt(j, v) - case query.TUInt: + case flux.TUInt: v, err := strconv.ParseUint(value, 10, 64) if err != nil { return err } builder.AppendUInt(j, v) - case query.TFloat: + case flux.TFloat: v, err := strconv.ParseFloat(value, 64) if err != nil { return err } builder.AppendFloat(j, v) - case query.TString: + case flux.TString: builder.AppendString(j, value) - case query.TTime: + case flux.TTime: t, err := decodeTime(value, c.fmt) if err != nil { return err @@ -1018,36 +1018,36 @@ func decodeValueInto(j int, c colMeta, value string, builder execute.TableBuilde func encodeValue(value values.Value, c colMeta) (string, error) { switch c.Type { - case query.TBool: + case flux.TBool: return strconv.FormatBool(value.Bool()), nil - case query.TInt: + case flux.TInt: return strconv.FormatInt(value.Int(), 10), nil - case query.TUInt: + case flux.TUInt: return strconv.FormatUint(value.UInt(), 10), nil - case query.TFloat: + case flux.TFloat: return strconv.FormatFloat(value.Float(), 'f', -1, 64), nil - case query.TString: + case flux.TString: return value.Str(), nil - case query.TTime: + case flux.TTime: return encodeTime(value.Time(), c.fmt), nil default: return "", fmt.Errorf("unknown type %v", c.Type) } } -func encodeValueFrom(i, j int, c colMeta, cr query.ColReader) (string, error) { +func encodeValueFrom(i, j int, c colMeta, cr flux.ColReader) (string, error) { switch c.Type { - case query.TBool: + case flux.TBool: return strconv.FormatBool(cr.Bools(j)[i]), nil - case query.TInt: + case flux.TInt: return strconv.FormatInt(cr.Ints(j)[i], 10), nil - case query.TUInt: + case flux.TUInt: return strconv.FormatUint(cr.UInts(j)[i], 10), nil - case query.TFloat: + case flux.TFloat: return strconv.FormatFloat(cr.Floats(j)[i], 'f', -1, 64), nil - case query.TString: + case flux.TString: return cr.Strings(j)[i], nil - case query.TTime: + case flux.TTime: return encodeTime(cr.Times(j)[i], c.fmt), nil default: return "", fmt.Errorf("unknown type %v", c.Type) @@ -1073,7 +1073,7 @@ func copyLine(line []string) []string { } // decodeType returns the execute.DataType and any additional format description. -func decodeType(datatype string) (t query.DataType, desc string, err error) { +func decodeType(datatype string) (t flux.DataType, desc string, err error) { split := strings.SplitN(datatype, ":", 2) if len(split) > 1 { desc = split[1] @@ -1081,17 +1081,17 @@ func decodeType(datatype string) (t query.DataType, desc string, err error) { typ := split[0] switch typ { case boolDatatype: - t = query.TBool + t = flux.TBool case intDatatype: - t = query.TInt + t = flux.TInt case uintDatatype: - t = query.TUInt + t = flux.TUInt case floatDatatype: - t = query.TFloat + t = flux.TFloat case stringDatatype: - t = query.TString + t = flux.TString case timeDatatype: - t = query.TTime + t = flux.TTime default: err = fmt.Errorf("unsupported data type %q", typ) } @@ -1110,8 +1110,8 @@ func equalCols(a, b []colMeta) bool { return true } -func NewMultiResultEncoder(c ResultEncoderConfig) query.MultiResultEncoder { - return &query.DelimitedMultiResultEncoder{ +func NewMultiResultEncoder(c ResultEncoderConfig) flux.MultiResultEncoder { + return &flux.DelimitedMultiResultEncoder{ Delimiter: []byte("\r\n"), Encoder: NewResultEncoder(c), } diff --git a/csv/result_test.go b/csv/result_test.go index cbaa69d308..e38d60ca8f 100644 --- a/csv/result_test.go +++ b/csv/result_test.go @@ -8,10 +8,10 @@ import ( "github.com/andreyvit/diff" "github.com/google/go-cmp/cmp" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/csv" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux" + "github.com/influxdata/flux/csv" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/values" "github.com/pkg/errors" ) @@ -39,13 +39,13 @@ var symetricalTestCases = []TestCase{ Nm: "_result", Tbls: []*executetest.Table{{ KeyCols: []string{"_start", "_stop", "_measurement", "host"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_measurement", Type: query.TString}, - {Label: "host", Type: query.TString}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_measurement", Type: flux.TString}, + {Label: "host", Type: flux.TString}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ { @@ -86,13 +86,13 @@ var symetricalTestCases = []TestCase{ "cpu", "A", }, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_measurement", Type: query.TString}, - {Label: "host", Type: query.TString}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_measurement", Type: flux.TString}, + {Label: "host", Type: flux.TString}, + {Label: "_value", Type: flux.TFloat}, }, }}, }, @@ -114,13 +114,13 @@ var symetricalTestCases = []TestCase{ Tbls: []*executetest.Table{ { KeyCols: []string{"_start", "_stop", "_measurement", "host"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_measurement", Type: query.TString}, - {Label: "host", Type: query.TString}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_measurement", Type: flux.TString}, + {Label: "host", Type: flux.TString}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ { @@ -143,13 +143,13 @@ var symetricalTestCases = []TestCase{ }, { KeyCols: []string{"_start", "_stop", "_measurement", "host"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_measurement", Type: query.TString}, - {Label: "host", Type: query.TString}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_measurement", Type: flux.TString}, + {Label: "host", Type: flux.TString}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ { @@ -199,13 +199,13 @@ var symetricalTestCases = []TestCase{ Tbls: []*executetest.Table{ { KeyCols: []string{"_start", "_stop", "_measurement", "host"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_measurement", Type: query.TString}, - {Label: "host", Type: query.TString}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_measurement", Type: flux.TString}, + {Label: "host", Type: flux.TString}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ { @@ -228,13 +228,13 @@ var symetricalTestCases = []TestCase{ }, { KeyCols: []string{"_start", "_stop", "_measurement", "host"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_measurement", Type: query.TString}, - {Label: "host", Type: query.TString}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_measurement", Type: flux.TString}, + {Label: "host", Type: flux.TString}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ { @@ -257,14 +257,14 @@ var symetricalTestCases = []TestCase{ }, { KeyCols: []string{"_start", "_stop", "location"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "location", Type: query.TString}, - {Label: "device", Type: query.TString}, - {Label: "min", Type: query.TFloat}, - {Label: "max", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "location", Type: flux.TString}, + {Label: "device", Type: flux.TString}, + {Label: "min", Type: flux.TFloat}, + {Label: "max", Type: flux.TFloat}, }, Data: [][]interface{}{ { @@ -289,14 +289,14 @@ var symetricalTestCases = []TestCase{ }, { KeyCols: []string{"_start", "_stop", "location"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "location", Type: query.TString}, - {Label: "device", Type: query.TString}, - {Label: "min", Type: query.TFloat}, - {Label: "max", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "location", Type: flux.TString}, + {Label: "device", Type: flux.TString}, + {Label: "min", Type: flux.TFloat}, + {Label: "max", Type: flux.TFloat}, }, Data: [][]interface{}{ { @@ -344,13 +344,13 @@ var symetricalTestCases = []TestCase{ Tbls: []*executetest.Table{ { KeyCols: []string{"_start", "_stop", "_measurement", "host"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_measurement", Type: query.TString}, - {Label: "host", Type: query.TString}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_measurement", Type: flux.TString}, + {Label: "host", Type: flux.TString}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ { @@ -373,13 +373,13 @@ var symetricalTestCases = []TestCase{ }, { KeyCols: []string{"_start", "_stop", "_measurement", "host"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_measurement", Type: query.TString}, - {Label: "host", Type: query.TString}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_measurement", Type: flux.TString}, + {Label: "host", Type: flux.TString}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ { @@ -408,13 +408,13 @@ var symetricalTestCases = []TestCase{ "cpu", "A", }, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_measurement", Type: query.TString}, - {Label: "host", Type: query.TString}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_measurement", Type: flux.TString}, + {Label: "host", Type: flux.TString}, + {Label: "_value", Type: flux.TFloat}, }, }, }, @@ -438,13 +438,13 @@ func TestResultDecoder(t *testing.T) { Nm: "_result", Tbls: []*executetest.Table{{ KeyCols: []string{"_start", "_stop", "_measurement", "host"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_measurement", Type: query.TString}, - {Label: "host", Type: query.TString}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_measurement", Type: flux.TString}, + {Label: "host", Type: flux.TString}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ { @@ -483,7 +483,7 @@ func TestResultDecoder(t *testing.T) { got := &executetest.Result{ Nm: result.Name(), } - if err := result.Tables().Do(func(tbl query.Table) error { + if err := result.Tables().Do(func(tbl flux.Table) error { cb, err := executetest.ConvertTable(tbl) if err != nil { return err @@ -534,7 +534,7 @@ func TestResultEncoder(t *testing.T) { func TestMultiResultEncoder(t *testing.T) { testCases := []struct { name string - results query.ResultIterator + results flux.ResultIterator encoded []byte err error config csv.ResultEncoderConfig @@ -542,17 +542,17 @@ func TestMultiResultEncoder(t *testing.T) { { name: "single result", config: csv.DefaultEncoderConfig(), - results: query.NewSliceResultIterator([]query.Result{&executetest.Result{ + results: flux.NewSliceResultIterator([]flux.Result{&executetest.Result{ Nm: "_result", Tbls: []*executetest.Table{{ KeyCols: []string{"_start", "_stop", "_measurement", "host"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_measurement", Type: query.TString}, - {Label: "host", Type: query.TString}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_measurement", Type: flux.TString}, + {Label: "host", Type: flux.TString}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ { @@ -586,18 +586,18 @@ func TestMultiResultEncoder(t *testing.T) { { name: "two results", config: csv.DefaultEncoderConfig(), - results: query.NewSliceResultIterator([]query.Result{ + results: flux.NewSliceResultIterator([]flux.Result{ &executetest.Result{ Nm: "_result", Tbls: []*executetest.Table{{ KeyCols: []string{"_start", "_stop", "_measurement", "host"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_measurement", Type: query.TString}, - {Label: "host", Type: query.TString}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_measurement", Type: flux.TString}, + {Label: "host", Type: flux.TString}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ { @@ -623,13 +623,13 @@ func TestMultiResultEncoder(t *testing.T) { Nm: "mean", Tbls: []*executetest.Table{{ KeyCols: []string{"_start", "_stop", "_measurement", "host"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_measurement", Type: query.TString}, - {Label: "host", Type: query.TString}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_measurement", Type: flux.TString}, + {Label: "host", Type: flux.TString}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ { @@ -681,7 +681,7 @@ test error, { name: "returns query errors", config: csv.DefaultEncoderConfig(), - results: query.NewSliceResultIterator([]query.Result{ + results: flux.NewSliceResultIterator([]flux.Result{ &executetest.Result{ Err: errors.New("execution error"), }, @@ -693,18 +693,18 @@ execution error, { name: "returns encoding errors", config: csv.DefaultEncoderConfig(), - results: query.NewSliceResultIterator([]query.Result{&executetest.Result{ + results: flux.NewSliceResultIterator([]flux.Result{&executetest.Result{ Nm: "mean", Tbls: []*executetest.Table{{ KeyCols: []string{"_start", "_stop", "_measurement", "host"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_measurement", Type: query.TString}, - {Label: "host", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_measurement", Type: flux.TString}, + {Label: "host", Type: flux.TString}, // Deliberately use invalid column type - {Label: "_value", Type: query.TInvalid}, + {Label: "_value", Type: flux.TInvalid}, }, Data: [][]interface{}{ { @@ -762,7 +762,7 @@ func (r errorResultIterator) More() bool { return false } -func (r errorResultIterator) Next() query.Result { +func (r errorResultIterator) Next() flux.Result { panic("no results") } diff --git a/dependency.go b/dependency.go index a6fdc54e75..77773a5b76 100644 --- a/dependency.go +++ b/dependency.go @@ -1,4 +1,4 @@ -package query +package flux import ( "context" diff --git a/execute/aggregate.go b/execute/aggregate.go index 5ec5ccce57..a05a84dd35 100644 --- a/execute/aggregate.go +++ b/execute/aggregate.go @@ -3,9 +3,9 @@ package execute import ( "fmt" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/interpreter" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux" + "github.com/influxdata/flux/interpreter" + "github.com/influxdata/flux/semantic" "github.com/pkg/errors" ) @@ -32,13 +32,13 @@ var DefaultAggregateConfig = AggregateConfig{ func DefaultAggregateSignature() semantic.FunctionSignature { return semantic.FunctionSignature{ Params: map[string]semantic.Type{ - query.TableParameter: query.TableObjectType, - "columns": semantic.NewArrayType(semantic.String), - "timeSrc": semantic.String, - "timeDst": semantic.String, + flux.TableParameter: flux.TableObjectType, + "columns": semantic.NewArrayType(semantic.String), + "timeSrc": semantic.String, + "timeDst": semantic.String, }, - ReturnType: query.TableObjectType, - PipeArgument: query.TableParameter, + ReturnType: flux.TableObjectType, + PipeArgument: flux.TableParameter, } } @@ -51,7 +51,7 @@ func (c AggregateConfig) Copy() AggregateConfig { return nc } -func (c *AggregateConfig) ReadArgs(args query.Arguments) error { +func (c *AggregateConfig) ReadArgs(args flux.Arguments) error { if label, ok, err := args.GetString("timeDst"); err != nil { return err } else if ok { @@ -97,21 +97,21 @@ func NewAggregateTransformationAndDataset(id DatasetID, mode AccumulationMode, a return NewAggregateTransformation(d, cache, agg, config), d } -func (t *aggregateTransformation) RetractTable(id DatasetID, key query.GroupKey) error { +func (t *aggregateTransformation) RetractTable(id DatasetID, key flux.GroupKey) error { //TODO(nathanielc): Store intermediate state for retractions return t.d.RetractTable(key) } -func (t *aggregateTransformation) Process(id DatasetID, tbl query.Table) error { +func (t *aggregateTransformation) Process(id DatasetID, tbl flux.Table) error { builder, new := t.cache.TableBuilder(tbl.Key()) if !new { return fmt.Errorf("aggregate found duplicate table with key: %v", tbl.Key()) } AddTableKeyCols(tbl.Key(), builder) - builder.AddCol(query.ColMeta{ + builder.AddCol(flux.ColMeta{ Label: t.config.TimeDst, - Type: query.TTime, + Type: flux.TTime, }) builderColMap := make([]int, len(t.config.Columns)) @@ -136,22 +136,22 @@ func (t *aggregateTransformation) Process(id DatasetID, tbl query.Table) error { } var vf ValueFunc switch c.Type { - case query.TBool: + case flux.TBool: vf = t.agg.NewBoolAgg() - case query.TInt: + case flux.TInt: vf = t.agg.NewIntAgg() - case query.TUInt: + case flux.TUInt: vf = t.agg.NewUIntAgg() - case query.TFloat: + case flux.TFloat: vf = t.agg.NewFloatAgg() - case query.TString: + case flux.TString: vf = t.agg.NewStringAgg() } if vf == nil { return fmt.Errorf("unsupported aggregate column type %v", c.Type) } aggregates[j] = vf - builderColMap[j] = builder.AddCol(query.ColMeta{ + builderColMap[j] = builder.AddCol(flux.ColMeta{ Label: c.Label, Type: vf.Type(), }) @@ -161,7 +161,7 @@ func (t *aggregateTransformation) Process(id DatasetID, tbl query.Table) error { return err } - tbl.Do(func(cr query.ColReader) error { + tbl.Do(func(cr flux.ColReader) error { for j := range t.config.Columns { vf := aggregates[j] @@ -169,15 +169,15 @@ func (t *aggregateTransformation) Process(id DatasetID, tbl query.Table) error { c := tbl.Cols()[tj] switch c.Type { - case query.TBool: + case flux.TBool: vf.(DoBoolAgg).DoBool(cr.Bools(tj)) - case query.TInt: + case flux.TInt: vf.(DoIntAgg).DoInt(cr.Ints(tj)) - case query.TUInt: + case flux.TUInt: vf.(DoUIntAgg).DoUInt(cr.UInts(tj)) - case query.TFloat: + case flux.TFloat: vf.(DoFloatAgg).DoFloat(cr.Floats(tj)) - case query.TString: + case flux.TString: vf.(DoStringAgg).DoString(cr.Strings(tj)) default: return fmt.Errorf("unsupport aggregate type %v", c.Type) @@ -189,15 +189,15 @@ func (t *aggregateTransformation) Process(id DatasetID, tbl query.Table) error { bj := builderColMap[j] // Append aggregated value switch vf.Type() { - case query.TBool: + case flux.TBool: builder.AppendBool(bj, vf.(BoolValueFunc).ValueBool()) - case query.TInt: + case flux.TInt: builder.AppendInt(bj, vf.(IntValueFunc).ValueInt()) - case query.TUInt: + case flux.TUInt: builder.AppendUInt(bj, vf.(UIntValueFunc).ValueUInt()) - case query.TFloat: + case flux.TFloat: builder.AppendFloat(bj, vf.(FloatValueFunc).ValueFloat()) - case query.TString: + case flux.TString: builder.AppendString(bj, vf.(StringValueFunc).ValueString()) } } @@ -217,13 +217,13 @@ func (t *aggregateTransformation) Finish(id DatasetID, err error) { t.d.Finish(err) } -func AppendAggregateTime(srcTime, dstTime string, key query.GroupKey, builder TableBuilder) error { +func AppendAggregateTime(srcTime, dstTime string, key flux.GroupKey, builder TableBuilder) error { srcTimeIdx := ColIdx(srcTime, key.Cols()) if srcTimeIdx < 0 { return fmt.Errorf("timeSrc column %q does not exist", srcTime) } srcTimeCol := key.Cols()[srcTimeIdx] - if srcTimeCol.Type != query.TTime { + if srcTimeCol.Type != flux.TTime { return fmt.Errorf("timeSrc column %q does not have type time", srcTime) } @@ -232,7 +232,7 @@ func AppendAggregateTime(srcTime, dstTime string, key query.GroupKey, builder Ta return fmt.Errorf("timeDst column %q does not exist", dstTime) } dstTimeCol := builder.Cols()[dstTimeIdx] - if dstTimeCol.Type != query.TTime { + if dstTimeCol.Type != flux.TTime { return fmt.Errorf("timeDst column %q does not have type time", dstTime) } @@ -249,7 +249,7 @@ type Aggregate interface { } type ValueFunc interface { - Type() query.DataType + Type() flux.DataType } type DoBoolAgg interface { ValueFunc diff --git a/execute/aggregate_test.go b/execute/aggregate_test.go index 13f3e9d45e..18f310dc6a 100644 --- a/execute/aggregate_test.go +++ b/execute/aggregate_test.go @@ -6,10 +6,10 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/functions" ) func TestAggregate_Process(t *testing.T) { @@ -28,11 +28,11 @@ func TestAggregate_Process(t *testing.T) { agg: sumAgg, data: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(100), execute.Time(0), 0.0}, @@ -49,11 +49,11 @@ func TestAggregate_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(100), execute.Time(100), 45.0}, @@ -70,11 +70,11 @@ func TestAggregate_Process(t *testing.T) { agg: sumAgg, data: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(100), execute.Time(0), 0.0}, @@ -91,11 +91,11 @@ func TestAggregate_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(100), execute.Time(0), 45.0}, @@ -109,11 +109,11 @@ func TestAggregate_Process(t *testing.T) { data: []*executetest.Table{ { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(100), execute.Time(0), 0.0}, @@ -130,11 +130,11 @@ func TestAggregate_Process(t *testing.T) { }, { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(100), execute.Time(200), execute.Time(100), 10.0}, @@ -153,11 +153,11 @@ func TestAggregate_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(100), execute.Time(100), 45.0}, @@ -165,11 +165,11 @@ func TestAggregate_Process(t *testing.T) { }, { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(100), execute.Time(200), execute.Time(200), 145.0}, @@ -184,12 +184,12 @@ func TestAggregate_Process(t *testing.T) { data: []*executetest.Table{ { KeyCols: []string{"_start", "_stop", "t1"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "t1", Type: query.TString}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "t1", Type: flux.TString}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(100), "a", execute.Time(0), 0.0}, @@ -206,12 +206,12 @@ func TestAggregate_Process(t *testing.T) { }, { KeyCols: []string{"_start", "_stop", "t1"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "t1", Type: query.TString}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "t1", Type: flux.TString}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(100), "b", execute.Time(0), 0.3}, @@ -228,12 +228,12 @@ func TestAggregate_Process(t *testing.T) { }, { KeyCols: []string{"_start", "_stop", "t1"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "t1", Type: query.TString}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "t1", Type: flux.TString}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(100), execute.Time(200), "a", execute.Time(100), 10.0}, @@ -250,12 +250,12 @@ func TestAggregate_Process(t *testing.T) { }, { KeyCols: []string{"_start", "_stop", "t1"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "t1", Type: query.TString}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "t1", Type: flux.TString}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(100), execute.Time(200), "b", execute.Time(100), 10.3}, @@ -274,12 +274,12 @@ func TestAggregate_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"_start", "_stop", "t1"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "t1", Type: query.TString}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "t1", Type: flux.TString}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(100), "a", execute.Time(100), 45.0}, @@ -287,12 +287,12 @@ func TestAggregate_Process(t *testing.T) { }, { KeyCols: []string{"_start", "_stop", "t1"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "t1", Type: query.TString}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "t1", Type: flux.TString}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(100), execute.Time(200), "a", execute.Time(200), 145.0}, @@ -300,12 +300,12 @@ func TestAggregate_Process(t *testing.T) { }, { KeyCols: []string{"_start", "_stop", "t1"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "t1", Type: query.TString}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "t1", Type: flux.TString}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(100), "b", execute.Time(100), 48.0}, @@ -313,12 +313,12 @@ func TestAggregate_Process(t *testing.T) { }, { KeyCols: []string{"_start", "_stop", "t1"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "t1", Type: query.TString}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "t1", Type: flux.TString}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(100), execute.Time(200), "b", execute.Time(200), 148.0}, @@ -336,12 +336,12 @@ func TestAggregate_Process(t *testing.T) { agg: sumAgg, data: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "x", Type: query.TFloat}, - {Label: "y", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "x", Type: flux.TFloat}, + {Label: "y", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(100), execute.Time(0), 0.0, 0.0}, @@ -358,12 +358,12 @@ func TestAggregate_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "x", Type: query.TFloat}, - {Label: "y", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "x", Type: flux.TFloat}, + {Label: "y", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(100), execute.Time(100), 45.0, -45.0}, @@ -380,12 +380,12 @@ func TestAggregate_Process(t *testing.T) { agg: countAgg, data: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "x", Type: query.TFloat}, - {Label: "y", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "x", Type: flux.TFloat}, + {Label: "y", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(100), execute.Time(0), 0.0, 0.0}, @@ -402,12 +402,12 @@ func TestAggregate_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "x", Type: query.TInt}, - {Label: "y", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "x", Type: flux.TInt}, + {Label: "y", Type: flux.TInt}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(100), execute.Time(100), int64(10), int64(10)}, diff --git a/execute/bounds.go b/execute/bounds.go index 412df745f0..b3383933ed 100644 --- a/execute/bounds.go +++ b/execute/bounds.go @@ -5,7 +5,7 @@ import ( "math" "time" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux/values" ) type Time = values.Time diff --git a/execute/bounds_test.go b/execute/bounds_test.go index 81983a4e30..af24b0223a 100644 --- a/execute/bounds_test.go +++ b/execute/bounds_test.go @@ -3,7 +3,7 @@ package execute_test import ( "testing" - "github.com/influxdata/platform/query/execute" + "github.com/influxdata/flux/execute" ) // Written to verify symmetrical behavior of execute.(Bounds).Overlaps diff --git a/execute/dataset.go b/execute/dataset.go index 05305e3002..0b8fa47a5c 100644 --- a/execute/dataset.go +++ b/execute/dataset.go @@ -1,7 +1,7 @@ package execute import ( - "github.com/influxdata/platform/query" + "github.com/influxdata/flux" uuid "github.com/satori/go.uuid" ) @@ -9,25 +9,25 @@ import ( type Dataset interface { Node - RetractTable(key query.GroupKey) error + RetractTable(key flux.GroupKey) error UpdateProcessingTime(t Time) error UpdateWatermark(mark Time) error Finish(error) - SetTriggerSpec(t query.TriggerSpec) + SetTriggerSpec(t flux.TriggerSpec) } // DataCache holds all working data for a transformation. type DataCache interface { - Table(query.GroupKey) (query.Table, error) + Table(flux.GroupKey) (flux.Table, error) - ForEach(func(query.GroupKey)) - ForEachWithContext(func(query.GroupKey, Trigger, TableContext)) + ForEach(func(flux.GroupKey)) + ForEachWithContext(func(flux.GroupKey, Trigger, TableContext)) - DiscardTable(query.GroupKey) - ExpireTable(query.GroupKey) + DiscardTable(flux.GroupKey) + ExpireTable(flux.GroupKey) - SetTriggerSpec(t query.TriggerSpec) + SetTriggerSpec(t flux.TriggerSpec) } type AccumulationMode int @@ -74,7 +74,7 @@ func (d *dataset) AddTransformation(t Transformation) { d.ts = append(d.ts, t) } -func (d *dataset) SetTriggerSpec(spec query.TriggerSpec) { +func (d *dataset) SetTriggerSpec(spec flux.TriggerSpec) { d.cache.SetTriggerSpec(spec) } @@ -105,7 +105,7 @@ func (d *dataset) UpdateProcessingTime(time Time) error { } func (d *dataset) evalTriggers() (err error) { - d.cache.ForEachWithContext(func(key query.GroupKey, trigger Trigger, bc TableContext) { + d.cache.ForEachWithContext(func(key flux.GroupKey, trigger Trigger, bc TableContext) { if err != nil { // Skip the rest once we have encountered an error return @@ -126,7 +126,7 @@ func (d *dataset) evalTriggers() (err error) { return err } -func (d *dataset) triggerTable(key query.GroupKey) error { +func (d *dataset) triggerTable(key flux.GroupKey) error { b, err := d.cache.Table(key) if err != nil { return err @@ -157,11 +157,11 @@ func (d *dataset) triggerTable(key query.GroupKey) error { return nil } -func (d *dataset) expireTable(key query.GroupKey) { +func (d *dataset) expireTable(key flux.GroupKey) { d.cache.ExpireTable(key) } -func (d *dataset) RetractTable(key query.GroupKey) error { +func (d *dataset) RetractTable(key flux.GroupKey) error { d.cache.DiscardTable(key) for _, t := range d.ts { if err := t.RetractTable(d.id, key); err != nil { @@ -174,7 +174,7 @@ func (d *dataset) RetractTable(key query.GroupKey) error { func (d *dataset) Finish(err error) { if err == nil { // Only trigger tables we if we not finishing because of an error. - d.cache.ForEach(func(bk query.GroupKey) { + d.cache.ForEach(func(bk flux.GroupKey) { if err != nil { return } diff --git a/execute/executetest/aggregate.go b/execute/executetest/aggregate.go index 973628f3a6..56a7b6d1f9 100644 --- a/execute/executetest/aggregate.go +++ b/execute/executetest/aggregate.go @@ -5,8 +5,8 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" ) // AggFuncTestHelper splits the data in half, runs Do over each split and compares @@ -24,15 +24,15 @@ func AggFuncTestHelper(t *testing.T, agg execute.Aggregate, data []float64, want var got interface{} switch vf.Type() { - case query.TBool: + case flux.TBool: got = vf.(execute.BoolValueFunc).ValueBool() - case query.TInt: + case flux.TInt: got = vf.(execute.IntValueFunc).ValueInt() - case query.TUInt: + case flux.TUInt: got = vf.(execute.UIntValueFunc).ValueUInt() - case query.TFloat: + case flux.TFloat: got = vf.(execute.FloatValueFunc).ValueFloat() - case query.TString: + case flux.TString: got = vf.(execute.StringValueFunc).ValueString() } @@ -50,15 +50,15 @@ func AggFuncBenchmarkHelper(b *testing.B, agg execute.Aggregate, data []float64, vf.DoFloat(data) var got interface{} switch vf.Type() { - case query.TBool: + case flux.TBool: got = vf.(execute.BoolValueFunc).ValueBool() - case query.TInt: + case flux.TInt: got = vf.(execute.IntValueFunc).ValueInt() - case query.TUInt: + case flux.TUInt: got = vf.(execute.UIntValueFunc).ValueUInt() - case query.TFloat: + case flux.TFloat: got = vf.(execute.FloatValueFunc).ValueFloat() - case query.TString: + case flux.TString: got = vf.(execute.StringValueFunc).ValueString() } if !cmp.Equal(want, got) { diff --git a/execute/executetest/allocator.go b/execute/executetest/allocator.go index 6ac99e0b22..7a62a222f7 100644 --- a/execute/executetest/allocator.go +++ b/execute/executetest/allocator.go @@ -3,7 +3,7 @@ package executetest import ( "math" - "github.com/influxdata/platform/query/execute" + "github.com/influxdata/flux/execute" ) var UnlimitedAllocator = &execute.Allocator{ diff --git a/execute/executetest/dataset.go b/execute/executetest/dataset.go index 5bdddb241d..fdff9beb07 100644 --- a/execute/executetest/dataset.go +++ b/execute/executetest/dataset.go @@ -4,8 +4,8 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" uuid "github.com/satori/go.uuid" ) @@ -15,7 +15,7 @@ func RandomDatasetID() execute.DatasetID { type Dataset struct { ID execute.DatasetID - Retractions []query.GroupKey + Retractions []flux.GroupKey ProcessingTimeUpdates []execute.Time WatermarkUpdates []execute.Time Finished bool @@ -32,7 +32,7 @@ func (d *Dataset) AddTransformation(t execute.Transformation) { panic("not implemented") } -func (d *Dataset) RetractTable(key query.GroupKey) error { +func (d *Dataset) RetractTable(key flux.GroupKey) error { d.Retractions = append(d.Retractions, key) return nil } @@ -55,7 +55,7 @@ func (d *Dataset) Finish(err error) { d.FinishedErr = err } -func (d *Dataset) SetTriggerSpec(t query.TriggerSpec) { +func (d *Dataset) SetTriggerSpec(t flux.TriggerSpec) { panic("not implemented") } @@ -80,7 +80,7 @@ func TransformationPassThroughTestHelper(t *testing.T, newTr NewTransformation) tr.Finish(parentID, nil) exp := &Dataset{ - ID: d.ID, + ID: d.ID, ProcessingTimeUpdates: []execute.Time{now}, WatermarkUpdates: []execute.Time{now}, Finished: true, diff --git a/execute/executetest/result.go b/execute/executetest/result.go index c5c0381d39..2fd1c899cf 100644 --- a/execute/executetest/result.go +++ b/execute/executetest/result.go @@ -1,7 +1,7 @@ package executetest import ( - "github.com/influxdata/platform/query" + "github.com/influxdata/flux" ) type Result struct { @@ -18,7 +18,7 @@ func (r *Result) Name() string { return r.Nm } -func (r *Result) Tables() query.TableIterator { +func (r *Result) Tables() flux.TableIterator { return &TableIterator{ r.Tbls, r.Err, @@ -34,7 +34,7 @@ type TableIterator struct { err error } -func (ti *TableIterator) Do(f func(query.Table) error) error { +func (ti *TableIterator) Do(f func(flux.Table) error) error { if ti.err != nil { return ti.err } diff --git a/execute/executetest/selector.go b/execute/executetest/selector.go index 376e660734..9946cbfafa 100644 --- a/execute/executetest/selector.go +++ b/execute/executetest/selector.go @@ -4,11 +4,11 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" ) -func RowSelectorFuncTestHelper(t *testing.T, selector execute.RowSelector, data query.Table, want []execute.Row) { +func RowSelectorFuncTestHelper(t *testing.T, selector execute.RowSelector, data flux.Table, want []execute.Row) { t.Helper() s := selector.NewFloatSelector() @@ -16,7 +16,7 @@ func RowSelectorFuncTestHelper(t *testing.T, selector execute.RowSelector, data if valueIdx < 0 { t.Fatal("no _value column found") } - data.Do(func(cr query.ColReader) error { + data.Do(func(cr flux.ColReader) error { s.DoFloat(cr.Floats(valueIdx), cr) return nil }) @@ -30,7 +30,7 @@ func RowSelectorFuncTestHelper(t *testing.T, selector execute.RowSelector, data var rows []execute.Row -func RowSelectorFuncBenchmarkHelper(b *testing.B, selector execute.RowSelector, data query.Table) { +func RowSelectorFuncBenchmarkHelper(b *testing.B, selector execute.RowSelector, data flux.Table) { b.Helper() valueIdx := execute.ColIdx(execute.DefaultValueColLabel, data.Cols()) @@ -41,7 +41,7 @@ func RowSelectorFuncBenchmarkHelper(b *testing.B, selector execute.RowSelector, b.ResetTimer() for n := 0; n < b.N; n++ { s := selector.NewFloatSelector() - data.Do(func(cr query.ColReader) error { + data.Do(func(cr flux.ColReader) error { s.DoFloat(cr.Floats(valueIdx), cr) return nil }) @@ -49,7 +49,7 @@ func RowSelectorFuncBenchmarkHelper(b *testing.B, selector execute.RowSelector, } } -func IndexSelectorFuncTestHelper(t *testing.T, selector execute.IndexSelector, data query.Table, want [][]int) { +func IndexSelectorFuncTestHelper(t *testing.T, selector execute.IndexSelector, data flux.Table, want [][]int) { t.Helper() var got [][]int @@ -58,7 +58,7 @@ func IndexSelectorFuncTestHelper(t *testing.T, selector execute.IndexSelector, d if valueIdx < 0 { t.Fatal("no _value column found") } - data.Do(func(cr query.ColReader) error { + data.Do(func(cr flux.ColReader) error { var cpy []int selected := s.DoFloat(cr.Floats(valueIdx)) if len(selected) > 0 { @@ -74,7 +74,7 @@ func IndexSelectorFuncTestHelper(t *testing.T, selector execute.IndexSelector, d } } -func IndexSelectorFuncBenchmarkHelper(b *testing.B, selector execute.IndexSelector, data query.Table) { +func IndexSelectorFuncBenchmarkHelper(b *testing.B, selector execute.IndexSelector, data flux.Table) { b.Helper() valueIdx := execute.ColIdx(execute.DefaultValueColLabel, data.Cols()) @@ -86,7 +86,7 @@ func IndexSelectorFuncBenchmarkHelper(b *testing.B, selector execute.IndexSelect var got [][]int for n := 0; n < b.N; n++ { s := selector.NewFloatSelector() - data.Do(func(cr query.ColReader) error { + data.Do(func(cr flux.ColReader) error { got = append(got, s.DoFloat(cr.Floats(valueIdx))) return nil }) diff --git a/execute/executetest/table.go b/execute/executetest/table.go index 51d05335ed..a514e5be31 100644 --- a/execute/executetest/table.go +++ b/execute/executetest/table.go @@ -3,9 +3,9 @@ package executetest import ( "fmt" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/values" ) // Table is an implementation of execute.Table @@ -14,7 +14,7 @@ import ( // Use Normalize to ensure that all fields are set before equality comparisons. type Table struct { // GroupKey of the table. Does not need to be set explicitly. - GroupKey query.GroupKey + GroupKey flux.GroupKey // KeyCols is a list of column that are part of the group key. // The column type is deduced from the ColMeta slice. KeyCols []string @@ -22,7 +22,7 @@ type Table struct { // Only needs to be set when no data is present on the table. KeyValues []interface{} // ColMeta is a list of columns of the table. - ColMeta []query.ColMeta + ColMeta []flux.ColMeta // Data is a list of rows, i.e. Data[row][col] // Each row must be a list with length equal to len(ColMeta) Data [][]interface{} @@ -31,7 +31,7 @@ type Table struct { // Normalize ensures all fields of the table are set correctly. func (t *Table) Normalize() { if t.GroupKey == nil { - cols := make([]query.ColMeta, len(t.KeyCols)) + cols := make([]flux.ColMeta, len(t.KeyCols)) vs := make([]values.Value, len(t.KeyCols)) if len(t.KeyValues) != len(t.KeyCols) { t.KeyValues = make([]interface{}, len(t.KeyCols)) @@ -61,16 +61,16 @@ func (t *Table) Empty() bool { func (t *Table) RefCount(n int) {} -func (t *Table) Cols() []query.ColMeta { +func (t *Table) Cols() []flux.ColMeta { return t.ColMeta } -func (t *Table) Key() query.GroupKey { +func (t *Table) Key() flux.GroupKey { t.Normalize() return t.GroupKey } -func (t *Table) Do(f func(query.ColReader) error) error { +func (t *Table) Do(f func(flux.ColReader) error) error { for _, r := range t.Data { if err := f(ColReader{ key: t.Key(), @@ -84,16 +84,16 @@ func (t *Table) Do(f func(query.ColReader) error) error { } type ColReader struct { - key query.GroupKey - cols []query.ColMeta + key flux.GroupKey + cols []flux.ColMeta row []interface{} } -func (cr ColReader) Cols() []query.ColMeta { +func (cr ColReader) Cols() []flux.ColMeta { return cr.cols } -func (cr ColReader) Key() query.GroupKey { +func (cr ColReader) Key() flux.GroupKey { return cr.key } func (cr ColReader) Len() int { @@ -125,11 +125,11 @@ func (cr ColReader) Times(j int) []execute.Time { } func TablesFromCache(c execute.DataCache) (tables []*Table, err error) { - c.ForEach(func(key query.GroupKey) { + c.ForEach(func(key flux.GroupKey) { if err != nil { return } - var tbl query.Table + var tbl flux.Table tbl, err = c.Table(key) if err != nil { return @@ -145,7 +145,7 @@ func TablesFromCache(c execute.DataCache) (tables []*Table, err error) { return tables, nil } -func ConvertTable(tbl query.Table) (*Table, error) { +func ConvertTable(tbl flux.Table) (*Table, error) { key := tbl.Key() blk := &Table{ GroupKey: key, @@ -160,17 +160,17 @@ func ConvertTable(tbl query.Table) (*Table, error) { blk.KeyCols[j] = c.Label var v interface{} switch c.Type { - case query.TBool: + case flux.TBool: v = key.ValueBool(j) - case query.TUInt: + case flux.TUInt: v = key.ValueUInt(j) - case query.TInt: + case flux.TInt: v = key.ValueInt(j) - case query.TFloat: + case flux.TFloat: v = key.ValueFloat(j) - case query.TString: + case flux.TString: v = key.ValueString(j) - case query.TTime: + case flux.TTime: v = key.ValueTime(j) default: return nil, fmt.Errorf("unsupported column type %v", c.Type) @@ -179,24 +179,24 @@ func ConvertTable(tbl query.Table) (*Table, error) { } } - err := tbl.Do(func(cr query.ColReader) error { + err := tbl.Do(func(cr flux.ColReader) error { l := cr.Len() for i := 0; i < l; i++ { row := make([]interface{}, len(blk.ColMeta)) for j, c := range blk.ColMeta { var v interface{} switch c.Type { - case query.TBool: + case flux.TBool: v = cr.Bools(j)[i] - case query.TInt: + case flux.TInt: v = cr.Ints(j)[i] - case query.TUInt: + case flux.TUInt: v = cr.UInts(j)[i] - case query.TFloat: + case flux.TFloat: v = cr.Floats(j)[i] - case query.TString: + case flux.TString: v = cr.Strings(j)[i] - case query.TTime: + case flux.TTime: v = cr.Times(j)[i] default: panic(fmt.Errorf("unknown column type %s", c.Type)) diff --git a/execute/executetest/transformation.go b/execute/executetest/transformation.go index de808a9d36..4359c37930 100644 --- a/execute/executetest/transformation.go +++ b/execute/executetest/transformation.go @@ -6,13 +6,13 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" ) func ProcessTestHelper( t *testing.T, - data []query.Table, + data []flux.Table, want []*Table, wantErr error, create func(d execute.Dataset, c execute.TableBuilderCache) execute.Transformation, diff --git a/execute/executor.go b/execute/executor.go index dafd8cfdc8..ac688df1ff 100644 --- a/execute/executor.go +++ b/execute/executor.go @@ -7,16 +7,16 @@ import ( "runtime/debug" "time" + "github.com/influxdata/flux" + "github.com/influxdata/flux/plan" "github.com/influxdata/platform" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/plan" "github.com/pkg/errors" "go.uber.org/zap" "go.uber.org/zap/zapcore" ) type Executor interface { - Execute(ctx context.Context, orgID platform.ID, p *plan.PlanSpec, a *Allocator) (map[string]query.Result, error) + Execute(ctx context.Context, orgID platform.ID, p *plan.PlanSpec, a *Allocator) (map[string]flux.Result, error) } type executor struct { @@ -57,9 +57,9 @@ type executionState struct { alloc *Allocator - resources query.ResourceManagement + resources flux.ResourceManagement - results map[string]query.Result + results map[string]flux.Result sources []Source transports []Transport @@ -68,7 +68,7 @@ type executionState struct { logger *zap.Logger } -func (e *executor) Execute(ctx context.Context, orgID platform.ID, p *plan.PlanSpec, a *Allocator) (map[string]query.Result, error) { +func (e *executor) Execute(ctx context.Context, orgID platform.ID, p *plan.PlanSpec, a *Allocator) (map[string]flux.Result, error) { es, err := e.createExecutionState(ctx, orgID, p, a) if err != nil { return nil, errors.Wrap(err, "failed to initialize execute state") @@ -97,7 +97,7 @@ func (e *executor) createExecutionState(ctx context.Context, orgID platform.ID, deps: e.deps, alloc: a, resources: p.Resources, - results: make(map[string]query.Result, len(p.Results)), + results: make(map[string]flux.Result, len(p.Results)), // TODO(nathanielc): Have the planner specify the dispatcher throughput dispatcher: newPoolDispatcher(10, e.logger), } @@ -116,10 +116,10 @@ func (e *executor) createExecutionState(ctx context.Context, orgID platform.ID, // DefaultTriggerSpec defines the triggering that should be used for datasets // whose parent transformation is not a windowing transformation. -var DefaultTriggerSpec = query.AfterWatermarkTriggerSpec{} +var DefaultTriggerSpec = flux.AfterWatermarkTriggerSpec{} type triggeringSpec interface { - TriggerSpec() query.TriggerSpec + TriggerSpec() flux.TriggerSpec } func (es *executionState) createNode(ctx context.Context, pr *plan.Procedure, nodes map[plan.ProcedureID]Node) (Node, error) { @@ -174,7 +174,7 @@ func (es *executionState) createNode(ctx context.Context, pr *plan.Procedure, no nodes[pr.ID] = ds // Setup triggering - var ts query.TriggerSpec = DefaultTriggerSpec + var ts flux.TriggerSpec = DefaultTriggerSpec if t, ok := pr.Spec.(triggeringSpec); ok { ts = t.TriggerSpec() } @@ -258,11 +258,11 @@ func (ec executionContext) OrganizationID() platform.ID { return ec.es.orgID } -func resolveTime(qt query.Time, now time.Time) Time { +func resolveTime(qt flux.Time, now time.Time) Time { return Time(qt.Time(now).UnixNano()) } -func (ec executionContext) ResolveTime(qt query.Time) Time { +func (ec executionContext) ResolveTime(qt flux.Time) Time { return resolveTime(qt, ec.es.p.Now) } diff --git a/execute/executor_test.go b/execute/executor_test.go index f2962f6a18..7517f74a5b 100644 --- a/execute/executor_test.go +++ b/execute/executor_test.go @@ -6,16 +6,16 @@ import ( "testing" "time" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux/values" "github.com/google/go-cmp/cmp" + "github.com/influxdata/flux" + _ "github.com/influxdata/flux/builtin" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/functions" + "github.com/influxdata/flux/plan" "github.com/influxdata/platform" - "github.com/influxdata/platform/query" - _ "github.com/influxdata/platform/query/builtin" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/plan" uuid "github.com/satori/go.uuid" "go.uber.org/zap/zaptest" ) @@ -37,7 +37,7 @@ func TestExecutor_Execute(t *testing.T) { name: "simple aggregate", plan: &plan.PlanSpec{ Now: epoch.Add(5), - Resources: query.ResourceManagement{ + Resources: flux.ResourceManagement{ ConcurrencyQuota: 1, MemoryBytesQuota: math.MaxInt64, }, @@ -47,11 +47,11 @@ func TestExecutor_Execute(t *testing.T) { Spec: newTestFromProcedureSource( []*executetest.Table{&executetest.Table{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(5), execute.Time(0), 1.0}, @@ -91,11 +91,11 @@ func TestExecutor_Execute(t *testing.T) { want: map[string][]*executetest.Table{ plan.DefaultYieldName: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(5), execute.Time(5), 15.0}, @@ -107,7 +107,7 @@ func TestExecutor_Execute(t *testing.T) { name: "simple join", plan: &plan.PlanSpec{ Now: epoch.Add(5), - Resources: query.ResourceManagement{ + Resources: flux.ResourceManagement{ ConcurrencyQuota: 1, MemoryBytesQuota: math.MaxInt64, }, @@ -117,11 +117,11 @@ func TestExecutor_Execute(t *testing.T) { Spec: newTestFromProcedureSource( []*executetest.Table{&executetest.Table{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TInt}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(5), execute.Time(0), int64(1)}, @@ -194,12 +194,12 @@ func TestExecutor_Execute(t *testing.T) { want: map[string][]*executetest.Table{ plan.DefaultYieldName: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "count__value", Type: query.TInt}, - {Label: "sum__value", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "count__value", Type: flux.TInt}, + {Label: "sum__value", Type: flux.TInt}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(5), execute.Time(5), int64(5), int64(15)}, @@ -211,7 +211,7 @@ func TestExecutor_Execute(t *testing.T) { name: "join with multiple tables", plan: &plan.PlanSpec{ Now: epoch.Add(5), - Resources: query.ResourceManagement{ + Resources: flux.ResourceManagement{ ConcurrencyQuota: 1, MemoryBytesQuota: math.MaxInt64, }, @@ -222,12 +222,12 @@ func TestExecutor_Execute(t *testing.T) { []*executetest.Table{ &executetest.Table{ KeyCols: []string{"_start", "_stop", "_key"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_key", Type: query.TString}, - {Label: "_value", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_key", Type: flux.TString}, + {Label: "_value", Type: flux.TInt}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(5), execute.Time(0), "a", int64(1)}, @@ -235,12 +235,12 @@ func TestExecutor_Execute(t *testing.T) { }, &executetest.Table{ KeyCols: []string{"_start", "_stop", "_key"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_key", Type: query.TString}, - {Label: "_value", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_key", Type: flux.TString}, + {Label: "_value", Type: flux.TInt}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(5), execute.Time(1), "b", int64(2)}, @@ -248,12 +248,12 @@ func TestExecutor_Execute(t *testing.T) { }, &executetest.Table{ KeyCols: []string{"_start", "_stop", "_key"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_key", Type: query.TString}, - {Label: "_value", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_key", Type: flux.TString}, + {Label: "_value", Type: flux.TInt}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(5), execute.Time(2), "c", int64(3)}, @@ -261,12 +261,12 @@ func TestExecutor_Execute(t *testing.T) { }, &executetest.Table{ KeyCols: []string{"_start", "_stop", "_key"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_key", Type: query.TString}, - {Label: "_value", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_key", Type: flux.TString}, + {Label: "_value", Type: flux.TInt}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(5), execute.Time(3), "d", int64(4)}, @@ -274,12 +274,12 @@ func TestExecutor_Execute(t *testing.T) { }, &executetest.Table{ KeyCols: []string{"_start", "_stop", "_key"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_key", Type: query.TString}, - {Label: "_value", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_key", Type: flux.TString}, + {Label: "_value", Type: flux.TInt}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(5), execute.Time(4), "e", int64(5)}, @@ -350,14 +350,14 @@ func TestExecutor_Execute(t *testing.T) { plan.DefaultYieldName: []*executetest.Table{ { KeyCols: []string{"_key", "_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_key", Type: query.TString}, - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "count__time", Type: query.TTime}, - {Label: "count__value", Type: query.TInt}, - {Label: "sum__time", Type: query.TTime}, - {Label: "sum__value", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_key", Type: flux.TString}, + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "count__time", Type: flux.TTime}, + {Label: "count__value", Type: flux.TInt}, + {Label: "sum__time", Type: flux.TTime}, + {Label: "sum__value", Type: flux.TInt}, }, Data: [][]interface{}{ {"a", execute.Time(0), execute.Time(5), execute.Time(5), int64(1), execute.Time(5), int64(1)}, @@ -365,14 +365,14 @@ func TestExecutor_Execute(t *testing.T) { }, { KeyCols: []string{"_key", "_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_key", Type: query.TString}, - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "count__time", Type: query.TTime}, - {Label: "count__value", Type: query.TInt}, - {Label: "sum__time", Type: query.TTime}, - {Label: "sum__value", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_key", Type: flux.TString}, + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "count__time", Type: flux.TTime}, + {Label: "count__value", Type: flux.TInt}, + {Label: "sum__time", Type: flux.TTime}, + {Label: "sum__value", Type: flux.TInt}, }, Data: [][]interface{}{ {"b", execute.Time(0), execute.Time(5), execute.Time(5), int64(1), execute.Time(5), int64(2)}, @@ -380,14 +380,14 @@ func TestExecutor_Execute(t *testing.T) { }, { KeyCols: []string{"_key", "_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_key", Type: query.TString}, - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "count__time", Type: query.TTime}, - {Label: "count__value", Type: query.TInt}, - {Label: "sum__time", Type: query.TTime}, - {Label: "sum__value", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_key", Type: flux.TString}, + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "count__time", Type: flux.TTime}, + {Label: "count__value", Type: flux.TInt}, + {Label: "sum__time", Type: flux.TTime}, + {Label: "sum__value", Type: flux.TInt}, }, Data: [][]interface{}{ {"c", execute.Time(0), execute.Time(5), execute.Time(5), int64(1), execute.Time(5), int64(3)}, @@ -395,14 +395,14 @@ func TestExecutor_Execute(t *testing.T) { }, { KeyCols: []string{"_key", "_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_key", Type: query.TString}, - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "count__time", Type: query.TTime}, - {Label: "count__value", Type: query.TInt}, - {Label: "sum__time", Type: query.TTime}, - {Label: "sum__value", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_key", Type: flux.TString}, + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "count__time", Type: flux.TTime}, + {Label: "count__value", Type: flux.TInt}, + {Label: "sum__time", Type: flux.TTime}, + {Label: "sum__value", Type: flux.TInt}, }, Data: [][]interface{}{ {"d", execute.Time(0), execute.Time(5), execute.Time(5), int64(1), execute.Time(5), int64(4)}, @@ -410,14 +410,14 @@ func TestExecutor_Execute(t *testing.T) { }, { KeyCols: []string{"_key", "_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_key", Type: query.TString}, - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "count__time", Type: query.TTime}, - {Label: "count__value", Type: query.TInt}, - {Label: "sum__time", Type: query.TTime}, - {Label: "sum__value", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_key", Type: flux.TString}, + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "count__time", Type: flux.TTime}, + {Label: "count__value", Type: flux.TInt}, + {Label: "sum__time", Type: flux.TTime}, + {Label: "sum__value", Type: flux.TInt}, }, Data: [][]interface{}{ {"e", execute.Time(0), execute.Time(5), execute.Time(5), int64(1), execute.Time(5), int64(5)}, @@ -430,7 +430,7 @@ func TestExecutor_Execute(t *testing.T) { name: "multiple aggregates", plan: &plan.PlanSpec{ Now: epoch.Add(5), - Resources: query.ResourceManagement{ + Resources: flux.ResourceManagement{ ConcurrencyQuota: 1, MemoryBytesQuota: math.MaxInt64, }, @@ -440,11 +440,11 @@ func TestExecutor_Execute(t *testing.T) { Spec: newTestFromProcedureSource( []*executetest.Table{&executetest.Table{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(5), execute.Time(0), 1.0}, @@ -502,11 +502,11 @@ func TestExecutor_Execute(t *testing.T) { want: map[string][]*executetest.Table{ "sum": []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(5), execute.Time(5), 15.0}, @@ -514,11 +514,11 @@ func TestExecutor_Execute(t *testing.T) { }}, "mean": []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(5), execute.Time(5), 3.0}, @@ -538,7 +538,7 @@ func TestExecutor_Execute(t *testing.T) { } got := make(map[string][]*executetest.Table, len(results)) for name, r := range results { - if err := r.Tables().Do(func(tbl query.Table) error { + if err := r.Tables().Do(func(tbl flux.Table) error { cb, err := executetest.ConvertTable(tbl) if err != nil { return err diff --git a/execute/format.go b/execute/format.go index c0e71cbe21..92a95e6d9e 100644 --- a/execute/format.go +++ b/execute/format.go @@ -6,14 +6,14 @@ import ( "strconv" "strings" - "github.com/influxdata/platform/query" + "github.com/influxdata/flux" ) const fixedWidthTimeFmt = "2006-01-02T15:04:05.000000000Z" // Formatter writes a table to a Writer. type Formatter struct { - tbl query.Table + tbl flux.Table widths []int maxWidth int newWidths []int @@ -40,7 +40,7 @@ var eol = []byte{'\n'} // NewFormatter creates a Formatter for a given table. // If opts is nil, the DefaultFormatOptions are used. -func NewFormatter(tbl query.Table, opts *FormatOptions) *Formatter { +func NewFormatter(tbl flux.Table, opts *FormatOptions) *Formatter { if opts == nil { opts = DefaultFormatOptions() } @@ -65,14 +65,14 @@ func (w *writeToHelper) write(data []byte) { w.err = err } -var minWidthsByType = map[query.DataType]int{ - query.TBool: 12, - query.TInt: 26, - query.TUInt: 27, - query.TFloat: 28, - query.TString: 22, - query.TTime: len(fixedWidthTimeFmt), - query.TInvalid: 10, +var minWidthsByType = map[flux.DataType]int{ + flux.TBool: 12, + flux.TInt: 26, + flux.TUInt: 27, + flux.TFloat: 28, + flux.TString: 22, + flux.TTime: len(fixedWidthTimeFmt), + flux.TInvalid: 10, } // WriteTo writes the formatted table data to w. @@ -118,7 +118,7 @@ func (f *Formatter) WriteTo(out io.Writer) (int64, error) { // Write rows r := 0 - w.err = f.tbl.Do(func(cr query.ColReader) error { + w.err = f.tbl.Do(func(cr flux.ColReader) error { if r == 0 { l := cr.Len() for i := 0; i < l; i++ { @@ -213,20 +213,20 @@ func (f *Formatter) writeHeaderSeparator(w *writeToHelper) { w.write(eol) } -func (f *Formatter) valueBuf(i, j int, typ query.DataType, cr query.ColReader) (buf []byte) { +func (f *Formatter) valueBuf(i, j int, typ flux.DataType, cr flux.ColReader) (buf []byte) { switch typ { - case query.TBool: + case flux.TBool: buf = strconv.AppendBool(f.fmtBuf[0:0], cr.Bools(j)[i]) - case query.TInt: + case flux.TInt: buf = strconv.AppendInt(f.fmtBuf[0:0], cr.Ints(j)[i], 10) - case query.TUInt: + case flux.TUInt: buf = strconv.AppendUint(f.fmtBuf[0:0], cr.UInts(j)[i], 10) - case query.TFloat: + case flux.TFloat: // TODO allow specifying format and precision buf = strconv.AppendFloat(f.fmtBuf[0:0], cr.Floats(j)[i], 'f', -1, 64) - case query.TString: + case flux.TString: buf = []byte(cr.Strings(j)[i]) - case query.TTime: + case flux.TTime: buf = []byte(cr.Times(j)[i].String()) } return @@ -241,16 +241,16 @@ func (f *Formatter) valueBuf(i, j int, typ query.DataType, cr query.ColReader) ( // type orderedCols struct { indexMap []int - cols []query.ColMeta - key query.GroupKey + cols []flux.ColMeta + key flux.GroupKey } -func newOrderedCols(cols []query.ColMeta, key query.GroupKey) orderedCols { +func newOrderedCols(cols []flux.ColMeta, key flux.GroupKey) orderedCols { indexMap := make([]int, len(cols)) for i := range indexMap { indexMap[i] = i } - cpy := make([]query.ColMeta, len(cols)) + cpy := make([]flux.ColMeta, len(cols)) copy(cpy, cols) return orderedCols{ indexMap: indexMap, diff --git a/execute/group_key.go b/execute/group_key.go index 352a141307..5d515642ab 100644 --- a/execute/group_key.go +++ b/execute/group_key.go @@ -4,23 +4,23 @@ import ( "fmt" "strings" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux" + "github.com/influxdata/flux/values" ) type groupKey struct { - cols []query.ColMeta + cols []flux.ColMeta values []values.Value } -func NewGroupKey(cols []query.ColMeta, values []values.Value) query.GroupKey { +func NewGroupKey(cols []flux.ColMeta, values []values.Value) flux.GroupKey { return &groupKey{ cols: cols, values: values, } } -func (k *groupKey) Cols() []query.ColMeta { +func (k *groupKey) Cols() []flux.ColMeta { return k.cols } func (k *groupKey) HasCol(label string) bool { @@ -57,11 +57,11 @@ func (k *groupKey) ValueTime(j int) Time { return k.values[j].Time() } -func (k *groupKey) Equal(o query.GroupKey) bool { +func (k *groupKey) Equal(o flux.GroupKey) bool { return groupKeyEqual(k, o) } -func (k *groupKey) Less(o query.GroupKey) bool { +func (k *groupKey) Less(o flux.GroupKey) bool { return groupKeyLess(k, o) } @@ -78,7 +78,7 @@ func (k *groupKey) String() string { return b.String() } -func groupKeyEqual(a, b query.GroupKey) bool { +func groupKeyEqual(a, b flux.GroupKey) bool { aCols := a.Cols() bCols := b.Cols() if len(aCols) != len(bCols) { @@ -89,27 +89,27 @@ func groupKeyEqual(a, b query.GroupKey) bool { return false } switch c.Type { - case query.TBool: + case flux.TBool: if a.ValueBool(j) != b.ValueBool(j) { return false } - case query.TInt: + case flux.TInt: if a.ValueInt(j) != b.ValueInt(j) { return false } - case query.TUInt: + case flux.TUInt: if a.ValueUInt(j) != b.ValueUInt(j) { return false } - case query.TFloat: + case flux.TFloat: if a.ValueFloat(j) != b.ValueFloat(j) { return false } - case query.TString: + case flux.TString: if a.ValueString(j) != b.ValueString(j) { return false } - case query.TTime: + case flux.TTime: if a.ValueTime(j) != b.ValueTime(j) { return false } @@ -118,7 +118,7 @@ func groupKeyEqual(a, b query.GroupKey) bool { return true } -func groupKeyLess(a, b query.GroupKey) bool { +func groupKeyLess(a, b flux.GroupKey) bool { aCols := a.Cols() bCols := b.Cols() if av, bv := len(aCols), len(bCols); av != bv { @@ -132,27 +132,27 @@ func groupKeyLess(a, b query.GroupKey) bool { return av < bv } switch c.Type { - case query.TBool: + case flux.TBool: if av, bv := a.ValueBool(j), b.ValueBool(j); av != bv { return av } - case query.TInt: + case flux.TInt: if av, bv := a.ValueInt(j), b.ValueInt(j); av != bv { return av < bv } - case query.TUInt: + case flux.TUInt: if av, bv := a.ValueUInt(j), b.ValueUInt(j); av != bv { return av < bv } - case query.TFloat: + case flux.TFloat: if av, bv := a.ValueFloat(j), b.ValueFloat(j); av != bv { return av < bv } - case query.TString: + case flux.TString: if av, bv := a.ValueString(j), b.ValueString(j); av != bv { return av < bv } - case query.TTime: + case flux.TTime: if av, bv := a.ValueTime(j), b.ValueTime(j); av != bv { return av < bv } diff --git a/execute/group_lookup.go b/execute/group_lookup.go index 7a5cad5df0..ae01401bc5 100644 --- a/execute/group_lookup.go +++ b/execute/group_lookup.go @@ -3,7 +3,7 @@ package execute import ( "sort" - "github.com/influxdata/platform/query" + "github.com/influxdata/flux" ) type GroupLookup struct { @@ -14,7 +14,7 @@ type GroupLookup struct { } type groupEntry struct { - key query.GroupKey + key flux.GroupKey value interface{} } @@ -24,7 +24,7 @@ func NewGroupLookup() *GroupLookup { } } -func (l *GroupLookup) findIdx(key query.GroupKey) int { +func (l *GroupLookup) findIdx(key flux.GroupKey) int { i := sort.Search(len(l.groups), func(i int) bool { return !l.groups[i].key.Less(key) }) @@ -34,7 +34,7 @@ func (l *GroupLookup) findIdx(key query.GroupKey) int { return -1 } -func (l *GroupLookup) Lookup(key query.GroupKey) (interface{}, bool) { +func (l *GroupLookup) Lookup(key flux.GroupKey) (interface{}, bool) { if key == nil { return nil, false } @@ -45,7 +45,7 @@ func (l *GroupLookup) Lookup(key query.GroupKey) (interface{}, bool) { return nil, false } -func (l *GroupLookup) Set(key query.GroupKey, value interface{}) { +func (l *GroupLookup) Set(key flux.GroupKey, value interface{}) { i := l.findIdx(key) if i >= 0 { l.groups[i].value = value @@ -58,7 +58,7 @@ func (l *GroupLookup) Set(key query.GroupKey, value interface{}) { } } -func (l *GroupLookup) Delete(key query.GroupKey) (v interface{}, found bool) { +func (l *GroupLookup) Delete(key flux.GroupKey) (v interface{}, found bool) { if key == nil { return } @@ -77,7 +77,7 @@ func (l *GroupLookup) Delete(key query.GroupKey) (v interface{}, found bool) { // Range will iterate over all groups keys in sorted order. // Range must not be called within another call to Range. // It is safe to call Set/Delete while ranging. -func (l *GroupLookup) Range(f func(key query.GroupKey, value interface{})) { +func (l *GroupLookup) Range(f func(key flux.GroupKey, value interface{})) { for l.rangeIdx = 0; l.rangeIdx < len(l.groups); l.rangeIdx++ { entry := l.groups[l.rangeIdx] f(entry.key, entry.value) diff --git a/execute/group_lookup_test.go b/execute/group_lookup_test.go index d1cd2619bc..29893bf01a 100644 --- a/execute/group_lookup_test.go +++ b/execute/group_lookup_test.go @@ -4,16 +4,16 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/values" ) var ( - cols = []query.ColMeta{ - {Label: "a", Type: query.TString}, - {Label: "b", Type: query.TString}, - {Label: "c", Type: query.TString}, + cols = []flux.ColMeta{ + {Label: "a", Type: flux.TString}, + {Label: "b", Type: flux.TString}, + {Label: "c", Type: flux.TString}, } key0 = execute.NewGroupKey( cols, @@ -63,7 +63,7 @@ func TestGroupLookup(t *testing.T) { } var got []entry - l.Range(func(k query.GroupKey, v interface{}) { + l.Range(func(k flux.GroupKey, v interface{}) { got = append(got, entry{ Key: k, Value: v.(int), @@ -114,7 +114,7 @@ func TestGroupLookup_RangeWithDelete(t *testing.T) { {Key: key1, Value: 1}, } var got []entry - l.Range(func(k query.GroupKey, v interface{}) { + l.Range(func(k flux.GroupKey, v interface{}) { // Delete the current key l.Delete(key0) // Delete a future key @@ -131,6 +131,6 @@ func TestGroupLookup_RangeWithDelete(t *testing.T) { } type entry struct { - Key query.GroupKey + Key flux.GroupKey Value int } diff --git a/execute/result.go b/execute/result.go index 00cd9a89af..687460f681 100644 --- a/execute/result.go +++ b/execute/result.go @@ -3,8 +3,8 @@ package execute import ( "sync" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/plan" + "github.com/influxdata/flux" + "github.com/influxdata/flux/plan" ) // result implements both the Transformation and Result interfaces, @@ -20,7 +20,7 @@ type result struct { } type resultMessage struct { - table query.Table + table flux.Table err error } @@ -37,12 +37,12 @@ func newResult(name string, spec plan.YieldSpec) *result { func (s *result) Name() string { return s.name } -func (s *result) RetractTable(DatasetID, query.GroupKey) error { +func (s *result) RetractTable(DatasetID, flux.GroupKey) error { //TODO implement return nil } -func (s *result) Process(id DatasetID, tbl query.Table) error { +func (s *result) Process(id DatasetID, tbl flux.Table) error { select { case s.tables <- resultMessage{ table: tbl, @@ -52,11 +52,11 @@ func (s *result) Process(id DatasetID, tbl query.Table) error { return nil } -func (s *result) Tables() query.TableIterator { +func (s *result) Tables() flux.TableIterator { return s } -func (s *result) Do(f func(query.Table) error) error { +func (s *result) Do(f func(flux.Table) error) error { for { select { case err := <-s.abortErr: diff --git a/execute/row_fn.go b/execute/row_fn.go index d169ac177c..930acbd2f8 100644 --- a/execute/row_fn.go +++ b/execute/row_fn.go @@ -4,10 +4,10 @@ import ( "fmt" "regexp" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/compiler" - "github.com/influxdata/platform/query/semantic" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux" + "github.com/influxdata/flux/compiler" + "github.com/influxdata/flux/semantic" + "github.com/influxdata/flux/values" "github.com/pkg/errors" ) @@ -29,7 +29,7 @@ func newRowFn(fn *semantic.FunctionExpression) (rowFn, error) { if len(fn.Params) != 1 { return rowFn{}, fmt.Errorf("function should only have a single parameter, got %d", len(fn.Params)) } - scope, decls := query.BuiltIns() + scope, decls := flux.BuiltIns() return rowFn{ compilationCache: compiler.NewCompilationCache(fn, scope, decls), scope: make(compiler.Scope, 1), @@ -39,7 +39,7 @@ func newRowFn(fn *semantic.FunctionExpression) (rowFn, error) { }, nil } -func (f *rowFn) prepare(cols []query.ColMeta) error { +func (f *rowFn) prepare(cols []flux.ColMeta) error { // Prepare types and recordCols propertyTypes := make(map[string]semantic.Type, len(f.references)) for _, r := range f.references { @@ -68,51 +68,51 @@ func (f *rowFn) prepare(cols []query.ColMeta) error { return nil } -func ConvertToKind(t query.DataType) semantic.Kind { +func ConvertToKind(t flux.DataType) semantic.Kind { // TODO make this an array lookup. switch t { - case query.TInvalid: + case flux.TInvalid: return semantic.Invalid - case query.TBool: + case flux.TBool: return semantic.Bool - case query.TInt: + case flux.TInt: return semantic.Int - case query.TUInt: + case flux.TUInt: return semantic.UInt - case query.TFloat: + case flux.TFloat: return semantic.Float - case query.TString: + case flux.TString: return semantic.String - case query.TTime: + case flux.TTime: return semantic.Time default: return semantic.Invalid } } -func ConvertFromKind(k semantic.Kind) query.DataType { +func ConvertFromKind(k semantic.Kind) flux.DataType { // TODO make this an array lookup. switch k { case semantic.Invalid: - return query.TInvalid + return flux.TInvalid case semantic.Bool: - return query.TBool + return flux.TBool case semantic.Int: - return query.TInt + return flux.TInt case semantic.UInt: - return query.TUInt + return flux.TUInt case semantic.Float: - return query.TFloat + return flux.TFloat case semantic.String: - return query.TString + return flux.TString case semantic.Time: - return query.TTime + return flux.TTime default: - return query.TInvalid + return flux.TInvalid } } -func (f *rowFn) eval(row int, cr query.ColReader) (values.Value, error) { +func (f *rowFn) eval(row int, cr flux.ColReader) (values.Value, error) { for _, r := range f.references { f.record.Set(r, ValueForRow(row, f.recordCols[r], cr)) } @@ -134,7 +134,7 @@ func NewRowPredicateFn(fn *semantic.FunctionExpression) (*RowPredicateFn, error) }, nil } -func (f *RowPredicateFn) Prepare(cols []query.ColMeta) error { +func (f *RowPredicateFn) Prepare(cols []flux.ColMeta) error { err := f.rowFn.prepare(cols) if err != nil { return err @@ -145,7 +145,7 @@ func (f *RowPredicateFn) Prepare(cols []query.ColMeta) error { return nil } -func (f *RowPredicateFn) Eval(row int, cr query.ColReader) (bool, error) { +func (f *RowPredicateFn) Eval(row int, cr flux.ColReader) (bool, error) { v, err := f.rowFn.eval(row, cr) if err != nil { return false, err @@ -170,7 +170,7 @@ func NewRowMapFn(fn *semantic.FunctionExpression) (*RowMapFn, error) { }, nil } -func (f *RowMapFn) Prepare(cols []query.ColMeta) error { +func (f *RowMapFn) Prepare(cols []flux.ColMeta) error { err := f.rowFn.prepare(cols) if err != nil { return err @@ -192,7 +192,7 @@ func (f *RowMapFn) Type() semantic.Type { return f.preparedFn.Type() } -func (f *RowMapFn) Eval(row int, cr query.ColReader) (values.Object, error) { +func (f *RowMapFn) Eval(row int, cr flux.ColReader) (values.Object, error) { v, err := f.rowFn.eval(row, cr) if err != nil { return nil, err @@ -204,20 +204,20 @@ func (f *RowMapFn) Eval(row int, cr query.ColReader) (values.Object, error) { return v.Object(), nil } -func ValueForRow(i, j int, cr query.ColReader) values.Value { +func ValueForRow(i, j int, cr flux.ColReader) values.Value { t := cr.Cols()[j].Type switch t { - case query.TString: + case flux.TString: return values.NewStringValue(cr.Strings(j)[i]) - case query.TInt: + case flux.TInt: return values.NewIntValue(cr.Ints(j)[i]) - case query.TUInt: + case flux.TUInt: return values.NewUIntValue(cr.UInts(j)[i]) - case query.TFloat: + case flux.TFloat: return values.NewFloatValue(cr.Floats(j)[i]) - case query.TBool: + case flux.TBool: return values.NewBoolValue(cr.Bools(j)[i]) - case query.TTime: + case flux.TTime: return values.NewTimeValue(cr.Times(j)[i]) default: PanicUnknownType(t) diff --git a/execute/selector.go b/execute/selector.go index 06116fd6f8..e88e62c391 100644 --- a/execute/selector.go +++ b/execute/selector.go @@ -3,8 +3,8 @@ package execute import ( "fmt" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux" + "github.com/influxdata/flux/semantic" ) type selectorTransformation struct { @@ -18,7 +18,7 @@ type SelectorConfig struct { Column string `json:"column"` } -func (c *SelectorConfig) ReadArgs(args query.Arguments) error { +func (c *SelectorConfig) ReadArgs(args flux.Arguments) error { if col, ok, err := args.GetString("column"); err != nil { return err } else if ok { @@ -30,11 +30,11 @@ func (c *SelectorConfig) ReadArgs(args query.Arguments) error { func DefaultSelectorSignature() semantic.FunctionSignature { return semantic.FunctionSignature{ Params: map[string]semantic.Type{ - query.TableParameter: query.TableObjectType, - "column": semantic.String, + flux.TableParameter: flux.TableObjectType, + "column": semantic.String, }, - ReturnType: query.TableObjectType, - PipeArgument: query.TableParameter, + ReturnType: flux.TableObjectType, + PipeArgument: flux.TableParameter, } } @@ -82,7 +82,7 @@ func newSelectorTransformation(d Dataset, c TableBuilderCache, config SelectorCo } } -func (t *selectorTransformation) RetractTable(id DatasetID, key query.GroupKey) error { +func (t *selectorTransformation) RetractTable(id DatasetID, key flux.GroupKey) error { //TODO(nathanielc): Store intermediate state for retractions return t.d.RetractTable(key) } @@ -96,7 +96,7 @@ func (t *selectorTransformation) Finish(id DatasetID, err error) { t.d.Finish(err) } -func (t *selectorTransformation) setupBuilder(tbl query.Table) (TableBuilder, int, error) { +func (t *selectorTransformation) setupBuilder(tbl flux.Table) (TableBuilder, int, error) { builder, new := t.cache.TableBuilder(tbl.Key()) if !new { return nil, 0, fmt.Errorf("found duplicate table with key: %v", tbl.Key()) @@ -111,7 +111,7 @@ func (t *selectorTransformation) setupBuilder(tbl query.Table) (TableBuilder, in return builder, valueIdx, nil } -func (t *indexSelectorTransformation) Process(id DatasetID, tbl query.Table) error { +func (t *indexSelectorTransformation) Process(id DatasetID, tbl flux.Table) error { builder, valueIdx, err := t.setupBuilder(tbl) if err != nil { return err @@ -120,35 +120,35 @@ func (t *indexSelectorTransformation) Process(id DatasetID, tbl query.Table) err var s interface{} switch valueCol.Type { - case query.TBool: + case flux.TBool: s = t.selector.NewBoolSelector() - case query.TInt: + case flux.TInt: s = t.selector.NewIntSelector() - case query.TUInt: + case flux.TUInt: s = t.selector.NewUIntSelector() - case query.TFloat: + case flux.TFloat: s = t.selector.NewFloatSelector() - case query.TString: + case flux.TString: s = t.selector.NewStringSelector() default: return fmt.Errorf("unsupported selector type %v", valueCol.Type) } - return tbl.Do(func(cr query.ColReader) error { + return tbl.Do(func(cr flux.ColReader) error { switch valueCol.Type { - case query.TBool: + case flux.TBool: selected := s.(DoBoolIndexSelector).DoBool(cr.Bools(valueIdx)) t.appendSelected(selected, builder, cr) - case query.TInt: + case flux.TInt: selected := s.(DoIntIndexSelector).DoInt(cr.Ints(valueIdx)) t.appendSelected(selected, builder, cr) - case query.TUInt: + case flux.TUInt: selected := s.(DoUIntIndexSelector).DoUInt(cr.UInts(valueIdx)) t.appendSelected(selected, builder, cr) - case query.TFloat: + case flux.TFloat: selected := s.(DoFloatIndexSelector).DoFloat(cr.Floats(valueIdx)) t.appendSelected(selected, builder, cr) - case query.TString: + case flux.TString: selected := s.(DoStringIndexSelector).DoString(cr.Strings(valueIdx)) t.appendSelected(selected, builder, cr) default: @@ -158,7 +158,7 @@ func (t *indexSelectorTransformation) Process(id DatasetID, tbl query.Table) err }) } -func (t *rowSelectorTransformation) Process(id DatasetID, tbl query.Table) error { +func (t *rowSelectorTransformation) Process(id DatasetID, tbl flux.Table) error { builder, valueIdx, err := t.setupBuilder(tbl) if err != nil { return err @@ -168,15 +168,15 @@ func (t *rowSelectorTransformation) Process(id DatasetID, tbl query.Table) error var rower Rower switch valueCol.Type { - case query.TBool: + case flux.TBool: rower = t.selector.NewBoolSelector() - case query.TInt: + case flux.TInt: rower = t.selector.NewIntSelector() - case query.TUInt: + case flux.TUInt: rower = t.selector.NewUIntSelector() - case query.TFloat: + case flux.TFloat: rower = t.selector.NewFloatSelector() - case query.TString: + case flux.TString: rower = t.selector.NewStringSelector() default: return fmt.Errorf("unsupported selector type %v", valueCol.Type) @@ -189,17 +189,17 @@ func (t *rowSelectorTransformation) Process(id DatasetID, tbl query.Table) error return fmt.Errorf("invalid use of function: %T has no implementation for type %v", t.selector, valueCol.Type) } - tbl.Do(func(cr query.ColReader) error { + tbl.Do(func(cr flux.ColReader) error { switch valueCol.Type { - case query.TBool: + case flux.TBool: rower.(DoBoolRowSelector).DoBool(cr.Bools(valueIdx), cr) - case query.TInt: + case flux.TInt: rower.(DoIntRowSelector).DoInt(cr.Ints(valueIdx), cr) - case query.TUInt: + case flux.TUInt: rower.(DoUIntRowSelector).DoUInt(cr.UInts(valueIdx), cr) - case query.TFloat: + case flux.TFloat: rower.(DoFloatRowSelector).DoFloat(cr.Floats(valueIdx), cr) - case query.TString: + case flux.TString: rower.(DoStringRowSelector).DoString(cr.Strings(valueIdx), cr) default: return fmt.Errorf("unsupported selector type %v", valueCol.Type) @@ -211,7 +211,7 @@ func (t *rowSelectorTransformation) Process(id DatasetID, tbl query.Table) error return nil } -func (t *indexSelectorTransformation) appendSelected(selected []int, builder TableBuilder, cr query.ColReader) { +func (t *indexSelectorTransformation) appendSelected(selected []int, builder TableBuilder, cr flux.ColReader) { if len(selected) == 0 { return } @@ -219,17 +219,17 @@ func (t *indexSelectorTransformation) appendSelected(selected []int, builder Tab for j, c := range cols { for _, i := range selected { switch c.Type { - case query.TBool: + case flux.TBool: builder.AppendBool(j, cr.Bools(j)[i]) - case query.TInt: + case flux.TInt: builder.AppendInt(j, cr.Ints(j)[i]) - case query.TUInt: + case flux.TUInt: builder.AppendUInt(j, cr.UInts(j)[i]) - case query.TFloat: + case flux.TFloat: builder.AppendFloat(j, cr.Floats(j)[i]) - case query.TString: + case flux.TString: builder.AppendString(j, cr.Strings(j)[i]) - case query.TTime: + case flux.TTime: builder.AppendTime(j, cr.Times(j)[i]) default: PanicUnknownType(c.Type) @@ -244,17 +244,17 @@ func (t *rowSelectorTransformation) appendRows(builder TableBuilder, rows []Row) for _, row := range rows { v := row.Values[j] switch c.Type { - case query.TBool: + case flux.TBool: builder.AppendBool(j, v.(bool)) - case query.TInt: + case flux.TInt: builder.AppendInt(j, v.(int64)) - case query.TUInt: + case flux.TUInt: builder.AppendUInt(j, v.(uint64)) - case query.TFloat: + case flux.TFloat: builder.AppendFloat(j, v.(float64)) - case query.TString: + case flux.TString: builder.AppendString(j, v.(string)) - case query.TTime: + case flux.TTime: builder.AppendTime(j, v.(Time)) default: PanicUnknownType(c.Type) @@ -300,45 +300,45 @@ type Rower interface { type DoBoolRowSelector interface { Rower - DoBool(vs []bool, cr query.ColReader) + DoBool(vs []bool, cr flux.ColReader) } type DoIntRowSelector interface { Rower - DoInt(vs []int64, cr query.ColReader) + DoInt(vs []int64, cr flux.ColReader) } type DoUIntRowSelector interface { Rower - DoUInt(vs []uint64, cr query.ColReader) + DoUInt(vs []uint64, cr flux.ColReader) } type DoFloatRowSelector interface { Rower - DoFloat(vs []float64, cr query.ColReader) + DoFloat(vs []float64, cr flux.ColReader) } type DoStringRowSelector interface { Rower - DoString(vs []string, cr query.ColReader) + DoString(vs []string, cr flux.ColReader) } type Row struct { Values []interface{} } -func ReadRow(i int, cr query.ColReader) (row Row) { +func ReadRow(i int, cr flux.ColReader) (row Row) { cols := cr.Cols() row.Values = make([]interface{}, len(cols)) for j, c := range cols { switch c.Type { - case query.TBool: + case flux.TBool: row.Values[j] = cr.Bools(j)[i] - case query.TInt: + case flux.TInt: row.Values[j] = cr.Ints(j)[i] - case query.TUInt: + case flux.TUInt: row.Values[j] = cr.UInts(j)[i] - case query.TFloat: + case flux.TFloat: row.Values[j] = cr.Floats(j)[i] - case query.TString: + case flux.TString: row.Values[j] = cr.Strings(j)[i] - case query.TTime: + case flux.TTime: row.Values[j] = cr.Times(j)[i] } } diff --git a/execute/selector_test.go b/execute/selector_test.go index 89276edb07..f8b591b34f 100644 --- a/execute/selector_test.go +++ b/execute/selector_test.go @@ -6,10 +6,10 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/functions" ) func TestRowSelector_Process(t *testing.T) { @@ -27,11 +27,11 @@ func TestRowSelector_Process(t *testing.T) { }, data: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(100), execute.Time(1), 0.0}, @@ -48,11 +48,11 @@ func TestRowSelector_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(100), execute.Time(1), 0.0}, @@ -66,11 +66,11 @@ func TestRowSelector_Process(t *testing.T) { }, data: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "x", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "x", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(100), execute.Time(1), 0.0}, @@ -87,11 +87,11 @@ func TestRowSelector_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "x", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "x", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(100), execute.Time(1), 0.0}, @@ -106,11 +106,11 @@ func TestRowSelector_Process(t *testing.T) { data: []*executetest.Table{ { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(100), execute.Time(1), 0.0}, @@ -127,11 +127,11 @@ func TestRowSelector_Process(t *testing.T) { }, { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(100), execute.Time(200), execute.Time(101), 10.0}, @@ -150,11 +150,11 @@ func TestRowSelector_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(100), execute.Time(1), 0.0}, @@ -162,11 +162,11 @@ func TestRowSelector_Process(t *testing.T) { }, { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(100), execute.Time(200), execute.Time(101), 10.0}, @@ -224,11 +224,11 @@ func TestIndexSelector_Process(t *testing.T) { }, data: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(100), execute.Time(1), 0.0}, @@ -245,11 +245,11 @@ func TestIndexSelector_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(100), execute.Time(1), 0.0}, @@ -264,11 +264,11 @@ func TestIndexSelector_Process(t *testing.T) { data: []*executetest.Table{ { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(100), execute.Time(1), 0.0}, @@ -285,11 +285,11 @@ func TestIndexSelector_Process(t *testing.T) { }, { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(100), execute.Time(200), execute.Time(101), 10.0}, @@ -308,11 +308,11 @@ func TestIndexSelector_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(100), execute.Time(1), 0.0}, @@ -320,11 +320,11 @@ func TestIndexSelector_Process(t *testing.T) { }, { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(100), execute.Time(200), execute.Time(101), 10.0}, diff --git a/execute/source.go b/execute/source.go index 6fec0bc11f..b0f4e20bf7 100644 --- a/execute/source.go +++ b/execute/source.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/influxdata/platform/query/plan" + "github.com/influxdata/flux/plan" ) type Node interface { diff --git a/execute/table.go b/execute/table.go index 4e69b472fd..a4e7eae25f 100644 --- a/execute/table.go +++ b/execute/table.go @@ -5,9 +5,9 @@ import ( "sort" "sync/atomic" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/semantic" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux" + "github.com/influxdata/flux/semantic" + "github.com/influxdata/flux/values" ) const ( @@ -17,8 +17,8 @@ const ( DefaultValueColLabel = "_value" ) -func GroupKeyForRowOn(i int, cr query.ColReader, on map[string]bool) query.GroupKey { - cols := make([]query.ColMeta, 0, len(on)) +func GroupKeyForRowOn(i int, cr flux.ColReader, on map[string]bool) flux.GroupKey { + cols := make([]flux.ColMeta, 0, len(on)) vs := make([]values.Value, 0, len(on)) for j, c := range cr.Cols() { if !on[c.Label] { @@ -26,17 +26,17 @@ func GroupKeyForRowOn(i int, cr query.ColReader, on map[string]bool) query.Group } cols = append(cols, c) switch c.Type { - case query.TBool: + case flux.TBool: vs = append(vs, values.NewBoolValue(cr.Bools(j)[i])) - case query.TInt: + case flux.TInt: vs = append(vs, values.NewIntValue(cr.Ints(j)[i])) - case query.TUInt: + case flux.TUInt: vs = append(vs, values.NewUIntValue(cr.UInts(j)[i])) - case query.TFloat: + case flux.TFloat: vs = append(vs, values.NewFloatValue(cr.Floats(j)[i])) - case query.TString: + case flux.TString: vs = append(vs, values.NewStringValue(cr.Strings(j)[i])) - case query.TTime: + case flux.TTime: vs = append(vs, values.NewTimeValue(cr.Times(j)[i])) } } @@ -46,14 +46,14 @@ func GroupKeyForRowOn(i int, cr query.ColReader, on map[string]bool) query.Group // OneTimeTable is a Table that permits reading data only once. // Specifically the ValueIterator may only be consumed once from any of the columns. type OneTimeTable interface { - query.Table + flux.Table onetime() } // CacheOneTimeTable returns a table that can be read multiple times. // If the table is not a OneTimeTable it is returned directly. // Otherwise its contents are read into a new table. -func CacheOneTimeTable(t query.Table, a *Allocator) query.Table { +func CacheOneTimeTable(t flux.Table, a *Allocator) flux.Table { _, ok := t.(OneTimeTable) if !ok { return t @@ -62,7 +62,7 @@ func CacheOneTimeTable(t query.Table, a *Allocator) query.Table { } // CopyTable returns a copy of the table and is OneTimeTable safe. -func CopyTable(t query.Table, a *Allocator) query.Table { +func CopyTable(t flux.Table, a *Allocator) flux.Table { builder := NewColListTableBuilder(t.Key(), a) cols := t.Cols() @@ -79,14 +79,14 @@ func CopyTable(t query.Table, a *Allocator) query.Table { } // AddTableCols adds the columns of b onto builder. -func AddTableCols(t query.Table, builder TableBuilder) { +func AddTableCols(t flux.Table, builder TableBuilder) { cols := t.Cols() for _, c := range cols { builder.AddCol(c) } } -func AddTableKeyCols(key query.GroupKey, builder TableBuilder) { +func AddTableKeyCols(key flux.GroupKey, builder TableBuilder) { for _, c := range key.Cols() { builder.AddCol(c) } @@ -94,7 +94,7 @@ func AddTableKeyCols(key query.GroupKey, builder TableBuilder) { // AddNewCols adds the columns of b onto builder that did not already exist. // Returns the mapping of builder cols to table cols. -func AddNewCols(t query.Table, builder TableBuilder) []int { +func AddNewCols(t flux.Table, builder TableBuilder) []int { cols := t.Cols() existing := builder.Cols() colMap := make([]int, len(existing)) @@ -117,12 +117,12 @@ func AddNewCols(t query.Table, builder TableBuilder) []int { // AppendMappedTable appends data from table t onto builder. // The colMap is a map of builder column index to table column index. -func AppendMappedTable(t query.Table, builder TableBuilder, colMap []int) { +func AppendMappedTable(t flux.Table, builder TableBuilder, colMap []int) { if len(t.Cols()) == 0 { return } - t.Do(func(cr query.ColReader) error { + t.Do(func(cr flux.ColReader) error { AppendMappedCols(cr, builder, colMap) return nil }) @@ -130,12 +130,12 @@ func AppendMappedTable(t query.Table, builder TableBuilder, colMap []int) { // AppendTable appends data from table t onto builder. // This function assumes builder and t have the same column schema. -func AppendTable(t query.Table, builder TableBuilder) { +func AppendTable(t flux.Table, builder TableBuilder) { if len(t.Cols()) == 0 { return } - t.Do(func(cr query.ColReader) error { + t.Do(func(cr flux.ColReader) error { AppendCols(cr, builder) return nil }) @@ -143,7 +143,7 @@ func AppendTable(t query.Table, builder TableBuilder) { // AppendMappedCols appends all columns from cr onto builder. // The colMap is a map of builder column index to cr column index. -func AppendMappedCols(cr query.ColReader, builder TableBuilder, colMap []int) { +func AppendMappedCols(cr flux.ColReader, builder TableBuilder, colMap []int) { for j := range builder.Cols() { AppendCol(j, colMap[j], cr, builder) } @@ -151,7 +151,7 @@ func AppendMappedCols(cr query.ColReader, builder TableBuilder, colMap []int) { // AppendCols appends all columns from cr onto builder. // This function assumes that builder and cr have the same column schema. -func AppendCols(cr query.ColReader, builder TableBuilder) { +func AppendCols(cr flux.ColReader, builder TableBuilder) { for j := range builder.Cols() { AppendCol(j, j, cr, builder) } @@ -159,20 +159,20 @@ func AppendCols(cr query.ColReader, builder TableBuilder) { // AppendCol append a column from cr onto builder // The indexes bj and cj are builder and col reader indexes respectively. -func AppendCol(bj, cj int, cr query.ColReader, builder TableBuilder) { +func AppendCol(bj, cj int, cr flux.ColReader, builder TableBuilder) { c := cr.Cols()[cj] switch c.Type { - case query.TBool: + case flux.TBool: builder.AppendBools(bj, cr.Bools(cj)) - case query.TInt: + case flux.TInt: builder.AppendInts(bj, cr.Ints(cj)) - case query.TUInt: + case flux.TUInt: builder.AppendUInts(bj, cr.UInts(cj)) - case query.TFloat: + case flux.TFloat: builder.AppendFloats(bj, cr.Floats(cj)) - case query.TString: + case flux.TString: builder.AppendStrings(bj, cr.Strings(cj)) - case query.TTime: + case flux.TTime: builder.AppendTimes(bj, cr.Times(cj)) default: PanicUnknownType(c.Type) @@ -180,20 +180,20 @@ func AppendCol(bj, cj int, cr query.ColReader, builder TableBuilder) { } // AppendRecord appends the record from cr onto builder assuming matching columns. -func AppendRecord(i int, cr query.ColReader, builder TableBuilder) { +func AppendRecord(i int, cr flux.ColReader, builder TableBuilder) { for j, c := range builder.Cols() { switch c.Type { - case query.TBool: + case flux.TBool: builder.AppendBool(j, cr.Bools(j)[i]) - case query.TInt: + case flux.TInt: builder.AppendInt(j, cr.Ints(j)[i]) - case query.TUInt: + case flux.TUInt: builder.AppendUInt(j, cr.UInts(j)[i]) - case query.TFloat: + case flux.TFloat: builder.AppendFloat(j, cr.Floats(j)[i]) - case query.TString: + case flux.TString: builder.AppendString(j, cr.Strings(j)[i]) - case query.TTime: + case flux.TTime: builder.AppendTime(j, cr.Times(j)[i]) default: PanicUnknownType(c.Type) @@ -202,20 +202,20 @@ func AppendRecord(i int, cr query.ColReader, builder TableBuilder) { } // AppendMappedRecord appends the records from cr onto builder, using colMap as a map of builder index to cr index. -func AppendMappedRecord(i int, cr query.ColReader, builder TableBuilder, colMap []int) { +func AppendMappedRecord(i int, cr flux.ColReader, builder TableBuilder, colMap []int) { for j, c := range builder.Cols() { switch c.Type { - case query.TBool: + case flux.TBool: builder.AppendBool(j, cr.Bools(colMap[j])[i]) - case query.TInt: + case flux.TInt: builder.AppendInt(j, cr.Ints(colMap[j])[i]) - case query.TUInt: + case flux.TUInt: builder.AppendUInt(j, cr.UInts(colMap[j])[i]) - case query.TFloat: + case flux.TFloat: builder.AppendFloat(j, cr.Floats(colMap[j])[i]) - case query.TString: + case flux.TString: builder.AppendString(j, cr.Strings(colMap[j])[i]) - case query.TTime: + case flux.TTime: builder.AppendTime(j, cr.Times(colMap[j])[i]) default: PanicUnknownType(c.Type) @@ -226,7 +226,7 @@ func AppendMappedRecord(i int, cr query.ColReader, builder TableBuilder, colMap // ColMap writes a mapping of builder index to column reader index into colMap. // When colMap does not have enough capacity a new colMap is allocated. // The colMap is always returned -func ColMap(colMap []int, builder TableBuilder, cr query.ColReader) []int { +func ColMap(colMap []int, builder TableBuilder, cr flux.ColReader) []int { l := len(builder.Cols()) if cap(colMap) < l { colMap = make([]int, len(builder.Cols())) @@ -241,20 +241,20 @@ func ColMap(colMap []int, builder TableBuilder, cr query.ColReader) []int { } // AppendRecordForCols appends the only the columns provided from cr onto builder. -func AppendRecordForCols(i int, cr query.ColReader, builder TableBuilder, cols []query.ColMeta) { +func AppendRecordForCols(i int, cr flux.ColReader, builder TableBuilder, cols []flux.ColMeta) { for j, c := range cols { switch c.Type { - case query.TBool: + case flux.TBool: builder.AppendBool(j, cr.Bools(j)[i]) - case query.TInt: + case flux.TInt: builder.AppendInt(j, cr.Ints(j)[i]) - case query.TUInt: + case flux.TUInt: builder.AppendUInt(j, cr.UInts(j)[i]) - case query.TFloat: + case flux.TFloat: builder.AppendFloat(j, cr.Floats(j)[i]) - case query.TString: + case flux.TString: builder.AppendString(j, cr.Strings(j)[i]) - case query.TTime: + case flux.TTime: builder.AppendTime(j, cr.Times(j)[i]) default: PanicUnknownType(c.Type) @@ -262,21 +262,21 @@ func AppendRecordForCols(i int, cr query.ColReader, builder TableBuilder, cols [ } } -func AppendKeyValues(key query.GroupKey, builder TableBuilder) { +func AppendKeyValues(key flux.GroupKey, builder TableBuilder) { for j, c := range key.Cols() { idx := ColIdx(c.Label, builder.Cols()) switch c.Type { - case query.TBool: + case flux.TBool: builder.AppendBool(idx, key.ValueBool(j)) - case query.TInt: + case flux.TInt: builder.AppendInt(idx, key.ValueInt(j)) - case query.TUInt: + case flux.TUInt: builder.AppendUInt(idx, key.ValueUInt(j)) - case query.TFloat: + case flux.TFloat: builder.AppendFloat(idx, key.ValueFloat(j)) - case query.TString: + case flux.TString: builder.AppendString(idx, key.ValueString(j)) - case query.TTime: + case flux.TTime: builder.AppendTime(idx, key.ValueTime(j)) default: PanicUnknownType(c.Type) @@ -293,7 +293,7 @@ func ContainsStr(strs []string, str string) bool { return false } -func ColIdx(label string, cols []query.ColMeta) int { +func ColIdx(label string, cols []flux.ColMeta) int { for j, c := range cols { if c.Label == label { return j @@ -301,21 +301,21 @@ func ColIdx(label string, cols []query.ColMeta) int { } return -1 } -func HasCol(label string, cols []query.ColMeta) bool { +func HasCol(label string, cols []flux.ColMeta) bool { return ColIdx(label, cols) >= 0 } // TableBuilder builds tables that can be used multiple times type TableBuilder interface { - Key() query.GroupKey + Key() flux.GroupKey NRows() int NCols() int - Cols() []query.ColMeta + Cols() []flux.ColMeta // AddCol increases the size of the table by one column. // The index of the column is returned. - AddCol(query.ColMeta) int + AddCol(flux.ColMeta) int // Set sets the value at the specified coordinates // The rows and columns must exist before calling set, otherwise Set panics. @@ -369,7 +369,7 @@ type TableBuilder interface { // Table returns the table that has been built. // Further modifications of the builder will not effect the returned table. - Table() (query.Table, error) + Table() (flux.Table, error) } type ColListTableBuilder struct { @@ -377,14 +377,14 @@ type ColListTableBuilder struct { alloc *Allocator } -func NewColListTableBuilder(key query.GroupKey, a *Allocator) *ColListTableBuilder { +func NewColListTableBuilder(key flux.GroupKey, a *Allocator) *ColListTableBuilder { return &ColListTableBuilder{ table: &ColListTable{key: key}, alloc: a, } } -func (b ColListTableBuilder) Key() query.GroupKey { +func (b ColListTableBuilder) Key() flux.GroupKey { return b.table.Key() } @@ -394,39 +394,39 @@ func (b ColListTableBuilder) NRows() int { func (b ColListTableBuilder) NCols() int { return len(b.table.cols) } -func (b ColListTableBuilder) Cols() []query.ColMeta { +func (b ColListTableBuilder) Cols() []flux.ColMeta { return b.table.colMeta } -func (b ColListTableBuilder) AddCol(c query.ColMeta) int { +func (b ColListTableBuilder) AddCol(c flux.ColMeta) int { var col column switch c.Type { - case query.TBool: + case flux.TBool: col = &boolColumn{ ColMeta: c, alloc: b.alloc, } - case query.TInt: + case flux.TInt: col = &intColumn{ ColMeta: c, alloc: b.alloc, } - case query.TUInt: + case flux.TUInt: col = &uintColumn{ ColMeta: c, alloc: b.alloc, } - case query.TFloat: + case flux.TFloat: col = &floatColumn{ ColMeta: c, alloc: b.alloc, } - case query.TString: + case flux.TString: col = &stringColumn{ ColMeta: c, alloc: b.alloc, } - case query.TTime: + case flux.TTime: col = &timeColumn{ ColMeta: c, alloc: b.alloc, @@ -440,139 +440,139 @@ func (b ColListTableBuilder) AddCol(c query.ColMeta) int { } func (b ColListTableBuilder) SetBool(i int, j int, value bool) { - b.checkColType(j, query.TBool) + b.checkColType(j, flux.TBool) b.table.cols[j].(*boolColumn).data[i] = value } func (b ColListTableBuilder) AppendBool(j int, value bool) { - b.checkColType(j, query.TBool) + b.checkColType(j, flux.TBool) col := b.table.cols[j].(*boolColumn) col.data = b.alloc.AppendBools(col.data, value) b.table.nrows = len(col.data) } func (b ColListTableBuilder) AppendBools(j int, values []bool) { - b.checkColType(j, query.TBool) + b.checkColType(j, flux.TBool) col := b.table.cols[j].(*boolColumn) col.data = b.alloc.AppendBools(col.data, values...) b.table.nrows = len(col.data) } func (b ColListTableBuilder) GrowBools(j, n int) { - b.checkColType(j, query.TBool) + b.checkColType(j, flux.TBool) col := b.table.cols[j].(*boolColumn) col.data = b.alloc.GrowBools(col.data, n) b.table.nrows = len(col.data) } func (b ColListTableBuilder) SetInt(i int, j int, value int64) { - b.checkColType(j, query.TInt) + b.checkColType(j, flux.TInt) b.table.cols[j].(*intColumn).data[i] = value } func (b ColListTableBuilder) AppendInt(j int, value int64) { - b.checkColType(j, query.TInt) + b.checkColType(j, flux.TInt) col := b.table.cols[j].(*intColumn) col.data = b.alloc.AppendInts(col.data, value) b.table.nrows = len(col.data) } func (b ColListTableBuilder) AppendInts(j int, values []int64) { - b.checkColType(j, query.TInt) + b.checkColType(j, flux.TInt) col := b.table.cols[j].(*intColumn) col.data = b.alloc.AppendInts(col.data, values...) b.table.nrows = len(col.data) } func (b ColListTableBuilder) GrowInts(j, n int) { - b.checkColType(j, query.TInt) + b.checkColType(j, flux.TInt) col := b.table.cols[j].(*intColumn) col.data = b.alloc.GrowInts(col.data, n) b.table.nrows = len(col.data) } func (b ColListTableBuilder) SetUInt(i int, j int, value uint64) { - b.checkColType(j, query.TUInt) + b.checkColType(j, flux.TUInt) b.table.cols[j].(*uintColumn).data[i] = value } func (b ColListTableBuilder) AppendUInt(j int, value uint64) { - b.checkColType(j, query.TUInt) + b.checkColType(j, flux.TUInt) col := b.table.cols[j].(*uintColumn) col.data = b.alloc.AppendUInts(col.data, value) b.table.nrows = len(col.data) } func (b ColListTableBuilder) AppendUInts(j int, values []uint64) { - b.checkColType(j, query.TUInt) + b.checkColType(j, flux.TUInt) col := b.table.cols[j].(*uintColumn) col.data = b.alloc.AppendUInts(col.data, values...) b.table.nrows = len(col.data) } func (b ColListTableBuilder) GrowUInts(j, n int) { - b.checkColType(j, query.TUInt) + b.checkColType(j, flux.TUInt) col := b.table.cols[j].(*uintColumn) col.data = b.alloc.GrowUInts(col.data, n) b.table.nrows = len(col.data) } func (b ColListTableBuilder) SetFloat(i int, j int, value float64) { - b.checkColType(j, query.TFloat) + b.checkColType(j, flux.TFloat) b.table.cols[j].(*floatColumn).data[i] = value } func (b ColListTableBuilder) AppendFloat(j int, value float64) { - b.checkColType(j, query.TFloat) + b.checkColType(j, flux.TFloat) col := b.table.cols[j].(*floatColumn) col.data = b.alloc.AppendFloats(col.data, value) b.table.nrows = len(col.data) } func (b ColListTableBuilder) AppendFloats(j int, values []float64) { - b.checkColType(j, query.TFloat) + b.checkColType(j, flux.TFloat) col := b.table.cols[j].(*floatColumn) col.data = b.alloc.AppendFloats(col.data, values...) b.table.nrows = len(col.data) } func (b ColListTableBuilder) GrowFloats(j, n int) { - b.checkColType(j, query.TFloat) + b.checkColType(j, flux.TFloat) col := b.table.cols[j].(*floatColumn) col.data = b.alloc.GrowFloats(col.data, n) b.table.nrows = len(col.data) } func (b ColListTableBuilder) SetString(i int, j int, value string) { - b.checkColType(j, query.TString) + b.checkColType(j, flux.TString) b.table.cols[j].(*stringColumn).data[i] = value } func (b ColListTableBuilder) AppendString(j int, value string) { meta := b.table.cols[j].Meta() - CheckColType(meta, query.TString) + CheckColType(meta, flux.TString) col := b.table.cols[j].(*stringColumn) col.data = b.alloc.AppendStrings(col.data, value) b.table.nrows = len(col.data) } func (b ColListTableBuilder) AppendStrings(j int, values []string) { - b.checkColType(j, query.TString) + b.checkColType(j, flux.TString) col := b.table.cols[j].(*stringColumn) col.data = b.alloc.AppendStrings(col.data, values...) b.table.nrows = len(col.data) } func (b ColListTableBuilder) GrowStrings(j, n int) { - b.checkColType(j, query.TString) + b.checkColType(j, flux.TString) col := b.table.cols[j].(*stringColumn) col.data = b.alloc.GrowStrings(col.data, n) b.table.nrows = len(col.data) } func (b ColListTableBuilder) SetTime(i int, j int, value Time) { - b.checkColType(j, query.TTime) + b.checkColType(j, flux.TTime) b.table.cols[j].(*timeColumn).data[i] = value } func (b ColListTableBuilder) AppendTime(j int, value Time) { - b.checkColType(j, query.TTime) + b.checkColType(j, flux.TTime) col := b.table.cols[j].(*timeColumn) col.data = b.alloc.AppendTimes(col.data, value) b.table.nrows = len(col.data) } func (b ColListTableBuilder) AppendTimes(j int, values []Time) { - b.checkColType(j, query.TTime) + b.checkColType(j, flux.TTime) col := b.table.cols[j].(*timeColumn) col.data = b.alloc.AppendTimes(col.data, values...) b.table.nrows = len(col.data) } func (b ColListTableBuilder) GrowTimes(j, n int) { - b.checkColType(j, query.TTime) + b.checkColType(j, flux.TTime) col := b.table.cols[j].(*timeColumn) col.data = b.alloc.GrowTimes(col.data, n) b.table.nrows = len(col.data) @@ -616,21 +616,21 @@ func (b ColListTableBuilder) AppendValue(j int, v values.Value) { } } -func (b ColListTableBuilder) checkColType(j int, typ query.DataType) { +func (b ColListTableBuilder) checkColType(j int, typ flux.DataType) { CheckColType(b.table.colMeta[j], typ) } -func CheckColType(col query.ColMeta, typ query.DataType) { +func CheckColType(col flux.ColMeta, typ flux.DataType) { if col.Type != typ { panic(fmt.Errorf("column %s is not of type %v", col.Label, typ)) } } -func PanicUnknownType(typ query.DataType) { +func PanicUnknownType(typ flux.DataType) { panic(fmt.Errorf("unknown type %v", typ)) } -func (b ColListTableBuilder) Table() (query.Table, error) { +func (b ColListTableBuilder) Table() (flux.Table, error) { // Create copy in mutable state return b.table.Copy(), nil } @@ -667,8 +667,8 @@ func (b ColListTableBuilder) Sort(cols []string, desc bool) { // All data for the table is stored in RAM. // As a result At* methods are provided directly on the table for easy access. type ColListTable struct { - key query.GroupKey - colMeta []query.ColMeta + key flux.GroupKey + colMeta []flux.ColMeta cols []column nrows int @@ -684,10 +684,10 @@ func (t *ColListTable) RefCount(n int) { } } -func (t *ColListTable) Key() query.GroupKey { +func (t *ColListTable) Key() flux.GroupKey { return t.key } -func (t *ColListTable) Cols() []query.ColMeta { +func (t *ColListTable) Cols() []flux.ColMeta { return t.colMeta } func (t *ColListTable) Empty() bool { @@ -701,33 +701,33 @@ func (t *ColListTable) Len() int { return t.nrows } -func (t *ColListTable) Do(f func(query.ColReader) error) error { +func (t *ColListTable) Do(f func(flux.ColReader) error) error { return f(t) } func (t *ColListTable) Bools(j int) []bool { - CheckColType(t.colMeta[j], query.TBool) + CheckColType(t.colMeta[j], flux.TBool) return t.cols[j].(*boolColumn).data } func (t *ColListTable) Ints(j int) []int64 { - CheckColType(t.colMeta[j], query.TInt) + CheckColType(t.colMeta[j], flux.TInt) return t.cols[j].(*intColumn).data } func (t *ColListTable) UInts(j int) []uint64 { - CheckColType(t.colMeta[j], query.TUInt) + CheckColType(t.colMeta[j], flux.TUInt) return t.cols[j].(*uintColumn).data } func (t *ColListTable) Floats(j int) []float64 { - CheckColType(t.colMeta[j], query.TFloat) + CheckColType(t.colMeta[j], flux.TFloat) return t.cols[j].(*floatColumn).data } func (t *ColListTable) Strings(j int) []string { meta := t.colMeta[j] - CheckColType(meta, query.TString) + CheckColType(meta, flux.TString) return t.cols[j].(*stringColumn).data } func (t *ColListTable) Times(j int) []Time { - CheckColType(t.colMeta[j], query.TTime) + CheckColType(t.colMeta[j], flux.TTime) return t.cols[j].(*timeColumn).data } @@ -736,7 +736,7 @@ func (t *ColListTable) Copy() *ColListTable { cpy.key = t.key cpy.nrows = t.nrows - cpy.colMeta = make([]query.ColMeta, len(t.colMeta)) + cpy.colMeta = make([]flux.ColMeta, len(t.colMeta)) copy(cpy.colMeta, t.colMeta) cpy.cols = make([]column, len(t.cols)) @@ -753,17 +753,17 @@ func (t *ColListTable) GetRow(row int) values.Object { var val values.Value for j, col := range t.colMeta { switch col.Type { - case query.TBool: + case flux.TBool: val = values.NewBoolValue(t.cols[j].(*boolColumn).data[row]) - case query.TInt: + case flux.TInt: val = values.NewIntValue(t.cols[j].(*intColumn).data[row]) - case query.TUInt: + case flux.TUInt: val = values.NewUIntValue(t.cols[j].(*uintColumn).data[row]) - case query.TFloat: + case flux.TFloat: val = values.NewFloatValue(t.cols[j].(*floatColumn).data[row]) - case query.TString: + case flux.TString: val = values.NewStringValue(t.cols[j].(*stringColumn).data[row]) - case query.TTime: + case flux.TTime: val = values.NewTimeValue(t.cols[j].(*timeColumn).data[row]) } record.Set(col.Label, val) @@ -801,7 +801,7 @@ func (c colListTableSorter) Swap(x int, y int) { } type column interface { - Meta() query.ColMeta + Meta() flux.ColMeta Clear() Copy() column Equal(i, j int) bool @@ -810,12 +810,12 @@ type column interface { } type boolColumn struct { - query.ColMeta + flux.ColMeta data []bool alloc *Allocator } -func (c *boolColumn) Meta() query.ColMeta { +func (c *boolColumn) Meta() flux.ColMeta { return c.ColMeta } @@ -847,12 +847,12 @@ func (c *boolColumn) Swap(i, j int) { } type intColumn struct { - query.ColMeta + flux.ColMeta data []int64 alloc *Allocator } -func (c *intColumn) Meta() query.ColMeta { +func (c *intColumn) Meta() flux.ColMeta { return c.ColMeta } @@ -881,12 +881,12 @@ func (c *intColumn) Swap(i, j int) { } type uintColumn struct { - query.ColMeta + flux.ColMeta data []uint64 alloc *Allocator } -func (c *uintColumn) Meta() query.ColMeta { +func (c *uintColumn) Meta() flux.ColMeta { return c.ColMeta } @@ -915,12 +915,12 @@ func (c *uintColumn) Swap(i, j int) { } type floatColumn struct { - query.ColMeta + flux.ColMeta data []float64 alloc *Allocator } -func (c *floatColumn) Meta() query.ColMeta { +func (c *floatColumn) Meta() flux.ColMeta { return c.ColMeta } @@ -949,12 +949,12 @@ func (c *floatColumn) Swap(i, j int) { } type stringColumn struct { - query.ColMeta + flux.ColMeta data []string alloc *Allocator } -func (c *stringColumn) Meta() query.ColMeta { +func (c *stringColumn) Meta() flux.ColMeta { return c.ColMeta } @@ -984,12 +984,12 @@ func (c *stringColumn) Swap(i, j int) { } type timeColumn struct { - query.ColMeta + flux.ColMeta data []Time alloc *Allocator } -func (c *timeColumn) Meta() query.ColMeta { +func (c *timeColumn) Meta() flux.ColMeta { return c.ColMeta } @@ -1020,15 +1020,15 @@ func (c *timeColumn) Swap(i, j int) { type TableBuilderCache interface { // TableBuilder returns an existing or new TableBuilder for the given meta data. // The boolean return value indicates if TableBuilder is new. - TableBuilder(key query.GroupKey) (TableBuilder, bool) - ForEachBuilder(f func(query.GroupKey, TableBuilder)) + TableBuilder(key flux.GroupKey) (TableBuilder, bool) + ForEachBuilder(f func(flux.GroupKey, TableBuilder)) } type tableBuilderCache struct { tables *GroupLookup alloc *Allocator - triggerSpec query.TriggerSpec + triggerSpec flux.TriggerSpec } func NewTableBuilderCache(a *Allocator) *tableBuilderCache { @@ -1043,11 +1043,11 @@ type tableState struct { trigger Trigger } -func (d *tableBuilderCache) SetTriggerSpec(ts query.TriggerSpec) { +func (d *tableBuilderCache) SetTriggerSpec(ts flux.TriggerSpec) { d.triggerSpec = ts } -func (d *tableBuilderCache) Table(key query.GroupKey) (query.Table, error) { +func (d *tableBuilderCache) Table(key flux.GroupKey) (flux.Table, error) { b, ok := d.lookupState(key) if !ok { return nil, fmt.Errorf("table not found with key %v", key) @@ -1055,7 +1055,7 @@ func (d *tableBuilderCache) Table(key query.GroupKey) (query.Table, error) { return b.builder.Table() } -func (d *tableBuilderCache) lookupState(key query.GroupKey) (tableState, bool) { +func (d *tableBuilderCache) lookupState(key flux.GroupKey) (tableState, bool) { v, ok := d.tables.Lookup(key) if !ok { return tableState{}, false @@ -1065,7 +1065,7 @@ func (d *tableBuilderCache) lookupState(key query.GroupKey) (tableState, bool) { // TableBuilder will return the builder for the specified table. // If no builder exists, one will be created. -func (d *tableBuilderCache) TableBuilder(key query.GroupKey) (TableBuilder, bool) { +func (d *tableBuilderCache) TableBuilder(key flux.GroupKey) (TableBuilder, bool) { b, ok := d.lookupState(key) if !ok { builder := NewColListTableBuilder(key, d.alloc) @@ -1079,34 +1079,34 @@ func (d *tableBuilderCache) TableBuilder(key query.GroupKey) (TableBuilder, bool return b.builder, !ok } -func (d *tableBuilderCache) ForEachBuilder(f func(query.GroupKey, TableBuilder)) { - d.tables.Range(func(key query.GroupKey, value interface{}) { +func (d *tableBuilderCache) ForEachBuilder(f func(flux.GroupKey, TableBuilder)) { + d.tables.Range(func(key flux.GroupKey, value interface{}) { f(key, value.(tableState).builder) }) } -func (d *tableBuilderCache) DiscardTable(key query.GroupKey) { +func (d *tableBuilderCache) DiscardTable(key flux.GroupKey) { b, ok := d.lookupState(key) if ok { b.builder.ClearData() } } -func (d *tableBuilderCache) ExpireTable(key query.GroupKey) { +func (d *tableBuilderCache) ExpireTable(key flux.GroupKey) { b, ok := d.tables.Delete(key) if ok { b.(tableState).builder.ClearData() } } -func (d *tableBuilderCache) ForEach(f func(query.GroupKey)) { - d.tables.Range(func(key query.GroupKey, value interface{}) { +func (d *tableBuilderCache) ForEach(f func(flux.GroupKey)) { + d.tables.Range(func(key flux.GroupKey, value interface{}) { f(key) }) } -func (d *tableBuilderCache) ForEachWithContext(f func(query.GroupKey, Trigger, TableContext)) { - d.tables.Range(func(key query.GroupKey, value interface{}) { +func (d *tableBuilderCache) ForEachWithContext(f func(flux.GroupKey, Trigger, TableContext)) { + d.tables.Range(func(key flux.GroupKey, value interface{}) { b := value.(tableState) f(key, b.trigger, TableContext{ Key: key, diff --git a/execute/transformation.go b/execute/transformation.go index 7e6c1613bc..057711f45f 100644 --- a/execute/transformation.go +++ b/execute/transformation.go @@ -3,14 +3,14 @@ package execute import ( "fmt" + "github.com/influxdata/flux" + "github.com/influxdata/flux/plan" "github.com/influxdata/platform" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/plan" ) type Transformation interface { - RetractTable(id DatasetID, key query.GroupKey) error - Process(id DatasetID, tbl query.Table) error + RetractTable(id DatasetID, key flux.GroupKey) error + Process(id DatasetID, tbl flux.Table) error UpdateWatermark(id DatasetID, t Time) error UpdateProcessingTime(id DatasetID, t Time) error Finish(id DatasetID, err error) @@ -25,7 +25,7 @@ type StreamContext interface { type Administration interface { OrganizationID() platform.ID - ResolveTime(qt query.Time) Time + ResolveTime(qt flux.Time) Time StreamContext() StreamContext Allocator() *Allocator Parents() []DatasetID diff --git a/execute/transport.go b/execute/transport.go index 7af07be110..75aad51b66 100644 --- a/execute/transport.go +++ b/execute/transport.go @@ -4,7 +4,7 @@ import ( "sync" "sync/atomic" - "github.com/influxdata/platform/query" + "github.com/influxdata/flux" ) type Transport interface { @@ -54,7 +54,7 @@ func (t *consecutiveTransport) Finished() <-chan struct{} { return t.finished } -func (t *consecutiveTransport) RetractTable(id DatasetID, key query.GroupKey) error { +func (t *consecutiveTransport) RetractTable(id DatasetID, key flux.GroupKey) error { select { case <-t.finished: return t.err() @@ -67,7 +67,7 @@ func (t *consecutiveTransport) RetractTable(id DatasetID, key query.GroupKey) er return nil } -func (t *consecutiveTransport) Process(id DatasetID, tbl query.Table) error { +func (t *consecutiveTransport) Process(id DatasetID, tbl flux.Table) error { select { case <-t.finished: return t.err() @@ -232,35 +232,35 @@ func (m srcMessage) SrcDatasetID() DatasetID { type RetractTableMsg interface { Message - Key() query.GroupKey + Key() flux.GroupKey } type retractTableMsg struct { srcMessage - key query.GroupKey + key flux.GroupKey } func (m *retractTableMsg) Type() MessageType { return RetractTableType } -func (m *retractTableMsg) Key() query.GroupKey { +func (m *retractTableMsg) Key() flux.GroupKey { return m.key } type ProcessMsg interface { Message - Table() query.Table + Table() flux.Table } type processMsg struct { srcMessage - table query.Table + table flux.Table } func (m *processMsg) Type() MessageType { return ProcessType } -func (m *processMsg) Table() query.Table { +func (m *processMsg) Table() flux.Table { return m.table } diff --git a/execute/trigger.go b/execute/trigger.go index ab5d947e18..cc90323603 100644 --- a/execute/trigger.go +++ b/execute/trigger.go @@ -3,7 +3,7 @@ package execute import ( "fmt" - "github.com/influxdata/platform/query" + "github.com/influxdata/flux" ) type Trigger interface { @@ -19,29 +19,29 @@ type TriggerContext struct { } type TableContext struct { - Key query.GroupKey + Key flux.GroupKey Count int } -func NewTriggerFromSpec(spec query.TriggerSpec) Trigger { +func NewTriggerFromSpec(spec flux.TriggerSpec) Trigger { switch s := spec.(type) { - case query.AfterWatermarkTriggerSpec: + case flux.AfterWatermarkTriggerSpec: return &afterWatermarkTrigger{ allowedLateness: Duration(s.AllowedLateness), } - case query.RepeatedTriggerSpec: + case flux.RepeatedTriggerSpec: return &repeatedlyForever{ t: NewTriggerFromSpec(s.Trigger), } - case query.AfterProcessingTimeTriggerSpec: + case flux.AfterProcessingTimeTriggerSpec: return &afterProcessingTimeTrigger{ duration: Duration(s.Duration), } - case query.AfterAtLeastCountTriggerSpec: + case flux.AfterAtLeastCountTriggerSpec: return &afterAtLeastCount{ atLeast: s.Count, } - case query.OrFinallyTriggerSpec: + case flux.OrFinallyTriggerSpec: return &orFinally{ main: NewTriggerFromSpec(s.Main), finally: NewTriggerFromSpec(s.Finally), diff --git a/querytest/README.md b/fluxtest/README.md similarity index 100% rename from querytest/README.md rename to fluxtest/README.md diff --git a/querytest/compile.go b/fluxtest/compile.go similarity index 84% rename from querytest/compile.go rename to fluxtest/compile.go index 5295ed31fd..2198b73f5f 100644 --- a/querytest/compile.go +++ b/fluxtest/compile.go @@ -1,23 +1,24 @@ -package querytest +package fluxtest import ( "context" "testing" "time" + "fmt" + "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/semantic/semantictest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/functions" + "github.com/influxdata/flux/semantic/semantictest" "github.com/influxdata/platform" - "fmt" ) type NewQueryTestCase struct { Name string Raw string - Want *query.Spec + Want *flux.Spec WantErr bool WantReadBuckets *[]platform.BucketFilter WantWriteBuckets *[]platform.BucketFilter @@ -25,9 +26,9 @@ type NewQueryTestCase struct { var opts = append( semantictest.CmpOptions, - cmp.AllowUnexported(query.Spec{}), + cmp.AllowUnexported(flux.Spec{}), cmp.AllowUnexported(functions.JoinOpSpec{}), - cmpopts.IgnoreUnexported(query.Spec{}), + cmpopts.IgnoreUnexported(flux.Spec{}), cmpopts.IgnoreUnexported(functions.JoinOpSpec{}), ) @@ -35,7 +36,7 @@ func NewQueryTestHelper(t *testing.T, tc NewQueryTestCase) { t.Helper() now := time.Now().UTC() - got, err := query.Compile(context.Background(), tc.Raw, now) + got, err := flux.Compile(context.Background(), tc.Raw, now) if (err != nil) != tc.WantErr { t.Errorf("query.NewQuery() error = %v, wantErr %v", err, tc.WantErr) return diff --git a/querytest/compiler.go b/fluxtest/compiler.go similarity index 65% rename from querytest/compiler.go rename to fluxtest/compiler.go index dd5a83ae73..6936cc3535 100644 --- a/querytest/compiler.go +++ b/fluxtest/compiler.go @@ -1,18 +1,18 @@ -package querytest +package fluxtest import ( "context" - "github.com/influxdata/platform/query" + "github.com/influxdata/flux" ) // FromCSVCompiler wraps a compiler and replaces all From operations with FromCSV type FromCSVCompiler struct { - query.Compiler + flux.Compiler InputFile string } -func (c FromCSVCompiler) Compile(ctx context.Context) (*query.Spec, error) { +func (c FromCSVCompiler) Compile(ctx context.Context) (*flux.Spec, error) { spec, err := c.Compiler.Compile(ctx) if err != nil { return nil, err diff --git a/fluxtest/doc.go b/fluxtest/doc.go new file mode 100644 index 0000000000..fd3b89b8f5 --- /dev/null +++ b/fluxtest/doc.go @@ -0,0 +1,2 @@ +// Package fluxtest contains utilities for testing the query end-to-end. +package fluxtest diff --git a/querytest/execute.go b/fluxtest/execute.go similarity index 55% rename from querytest/execute.go rename to fluxtest/execute.go index 2dfa815ee3..0a1b11bce4 100644 --- a/querytest/execute.go +++ b/fluxtest/execute.go @@ -1,12 +1,12 @@ -package querytest +package fluxtest import ( "math" + "github.com/influxdata/flux" + "github.com/influxdata/flux/control" + "github.com/influxdata/flux/functions" "github.com/influxdata/platform" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/control" - "github.com/influxdata/platform/query/functions" ) var ( @@ -17,7 +17,7 @@ func init() { staticResultID.DecodeFromString("1") } -func GetProxyQueryServiceBridge() query.ProxyQueryServiceBridge { +func GetProxyQueryServiceBridge() flux.ProxyQueryServiceBridge { config := control.Config{ ConcurrencyQuota: 1, MemoryBytesQuota: math.MaxInt64, @@ -25,14 +25,14 @@ func GetProxyQueryServiceBridge() query.ProxyQueryServiceBridge { c := control.New(config) - return query.ProxyQueryServiceBridge{ - QueryService: query.QueryServiceBridge{ + return flux.ProxyQueryServiceBridge{ + QueryService: flux.QueryServiceBridge{ AsyncQueryService: c, }, } } -func ReplaceFromSpec(q *query.Spec, csvSrc string) { +func ReplaceFromSpec(q *flux.Spec, csvSrc string) { for _, op := range q.Operations { if op.Spec.Kind() == functions.FromKind { op.Spec = &functions.FromCSVOpSpec{ diff --git a/querytest/operations.go b/fluxtest/operations.go similarity index 78% rename from querytest/operations.go rename to fluxtest/operations.go index 66ef85a8c9..db4c9ec1e0 100644 --- a/querytest/operations.go +++ b/fluxtest/operations.go @@ -1,4 +1,4 @@ -package querytest +package fluxtest import ( "encoding/json" @@ -6,12 +6,12 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/semantic/semantictest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/functions" + "github.com/influxdata/flux/semantic/semantictest" ) -func OperationMarshalingTestHelper(t *testing.T, data []byte, expOp *query.Operation) { +func OperationMarshalingTestHelper(t *testing.T, data []byte, expOp *flux.Operation) { t.Helper() opts := append( @@ -21,7 +21,7 @@ func OperationMarshalingTestHelper(t *testing.T, data []byte, expOp *query.Opera ) // Ensure we can properly unmarshal a spec - gotOp := new(query.Operation) + gotOp := new(flux.Operation) if err := json.Unmarshal(data, gotOp); err != nil { t.Fatal(err) } @@ -34,7 +34,7 @@ func OperationMarshalingTestHelper(t *testing.T, data []byte, expOp *query.Opera if err != nil { t.Fatal(err) } - gotOp = new(query.Operation) + gotOp = new(flux.Operation) if err := json.Unmarshal(data, gotOp); err != nil { t.Fatal(err) } diff --git a/format.go b/format.go index fcbd7a8ff5..767acc7dc8 100644 --- a/format.go +++ b/format.go @@ -1,4 +1,4 @@ -package query +package flux import ( "encoding/json" diff --git a/functions/compspecs/compspecs.go b/functions/compspecs/compspecs.go deleted file mode 100644 index 3142bf98f3..0000000000 --- a/functions/compspecs/compspecs.go +++ /dev/null @@ -1,114 +0,0 @@ -package main - -import ( - "context" - "fmt" - "io/ioutil" - "os" - "path/filepath" - "regexp" - "strings" - "time" - - "github.com/google/go-cmp/cmp/cmpopts" - "github.com/influxdata/platform" - "github.com/influxdata/platform/mock" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/influxql" - "github.com/influxdata/platform/query/semantic/semantictest" - - "github.com/google/go-cmp/cmp" - "golang.org/x/text/unicode/norm" -) - -func normalizeString(s string) []byte { - result := norm.NFC.String(strings.TrimSpace(s)) - re := regexp.MustCompile(`\r?\n`) - return []byte(re.ReplaceAllString(result, "\r\n")) -} - -func printUsage() { - fmt.Println("usage: prepcsvtests /path/to/testfiles [testname]") -} - -func main() { - fnames := make([]string, 0) - path := "" - var err error - if len(os.Args) == 3 { - path = os.Args[1] - fnames = append(fnames, filepath.Join(path, os.Args[2])+".flux") - } else if len(os.Args) == 2 { - path = os.Args[1] - fnames, err = filepath.Glob(filepath.Join(path, "*.flux")) - if err != nil { - return - } - } else { - printUsage() - return - } - - for _, fname := range fnames { - ext := ".flux" - testName := fname[0 : len(fname)-len(ext)] - - fluxText, err := ioutil.ReadFile(fname) - if err != nil { - fmt.Printf("error reading ifq l query text: %s", err) - return - } - - influxqlText, err := ioutil.ReadFile(testName + ".influxql") - if err != nil { - fmt.Printf("error reading influxql query text: %s", err) - return - } - - fluxSpec, err := query.Compile(context.Background(), string(fluxText), time.Now().UTC()) - if err != nil { - fmt.Printf("error compiling. \n query: \n %s \n err: %s", string(fluxText), err) - return - } - - transpiler := influxql.NewTranspiler(dbrpMappingSvc) - influxqlSpec, err := transpiler.Transpile(context.Background(), string(influxqlText)) - if err != nil { - fmt.Printf("error transpiling. \n query: \n %s \n err: %s", string(influxqlText), err) - return - } - var opts = append( - semantictest.CmpOptions, - cmp.AllowUnexported(query.Spec{}), - cmpopts.IgnoreUnexported(query.Spec{})) - - difference := cmp.Diff(fluxSpec, influxqlSpec, opts...) - - fmt.Printf("compiled vs transpiled diff: \n%s", difference) - } -} - -// Setup mock DBRPMappingService to always return `db.rp`. -var dbrpMappingSvc = mock.NewDBRPMappingService() - -func init() { - organizationID := platform.ID("aaaa") - bucketID := platform.ID("bbbb") - mapping := platform.DBRPMapping{ - Cluster: "cluster", - Database: "db", - RetentionPolicy: "rp", - Default: true, - OrganizationID: organizationID, - BucketID: bucketID, - } - dbrpMappingSvc.FindByFn = func(ctx context.Context, cluster string, db string, rp string) (*platform.DBRPMapping, error) { - return &mapping, nil - } - dbrpMappingSvc.FindFn = func(ctx context.Context, filter platform.DBRPMappingFilter) (*platform.DBRPMapping, error) { - return &mapping, nil - } - dbrpMappingSvc.FindManyFn = func(ctx context.Context, filter platform.DBRPMappingFilter, opt ...platform.FindOptions) ([]*platform.DBRPMapping, int, error) { - return []*platform.DBRPMapping{&mapping}, 1, nil - } -} diff --git a/functions/count.go b/functions/count.go index 64e7449b8a..72a18f2f34 100644 --- a/functions/count.go +++ b/functions/count.go @@ -3,9 +3,9 @@ package functions import ( "fmt" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/plan" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/plan" ) const CountKind = "count" @@ -17,13 +17,13 @@ type CountOpSpec struct { var countSignature = execute.DefaultAggregateSignature() func init() { - query.RegisterFunction(CountKind, createCountOpSpec, countSignature) - query.RegisterOpSpec(CountKind, newCountOp) + flux.RegisterFunction(CountKind, createCountOpSpec, countSignature) + flux.RegisterOpSpec(CountKind, newCountOp) plan.RegisterProcedureSpec(CountKind, newCountProcedure, CountKind) execute.RegisterTransformation(CountKind, createCountTransformation) } -func createCountOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createCountOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -34,11 +34,11 @@ func createCountOpSpec(args query.Arguments, a *query.Administration) (query.Ope return s, nil } -func newCountOp() query.OperationSpec { +func newCountOp() flux.OperationSpec { return new(CountOpSpec) } -func (s *CountOpSpec) Kind() query.OperationKind { +func (s *CountOpSpec) Kind() flux.OperationKind { return CountKind } @@ -46,7 +46,7 @@ type CountProcedureSpec struct { execute.AggregateConfig } -func newCountProcedure(qs query.OperationSpec, a plan.Administration) (plan.ProcedureSpec, error) { +func newCountProcedure(qs flux.OperationSpec, a plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*CountOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -143,8 +143,8 @@ func (a *CountAgg) DoString(vs []string) { a.count += int64(len(vs)) } -func (a *CountAgg) Type() query.DataType { - return query.TInt +func (a *CountAgg) Type() flux.DataType { + return flux.TInt } func (a *CountAgg) ValueInt() int64 { return a.count diff --git a/functions/count_test.go b/functions/count_test.go index a994d6746f..da945f3ccb 100644 --- a/functions/count_test.go +++ b/functions/count_test.go @@ -4,22 +4,22 @@ import ( "testing" "time" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/plan/plantest" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/plan/plantest" ) func TestCount_NewQuery(t *testing.T) { - tests := []querytest.NewQueryTestCase{ + tests := []fluxtest.NewQueryTestCase{ { Name: "from with range and count", Raw: `from(bucket:"mydb") |> range(start:-4h, stop:-2h) |> count()`, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "from0", Spec: &functions.FromOpSpec{ @@ -29,11 +29,11 @@ func TestCount_NewQuery(t *testing.T) { { ID: "range1", Spec: &functions.RangeOpSpec{ - Start: query.Time{ + Start: flux.Time{ Relative: -4 * time.Hour, IsRelative: true, }, - Stop: query.Time{ + Stop: flux.Time{ Relative: -2 * time.Hour, IsRelative: true, }, @@ -49,7 +49,7 @@ func TestCount_NewQuery(t *testing.T) { }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "from0", Child: "range1"}, {Parent: "range1", Child: "count2"}, }, @@ -60,19 +60,19 @@ func TestCount_NewQuery(t *testing.T) { tc := tc t.Run(tc.Name, func(t *testing.T) { t.Parallel() - querytest.NewQueryTestHelper(t, tc) + fluxtest.NewQueryTestHelper(t, tc) }) } } func TestCountOperation_Marshaling(t *testing.T) { data := []byte(`{"id":"count","kind":"count"}`) - op := &query.Operation{ + op := &flux.Operation{ ID: "count", Spec: &functions.CountOpSpec{}, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestCount_Process(t *testing.T) { diff --git a/functions/covariance.go b/functions/covariance.go index b3686d6f4d..46285ecebb 100644 --- a/functions/covariance.go +++ b/functions/covariance.go @@ -4,10 +4,10 @@ import ( "fmt" "math" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" "github.com/pkg/errors" ) @@ -25,9 +25,9 @@ func init() { covarianceSignature.Params["pearsonr"] = semantic.Bool covarianceSignature.Params["valueDst"] = semantic.String - query.RegisterBuiltIn("covariance", covarianceBuiltIn) - query.RegisterFunction(CovarianceKind, createCovarianceOpSpec, covarianceSignature) - query.RegisterOpSpec(CovarianceKind, newCovarianceOp) + flux.RegisterBuiltIn("covariance", covarianceBuiltIn) + flux.RegisterFunction(CovarianceKind, createCovarianceOpSpec, covarianceSignature) + flux.RegisterOpSpec(CovarianceKind, newCovarianceOp) plan.RegisterProcedureSpec(CovarianceKind, newCovarianceProcedure, CovarianceKind) execute.RegisterTransformation(CovarianceKind, createCovarianceTransformation) } @@ -44,7 +44,7 @@ cov = (x,y,on,pearsonr=false) => pearsonr = (x,y,on) => cov(x:x, y:y, on:on, pearsonr:true) ` -func createCovarianceOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createCovarianceOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -75,11 +75,11 @@ func createCovarianceOpSpec(args query.Arguments, a *query.Administration) (quer return spec, nil } -func newCovarianceOp() query.OperationSpec { +func newCovarianceOp() flux.OperationSpec { return new(CovarianceOpSpec) } -func (s *CovarianceOpSpec) Kind() query.OperationKind { +func (s *CovarianceOpSpec) Kind() flux.OperationKind { return CovarianceKind } @@ -89,7 +89,7 @@ type CovarianceProcedureSpec struct { execute.AggregateConfig } -func newCovarianceProcedure(qs query.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { +func newCovarianceProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*CovarianceOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -150,24 +150,24 @@ func NewCovarianceTransformation(d execute.Dataset, cache execute.TableBuilderCa } } -func (t *CovarianceTransformation) RetractTable(id execute.DatasetID, key query.GroupKey) error { +func (t *CovarianceTransformation) RetractTable(id execute.DatasetID, key flux.GroupKey) error { return t.d.RetractTable(key) } -func (t *CovarianceTransformation) Process(id execute.DatasetID, tbl query.Table) error { +func (t *CovarianceTransformation) Process(id execute.DatasetID, tbl flux.Table) error { cols := tbl.Cols() builder, created := t.cache.TableBuilder(tbl.Key()) if !created { return fmt.Errorf("covariance found duplicate table with key: %v", tbl.Key()) } execute.AddTableKeyCols(tbl.Key(), builder) - builder.AddCol(query.ColMeta{ + builder.AddCol(flux.ColMeta{ Label: t.spec.TimeDst, - Type: query.TTime, + Type: flux.TTime, }) - valueIdx := builder.AddCol(query.ColMeta{ + valueIdx := builder.AddCol(flux.ColMeta{ Label: t.spec.ValueLabel, - Type: query.TFloat, + Type: flux.TFloat, }) xIdx := execute.ColIdx(t.spec.Columns[0], cols) yIdx := execute.ColIdx(t.spec.Columns[1], cols) @@ -180,9 +180,9 @@ func (t *CovarianceTransformation) Process(id execute.DatasetID, tbl query.Table } t.reset() - tbl.Do(func(cr query.ColReader) error { + tbl.Do(func(cr flux.ColReader) error { switch typ := cols[xIdx].Type; typ { - case query.TFloat: + case flux.TFloat: t.DoFloat(cr.Floats(xIdx), cr.Floats(yIdx)) default: return fmt.Errorf("covariance does not support %v", typ) diff --git a/functions/covariance_test.go b/functions/covariance_test.go index 94b6f0e336..7345e07e9a 100644 --- a/functions/covariance_test.go +++ b/functions/covariance_test.go @@ -3,20 +3,20 @@ package functions_test import ( "testing" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" ) func TestCovariance_NewQuery(t *testing.T) { - tests := []querytest.NewQueryTestCase{ + tests := []fluxtest.NewQueryTestCase{ { Name: "simple covariance", Raw: `from(bucket:"mybucket") |> covariance(columns:["a","b"],)`, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "from0", Spec: &functions.FromOpSpec{ @@ -35,7 +35,7 @@ func TestCovariance_NewQuery(t *testing.T) { }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "from0", Child: "covariance1"}, }, }, @@ -43,8 +43,8 @@ func TestCovariance_NewQuery(t *testing.T) { { Name: "pearsonr", Raw: `from(bucket:"mybucket")|>covariance(columns:["a","b"],pearsonr:true)`, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "from0", Spec: &functions.FromOpSpec{ @@ -64,7 +64,7 @@ func TestCovariance_NewQuery(t *testing.T) { }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "from0", Child: "covariance1"}, }, }, @@ -72,8 +72,8 @@ func TestCovariance_NewQuery(t *testing.T) { { Name: "global covariance", Raw: `cov(x: from(bucket:"mybucket"), y:from(bucket:"mybucket"), on:["host"], pearsonr:true)`, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "from0", Spec: &functions.FromOpSpec{ @@ -90,7 +90,7 @@ func TestCovariance_NewQuery(t *testing.T) { ID: "join2", Spec: &functions.JoinOpSpec{ On: []string{"host"}, - TableNames: map[query.OperationID]string{ + TableNames: map[flux.OperationID]string{ "from0": "x", "from1": "y", }, @@ -110,7 +110,7 @@ func TestCovariance_NewQuery(t *testing.T) { }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "from0", Child: "join2"}, {Parent: "from1", Child: "join2"}, {Parent: "join2", Child: "covariance3"}, @@ -122,7 +122,7 @@ func TestCovariance_NewQuery(t *testing.T) { tc := tc t.Run(tc.Name, func(t *testing.T) { t.Parallel() - querytest.NewQueryTestHelper(t, tc) + fluxtest.NewQueryTestHelper(t, tc) }) } } @@ -135,20 +135,20 @@ func TestCovarianceOperation_Marshaling(t *testing.T) { "pearsonr":true } }`) - op := &query.Operation{ + op := &flux.Operation{ ID: "covariance", Spec: &functions.CovarianceOpSpec{ PearsonCorrelation: true, }, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestCovariance_Process(t *testing.T) { testCases := []struct { name string spec *functions.CovarianceProcedureSpec - data []query.Table + data []flux.Table want []*executetest.Table }{ { @@ -161,14 +161,14 @@ func TestCovariance_Process(t *testing.T) { Columns: []string{"x", "y"}, }, }, - data: []query.Table{&executetest.Table{ + data: []flux.Table{&executetest.Table{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "x", Type: query.TFloat}, - {Label: "y", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "x", Type: flux.TFloat}, + {Label: "y", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(5), execute.Time(0), 1.0, 1.0}, @@ -180,11 +180,11 @@ func TestCovariance_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(5), execute.Time(5), 2.5}, @@ -201,14 +201,14 @@ func TestCovariance_Process(t *testing.T) { Columns: []string{"x", "y"}, }, }, - data: []query.Table{&executetest.Table{ + data: []flux.Table{&executetest.Table{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "x", Type: query.TFloat}, - {Label: "y", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "x", Type: flux.TFloat}, + {Label: "y", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(5), execute.Time(0), 1.0, 5.0}, @@ -220,11 +220,11 @@ func TestCovariance_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(5), execute.Time(5), -2.5}, @@ -241,14 +241,14 @@ func TestCovariance_Process(t *testing.T) { Columns: []string{"x", "y"}, }, }, - data: []query.Table{&executetest.Table{ + data: []flux.Table{&executetest.Table{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "x", Type: query.TFloat}, - {Label: "y", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "x", Type: flux.TFloat}, + {Label: "y", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(5), execute.Time(0), 1.0, 1.0}, @@ -260,11 +260,11 @@ func TestCovariance_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(5), execute.Time(5), 0.5}, @@ -282,14 +282,14 @@ func TestCovariance_Process(t *testing.T) { Columns: []string{"x", "y"}, }, }, - data: []query.Table{&executetest.Table{ + data: []flux.Table{&executetest.Table{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "x", Type: query.TFloat}, - {Label: "y", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "x", Type: flux.TFloat}, + {Label: "y", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(5), execute.Time(0), 1.0, 1.0}, @@ -301,11 +301,11 @@ func TestCovariance_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(5), execute.Time(5), 1.0}, @@ -323,14 +323,14 @@ func TestCovariance_Process(t *testing.T) { Columns: []string{"x", "y"}, }, }, - data: []query.Table{&executetest.Table{ + data: []flux.Table{&executetest.Table{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "x", Type: query.TFloat}, - {Label: "y", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "x", Type: flux.TFloat}, + {Label: "y", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(5), execute.Time(0), 1.0, 5.0}, @@ -342,11 +342,11 @@ func TestCovariance_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(5), execute.Time(5), -1.0}, diff --git a/functions/cumulative_sum.go b/functions/cumulative_sum.go index fa416322e6..a9c5787ceb 100644 --- a/functions/cumulative_sum.go +++ b/functions/cumulative_sum.go @@ -3,11 +3,11 @@ package functions import ( "fmt" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/interpreter" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/interpreter" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" ) const CumulativeSumKind = "cumulativeSum" @@ -16,18 +16,18 @@ type CumulativeSumOpSpec struct { Columns []string `json:"columns"` } -var cumulativeSumSignature = query.DefaultFunctionSignature() +var cumulativeSumSignature = flux.DefaultFunctionSignature() func init() { cumulativeSumSignature.Params["columns"] = semantic.NewArrayType(semantic.String) - query.RegisterFunction(CumulativeSumKind, createCumulativeSumOpSpec, cumulativeSumSignature) - query.RegisterOpSpec(CumulativeSumKind, newCumulativeSumOp) + flux.RegisterFunction(CumulativeSumKind, createCumulativeSumOpSpec, cumulativeSumSignature) + flux.RegisterOpSpec(CumulativeSumKind, newCumulativeSumOp) plan.RegisterProcedureSpec(CumulativeSumKind, newCumulativeSumProcedure, CumulativeSumKind) execute.RegisterTransformation(CumulativeSumKind, createCumulativeSumTransformation) } -func createCumulativeSumOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createCumulativeSumOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -47,11 +47,11 @@ func createCumulativeSumOpSpec(args query.Arguments, a *query.Administration) (q return spec, nil } -func newCumulativeSumOp() query.OperationSpec { +func newCumulativeSumOp() flux.OperationSpec { return new(CumulativeSumOpSpec) } -func (s *CumulativeSumOpSpec) Kind() query.OperationKind { +func (s *CumulativeSumOpSpec) Kind() flux.OperationKind { return CumulativeSumKind } @@ -59,7 +59,7 @@ type CumulativeSumProcedureSpec struct { Columns []string } -func newCumulativeSumProcedure(qs query.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { +func newCumulativeSumProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*CumulativeSumOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -108,11 +108,11 @@ func NewCumulativeSumTransformation(d execute.Dataset, cache execute.TableBuilde } } -func (t *cumulativeSumTransformation) RetractTable(id execute.DatasetID, key query.GroupKey) error { +func (t *cumulativeSumTransformation) RetractTable(id execute.DatasetID, key flux.GroupKey) error { return t.d.RetractTable(key) } -func (t *cumulativeSumTransformation) Process(id execute.DatasetID, tbl query.Table) error { +func (t *cumulativeSumTransformation) Process(id execute.DatasetID, tbl flux.Table) error { builder, created := t.cache.TableBuilder(tbl.Key()) if !created { return fmt.Errorf("cumulative sum found duplicate table with key: %v", tbl.Key()) @@ -129,13 +129,13 @@ func (t *cumulativeSumTransformation) Process(id execute.DatasetID, tbl query.Ta } } } - return tbl.Do(func(cr query.ColReader) error { + return tbl.Do(func(cr flux.ColReader) error { l := cr.Len() for j, c := range cols { switch c.Type { - case query.TBool: + case flux.TBool: builder.AppendBools(j, cr.Bools(j)) - case query.TInt: + case flux.TInt: if sumers[j] != nil { for i := 0; i < l; i++ { builder.AppendInt(j, sumers[j].sumInt(cr.Ints(j)[i])) @@ -143,7 +143,7 @@ func (t *cumulativeSumTransformation) Process(id execute.DatasetID, tbl query.Ta } else { builder.AppendInts(j, cr.Ints(j)) } - case query.TUInt: + case flux.TUInt: if sumers[j] != nil { for i := 0; i < l; i++ { builder.AppendUInt(j, sumers[j].sumUInt(cr.UInts(j)[i])) @@ -151,7 +151,7 @@ func (t *cumulativeSumTransformation) Process(id execute.DatasetID, tbl query.Ta } else { builder.AppendUInts(j, cr.UInts(j)) } - case query.TFloat: + case flux.TFloat: if sumers[j] != nil { for i := 0; i < l; i++ { builder.AppendFloat(j, sumers[j].sumFloat(cr.Floats(j)[i])) @@ -159,9 +159,9 @@ func (t *cumulativeSumTransformation) Process(id execute.DatasetID, tbl query.Ta } else { builder.AppendFloats(j, cr.Floats(j)) } - case query.TString: + case flux.TString: builder.AppendStrings(j, cr.Strings(j)) - case query.TTime: + case flux.TTime: builder.AppendTimes(j, cr.Times(j)) } } diff --git a/functions/cumulative_sum_test.go b/functions/cumulative_sum_test.go index 054136030e..2436851ea8 100644 --- a/functions/cumulative_sum_test.go +++ b/functions/cumulative_sum_test.go @@ -3,20 +3,20 @@ package functions_test import ( "testing" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" ) func TestCumulativeSumOperation_Marshaling(t *testing.T) { data := []byte(`{"id":"cumulativeSum","kind":"cumulativeSum","spec":{}}`) - op := &query.Operation{ + op := &flux.Operation{ ID: "cumulativeSum", Spec: &functions.CumulativeSumOpSpec{}, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestCumulativeSum_PassThrough(t *testing.T) { @@ -34,7 +34,7 @@ func TestCumulativeSum_Process(t *testing.T) { testCases := []struct { name string spec *functions.CumulativeSumProcedureSpec - data []query.Table + data []flux.Table want []*executetest.Table }{ { @@ -42,10 +42,10 @@ func TestCumulativeSum_Process(t *testing.T) { spec: &functions.CumulativeSumProcedureSpec{ Columns: []string{execute.DefaultValueColLabel}, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), 2.0}, @@ -61,9 +61,9 @@ func TestCumulativeSum_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), 2.0}, @@ -84,12 +84,12 @@ func TestCumulativeSum_Process(t *testing.T) { spec: &functions.CumulativeSumProcedureSpec{ Columns: []string{"int", "uint", "float"}, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "int", Type: query.TInt}, - {Label: "uint", Type: query.TUInt}, - {Label: "float", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "int", Type: flux.TInt}, + {Label: "uint", Type: flux.TUInt}, + {Label: "float", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), int64(2), uint64(1), 1.0}, @@ -105,11 +105,11 @@ func TestCumulativeSum_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "int", Type: query.TInt}, - {Label: "uint", Type: query.TUInt}, - {Label: "float", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "int", Type: flux.TInt}, + {Label: "uint", Type: flux.TUInt}, + {Label: "float", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), int64(2), uint64(1), 1.0}, @@ -130,12 +130,12 @@ func TestCumulativeSum_Process(t *testing.T) { spec: &functions.CumulativeSumProcedureSpec{ Columns: []string{"int", "float"}, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "time2", Type: query.TTime}, - {Label: "int", Type: query.TInt}, - {Label: "float", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "time2", Type: flux.TTime}, + {Label: "int", Type: flux.TInt}, + {Label: "float", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(0), int64(2), 1.0}, @@ -151,11 +151,11 @@ func TestCumulativeSum_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "time2", Type: query.TTime}, - {Label: "int", Type: query.TInt}, - {Label: "float", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "time2", Type: flux.TTime}, + {Label: "int", Type: flux.TInt}, + {Label: "float", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(0), int64(2), 1.0}, @@ -176,11 +176,11 @@ func TestCumulativeSum_Process(t *testing.T) { spec: &functions.CumulativeSumProcedureSpec{ Columns: []string{"int"}, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "int", Type: query.TInt}, - {Label: "t", Type: query.TString}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "int", Type: flux.TInt}, + {Label: "t", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(0), int64(2), "tag0"}, @@ -196,10 +196,10 @@ func TestCumulativeSum_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "int", Type: query.TInt}, - {Label: "t", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "int", Type: flux.TInt}, + {Label: "t", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(0), int64(2), "tag0"}, diff --git a/functions/data_test.go b/functions/data_test.go index bd78312533..aaad7c249f 100644 --- a/functions/data_test.go +++ b/functions/data_test.go @@ -5,11 +5,11 @@ import ( "time" "github.com/gonum/stat/distuv" - "github.com/influxdata/platform/query" - _ "github.com/influxdata/platform/query/builtin" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux" + _ "github.com/influxdata/flux/builtin" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/values" ) const ( @@ -24,7 +24,7 @@ const ( var NormalData []float64 // NormalTable is a table of data whose value col is NormalData. -var NormalTable query.Table +var NormalTable flux.Table func init() { dist := distuv.Normal{ @@ -40,10 +40,10 @@ func init() { stop := execute.Time(time.Date(2017, 10, 10, 0, 0, 0, 0, time.UTC).UnixNano()) t1Value := "a" key := execute.NewGroupKey( - []query.ColMeta{ - {Label: execute.DefaultStartColLabel, Type: query.TTime}, - {Label: execute.DefaultStopColLabel, Type: query.TTime}, - {Label: "t1", Type: query.TString}, + []flux.ColMeta{ + {Label: execute.DefaultStartColLabel, Type: flux.TTime}, + {Label: execute.DefaultStopColLabel, Type: flux.TTime}, + {Label: "t1", Type: flux.TString}, }, []values.Value{ values.NewTimeValue(start), @@ -53,12 +53,12 @@ func init() { ) normalTableBuilder := execute.NewColListTableBuilder(key, executetest.UnlimitedAllocator) - normalTableBuilder.AddCol(query.ColMeta{Label: execute.DefaultTimeColLabel, Type: query.TTime}) - normalTableBuilder.AddCol(query.ColMeta{Label: execute.DefaultStartColLabel, Type: query.TTime}) - normalTableBuilder.AddCol(query.ColMeta{Label: execute.DefaultStopColLabel, Type: query.TTime}) - normalTableBuilder.AddCol(query.ColMeta{Label: execute.DefaultValueColLabel, Type: query.TFloat}) - normalTableBuilder.AddCol(query.ColMeta{Label: "t1", Type: query.TString}) - normalTableBuilder.AddCol(query.ColMeta{Label: "t2", Type: query.TString}) + normalTableBuilder.AddCol(flux.ColMeta{Label: execute.DefaultTimeColLabel, Type: flux.TTime}) + normalTableBuilder.AddCol(flux.ColMeta{Label: execute.DefaultStartColLabel, Type: flux.TTime}) + normalTableBuilder.AddCol(flux.ColMeta{Label: execute.DefaultStopColLabel, Type: flux.TTime}) + normalTableBuilder.AddCol(flux.ColMeta{Label: execute.DefaultValueColLabel, Type: flux.TFloat}) + normalTableBuilder.AddCol(flux.ColMeta{Label: "t1", Type: flux.TString}) + normalTableBuilder.AddCol(flux.ColMeta{Label: "t2", Type: flux.TString}) times := make([]execute.Time, N) startTimes := make([]execute.Time, N) diff --git a/functions/derivative.go b/functions/derivative.go index d11a581987..aec0281a60 100644 --- a/functions/derivative.go +++ b/functions/derivative.go @@ -5,23 +5,23 @@ import ( "math" "time" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/interpreter" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/interpreter" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" ) const DerivativeKind = "derivative" type DerivativeOpSpec struct { - Unit query.Duration `json:"unit"` - NonNegative bool `json:"nonNegative"` - Columns []string `json:"columns"` - TimeSrc string `json:"timeSrc"` + Unit flux.Duration `json:"unit"` + NonNegative bool `json:"nonNegative"` + Columns []string `json:"columns"` + TimeSrc string `json:"timeSrc"` } -var derivativeSignature = query.DefaultFunctionSignature() +var derivativeSignature = flux.DefaultFunctionSignature() func init() { derivativeSignature.Params["unit"] = semantic.Duration @@ -29,13 +29,13 @@ func init() { derivativeSignature.Params["columns"] = semantic.NewArrayType(semantic.String) derivativeSignature.Params["timeSrc"] = semantic.String - query.RegisterFunction(DerivativeKind, createDerivativeOpSpec, derivativeSignature) - query.RegisterOpSpec(DerivativeKind, newDerivativeOp) + flux.RegisterFunction(DerivativeKind, createDerivativeOpSpec, derivativeSignature) + flux.RegisterOpSpec(DerivativeKind, newDerivativeOp) plan.RegisterProcedureSpec(DerivativeKind, newDerivativeProcedure, DerivativeKind) execute.RegisterTransformation(DerivativeKind, createDerivativeTransformation) } -func createDerivativeOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createDerivativeOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -48,7 +48,7 @@ func createDerivativeOpSpec(args query.Arguments, a *query.Administration) (quer spec.Unit = unit } else { //Default is 1s - spec.Unit = query.Duration(time.Second) + spec.Unit = flux.Duration(time.Second) } if nn, ok, err := args.GetBool("nonNegative"); err != nil { @@ -78,22 +78,22 @@ func createDerivativeOpSpec(args query.Arguments, a *query.Administration) (quer return spec, nil } -func newDerivativeOp() query.OperationSpec { +func newDerivativeOp() flux.OperationSpec { return new(DerivativeOpSpec) } -func (s *DerivativeOpSpec) Kind() query.OperationKind { +func (s *DerivativeOpSpec) Kind() flux.OperationKind { return DerivativeKind } type DerivativeProcedureSpec struct { - Unit query.Duration `json:"unit"` - NonNegative bool `json:"non_negative"` - Columns []string `json:"columns"` - TimeCol string `json:"time_col"` + Unit flux.Duration `json:"unit"` + NonNegative bool `json:"non_negative"` + Columns []string `json:"columns"` + TimeCol string `json:"time_col"` } -func newDerivativeProcedure(qs query.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { +func newDerivativeProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*DerivativeOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -152,11 +152,11 @@ func NewDerivativeTransformation(d execute.Dataset, cache execute.TableBuilderCa } } -func (t *derivativeTransformation) RetractTable(id execute.DatasetID, key query.GroupKey) error { +func (t *derivativeTransformation) RetractTable(id execute.DatasetID, key flux.GroupKey) error { return t.d.RetractTable(key) } -func (t *derivativeTransformation) Process(id execute.DatasetID, tbl query.Table) error { +func (t *derivativeTransformation) Process(id execute.DatasetID, tbl flux.Table) error { builder, created := t.cache.TableBuilder(tbl.Key()) if !created { return fmt.Errorf("derivative found duplicate table with key: %v", tbl.Key()) @@ -179,7 +179,7 @@ func (t *derivativeTransformation) Process(id execute.DatasetID, tbl query.Table if found { dc := c // Derivative always results in a float - dc.Type = query.TFloat + dc.Type = flux.TFloat builder.AddCol(dc) derivatives[j] = newDerivative(j, t.unit, t.nonNegative) } else { @@ -192,14 +192,14 @@ func (t *derivativeTransformation) Process(id execute.DatasetID, tbl query.Table // We need to drop the first row since its derivative is undefined firstIdx := 1 - return tbl.Do(func(cr query.ColReader) error { + return tbl.Do(func(cr flux.ColReader) error { l := cr.Len() for j, c := range cols { d := derivatives[j] switch c.Type { - case query.TBool: + case flux.TBool: builder.AppendBools(j, cr.Bools(j)[firstIdx:]) - case query.TInt: + case flux.TInt: if d != nil { for i := 0; i < l; i++ { time := cr.Times(timeIdx)[i] @@ -211,7 +211,7 @@ func (t *derivativeTransformation) Process(id execute.DatasetID, tbl query.Table } else { builder.AppendInts(j, cr.Ints(j)[firstIdx:]) } - case query.TUInt: + case flux.TUInt: if d != nil { for i := 0; i < l; i++ { time := cr.Times(timeIdx)[i] @@ -223,7 +223,7 @@ func (t *derivativeTransformation) Process(id execute.DatasetID, tbl query.Table } else { builder.AppendUInts(j, cr.UInts(j)[firstIdx:]) } - case query.TFloat: + case flux.TFloat: if d != nil { for i := 0; i < l; i++ { time := cr.Times(timeIdx)[i] @@ -235,9 +235,9 @@ func (t *derivativeTransformation) Process(id execute.DatasetID, tbl query.Table } else { builder.AppendFloats(j, cr.Floats(j)[firstIdx:]) } - case query.TString: + case flux.TString: builder.AppendStrings(j, cr.Strings(j)[firstIdx:]) - case query.TTime: + case flux.TTime: builder.AppendTimes(j, cr.Times(j)[firstIdx:]) } } diff --git a/functions/derivative_test.go b/functions/derivative_test.go index 802eedfd70..8b7985a868 100644 --- a/functions/derivative_test.go +++ b/functions/derivative_test.go @@ -4,23 +4,23 @@ import ( "testing" "time" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" ) func TestDerivativeOperation_Marshaling(t *testing.T) { data := []byte(`{"id":"derivative","kind":"derivative","spec":{"unit":"1m","nonNegative":true}}`) - op := &query.Operation{ + op := &flux.Operation{ ID: "derivative", Spec: &functions.DerivativeOpSpec{ - Unit: query.Duration(time.Minute), + Unit: flux.Duration(time.Minute), NonNegative: true, }, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestDerivative_PassThrough(t *testing.T) { @@ -38,7 +38,7 @@ func TestDerivative_Process(t *testing.T) { testCases := []struct { name string spec *functions.DerivativeProcedureSpec - data []query.Table + data []flux.Table want []*executetest.Table }{ { @@ -48,10 +48,10 @@ func TestDerivative_Process(t *testing.T) { TimeCol: execute.DefaultTimeColLabel, Unit: 1, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 2.0}, @@ -59,9 +59,9 @@ func TestDerivative_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(2), -1.0}, @@ -73,12 +73,12 @@ func TestDerivative_Process(t *testing.T) { spec: &functions.DerivativeProcedureSpec{ Columns: []string{execute.DefaultValueColLabel}, TimeCol: execute.DefaultTimeColLabel, - Unit: query.Duration(time.Second), + Unit: flux.Duration(time.Second), }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1 * time.Second), 2.0}, @@ -86,9 +86,9 @@ func TestDerivative_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(3 * time.Second), -0.5}, @@ -102,10 +102,10 @@ func TestDerivative_Process(t *testing.T) { TimeCol: execute.DefaultTimeColLabel, Unit: 1, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TInt}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TInt}, }, Data: [][]interface{}{ {execute.Time(1), int64(20)}, @@ -113,9 +113,9 @@ func TestDerivative_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(2), -10.0}, @@ -127,12 +127,12 @@ func TestDerivative_Process(t *testing.T) { spec: &functions.DerivativeProcedureSpec{ Columns: []string{execute.DefaultValueColLabel}, TimeCol: execute.DefaultTimeColLabel, - Unit: query.Duration(time.Second), + Unit: flux.Duration(time.Second), }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TInt}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TInt}, }, Data: [][]interface{}{ {execute.Time(1 * time.Second), int64(20)}, @@ -140,9 +140,9 @@ func TestDerivative_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(3 * time.Second), -5.0}, @@ -157,10 +157,10 @@ func TestDerivative_Process(t *testing.T) { Unit: 1, NonNegative: true, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TInt}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TInt}, }, Data: [][]interface{}{ {execute.Time(1), int64(20)}, @@ -169,9 +169,9 @@ func TestDerivative_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(2), 10.0}, @@ -186,10 +186,10 @@ func TestDerivative_Process(t *testing.T) { TimeCol: execute.DefaultTimeColLabel, Unit: 1, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TUInt}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TUInt}, }, Data: [][]interface{}{ {execute.Time(1), uint64(10)}, @@ -197,9 +197,9 @@ func TestDerivative_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(2), 10.0}, @@ -213,10 +213,10 @@ func TestDerivative_Process(t *testing.T) { TimeCol: execute.DefaultTimeColLabel, Unit: 1, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TUInt}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TUInt}, }, Data: [][]interface{}{ {execute.Time(1), uint64(20)}, @@ -224,9 +224,9 @@ func TestDerivative_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(2), -10.0}, @@ -241,10 +241,10 @@ func TestDerivative_Process(t *testing.T) { Unit: 1, NonNegative: true, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TUInt}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TUInt}, }, Data: [][]interface{}{ {execute.Time(1), uint64(20)}, @@ -253,9 +253,9 @@ func TestDerivative_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(2), 10.0}, @@ -268,12 +268,12 @@ func TestDerivative_Process(t *testing.T) { spec: &functions.DerivativeProcedureSpec{ Columns: []string{execute.DefaultValueColLabel}, TimeCol: execute.DefaultTimeColLabel, - Unit: query.Duration(time.Second), + Unit: flux.Duration(time.Second), }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TUInt}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TUInt}, }, Data: [][]interface{}{ {execute.Time(1 * time.Second), uint64(20)}, @@ -281,9 +281,9 @@ func TestDerivative_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(3 * time.Second), -5.0}, @@ -298,10 +298,10 @@ func TestDerivative_Process(t *testing.T) { Unit: 1, NonNegative: true, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 2.0}, @@ -310,9 +310,9 @@ func TestDerivative_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(2), 1.0}, @@ -327,11 +327,11 @@ func TestDerivative_Process(t *testing.T) { TimeCol: execute.DefaultTimeColLabel, Unit: 1, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t", Type: query.TString}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 2.0, "a"}, @@ -339,10 +339,10 @@ func TestDerivative_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(2), -1.0, "b"}, @@ -356,11 +356,11 @@ func TestDerivative_Process(t *testing.T) { TimeCol: execute.DefaultTimeColLabel, Unit: 1, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "x", Type: query.TFloat}, - {Label: "y", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "x", Type: flux.TFloat}, + {Label: "y", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 2.0, 20.0}, @@ -368,10 +368,10 @@ func TestDerivative_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "x", Type: query.TFloat}, - {Label: "y", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "x", Type: flux.TFloat}, + {Label: "y", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(2), -1.0, -10.0}, @@ -386,11 +386,11 @@ func TestDerivative_Process(t *testing.T) { Unit: 1, NonNegative: true, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "x", Type: query.TFloat}, - {Label: "y", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "x", Type: flux.TFloat}, + {Label: "y", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 2.0, 20.0}, @@ -399,10 +399,10 @@ func TestDerivative_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "x", Type: query.TFloat}, - {Label: "y", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "x", Type: flux.TFloat}, + {Label: "y", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(2), 1.0, 10.0}, diff --git a/functions/difference.go b/functions/difference.go index ce2b020992..906d9ba2bd 100644 --- a/functions/difference.go +++ b/functions/difference.go @@ -4,11 +4,11 @@ import ( "fmt" "math" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/interpreter" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/interpreter" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" ) const DifferenceKind = "difference" @@ -18,19 +18,19 @@ type DifferenceOpSpec struct { Columns []string `json:"columns"` } -var differenceSignature = query.DefaultFunctionSignature() +var differenceSignature = flux.DefaultFunctionSignature() func init() { differenceSignature.Params["nonNegative"] = semantic.Bool derivativeSignature.Params["columns"] = semantic.NewArrayType(semantic.String) - query.RegisterFunction(DifferenceKind, createDifferenceOpSpec, differenceSignature) - query.RegisterOpSpec(DifferenceKind, newDifferenceOp) + flux.RegisterFunction(DifferenceKind, createDifferenceOpSpec, differenceSignature) + flux.RegisterOpSpec(DifferenceKind, newDifferenceOp) plan.RegisterProcedureSpec(DifferenceKind, newDifferenceProcedure, DifferenceKind) execute.RegisterTransformation(DifferenceKind, createDifferenceTransformation) } -func createDifferenceOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createDifferenceOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -63,11 +63,11 @@ func createDifferenceOpSpec(args query.Arguments, a *query.Administration) (quer return spec, nil } -func newDifferenceOp() query.OperationSpec { +func newDifferenceOp() flux.OperationSpec { return new(DifferenceOpSpec) } -func (s *DifferenceOpSpec) Kind() query.OperationKind { +func (s *DifferenceOpSpec) Kind() flux.OperationKind { return DifferenceKind } @@ -76,7 +76,7 @@ type DifferenceProcedureSpec struct { Columns []string `json:"columns"` } -func newDifferenceProcedure(qs query.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { +func newDifferenceProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*DifferenceOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -129,11 +129,11 @@ func NewDifferenceTransformation(d execute.Dataset, cache execute.TableBuilderCa } } -func (t *differenceTransformation) RetractTable(id execute.DatasetID, key query.GroupKey) error { +func (t *differenceTransformation) RetractTable(id execute.DatasetID, key flux.GroupKey) error { return t.d.RetractTable(key) } -func (t *differenceTransformation) Process(id execute.DatasetID, tbl query.Table) error { +func (t *differenceTransformation) Process(id execute.DatasetID, tbl flux.Table) error { builder, created := t.cache.TableBuilder(tbl.Key()) if !created { return fmt.Errorf("difference found duplicate table with key: %v", tbl.Key()) @@ -150,14 +150,14 @@ func (t *differenceTransformation) Process(id execute.DatasetID, tbl query.Table } if found { - var typ query.DataType + var typ flux.DataType switch c.Type { - case query.TInt, query.TUInt: - typ = query.TInt - case query.TFloat: - typ = query.TFloat + case flux.TInt, flux.TUInt: + typ = flux.TInt + case flux.TFloat: + typ = flux.TFloat } - builder.AddCol(query.ColMeta{ + builder.AddCol(flux.ColMeta{ Label: c.Label, Type: typ, }) @@ -169,16 +169,16 @@ func (t *differenceTransformation) Process(id execute.DatasetID, tbl query.Table // We need to drop the first row since its derivative is undefined firstIdx := 1 - return tbl.Do(func(cr query.ColReader) error { + return tbl.Do(func(cr flux.ColReader) error { l := cr.Len() if l != 0 { for j, c := range cols { d := differences[j] switch c.Type { - case query.TBool: + case flux.TBool: builder.AppendBools(j, cr.Bools(j)[firstIdx:]) - case query.TInt: + case flux.TInt: if d != nil { for i := 0; i < l; i++ { v := d.updateInt(cr.Ints(j)[i]) @@ -189,7 +189,7 @@ func (t *differenceTransformation) Process(id execute.DatasetID, tbl query.Table } else { builder.AppendInts(j, cr.Ints(j)[firstIdx:]) } - case query.TUInt: + case flux.TUInt: if d != nil { for i := 0; i < l; i++ { v := d.updateUInt(cr.UInts(j)[i]) @@ -200,7 +200,7 @@ func (t *differenceTransformation) Process(id execute.DatasetID, tbl query.Table } else { builder.AppendUInts(j, cr.UInts(j)[firstIdx:]) } - case query.TFloat: + case flux.TFloat: if d != nil { for i := 0; i < l; i++ { v := d.updateFloat(cr.Floats(j)[i]) @@ -211,9 +211,9 @@ func (t *differenceTransformation) Process(id execute.DatasetID, tbl query.Table } else { builder.AppendFloats(j, cr.Floats(j)[firstIdx:]) } - case query.TString: + case flux.TString: builder.AppendStrings(j, cr.Strings(j)[firstIdx:]) - case query.TTime: + case flux.TTime: builder.AppendTimes(j, cr.Times(j)[firstIdx:]) } } @@ -266,7 +266,7 @@ func (d *difference) updateInt(v int64) int64 { if d.nonNegative && diff < 0 { //TODO(nathanielc): Return null when we have null support - // Also see https://github.com/influxdata/platform/query/issues/217 + // Also see https://github.com/influxdata/flux/issues/217 return v } @@ -291,7 +291,7 @@ func (d *difference) updateUInt(v uint64) int64 { if d.nonNegative && diff < 0 { //TODO(nathanielc): Return null when we have null support - // Also see https://github.com/influxdata/platform/query/issues/217 + // Also see https://github.com/influxdata/flux/issues/217 return int64(v) } @@ -309,7 +309,7 @@ func (d *difference) updateFloat(v float64) float64 { if d.nonNegative && diff < 0 { //TODO(nathanielc): Return null when we have null support - // Also see https://github.com/influxdata/platform/query/issues/217 + // Also see https://github.com/influxdata/flux/issues/217 return v } diff --git a/functions/difference_test.go b/functions/difference_test.go index 79b199b9b5..e495acb417 100644 --- a/functions/difference_test.go +++ b/functions/difference_test.go @@ -3,22 +3,22 @@ package functions_test import ( "testing" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" ) func TestDifferenceOperation_Marshaling(t *testing.T) { data := []byte(`{"id":"difference","kind":"difference","spec":{"nonNegative":true}}`) - op := &query.Operation{ + op := &flux.Operation{ ID: "difference", Spec: &functions.DifferenceOpSpec{ NonNegative: true, }, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestDifference_PassThrough(t *testing.T) { @@ -36,7 +36,7 @@ func TestDifference_Process(t *testing.T) { testCases := []struct { name string spec *functions.DifferenceProcedureSpec - data []query.Table + data []flux.Table want []*executetest.Table }{ { @@ -44,10 +44,10 @@ func TestDifference_Process(t *testing.T) { spec: &functions.DifferenceProcedureSpec{ Columns: []string{execute.DefaultValueColLabel}, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 2.0}, @@ -55,9 +55,9 @@ func TestDifference_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(2), -1.0}, @@ -69,10 +69,10 @@ func TestDifference_Process(t *testing.T) { spec: &functions.DifferenceProcedureSpec{ Columns: []string{execute.DefaultValueColLabel}, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TInt}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TInt}, }, Data: [][]interface{}{ {execute.Time(1), int64(20)}, @@ -80,9 +80,9 @@ func TestDifference_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TInt}, }, Data: [][]interface{}{ {execute.Time(2), int64(-10)}, @@ -95,10 +95,10 @@ func TestDifference_Process(t *testing.T) { Columns: []string{execute.DefaultValueColLabel}, NonNegative: true, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TInt}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TInt}, }, Data: [][]interface{}{ {execute.Time(1), int64(20)}, @@ -107,9 +107,9 @@ func TestDifference_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TInt}, }, Data: [][]interface{}{ {execute.Time(2), int64(10)}, @@ -122,10 +122,10 @@ func TestDifference_Process(t *testing.T) { spec: &functions.DifferenceProcedureSpec{ Columns: []string{execute.DefaultValueColLabel}, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TUInt}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TUInt}, }, Data: [][]interface{}{ {execute.Time(1), uint64(10)}, @@ -133,9 +133,9 @@ func TestDifference_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TInt}, }, Data: [][]interface{}{ {execute.Time(2), int64(10)}, @@ -147,10 +147,10 @@ func TestDifference_Process(t *testing.T) { spec: &functions.DifferenceProcedureSpec{ Columns: []string{execute.DefaultValueColLabel}, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TUInt}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TUInt}, }, Data: [][]interface{}{ {execute.Time(1), uint64(20)}, @@ -158,9 +158,9 @@ func TestDifference_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TInt}, }, Data: [][]interface{}{ {execute.Time(2), int64(-10)}, @@ -173,10 +173,10 @@ func TestDifference_Process(t *testing.T) { Columns: []string{execute.DefaultValueColLabel}, NonNegative: true, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TUInt}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TUInt}, }, Data: [][]interface{}{ {execute.Time(1), uint64(20)}, @@ -185,9 +185,9 @@ func TestDifference_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TInt}, }, Data: [][]interface{}{ {execute.Time(2), int64(10)}, @@ -201,10 +201,10 @@ func TestDifference_Process(t *testing.T) { Columns: []string{execute.DefaultValueColLabel}, NonNegative: true, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 2.0}, @@ -213,9 +213,9 @@ func TestDifference_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(2), 1.0}, @@ -228,11 +228,11 @@ func TestDifference_Process(t *testing.T) { spec: &functions.DifferenceProcedureSpec{ Columns: []string{execute.DefaultValueColLabel}, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t", Type: query.TString}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 2.0, "a"}, @@ -240,10 +240,10 @@ func TestDifference_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(2), -1.0, "b"}, @@ -255,11 +255,11 @@ func TestDifference_Process(t *testing.T) { spec: &functions.DifferenceProcedureSpec{ Columns: []string{"x", "y"}, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "x", Type: query.TFloat}, - {Label: "y", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "x", Type: flux.TFloat}, + {Label: "y", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 2.0, 20.0}, @@ -267,10 +267,10 @@ func TestDifference_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "x", Type: query.TFloat}, - {Label: "y", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "x", Type: flux.TFloat}, + {Label: "y", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(2), -1.0, -10.0}, @@ -283,11 +283,11 @@ func TestDifference_Process(t *testing.T) { Columns: []string{"x", "y"}, NonNegative: true, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "x", Type: query.TFloat}, - {Label: "y", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "x", Type: flux.TFloat}, + {Label: "y", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 2.0, 20.0}, @@ -296,10 +296,10 @@ func TestDifference_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "x", Type: query.TFloat}, - {Label: "y", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "x", Type: flux.TFloat}, + {Label: "y", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(2), 1.0, 10.0}, @@ -313,19 +313,19 @@ func TestDifference_Process(t *testing.T) { Columns: []string{"x", "y"}, NonNegative: true, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "x", Type: query.TFloat}, - {Label: "y", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "x", Type: flux.TFloat}, + {Label: "y", Type: flux.TFloat}, }, Data: [][]interface{}{}, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "x", Type: query.TFloat}, - {Label: "y", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "x", Type: flux.TFloat}, + {Label: "y", Type: flux.TFloat}, }, Data: [][]interface{}(nil), }}, @@ -336,21 +336,21 @@ func TestDifference_Process(t *testing.T) { Columns: []string{"x", "y"}, NonNegative: true, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "x", Type: query.TFloat}, - {Label: "y", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "x", Type: flux.TFloat}, + {Label: "y", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(3), 10.0, 20.0}, }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "x", Type: query.TFloat}, - {Label: "y", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "x", Type: flux.TFloat}, + {Label: "y", Type: flux.TFloat}, }, Data: [][]interface{}(nil), }}, diff --git a/functions/distinct.go b/functions/distinct.go index 4bdb99a133..eb7aa8969d 100644 --- a/functions/distinct.go +++ b/functions/distinct.go @@ -3,10 +3,10 @@ package functions import ( "fmt" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" ) const DistinctKind = "distinct" @@ -15,19 +15,19 @@ type DistinctOpSpec struct { Column string `json:"column"` } -var distinctSignature = query.DefaultFunctionSignature() +var distinctSignature = flux.DefaultFunctionSignature() func init() { distinctSignature.Params["column"] = semantic.String - query.RegisterFunction(DistinctKind, createDistinctOpSpec, distinctSignature) - query.RegisterOpSpec(DistinctKind, newDistinctOp) + flux.RegisterFunction(DistinctKind, createDistinctOpSpec, distinctSignature) + flux.RegisterOpSpec(DistinctKind, newDistinctOp) plan.RegisterProcedureSpec(DistinctKind, newDistinctProcedure, DistinctKind) plan.RegisterRewriteRule(DistinctPointLimitRewriteRule{}) execute.RegisterTransformation(DistinctKind, createDistinctTransformation) } -func createDistinctOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createDistinctOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -45,11 +45,11 @@ func createDistinctOpSpec(args query.Arguments, a *query.Administration) (query. return spec, nil } -func newDistinctOp() query.OperationSpec { +func newDistinctOp() flux.OperationSpec { return new(DistinctOpSpec) } -func (s *DistinctOpSpec) Kind() query.OperationKind { +func (s *DistinctOpSpec) Kind() flux.OperationKind { return DistinctKind } @@ -57,7 +57,7 @@ type DistinctProcedureSpec struct { Column string } -func newDistinctProcedure(qs query.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { +func newDistinctProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*DistinctOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -140,11 +140,11 @@ func NewDistinctTransformation(d execute.Dataset, cache execute.TableBuilderCach } } -func (t *distinctTransformation) RetractTable(id execute.DatasetID, key query.GroupKey) error { +func (t *distinctTransformation) RetractTable(id execute.DatasetID, key flux.GroupKey) error { return t.d.RetractTable(key) } -func (t *distinctTransformation) Process(id execute.DatasetID, tbl query.Table) error { +func (t *distinctTransformation) Process(id execute.DatasetID, tbl flux.Table) error { builder, created := t.cache.TableBuilder(tbl.Key()) if !created { return fmt.Errorf("distinct found duplicate table with key: %v", tbl.Key()) @@ -154,14 +154,14 @@ func (t *distinctTransformation) Process(id execute.DatasetID, tbl query.Table) if colIdx < 0 { // doesn't exist in this table, so add an empty value execute.AddTableKeyCols(tbl.Key(), builder) - colIdx = builder.AddCol(query.ColMeta{ + colIdx = builder.AddCol(flux.ColMeta{ Label: execute.DefaultValueColLabel, - Type: query.TString, + Type: flux.TString, }) builder.AppendString(colIdx, "") execute.AppendKeyValues(tbl.Key(), builder) // TODO: hack required to ensure data flows downstream - return tbl.Do(func(query.ColReader) error { + return tbl.Do(func(flux.ColReader) error { return nil }) } @@ -169,7 +169,7 @@ func (t *distinctTransformation) Process(id execute.DatasetID, tbl query.Table) col := tbl.Cols()[colIdx] execute.AddTableKeyCols(tbl.Key(), builder) - colIdx = builder.AddCol(query.ColMeta{ + colIdx = builder.AddCol(flux.ColMeta{ Label: execute.DefaultValueColLabel, Type: col.Type, }) @@ -177,23 +177,23 @@ func (t *distinctTransformation) Process(id execute.DatasetID, tbl query.Table) if tbl.Key().HasCol(t.column) { j := execute.ColIdx(t.column, tbl.Key().Cols()) switch col.Type { - case query.TBool: + case flux.TBool: builder.AppendBool(colIdx, tbl.Key().ValueBool(j)) - case query.TInt: + case flux.TInt: builder.AppendInt(colIdx, tbl.Key().ValueInt(j)) - case query.TUInt: + case flux.TUInt: builder.AppendUInt(colIdx, tbl.Key().ValueUInt(j)) - case query.TFloat: + case flux.TFloat: builder.AppendFloat(colIdx, tbl.Key().ValueFloat(j)) - case query.TString: + case flux.TString: builder.AppendString(colIdx, tbl.Key().ValueString(j)) - case query.TTime: + case flux.TTime: builder.AppendTime(colIdx, tbl.Key().ValueTime(j)) } execute.AppendKeyValues(tbl.Key(), builder) // TODO: hack required to ensure data flows downstream - return tbl.Do(func(query.ColReader) error { + return tbl.Do(func(flux.ColReader) error { return nil }) } @@ -207,61 +207,61 @@ func (t *distinctTransformation) Process(id execute.DatasetID, tbl query.Table) timeDistinct map[execute.Time]bool ) switch col.Type { - case query.TBool: + case flux.TBool: boolDistinct = make(map[bool]bool) - case query.TInt: + case flux.TInt: intDistinct = make(map[int64]bool) - case query.TUInt: + case flux.TUInt: uintDistinct = make(map[uint64]bool) - case query.TFloat: + case flux.TFloat: floatDistinct = make(map[float64]bool) - case query.TString: + case flux.TString: stringDistinct = make(map[string]bool) - case query.TTime: + case flux.TTime: timeDistinct = make(map[execute.Time]bool) } - return tbl.Do(func(cr query.ColReader) error { + return tbl.Do(func(cr flux.ColReader) error { l := cr.Len() for i := 0; i < l; i++ { // Check distinct switch col.Type { - case query.TBool: + case flux.TBool: v := cr.Bools(colIdx)[i] if boolDistinct[v] { continue } boolDistinct[v] = true builder.AppendBool(colIdx, v) - case query.TInt: + case flux.TInt: v := cr.Ints(colIdx)[i] if intDistinct[v] { continue } intDistinct[v] = true builder.AppendInt(colIdx, v) - case query.TUInt: + case flux.TUInt: v := cr.UInts(colIdx)[i] if uintDistinct[v] { continue } uintDistinct[v] = true builder.AppendUInt(colIdx, v) - case query.TFloat: + case flux.TFloat: v := cr.Floats(colIdx)[i] if floatDistinct[v] { continue } floatDistinct[v] = true builder.AppendFloat(colIdx, v) - case query.TString: + case flux.TString: v := cr.Strings(colIdx)[i] if stringDistinct[v] { continue } stringDistinct[v] = true builder.AppendString(colIdx, v) - case query.TTime: + case flux.TTime: v := cr.Times(colIdx)[i] if timeDistinct[v] { continue diff --git a/functions/doc.go b/functions/doc.go index ab161fe1dc..b9a7486ef3 100644 --- a/functions/doc.go +++ b/functions/doc.go @@ -18,13 +18,13 @@ The plan phase is for creating a final execution plan, and the execution phase i and computing a final result. The query phase takes each function call in a query and performs a match against the registry to see if -there are type definitions for a built-in operation. If matched, it will instantiate the correct query.OperationSpec +there are type definitions for a built-in operation. If matched, it will instantiate the correct flux.OperationSpec type for that function, given the runtime parameters. If a builtin OperationSpec is not found, then it will check for functions defined at runtime, and otherwise return an error. The following registrations are typically executed in the function's init() for the query phase to execute properly: - query.RegisterFunction(name string, c query.CreateOperationSpec, sig semantic.FunctionSignature) - query.RegisterOpSpec(k query.OperationKind, c query.NewOperationSpec) + flux.RegisterFunction(name string, c flux.CreateOperationSpec, sig semantic.FunctionSignature) + flux.RegisterOpSpec(k flux.OperationKind, c flux.NewOperationSpec) In the plan phase, an operation spec must be converted to a plan.ProcedureSpec. A query plan must know what operations to carry out, including the function names and parameters. In the trivial case, the OperationSpec @@ -39,12 +39,12 @@ of the object. Refer to the following interfaces for more information about des plan.ParentAwareProcedureSpec Once you have determined the interface(s) that must be implemented for your function, you register them with - plan.RegisterProcedureSpec(k ProcedureKind, c CreateProcedureSpec, qks ...query.OperationKind) + plan.RegisterProcedureSpec(k ProcedureKind, c CreateProcedureSpec, qks ...flux.OperationKind) The registration in this phase creates two lookups. First, it creates a named lookup in a similar fashion as for OperationSpecs in the query phase. Second, it creates a mapping from OperationSpec types to ProcedureSpec types so that the collection of OperationSpecs for the query can be quickly converted to corresponding Procedure specs. One feature to note is that the -registration takes a list of query.OperationSpec values. This is because several user-facing query functions may map +registration takes a list of flux.OperationSpec values. This is because several user-facing query functions may map to the same internal procedure. The primary function of the plan phase is to re-order, re-write and possibly combine the operations @@ -79,17 +79,17 @@ the transformation process: execute.TableBuilder execute.NewAggregateTransformationAndDataset execute.NewRowSelectorTransformationAndDataset - query.Table - query.GroupKey - query.ColMeta - query.ColReader + flux.Table + flux.GroupKey + flux.ColMeta + flux.ColReader -The most important part of a function implementation is for the interface method execute.Transformation.Process(id execute.DatasetID, tbl query.Table). +The most important part of a function implementation is for the interface method execute.Transformation.Process(id execute.DatasetID, tbl flux.Table). While the full details of how to implement this function are out of the scope of this document, a typical implementation will do the following: 1. Validate the incoming table schema if needed 2. Construct the column and group key schema for the output table via the table builder. -3. Process the incoming table via query.Table.Do, and use the input data to determine the output rows for the table builder. +3. Process the incoming table via flux.Table.Do, and use the input data to determine the output rows for the table builder. 4. Add rows to the output table. Finally, there is a special class of functions do not receive an input table from another function's output. @@ -99,6 +99,6 @@ They are registered using: execute.RegisterSource(k plan.ProcedureKind, c execute.CreateSource) The substantial part of a source implementation is its Run method, which should connect to the data source, -collect its data into query.Table structures, and apply any transformations associated with the source. +collect its data into flux.Table structures, and apply any transformations associated with the source. */ package functions diff --git a/functions/filter.go b/functions/filter.go index a9ed0712ea..9ebba8e90c 100644 --- a/functions/filter.go +++ b/functions/filter.go @@ -4,12 +4,12 @@ import ( "fmt" "log" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/interpreter" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux" + "github.com/influxdata/flux/ast" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/interpreter" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" ) const FilterKind = "filter" @@ -18,19 +18,19 @@ type FilterOpSpec struct { Fn *semantic.FunctionExpression `json:"fn"` } -var filterSignature = query.DefaultFunctionSignature() +var filterSignature = flux.DefaultFunctionSignature() func init() { //TODO(nathanielc): Use complete function signature here, or formalize soft kind validation instead of complete function validation. filterSignature.Params["fn"] = semantic.Function - query.RegisterFunction(FilterKind, createFilterOpSpec, filterSignature) - query.RegisterOpSpec(FilterKind, newFilterOp) + flux.RegisterFunction(FilterKind, createFilterOpSpec, filterSignature) + flux.RegisterOpSpec(FilterKind, newFilterOp) plan.RegisterProcedureSpec(FilterKind, newFilterProcedure, FilterKind) execute.RegisterTransformation(FilterKind, createFilterTransformation) } -func createFilterOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createFilterOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -48,11 +48,11 @@ func createFilterOpSpec(args query.Arguments, a *query.Administration) (query.Op Fn: fn, }, nil } -func newFilterOp() query.OperationSpec { +func newFilterOp() flux.OperationSpec { return new(FilterOpSpec) } -func (s *FilterOpSpec) Kind() query.OperationKind { +func (s *FilterOpSpec) Kind() flux.OperationKind { return FilterKind } @@ -60,7 +60,7 @@ type FilterProcedureSpec struct { Fn *semantic.FunctionExpression } -func newFilterProcedure(qs query.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { +func newFilterProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*FilterOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -217,11 +217,11 @@ func NewFilterTransformation(d execute.Dataset, cache execute.TableBuilderCache, }, nil } -func (t *filterTransformation) RetractTable(id execute.DatasetID, key query.GroupKey) error { +func (t *filterTransformation) RetractTable(id execute.DatasetID, key flux.GroupKey) error { return t.d.RetractTable(key) } -func (t *filterTransformation) Process(id execute.DatasetID, tbl query.Table) error { +func (t *filterTransformation) Process(id execute.DatasetID, tbl flux.Table) error { builder, created := t.cache.TableBuilder(tbl.Key()) if !created { return fmt.Errorf("filter found duplicate table with key: %v", tbl.Key()) @@ -236,7 +236,7 @@ func (t *filterTransformation) Process(id execute.DatasetID, tbl query.Table) er } // Append only matching rows to table - return tbl.Do(func(cr query.ColReader) error { + return tbl.Do(func(cr flux.ColReader) error { l := cr.Len() for i := 0; i < l; i++ { if pass, err := t.fn.Eval(i, cr); err != nil { diff --git a/functions/filter_test.go b/functions/filter_test.go index e31083f1e9..1ea4650fb5 100644 --- a/functions/filter_test.go +++ b/functions/filter_test.go @@ -5,24 +5,24 @@ import ( "testing" "time" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/plan/plantest" - "github.com/influxdata/platform/query/querytest" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux" + "github.com/influxdata/flux/ast" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/plan/plantest" + "github.com/influxdata/flux/semantic" ) func TestFilter_NewQuery(t *testing.T) { - tests := []querytest.NewQueryTestCase{ + tests := []fluxtest.NewQueryTestCase{ { Name: "from with database filter and range", Raw: `from(bucket:"mybucket") |> filter(fn: (r) => r["t1"]=="val1" and r["t2"]=="val2") |> range(start:-4h, stop:-2h) |> count()`, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "from0", Spec: &functions.FromOpSpec{ @@ -59,11 +59,11 @@ func TestFilter_NewQuery(t *testing.T) { { ID: "range2", Spec: &functions.RangeOpSpec{ - Start: query.Time{ + Start: flux.Time{ Relative: -4 * time.Hour, IsRelative: true, }, - Stop: query.Time{ + Stop: flux.Time{ Relative: -2 * time.Hour, IsRelative: true, }, @@ -79,7 +79,7 @@ func TestFilter_NewQuery(t *testing.T) { }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "from0", Child: "filter1"}, {Parent: "filter1", Child: "range2"}, {Parent: "range2", Child: "count3"}, @@ -100,8 +100,8 @@ func TestFilter_NewQuery(t *testing.T) { ) |> range(start:-4h, stop:-2h) |> count()`, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "from0", Spec: &functions.FromOpSpec{ @@ -149,11 +149,11 @@ func TestFilter_NewQuery(t *testing.T) { { ID: "range2", Spec: &functions.RangeOpSpec{ - Start: query.Time{ + Start: flux.Time{ Relative: -4 * time.Hour, IsRelative: true, }, - Stop: query.Time{ + Stop: flux.Time{ Relative: -2 * time.Hour, IsRelative: true, }, @@ -169,7 +169,7 @@ func TestFilter_NewQuery(t *testing.T) { }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "from0", Child: "filter1"}, {Parent: "filter1", Child: "range2"}, {Parent: "range2", Child: "count3"}, @@ -186,8 +186,8 @@ func TestFilter_NewQuery(t *testing.T) { ) |> range(start:-4h, stop:-2h) |> count()`, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "from0", Spec: &functions.FromOpSpec{ @@ -224,11 +224,11 @@ func TestFilter_NewQuery(t *testing.T) { { ID: "range2", Spec: &functions.RangeOpSpec{ - Start: query.Time{ + Start: flux.Time{ Relative: -4 * time.Hour, IsRelative: true, }, - Stop: query.Time{ + Stop: flux.Time{ Relative: -2 * time.Hour, IsRelative: true, }, @@ -244,7 +244,7 @@ func TestFilter_NewQuery(t *testing.T) { }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "from0", Child: "filter1"}, {Parent: "filter1", Child: "range2"}, {Parent: "range2", Child: "count3"}, @@ -261,8 +261,8 @@ func TestFilter_NewQuery(t *testing.T) { ) |> range(start:-4h, stop:-2h) |> count()`, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "from0", Spec: &functions.FromOpSpec{ @@ -299,11 +299,11 @@ func TestFilter_NewQuery(t *testing.T) { { ID: "range2", Spec: &functions.RangeOpSpec{ - Start: query.Time{ + Start: flux.Time{ Relative: -4 * time.Hour, IsRelative: true, }, - Stop: query.Time{ + Stop: flux.Time{ Relative: -2 * time.Hour, IsRelative: true, }, @@ -319,7 +319,7 @@ func TestFilter_NewQuery(t *testing.T) { }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "from0", Child: "filter1"}, {Parent: "filter1", Child: "range2"}, {Parent: "range2", Child: "count3"}, @@ -336,8 +336,8 @@ func TestFilter_NewQuery(t *testing.T) { ) |> range(start:-4h, stop:-2h) |> count()`, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "from0", Spec: &functions.FromOpSpec{ @@ -374,11 +374,11 @@ func TestFilter_NewQuery(t *testing.T) { { ID: "range2", Spec: &functions.RangeOpSpec{ - Start: query.Time{ + Start: flux.Time{ Relative: -4 * time.Hour, IsRelative: true, }, - Stop: query.Time{ + Stop: flux.Time{ Relative: -2 * time.Hour, IsRelative: true, }, @@ -394,7 +394,7 @@ func TestFilter_NewQuery(t *testing.T) { }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "from0", Child: "filter1"}, {Parent: "filter1", Child: "range2"}, {Parent: "range2", Child: "count3"}, @@ -407,8 +407,8 @@ func TestFilter_NewQuery(t *testing.T) { |> filter(fn: (r) => r["t1"]==/va\/l1/ )`, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "from0", Spec: &functions.FromOpSpec{ @@ -432,7 +432,7 @@ func TestFilter_NewQuery(t *testing.T) { }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "from0", Child: "filter1"}, }, }, @@ -445,8 +445,8 @@ func TestFilter_NewQuery(t *testing.T) { and r["t2"] != /val2/ )`, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "from0", Spec: &functions.FromOpSpec{ @@ -481,7 +481,7 @@ func TestFilter_NewQuery(t *testing.T) { }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "from0", Child: "filter1"}, }, }, @@ -491,7 +491,7 @@ func TestFilter_NewQuery(t *testing.T) { tc := tc t.Run(tc.Name, func(t *testing.T) { t.Parallel() - querytest.NewQueryTestHelper(t, tc) + fluxtest.NewQueryTestHelper(t, tc) }) } } @@ -522,7 +522,7 @@ func TestFilterOperation_Marshaling(t *testing.T) { } } }`) - op := &query.Operation{ + op := &flux.Operation{ ID: "filter", Spec: &functions.FilterOpSpec{ Fn: &semantic.FunctionExpression{ @@ -538,14 +538,14 @@ func TestFilterOperation_Marshaling(t *testing.T) { }, }, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestFilter_Process(t *testing.T) { testCases := []struct { name string spec *functions.FilterProcedureSpec - data []query.Table + data []flux.Table want []*executetest.Table }{ { @@ -563,10 +563,10 @@ func TestFilter_Process(t *testing.T) { }, }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 1.0}, @@ -574,9 +574,9 @@ func TestFilter_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(2), 6.0}, @@ -600,13 +600,13 @@ func TestFilter_Process(t *testing.T) { }, }, }, - data: []query.Table{ + data: []flux.Table{ &executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "t1", Type: query.TString}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "t1", Type: flux.TString}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {"a", execute.Time(1), 3.0}, @@ -616,10 +616,10 @@ func TestFilter_Process(t *testing.T) { }, &executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "t1", Type: query.TString}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "t1", Type: flux.TString}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {"b", execute.Time(3), 3.0}, @@ -631,10 +631,10 @@ func TestFilter_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "t1", Type: query.TString}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "t1", Type: flux.TString}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {"a", execute.Time(2), 6.0}, @@ -642,10 +642,10 @@ func TestFilter_Process(t *testing.T) { }, { KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "t1", Type: query.TString}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "t1", Type: flux.TString}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {"b", execute.Time(4), 8.0}, @@ -696,12 +696,12 @@ func TestFilter_Process(t *testing.T) { }, }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "a", "x"}, @@ -710,11 +710,11 @@ func TestFilter_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(3), 8.0, "a", "y"}, diff --git a/functions/first.go b/functions/first.go index 82bd6c751f..5914a97d51 100644 --- a/functions/first.go +++ b/functions/first.go @@ -3,9 +3,9 @@ package functions import ( "fmt" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/plan" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/plan" ) const FirstKind = "first" @@ -17,13 +17,13 @@ type FirstOpSpec struct { var firstSignature = execute.DefaultSelectorSignature() func init() { - query.RegisterFunction(FirstKind, createFirstOpSpec, firstSignature) - query.RegisterOpSpec(FirstKind, newFirstOp) + flux.RegisterFunction(FirstKind, createFirstOpSpec, firstSignature) + flux.RegisterOpSpec(FirstKind, newFirstOp) plan.RegisterProcedureSpec(FirstKind, newFirstProcedure, FirstKind) execute.RegisterTransformation(FirstKind, createFirstTransformation) } -func createFirstOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createFirstOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -36,11 +36,11 @@ func createFirstOpSpec(args query.Arguments, a *query.Administration) (query.Ope return spec, nil } -func newFirstOp() query.OperationSpec { +func newFirstOp() flux.OperationSpec { return new(FirstOpSpec) } -func (s *FirstOpSpec) Kind() query.OperationKind { +func (s *FirstOpSpec) Kind() flux.OperationKind { return FirstKind } @@ -48,7 +48,7 @@ type FirstProcedureSpec struct { execute.SelectorConfig } -func newFirstProcedure(qs query.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { +func newFirstProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*FirstOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -78,7 +78,7 @@ func (s *FirstProcedureSpec) PushDown(root *plan.Procedure, dup func() *plan.Pro root = dup() selectSpec = root.Spec.(*FromProcedureSpec) selectSpec.BoundsSet = false - selectSpec.Bounds = query.Bounds{} + selectSpec.Bounds = flux.Bounds{} selectSpec.LimitSet = false selectSpec.PointsLimit = 0 selectSpec.SeriesLimit = 0 @@ -88,9 +88,9 @@ func (s *FirstProcedureSpec) PushDown(root *plan.Procedure, dup func() *plan.Pro return } selectSpec.BoundsSet = true - selectSpec.Bounds = query.Bounds{ - Start: query.MinTime, - Stop: query.Now, + selectSpec.Bounds = flux.Bounds{ + Start: flux.MinTime, + Stop: flux.Now, } selectSpec.LimitSet = true selectSpec.PointsLimit = 1 diff --git a/functions/first_test.go b/functions/first_test.go index bc7900bc27..f2d5416f4f 100644 --- a/functions/first_test.go +++ b/functions/first_test.go @@ -3,18 +3,18 @@ package functions_test import ( "testing" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/plan/plantest" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/plan/plantest" ) func TestFirstOperation_Marshaling(t *testing.T) { data := []byte(`{"id":"first","kind":"first","spec":{"column":"foo"}}`) - op := &query.Operation{ + op := &flux.Operation{ ID: "first", Spec: &functions.FirstOpSpec{ SelectorConfig: execute.SelectorConfig{ @@ -23,7 +23,7 @@ func TestFirstOperation_Marshaling(t *testing.T) { }, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestFirst_Process(t *testing.T) { @@ -35,11 +35,11 @@ func TestFirst_Process(t *testing.T) { { name: "first", data: &executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(0), 0.0, "a", "y"}, @@ -95,9 +95,9 @@ func TestFirst_PushDown(t *testing.T) { want := &plan.Procedure{ Spec: &functions.FromProcedureSpec{ BoundsSet: true, - Bounds: query.Bounds{ - Start: query.MinTime, - Stop: query.Now, + Bounds: flux.Bounds{ + Start: flux.MinTime, + Stop: flux.Now, }, LimitSet: true, PointsLimit: 1, @@ -113,9 +113,9 @@ func TestFirst_PushDown_Duplicate(t *testing.T) { root := &plan.Procedure{ Spec: &functions.FromProcedureSpec{ BoundsSet: true, - Bounds: query.Bounds{ - Start: query.MinTime, - Stop: query.Now, + Bounds: flux.Bounds{ + Start: flux.MinTime, + Stop: flux.Now, }, LimitSet: true, PointsLimit: 1, diff --git a/functions/from.go b/functions/from.go index b0ad6a8fc4..5613186add 100644 --- a/functions/from.go +++ b/functions/from.go @@ -3,12 +3,12 @@ package functions import ( "fmt" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/functions/storage" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" "github.com/influxdata/platform" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/functions/storage" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" "github.com/pkg/errors" ) @@ -24,17 +24,17 @@ var fromSignature = semantic.FunctionSignature{ "bucket": semantic.String, "bucketID": semantic.String, }, - ReturnType: query.TableObjectType, + ReturnType: flux.TableObjectType, } func init() { - query.RegisterFunction(FromKind, createFromOpSpec, fromSignature) - query.RegisterOpSpec(FromKind, newFromOp) + flux.RegisterFunction(FromKind, createFromOpSpec, fromSignature) + flux.RegisterOpSpec(FromKind, newFromOp) plan.RegisterProcedureSpec(FromKind, newFromProcedure, FromKind) execute.RegisterSource(FromKind, createFromSource) } -func createFromOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createFromOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { spec := new(FromOpSpec) if bucket, ok, err := args.GetString("bucket"); err != nil { @@ -61,11 +61,11 @@ func createFromOpSpec(args query.Arguments, a *query.Administration) (query.Oper return spec, nil } -func newFromOp() query.OperationSpec { +func newFromOp() flux.OperationSpec { return new(FromOpSpec) } -func (s *FromOpSpec) Kind() query.OperationKind { +func (s *FromOpSpec) Kind() flux.OperationKind { return FromKind } @@ -90,7 +90,7 @@ type FromProcedureSpec struct { BucketID platform.ID BoundsSet bool - Bounds query.Bounds + Bounds flux.Bounds FilterSet bool Filter *semantic.FunctionExpression @@ -115,7 +115,7 @@ type FromProcedureSpec struct { AggregateMethod string } -func newFromProcedure(qs query.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { +func newFromProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*FromOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -130,7 +130,7 @@ func newFromProcedure(qs query.OperationSpec, pa plan.Administration) (plan.Proc func (s *FromProcedureSpec) Kind() plan.ProcedureKind { return FromKind } -func (s *FromProcedureSpec) TimeBounds() query.Bounds { +func (s *FromProcedureSpec) TimeBounds() flux.Bounds { return s.Bounds } func (s *FromProcedureSpec) Copy() plan.ProcedureSpec { diff --git a/functions/from_csv.go b/functions/from_csv.go index 9578a3a265..d4b010b28a 100644 --- a/functions/from_csv.go +++ b/functions/from_csv.go @@ -8,11 +8,11 @@ import ( "context" "strings" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/csv" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux" + "github.com/influxdata/flux/csv" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" "github.com/pkg/errors" ) @@ -28,17 +28,17 @@ var fromCSVSignature = semantic.FunctionSignature{ "csv": semantic.String, "file": semantic.String, }, - ReturnType: query.TableObjectType, + ReturnType: flux.TableObjectType, } func init() { - query.RegisterFunction(FromCSVKind, createFromCSVOpSpec, fromCSVSignature) - query.RegisterOpSpec(FromCSVKind, newFromCSVOp) + flux.RegisterFunction(FromCSVKind, createFromCSVOpSpec, fromCSVSignature) + flux.RegisterOpSpec(FromCSVKind, newFromCSVOp) plan.RegisterProcedureSpec(FromCSVKind, newFromCSVProcedure, FromCSVKind) execute.RegisterSource(FromCSVKind, createFromCSVSource) } -func createFromCSVOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createFromCSVOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { spec := new(FromCSVOpSpec) if csv, ok, err := args.GetString("csv"); err != nil { @@ -70,11 +70,11 @@ func createFromCSVOpSpec(args query.Arguments, a *query.Administration) (query.O return spec, nil } -func newFromCSVOp() query.OperationSpec { +func newFromCSVOp() flux.OperationSpec { return new(FromCSVOpSpec) } -func (s *FromCSVOpSpec) Kind() query.OperationKind { +func (s *FromCSVOpSpec) Kind() flux.OperationKind { return FromCSVKind } @@ -83,7 +83,7 @@ type FromCSVProcedureSpec struct { File string } -func newFromCSVProcedure(qs query.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { +func newFromCSVProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*FromCSVOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -134,7 +134,7 @@ func createFromCSVSource(prSpec plan.ProcedureSpec, dsid execute.DatasetID, a ex type CSVSource struct { id execute.DatasetID - data query.Result + data flux.Result ts []execute.Transformation } @@ -146,7 +146,7 @@ func (c *CSVSource) Run(ctx context.Context) { var err error var max execute.Time maxSet := false - err = c.data.Tables().Do(func(tbl query.Table) error { + err = c.data.Tables().Do(func(tbl flux.Table) error { for _, t := range c.ts { err := t.Process(c.id, tbl) if err != nil { diff --git a/functions/from_csv_test.go b/functions/from_csv_test.go index a14acf27ec..77852ea232 100644 --- a/functions/from_csv_test.go +++ b/functions/from_csv_test.go @@ -4,14 +4,14 @@ import ( "testing" "time" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" ) func TestFromCSV_NewQuery(t *testing.T) { - tests := []querytest.NewQueryTestCase{ + tests := []fluxtest.NewQueryTestCase{ { Name: "from no args", Raw: `fromCSV()`, @@ -35,8 +35,8 @@ func TestFromCSV_NewQuery(t *testing.T) { { Name: "fromCSV text", Raw: `fromCSV(csv: "1,2") |> range(start:-4h, stop:-2h) |> sum()`, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "fromCSV0", Spec: &functions.FromCSVOpSpec{ @@ -46,11 +46,11 @@ func TestFromCSV_NewQuery(t *testing.T) { { ID: "range1", Spec: &functions.RangeOpSpec{ - Start: query.Time{ + Start: flux.Time{ Relative: -4 * time.Hour, IsRelative: true, }, - Stop: query.Time{ + Stop: flux.Time{ Relative: -2 * time.Hour, IsRelative: true, }, @@ -66,7 +66,7 @@ func TestFromCSV_NewQuery(t *testing.T) { }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "fromCSV0", Child: "range1"}, {Parent: "range1", Child: "sum2"}, }, @@ -82,18 +82,18 @@ func TestFromCSV_NewQuery(t *testing.T) { tc := tc t.Run(tc.Name, func(t *testing.T) { t.Parallel() - querytest.NewQueryTestHelper(t, tc) + fluxtest.NewQueryTestHelper(t, tc) }) } } func TestFromCSVOperation_Marshaling(t *testing.T) { data := []byte(`{"id":"fromCSV","kind":"fromCSV","spec":{"csv":"1,2"}}`) - op := &query.Operation{ + op := &flux.Operation{ ID: "fromCSV", Spec: &functions.FromCSVOpSpec{ CSV: "1,2", }, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } diff --git a/functions/from_test.go b/functions/from_test.go index 89c6736a91..8fe11b05c1 100644 --- a/functions/from_test.go +++ b/functions/from_test.go @@ -4,15 +4,15 @@ import ( "testing" "time" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" "github.com/influxdata/platform" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/querytest" ) func TestFrom_NewQuery(t *testing.T) { - tests := []querytest.NewQueryTestCase{ + tests := []fluxtest.NewQueryTestCase{ { Name: "from no args", Raw: `from()`, @@ -41,8 +41,8 @@ func TestFrom_NewQuery(t *testing.T) { { Name: "from bucket ID", Raw: `from(bucketID:"aaaaaaaa")`, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "from0", Spec: &functions.FromOpSpec{ @@ -55,8 +55,8 @@ func TestFrom_NewQuery(t *testing.T) { { Name: "from with database", Raw: `from(bucket:"mybucket") |> range(start:-4h, stop:-2h) |> sum()`, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "from0", Spec: &functions.FromOpSpec{ @@ -66,11 +66,11 @@ func TestFrom_NewQuery(t *testing.T) { { ID: "range1", Spec: &functions.RangeOpSpec{ - Start: query.Time{ + Start: flux.Time{ Relative: -4 * time.Hour, IsRelative: true, }, - Stop: query.Time{ + Stop: flux.Time{ Relative: -2 * time.Hour, IsRelative: true, }, @@ -86,7 +86,7 @@ func TestFrom_NewQuery(t *testing.T) { }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "from0", Child: "range1"}, {Parent: "range1", Child: "sum2"}, }, @@ -97,26 +97,26 @@ func TestFrom_NewQuery(t *testing.T) { tc := tc t.Run(tc.Name, func(t *testing.T) { t.Parallel() - querytest.NewQueryTestHelper(t, tc) + fluxtest.NewQueryTestHelper(t, tc) }) } } func TestFromOperation_Marshaling(t *testing.T) { data := []byte(`{"id":"from","kind":"from","spec":{"bucket":"mybucket"}}`) - op := &query.Operation{ + op := &flux.Operation{ ID: "from", Spec: &functions.FromOpSpec{ Bucket: "mybucket", }, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestFromOpSpec_BucketsAccessed(t *testing.T) { bucketName := "my_bucket" bucketID, _ := platform.IDFromString("deadbeef") - tests := []querytest.NewQueryTestCase{ + tests := []fluxtest.NewQueryTestCase{ { Name: "From with bucket", Raw: `from(bucket:"my_bucket")`, @@ -134,7 +134,7 @@ func TestFromOpSpec_BucketsAccessed(t *testing.T) { tc := tc t.Run(tc.Name, func(t *testing.T) { t.Parallel() - querytest.NewQueryTestHelper(t, tc) + fluxtest.NewQueryTestHelper(t, tc) }) } } diff --git a/functions/group.go b/functions/group.go index 07518745d4..43d8929135 100644 --- a/functions/group.go +++ b/functions/group.go @@ -7,11 +7,11 @@ import ( "math/bits" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/interpreter" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/interpreter" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" ) const GroupKind = "group" @@ -23,7 +23,7 @@ type GroupOpSpec struct { None bool `json:"none"` } -var groupSignature = query.DefaultFunctionSignature() +var groupSignature = flux.DefaultFunctionSignature() func init() { groupSignature.Params["by"] = semantic.NewArrayType(semantic.String) @@ -31,14 +31,14 @@ func init() { groupSignature.Params["none"] = semantic.Bool groupSignature.Params["all"] = semantic.Bool - query.RegisterFunction(GroupKind, createGroupOpSpec, groupSignature) - query.RegisterOpSpec(GroupKind, newGroupOp) + flux.RegisterFunction(GroupKind, createGroupOpSpec, groupSignature) + flux.RegisterOpSpec(GroupKind, newGroupOp) plan.RegisterProcedureSpec(GroupKind, newGroupProcedure, GroupKind) plan.RegisterRewriteRule(AggregateGroupRewriteRule{}) execute.RegisterTransformation(GroupKind, createGroupTransformation) } -func createGroupOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createGroupOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -86,11 +86,11 @@ func createGroupOpSpec(args query.Arguments, a *query.Administration) (query.Ope return spec, nil } -func newGroupOp() query.OperationSpec { +func newGroupOp() flux.OperationSpec { return new(GroupOpSpec) } -func (s *GroupOpSpec) Kind() query.OperationKind { +func (s *GroupOpSpec) Kind() flux.OperationKind { return GroupKind } @@ -135,7 +135,7 @@ type GroupProcedureSpec struct { GroupKeys []string } -func newGroupProcedure(qs query.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { +func newGroupProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*GroupOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -281,11 +281,11 @@ func NewGroupTransformation(d execute.Dataset, cache execute.TableBuilderCache, return t } -func (t *groupTransformation) RetractTable(id execute.DatasetID, key query.GroupKey) (err error) { +func (t *groupTransformation) RetractTable(id execute.DatasetID, key flux.GroupKey) (err error) { panic("not implemented") } -func (t *groupTransformation) Process(id execute.DatasetID, tbl query.Table) error { +func (t *groupTransformation) Process(id execute.DatasetID, tbl flux.Table) error { cols := tbl.Cols() on := make(map[string]bool, len(cols)) if t.mode == GroupModeBy && len(t.keys) > 0 { @@ -304,7 +304,7 @@ func (t *groupTransformation) Process(id execute.DatasetID, tbl query.Table) err } } colMap := make([]int, 0, len(tbl.Cols())) - return tbl.Do(func(cr query.ColReader) error { + return tbl.Do(func(cr flux.ColReader) error { l := cr.Len() for i := 0; i < l; i++ { key := execute.GroupKeyForRowOn(i, cr, on) diff --git a/functions/group_test.go b/functions/group_test.go index 6d0418af73..a471b4c95c 100644 --- a/functions/group_test.go +++ b/functions/group_test.go @@ -3,31 +3,31 @@ package functions_test import ( "testing" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/plan/plantest" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/plan/plantest" ) func TestGroupOperation_Marshaling(t *testing.T) { data := []byte(`{"id":"group","kind":"group","spec":{"by":["t1","t2"]}}`) - op := &query.Operation{ + op := &flux.Operation{ ID: "group", Spec: &functions.GroupOpSpec{ By: []string{"t1", "t2"}, }, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestGroup_Process(t *testing.T) { testCases := []struct { name string spec *functions.GroupProcedureSpec - data []query.Table + data []flux.Table want []*executetest.Table }{ { @@ -36,14 +36,14 @@ func TestGroup_Process(t *testing.T) { GroupMode: functions.GroupModeBy, GroupKeys: []string{"t1"}, }, - data: []query.Table{ + data: []flux.Table{ &executetest.Table{ KeyCols: []string{"t1", "t2"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 2.0, "a", "x"}, @@ -51,11 +51,11 @@ func TestGroup_Process(t *testing.T) { }, &executetest.Table{ KeyCols: []string{"t1", "t2"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(2), 1.0, "a", "y"}, @@ -63,11 +63,11 @@ func TestGroup_Process(t *testing.T) { }, &executetest.Table{ KeyCols: []string{"t1", "t2"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 4.0, "b", "x"}, @@ -75,11 +75,11 @@ func TestGroup_Process(t *testing.T) { }, &executetest.Table{ KeyCols: []string{"t1", "t2"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(2), 7.0, "b", "y"}, @@ -89,11 +89,11 @@ func TestGroup_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 2.0, "a", "x"}, @@ -102,11 +102,11 @@ func TestGroup_Process(t *testing.T) { }, { KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 4.0, "b", "x"}, @@ -121,15 +121,15 @@ func TestGroup_Process(t *testing.T) { GroupMode: functions.GroupModeExcept, GroupKeys: []string{"_time", "_value", "t2"}, }, - data: []query.Table{ + data: []flux.Table{ &executetest.Table{ KeyCols: []string{"t1", "t2", "t3"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, - {Label: "t3", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, + {Label: "t3", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 2.0, "a", "m", "x"}, @@ -137,12 +137,12 @@ func TestGroup_Process(t *testing.T) { }, &executetest.Table{ KeyCols: []string{"t1", "t2", "t3"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, - {Label: "t3", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, + {Label: "t3", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(2), 1.0, "a", "n", "x"}, @@ -150,12 +150,12 @@ func TestGroup_Process(t *testing.T) { }, &executetest.Table{ KeyCols: []string{"t1", "t2", "t3"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, - {Label: "t3", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, + {Label: "t3", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 4.0, "b", "m", "x"}, @@ -163,12 +163,12 @@ func TestGroup_Process(t *testing.T) { }, &executetest.Table{ KeyCols: []string{"t1", "t2", "t3"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, - {Label: "t3", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, + {Label: "t3", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(2), 7.0, "b", "n", "x"}, @@ -178,12 +178,12 @@ func TestGroup_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"t1", "t3"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, - {Label: "t3", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, + {Label: "t3", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 2.0, "a", "m", "x"}, @@ -192,12 +192,12 @@ func TestGroup_Process(t *testing.T) { }, { KeyCols: []string{"t1", "t3"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, - {Label: "t3", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, + {Label: "t3", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 4.0, "b", "m", "x"}, @@ -215,14 +215,14 @@ func TestGroup_Process(t *testing.T) { GroupMode: functions.GroupModeBy, GroupKeys: []string{"t1"}, }, - data: []query.Table{ + data: []flux.Table{ &executetest.Table{ KeyCols: []string{"t1", "t2"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(2), 1.0, "a", "y"}, @@ -230,12 +230,12 @@ func TestGroup_Process(t *testing.T) { }, &executetest.Table{ KeyCols: []string{"t1", "t3", "t2"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t3", Type: query.TInt}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t3", Type: flux.TInt}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 2.0, "a", int64(5), "x"}, @@ -243,11 +243,11 @@ func TestGroup_Process(t *testing.T) { }, &executetest.Table{ KeyCols: []string{"t1", "t2"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(2), 7.0, "b", "y"}, @@ -255,12 +255,12 @@ func TestGroup_Process(t *testing.T) { }, &executetest.Table{ KeyCols: []string{"t1", "t3", "t2"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t3", Type: query.TInt}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t3", Type: flux.TInt}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 4.0, "b", int64(7), "x"}, @@ -270,11 +270,11 @@ func TestGroup_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(2), 1.0, "a", "y"}, @@ -283,11 +283,11 @@ func TestGroup_Process(t *testing.T) { }, { KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(2), 7.0, "b", "y"}, @@ -302,11 +302,11 @@ func TestGroup_Process(t *testing.T) { GroupMode: functions.GroupModeBy, GroupKeys: []string{"t1"}, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 2.0, "a"}, @@ -316,10 +316,10 @@ func TestGroup_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 2.0, "a"}, @@ -327,10 +327,10 @@ func TestGroup_Process(t *testing.T) { }, { KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(2), 1.0, "b"}, @@ -344,13 +344,13 @@ func TestGroup_Process(t *testing.T) { GroupMode: functions.GroupModeExcept, GroupKeys: []string{"_time", "_value", "t2"}, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, - {Label: "t3", Type: query.TString}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, + {Label: "t3", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 2.0, "a", "m", "x"}, @@ -360,12 +360,12 @@ func TestGroup_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"t1", "t3"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, - {Label: "t3", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, + {Label: "t3", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 2.0, "a", "m", "x"}, @@ -373,12 +373,12 @@ func TestGroup_Process(t *testing.T) { }, { KeyCols: []string{"t1", "t3"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, - {Label: "t3", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, + {Label: "t3", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(2), 1.0, "a", "n", "y"}, diff --git a/functions/histogram.go b/functions/histogram.go index 1146fe75a8..1894ff57ea 100644 --- a/functions/histogram.go +++ b/functions/histogram.go @@ -6,12 +6,12 @@ import ( "regexp" "sort" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/interpreter" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/interpreter" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" + "github.com/influxdata/flux/values" "github.com/pkg/errors" ) @@ -33,15 +33,15 @@ func init() { histogramSignature.Params["buckets"] = semantic.NewArrayType(semantic.Float) histogramSignature.Params["normalize"] = semantic.Bool - query.RegisterFunction(HistogramKind, createHistogramOpSpec, histogramSignature) - query.RegisterBuiltInValue("linearBuckets", linearBuckets{}) - query.RegisterBuiltInValue("logarithmicBuckets", logarithmicBuckets{}) - query.RegisterOpSpec(HistogramKind, newHistogramOp) + flux.RegisterFunction(HistogramKind, createHistogramOpSpec, histogramSignature) + flux.RegisterBuiltInValue("linearBuckets", linearBuckets{}) + flux.RegisterBuiltInValue("logarithmicBuckets", logarithmicBuckets{}) + flux.RegisterOpSpec(HistogramKind, newHistogramOp) plan.RegisterProcedureSpec(HistogramKind, newHistogramProcedure, HistogramKind) execute.RegisterTransformation(HistogramKind, createHistogramTransformation) } -func createHistogramOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createHistogramOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -86,11 +86,11 @@ func createHistogramOpSpec(args query.Arguments, a *query.Administration) (query return spec, nil } -func newHistogramOp() query.OperationSpec { +func newHistogramOp() flux.OperationSpec { return new(HistogramOpSpec) } -func (s *HistogramOpSpec) Kind() query.OperationKind { +func (s *HistogramOpSpec) Kind() flux.OperationKind { return HistogramKind } @@ -98,7 +98,7 @@ type HistogramProcedureSpec struct { HistogramOpSpec } -func newHistogramProcedure(qs query.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { +func newHistogramProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*HistogramOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -149,11 +149,11 @@ func NewHistogramTransformation(d execute.Dataset, cache execute.TableBuilderCac } } -func (t *histogramTransformation) RetractTable(id execute.DatasetID, key query.GroupKey) error { +func (t *histogramTransformation) RetractTable(id execute.DatasetID, key flux.GroupKey) error { return t.d.RetractTable(key) } -func (t *histogramTransformation) Process(id execute.DatasetID, tbl query.Table) error { +func (t *histogramTransformation) Process(id execute.DatasetID, tbl flux.Table) error { builder, created := t.cache.TableBuilder(tbl.Key()) if !created { return fmt.Errorf("histogram found duplicate table with key: %v", tbl.Key()) @@ -162,22 +162,22 @@ func (t *histogramTransformation) Process(id execute.DatasetID, tbl query.Table) if valueIdx < 0 { return fmt.Errorf("column %q is missing", t.spec.Column) } - if col := tbl.Cols()[valueIdx]; col.Type != query.TFloat { + if col := tbl.Cols()[valueIdx]; col.Type != flux.TFloat { return fmt.Errorf("column %q must be a float got %v", t.spec.Column, col.Type) } execute.AddTableKeyCols(tbl.Key(), builder) - boundIdx := builder.AddCol(query.ColMeta{ + boundIdx := builder.AddCol(flux.ColMeta{ Label: t.spec.UpperBoundColumn, - Type: query.TFloat, + Type: flux.TFloat, }) - countIdx := builder.AddCol(query.ColMeta{ + countIdx := builder.AddCol(flux.ColMeta{ Label: t.spec.CountColumn, - Type: query.TFloat, + Type: flux.TFloat, }) totalRows := 0.0 counts := make([]float64, len(t.spec.Buckets)) - err := tbl.Do(func(cr query.ColReader) error { + err := tbl.Do(func(cr flux.ColReader) error { totalRows += float64(cr.Len()) for _, v := range cr.Floats(valueIdx) { idx := sort.Search(len(t.spec.Buckets), func(i int) bool { diff --git a/functions/histogram_quantile.go b/functions/histogram_quantile.go index 4db1ab4a21..caacf2c35d 100644 --- a/functions/histogram_quantile.go +++ b/functions/histogram_quantile.go @@ -5,10 +5,10 @@ import ( "math" "sort" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" "github.com/pkg/errors" ) @@ -24,7 +24,7 @@ type HistogramQuantileOpSpec struct { MinValue float64 `json:"minValue"` } -var histogramQuantileSignature = query.DefaultFunctionSignature() +var histogramQuantileSignature = flux.DefaultFunctionSignature() func init() { histogramQuantileSignature.Params["quantile"] = semantic.Float @@ -33,12 +33,12 @@ func init() { histogramQuantileSignature.Params["valueColumn"] = semantic.String histogramQuantileSignature.Params["minValue"] = semantic.Float - query.RegisterFunction(HistogramQuantileKind, createHistogramQuantileOpSpec, histogramQuantileSignature) - query.RegisterOpSpec(HistogramQuantileKind, newHistogramQuantileOp) + flux.RegisterFunction(HistogramQuantileKind, createHistogramQuantileOpSpec, histogramQuantileSignature) + flux.RegisterOpSpec(HistogramQuantileKind, newHistogramQuantileOp) plan.RegisterProcedureSpec(HistogramQuantileKind, newHistogramQuantileProcedure, HistogramQuantileKind) execute.RegisterTransformation(HistogramQuantileKind, createHistogramQuantileTransformation) } -func createHistogramQuantileOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createHistogramQuantileOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -83,11 +83,11 @@ func createHistogramQuantileOpSpec(args query.Arguments, a *query.Administration return s, nil } -func newHistogramQuantileOp() query.OperationSpec { +func newHistogramQuantileOp() flux.OperationSpec { return new(HistogramQuantileOpSpec) } -func (s *HistogramQuantileOpSpec) Kind() query.OperationKind { +func (s *HistogramQuantileOpSpec) Kind() flux.OperationKind { return HistogramQuantileKind } @@ -99,7 +99,7 @@ type HistogramQuantileProcedureSpec struct { MinValue float64 `json:"minValue"` } -func newHistogramQuantileProcedure(qs query.OperationSpec, a plan.Administration) (plan.ProcedureSpec, error) { +func newHistogramQuantileProcedure(qs flux.OperationSpec, a plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*HistogramQuantileOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -157,41 +157,41 @@ func NewHistorgramQuantileTransformation( } } -func (t histogramQuantileTransformation) RetractTable(id execute.DatasetID, key query.GroupKey) error { +func (t histogramQuantileTransformation) RetractTable(id execute.DatasetID, key flux.GroupKey) error { // TODO return nil } -func (t histogramQuantileTransformation) Process(id execute.DatasetID, tbl query.Table) error { +func (t histogramQuantileTransformation) Process(id execute.DatasetID, tbl flux.Table) error { builder, created := t.cache.TableBuilder(tbl.Key()) if !created { return fmt.Errorf("histogramQuantile found duplicate table with key: %v", tbl.Key()) } execute.AddTableKeyCols(tbl.Key(), builder) - valueIdx := builder.AddCol(query.ColMeta{ + valueIdx := builder.AddCol(flux.ColMeta{ Label: t.spec.ValueColumn, - Type: query.TFloat, + Type: flux.TFloat, }) countIdx := execute.ColIdx(t.spec.CountColumn, tbl.Cols()) if countIdx < 0 { return fmt.Errorf("table is missing count column %q", t.spec.CountColumn) } - if tbl.Cols()[countIdx].Type != query.TFloat { + if tbl.Cols()[countIdx].Type != flux.TFloat { return fmt.Errorf("count column %q must be of type float", t.spec.CountColumn) } upperBoundIdx := execute.ColIdx(t.spec.UpperBoundColumn, tbl.Cols()) if upperBoundIdx < 0 { return fmt.Errorf("table is missing upper bound column %q", t.spec.UpperBoundColumn) } - if tbl.Cols()[upperBoundIdx].Type != query.TFloat { + if tbl.Cols()[upperBoundIdx].Type != flux.TFloat { return fmt.Errorf("upper bound column %q must be of type float", t.spec.UpperBoundColumn) } // Read buckets var cdf []bucket sorted := true //track if the cdf was naturally sorted - err := tbl.Do(func(cr query.ColReader) error { + err := tbl.Do(func(cr flux.ColReader) error { offset := len(cdf) // Grow cdf by number of rows l := offset + cr.Len() diff --git a/functions/histogram_quantile_test.go b/functions/histogram_quantile_test.go index 96b4023fd7..a0685e8d0b 100644 --- a/functions/histogram_quantile_test.go +++ b/functions/histogram_quantile_test.go @@ -4,20 +4,20 @@ import ( "math" "testing" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/functions" ) -var linearHist = []query.Table{&executetest.Table{ +var linearHist = []flux.Table{&executetest.Table{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "le", Type: query.TFloat}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "le", Type: flux.TFloat}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), execute.Time(1), 0.1, 1.0}, @@ -33,14 +33,14 @@ var linearHist = []query.Table{&executetest.Table{ {execute.Time(1), execute.Time(3), execute.Time(1), math.Inf(1), 10.0}, }, }} -var linearHistNoMax = []query.Table{&executetest.Table{ +var linearHistNoMax = []flux.Table{&executetest.Table{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "le", Type: query.TFloat}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "le", Type: flux.TFloat}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), execute.Time(1), 0.2, 2.0}, @@ -50,14 +50,14 @@ var linearHistNoMax = []query.Table{&executetest.Table{ {execute.Time(1), execute.Time(3), execute.Time(1), 1.0, 10.0}, }, }} -var unsortedOddHist = []query.Table{&executetest.Table{ +var unsortedOddHist = []flux.Table{&executetest.Table{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "le", Type: query.TFloat}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "le", Type: flux.TFloat}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), execute.Time(1), 0.4, 4.0}, @@ -67,14 +67,14 @@ var unsortedOddHist = []query.Table{&executetest.Table{ {execute.Time(1), execute.Time(3), execute.Time(1), 0.8, 10.0}, }, }} -var nonLinearHist = []query.Table{&executetest.Table{ +var nonLinearHist = []flux.Table{&executetest.Table{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "le", Type: query.TFloat}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "le", Type: flux.TFloat}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), execute.Time(1), 0.1, 1.0}, @@ -88,7 +88,7 @@ func TestHistogramQuantile_Process(t *testing.T) { testCases := []struct { name string spec *functions.HistogramQuantileProcedureSpec - data []query.Table + data []flux.Table want []*executetest.Table }{ { @@ -102,10 +102,10 @@ func TestHistogramQuantile_Process(t *testing.T) { data: linearHist, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), 0.9}, @@ -123,10 +123,10 @@ func TestHistogramQuantile_Process(t *testing.T) { data: linearHist, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), 0.0}, @@ -144,10 +144,10 @@ func TestHistogramQuantile_Process(t *testing.T) { data: linearHist, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), 0.05}, @@ -166,10 +166,10 @@ func TestHistogramQuantile_Process(t *testing.T) { data: linearHist, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), 0.0}, @@ -188,10 +188,10 @@ func TestHistogramQuantile_Process(t *testing.T) { data: linearHist, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), 0.1}, @@ -209,10 +209,10 @@ func TestHistogramQuantile_Process(t *testing.T) { data: linearHist, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), 0.1}, @@ -230,10 +230,10 @@ func TestHistogramQuantile_Process(t *testing.T) { data: linearHist, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), 0.95}, @@ -251,10 +251,10 @@ func TestHistogramQuantile_Process(t *testing.T) { data: linearHist, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), 0.99999}, @@ -272,10 +272,10 @@ func TestHistogramQuantile_Process(t *testing.T) { data: linearHist, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), math.Inf(1)}, @@ -293,10 +293,10 @@ func TestHistogramQuantile_Process(t *testing.T) { data: linearHistNoMax, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), 1.0}, @@ -314,10 +314,10 @@ func TestHistogramQuantile_Process(t *testing.T) { data: unsortedOddHist, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), 0.75}, @@ -335,10 +335,10 @@ func TestHistogramQuantile_Process(t *testing.T) { data: unsortedOddHist, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), 1.0}, @@ -356,10 +356,10 @@ func TestHistogramQuantile_Process(t *testing.T) { data: nonLinearHist, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), 0.99}, @@ -377,10 +377,10 @@ func TestHistogramQuantile_Process(t *testing.T) { data: nonLinearHist, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), 1.0}, diff --git a/functions/histogram_test.go b/functions/histogram_test.go index 68a5fc09a3..858d178c71 100644 --- a/functions/histogram_test.go +++ b/functions/histogram_test.go @@ -4,22 +4,22 @@ import ( "math" "testing" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" ) func TestHistogramOperation_Marshaling(t *testing.T) { data := []byte(`{"id":"histogram","kind":"histogram","spec":{"column":"_value"}}`) - op := &query.Operation{ + op := &flux.Operation{ ID: "histogram", Spec: &functions.HistogramOpSpec{ Column: "_value", }, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestHistogram_PassThrough(t *testing.T) { @@ -37,7 +37,7 @@ func TestHistogram_Process(t *testing.T) { testCases := []struct { name string spec *functions.HistogramProcedureSpec - data []query.Table + data []flux.Table want []*executetest.Table }{ { @@ -48,13 +48,13 @@ func TestHistogram_Process(t *testing.T) { CountColumn: "_value", Buckets: []float64{0, 10, 20, 30, 40}, }}, - data: []query.Table{&executetest.Table{ + data: []flux.Table{&executetest.Table{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), execute.Time(1), 02.0}, @@ -71,11 +71,11 @@ func TestHistogram_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "le", Type: query.TFloat}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "le", Type: flux.TFloat}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), 0.0, 0.0}, @@ -94,13 +94,13 @@ func TestHistogram_Process(t *testing.T) { CountColumn: "_value", Buckets: []float64{0, 10, 20, 30, 40, math.Inf(1)}, }}, - data: []query.Table{&executetest.Table{ + data: []flux.Table{&executetest.Table{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), execute.Time(1), 02.0}, @@ -118,11 +118,11 @@ func TestHistogram_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "le", Type: query.TFloat}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "le", Type: flux.TFloat}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), 0.0, 0.0}, @@ -143,13 +143,13 @@ func TestHistogram_Process(t *testing.T) { Buckets: []float64{0, 10, 20, 30, 40}, Normalize: true, }}, - data: []query.Table{&executetest.Table{ + data: []flux.Table{&executetest.Table{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), execute.Time(1), 02.0}, @@ -166,11 +166,11 @@ func TestHistogram_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "le", Type: query.TFloat}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "le", Type: flux.TFloat}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), 0.0, 0.0}, @@ -189,13 +189,13 @@ func TestHistogram_Process(t *testing.T) { CountColumn: "_value", Buckets: []float64{1, 2, 4, 8, 16, 32, 64}, }}, - data: []query.Table{&executetest.Table{ + data: []flux.Table{&executetest.Table{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), execute.Time(1), 02.0}, @@ -212,11 +212,11 @@ func TestHistogram_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "le", Type: query.TFloat}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "le", Type: flux.TFloat}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), 1.0, 0.0}, @@ -237,13 +237,13 @@ func TestHistogram_Process(t *testing.T) { CountColumn: "_value", Buckets: []float64{1, 64, 2, 4, 16, 8, 32}, }}, - data: []query.Table{&executetest.Table{ + data: []flux.Table{&executetest.Table{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), execute.Time(1), 02.0}, @@ -260,11 +260,11 @@ func TestHistogram_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "le", Type: query.TFloat}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "le", Type: flux.TFloat}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), 1.0, 0.0}, @@ -285,13 +285,13 @@ func TestHistogram_Process(t *testing.T) { CountColumn: "_value", Buckets: []float64{1, 2, 3, 5, 8, 13, 21, 34, 55}, }}, - data: []query.Table{&executetest.Table{ + data: []flux.Table{&executetest.Table{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), execute.Time(1), 02.0}, @@ -308,11 +308,11 @@ func TestHistogram_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "le", Type: query.TFloat}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "le", Type: flux.TFloat}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), 1.0, 0.0}, diff --git a/functions/increase.go b/functions/increase.go index 3882ba41e9..35d1b3fff5 100644 --- a/functions/increase.go +++ b/functions/increase.go @@ -1,9 +1,9 @@ package functions -import "github.com/influxdata/platform/query" +import "github.com/influxdata/flux" func init() { - query.RegisterBuiltIn("increase", increaseBuiltIn) + flux.RegisterBuiltIn("increase", increaseBuiltIn) } var increaseBuiltIn = ` diff --git a/functions/integral.go b/functions/integral.go index cd647d700b..961b8d8b6e 100644 --- a/functions/integral.go +++ b/functions/integral.go @@ -4,16 +4,16 @@ import ( "fmt" "time" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" ) const IntegralKind = "integral" type IntegralOpSpec struct { - Unit query.Duration `json:"unit"` + Unit flux.Duration `json:"unit"` execute.AggregateConfig } @@ -22,13 +22,13 @@ var integralSignature = execute.DefaultAggregateSignature() func init() { integralSignature.Params["unit"] = semantic.Duration - query.RegisterFunction(IntegralKind, createIntegralOpSpec, integralSignature) - query.RegisterOpSpec(IntegralKind, newIntegralOp) + flux.RegisterFunction(IntegralKind, createIntegralOpSpec, integralSignature) + flux.RegisterOpSpec(IntegralKind, newIntegralOp) plan.RegisterProcedureSpec(IntegralKind, newIntegralProcedure, IntegralKind) execute.RegisterTransformation(IntegralKind, createIntegralTransformation) } -func createIntegralOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createIntegralOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -41,7 +41,7 @@ func createIntegralOpSpec(args query.Arguments, a *query.Administration) (query. spec.Unit = unit } else { //Default is 1s - spec.Unit = query.Duration(time.Second) + spec.Unit = flux.Duration(time.Second) } if err := spec.AggregateConfig.ReadArgs(args); err != nil { @@ -50,20 +50,20 @@ func createIntegralOpSpec(args query.Arguments, a *query.Administration) (query. return spec, nil } -func newIntegralOp() query.OperationSpec { +func newIntegralOp() flux.OperationSpec { return new(IntegralOpSpec) } -func (s *IntegralOpSpec) Kind() query.OperationKind { +func (s *IntegralOpSpec) Kind() flux.OperationKind { return IntegralKind } type IntegralProcedureSpec struct { - Unit query.Duration `json:"unit"` + Unit flux.Duration `json:"unit"` execute.AggregateConfig } -func newIntegralProcedure(qs query.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { +func newIntegralProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*IntegralOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -113,20 +113,20 @@ func NewIntegralTransformation(d execute.Dataset, cache execute.TableBuilderCach } } -func (t *integralTransformation) RetractTable(id execute.DatasetID, key query.GroupKey) error { +func (t *integralTransformation) RetractTable(id execute.DatasetID, key flux.GroupKey) error { return t.d.RetractTable(key) } -func (t *integralTransformation) Process(id execute.DatasetID, tbl query.Table) error { +func (t *integralTransformation) Process(id execute.DatasetID, tbl flux.Table) error { builder, created := t.cache.TableBuilder(tbl.Key()) if !created { return fmt.Errorf("integral found duplicate table with key: %v", tbl.Key()) } execute.AddTableKeyCols(tbl.Key(), builder) - builder.AddCol(query.ColMeta{ + builder.AddCol(flux.ColMeta{ Label: t.spec.TimeDst, - Type: query.TTime, + Type: flux.TTime, }) cols := tbl.Cols() integrals := make([]*integral, len(cols)) @@ -134,9 +134,9 @@ func (t *integralTransformation) Process(id execute.DatasetID, tbl query.Table) for j, c := range cols { if execute.ContainsStr(t.spec.Columns, c.Label) { integrals[j] = newIntegral(time.Duration(t.spec.Unit)) - colMap[j] = builder.AddCol(query.ColMeta{ + colMap[j] = builder.AddCol(flux.ColMeta{ Label: c.Label, - Type: query.TFloat, + Type: flux.TFloat, }) } } @@ -149,7 +149,7 @@ func (t *integralTransformation) Process(id execute.DatasetID, tbl query.Table) if timeIdx < 0 { return fmt.Errorf("no column %q exists", t.spec.TimeSrc) } - err := tbl.Do(func(cr query.ColReader) error { + err := tbl.Do(func(cr flux.ColReader) error { for j, in := range integrals { if in == nil { continue diff --git a/functions/integral_test.go b/functions/integral_test.go index fc6b2ef552..d7c9381e0d 100644 --- a/functions/integral_test.go +++ b/functions/integral_test.go @@ -4,22 +4,22 @@ import ( "testing" "time" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" ) func TestIntegralOperation_Marshaling(t *testing.T) { data := []byte(`{"id":"integral","kind":"integral","spec":{"unit":"1m"}}`) - op := &query.Operation{ + op := &flux.Operation{ ID: "integral", Spec: &functions.IntegralOpSpec{ - Unit: query.Duration(time.Minute), + Unit: flux.Duration(time.Minute), }, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestIntegral_PassThrough(t *testing.T) { @@ -37,7 +37,7 @@ func TestIntegral_Process(t *testing.T) { testCases := []struct { name string spec *functions.IntegralProcedureSpec - data []query.Table + data []flux.Table want []*executetest.Table }{ { @@ -46,13 +46,13 @@ func TestIntegral_Process(t *testing.T) { Unit: 1, AggregateConfig: execute.DefaultAggregateConfig, }, - data: []query.Table{&executetest.Table{ + data: []flux.Table{&executetest.Table{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), execute.Time(1), 2.0}, @@ -61,11 +61,11 @@ func TestIntegral_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), execute.Time(3), 1.5}, @@ -75,16 +75,16 @@ func TestIntegral_Process(t *testing.T) { { name: "float with units", spec: &functions.IntegralProcedureSpec{ - Unit: query.Duration(time.Second), + Unit: flux.Duration(time.Second), AggregateConfig: execute.DefaultAggregateConfig, }, - data: []query.Table{&executetest.Table{ + data: []flux.Table{&executetest.Table{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1 * time.Second), execute.Time(4 * time.Second), execute.Time(1 * time.Second), 2.0}, @@ -93,11 +93,11 @@ func TestIntegral_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1 * time.Second), execute.Time(4 * time.Second), execute.Time(4 * time.Second), 3.0}, @@ -110,14 +110,14 @@ func TestIntegral_Process(t *testing.T) { Unit: 1, AggregateConfig: execute.DefaultAggregateConfig, }, - data: []query.Table{&executetest.Table{ + data: []flux.Table{&executetest.Table{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), execute.Time(1), 2.0, "a"}, @@ -126,11 +126,11 @@ func TestIntegral_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), execute.Time(3), 1.5}, @@ -147,14 +147,14 @@ func TestIntegral_Process(t *testing.T) { Columns: []string{"x", "y"}, }, }, - data: []query.Table{&executetest.Table{ + data: []flux.Table{&executetest.Table{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "x", Type: query.TFloat}, - {Label: "y", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "x", Type: flux.TFloat}, + {Label: "y", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(5), execute.Time(1), 2.0, 20.0}, @@ -165,12 +165,12 @@ func TestIntegral_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "x", Type: query.TFloat}, - {Label: "y", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "x", Type: flux.TFloat}, + {Label: "y", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(5), execute.Time(5), 4.5, 45.0}, diff --git a/functions/join.go b/functions/join.go index 27e655f0e7..3413064f31 100644 --- a/functions/join.go +++ b/functions/join.go @@ -6,12 +6,12 @@ import ( "sort" "sync" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/interpreter" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/interpreter" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" + "github.com/influxdata/flux/values" "github.com/pkg/errors" ) @@ -30,16 +30,16 @@ type JoinOpSpec struct { // The first parent is referenced by the first name and so forth. // TODO(nathanielc): Change this to a map of parent operation IDs to names. // Then make it possible for the transformation to map operation IDs to parent IDs. - TableNames map[query.OperationID]string `json:"tableNames"` + TableNames map[flux.OperationID]string `json:"tableNames"` // Method is a the type of join to perform Method string `json:"method"` // tableNames maps each TableObject being joined to the parameter that holds it. - tableNames map[*query.TableObject]string + tableNames map[*flux.TableObject]string } type params struct { vars []string - vals []*query.TableObject + vals []*flux.TableObject } type joinParams params @@ -47,12 +47,12 @@ type joinParams params func newJoinParams(capacity int) *joinParams { params := &joinParams{ vars: make([]string, 0, capacity), - vals: make([]*query.TableObject, 0, capacity), + vals: make([]*flux.TableObject, 0, capacity), } return params } -func (params *joinParams) add(newVar string, newVal *query.TableObject) { +func (params *joinParams) add(newVar string, newVal *flux.TableObject) { params.vars = append(params.vars, newVar) params.vals = append(params.vals, newVal) } @@ -76,22 +76,22 @@ var joinSignature = semantic.FunctionSignature{ "on": semantic.NewArrayType(semantic.String), "method": semantic.String, }, - ReturnType: query.TableObjectType, + ReturnType: flux.TableObjectType, PipeArgument: "tables", } func init() { - query.RegisterFunction(JoinKind, createJoinOpSpec, joinSignature) - query.RegisterOpSpec(JoinKind, newJoinOp) + flux.RegisterFunction(JoinKind, createJoinOpSpec, joinSignature) + flux.RegisterOpSpec(JoinKind, newJoinOp) //TODO(nathanielc): Allow for other types of join implementations plan.RegisterProcedureSpec(MergeJoinKind, newMergeJoinProcedure, JoinKind) execute.RegisterTransformation(MergeJoinKind, createMergeJoinTransformation) } -func createJoinOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createJoinOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { spec := &JoinOpSpec{ - TableNames: make(map[query.OperationID]string), - tableNames: make(map[*query.TableObject]string), + TableNames: make(map[flux.OperationID]string), + tableNames: make(map[*flux.TableObject]string), } // On specifies the columns to join on. If 'on' is not present in the arguments @@ -137,11 +137,11 @@ func createJoinOpSpec(args query.Arguments, a *query.Administration) (query.Oper err = fmt.Errorf("value for key %q in tables must be an object: got %v", k, t.Type().Kind()) return } - if t.Type() != query.TableObjectType { + if t.Type() != flux.TableObjectType { err = fmt.Errorf("value for key %q in tables must be an table object: got %v", k, t.Type()) return } - p := t.(*query.TableObject) + p := t.(*flux.TableObject) joinParams.add(k, p) spec.tableNames[p] = k }) @@ -159,17 +159,17 @@ func createJoinOpSpec(args query.Arguments, a *query.Administration) (query.Oper return spec, nil } -func (t *JoinOpSpec) IDer(ider query.IDer) { +func (t *JoinOpSpec) IDer(ider flux.IDer) { for p, k := range t.tableNames { t.TableNames[ider.ID(p)] = k } } -func newJoinOp() query.OperationSpec { +func newJoinOp() flux.OperationSpec { return new(JoinOpSpec) } -func (s *JoinOpSpec) Kind() query.OperationKind { +func (s *JoinOpSpec) Kind() flux.OperationKind { return JoinKind } @@ -178,7 +178,7 @@ type MergeJoinProcedureSpec struct { TableNames map[plan.ProcedureID]string `json:"table_names"` } -func newMergeJoinProcedure(qs query.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { +func newMergeJoinProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*JoinOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -279,14 +279,14 @@ type mergeJoinParentState struct { finished bool } -func (t *mergeJoinTransformation) RetractTable(id execute.DatasetID, key query.GroupKey) error { +func (t *mergeJoinTransformation) RetractTable(id execute.DatasetID, key flux.GroupKey) error { panic("not implemented") } // Process processes a table from an incoming data stream. // It adds the table to an internal buffer and stores any output // group keys that can be constructed as a result of the new addition. -func (t *mergeJoinTransformation) Process(id execute.DatasetID, tbl query.Table) error { +func (t *mergeJoinTransformation) Process(id execute.DatasetID, tbl flux.Table) error { t.mu.Lock() defer t.mu.Unlock() @@ -379,41 +379,41 @@ type MergeJoinCache struct { intersection map[string]bool schema schema - colIndex map[query.ColMeta]int - schemaMap map[tableCol]query.ColMeta + colIndex map[flux.ColMeta]int + schemaMap map[tableCol]flux.ColMeta postJoinKeys *execute.GroupLookup - reverseLookup map[query.GroupKey]preJoinGroupKeys + reverseLookup map[flux.GroupKey]preJoinGroupKeys - tables map[query.GroupKey]query.Table + tables map[flux.GroupKey]flux.Table alloc *execute.Allocator - triggerSpec query.TriggerSpec + triggerSpec flux.TriggerSpec } type streamBuffer struct { - data map[query.GroupKey]*execute.ColListTableBuilder + data map[flux.GroupKey]*execute.ColListTableBuilder consumed map[values.Value]int ready map[values.Value]bool - stale map[query.GroupKey]bool + stale map[flux.GroupKey]bool last values.Value alloc *execute.Allocator } func newStreamBuffer(alloc *execute.Allocator) *streamBuffer { return &streamBuffer{ - data: make(map[query.GroupKey]*execute.ColListTableBuilder), + data: make(map[flux.GroupKey]*execute.ColListTableBuilder), consumed: make(map[values.Value]int), ready: make(map[values.Value]bool), - stale: make(map[query.GroupKey]bool), + stale: make(map[flux.GroupKey]bool), alloc: alloc, } } -func (buf *streamBuffer) table(key query.GroupKey) *execute.ColListTableBuilder { +func (buf *streamBuffer) table(key flux.GroupKey) *execute.ColListTableBuilder { return buf.data[key] } -func (buf *streamBuffer) insert(table query.Table) { +func (buf *streamBuffer) insert(table flux.Table) { // Construct a new table builder with same schema as input table builder := execute.NewColListTableBuilder(table.Key(), buf.alloc) execute.AddTableCols(table, builder) @@ -441,7 +441,7 @@ func (buf *streamBuffer) insert(table query.Table) { } } -func (buf *streamBuffer) expire(key query.GroupKey) { +func (buf *streamBuffer) expire(key flux.GroupKey) { if !buf.stale[key] && len(key.Cols()) > 0 { leftKeyValue := key.Value(0) consumedTables := buf.consumed[leftKeyValue] @@ -450,14 +450,14 @@ func (buf *streamBuffer) expire(key query.GroupKey) { } } -func (buf *streamBuffer) evict(key query.GroupKey) { +func (buf *streamBuffer) evict(key flux.GroupKey) { if builder, ok := buf.data[key]; ok { builder.ClearData() delete(buf.data, key) } } -func (buf *streamBuffer) clear(f func(query.GroupKey) bool) { +func (buf *streamBuffer) clear(f func(flux.GroupKey) bool) { for key := range buf.stale { if f(key) { buf.evict(key) @@ -466,7 +466,7 @@ func (buf *streamBuffer) clear(f func(query.GroupKey) bool) { } } -func (buf *streamBuffer) iterate(f func(query.GroupKey)) { +func (buf *streamBuffer) iterate(f func(flux.GroupKey)) { for key := range buf.data { f(key) } @@ -477,12 +477,12 @@ type tableCol struct { } type preJoinGroupKeys struct { - left, right query.GroupKey + left, right flux.GroupKey } type schema struct { - key []query.ColMeta - columns []query.ColMeta + key []flux.ColMeta + columns []flux.ColMeta } func (s schema) Len() int { @@ -529,15 +529,15 @@ func NewMergeJoinCache(alloc *execute.Allocator, datasetIDs []execute.DatasetID, names: names, schemas: schemas, buffers: buffers, - reverseLookup: make(map[query.GroupKey]preJoinGroupKeys), + reverseLookup: make(map[flux.GroupKey]preJoinGroupKeys), postJoinKeys: execute.NewGroupLookup(), - tables: make(map[query.GroupKey]query.Table), + tables: make(map[flux.GroupKey]flux.Table), alloc: alloc, } } // Table joins the two tables associated with a single output group key and returns the resulting table -func (c *MergeJoinCache) Table(key query.GroupKey) (query.Table, error) { +func (c *MergeJoinCache) Table(key flux.GroupKey) (flux.Table, error) { preJoinGroupKeys, ok := c.reverseLookup[key] if !ok { @@ -567,8 +567,8 @@ func (c *MergeJoinCache) Table(key query.GroupKey) (query.Table, error) { } // ForEach iterates over each table in the output stream -func (c *MergeJoinCache) ForEach(f func(query.GroupKey)) { - c.postJoinKeys.Range(func(key query.GroupKey, value interface{}) { +func (c *MergeJoinCache) ForEach(f func(flux.GroupKey)) { + c.postJoinKeys.Range(func(key flux.GroupKey, value interface{}) { if _, ok := c.tables[key]; !ok { @@ -593,10 +593,10 @@ func (c *MergeJoinCache) ForEach(f func(query.GroupKey)) { } // ForEachWithContext iterates over each table in the output stream -func (c *MergeJoinCache) ForEachWithContext(f func(query.GroupKey, execute.Trigger, execute.TableContext)) { +func (c *MergeJoinCache) ForEachWithContext(f func(flux.GroupKey, execute.Trigger, execute.TableContext)) { trigger := execute.NewTriggerFromSpec(c.triggerSpec) - c.postJoinKeys.Range(func(key query.GroupKey, value interface{}) { + c.postJoinKeys.Range(func(key flux.GroupKey, value interface{}) { preJoinGroupKeys := c.reverseLookup[key] @@ -631,7 +631,7 @@ func (c *MergeJoinCache) ForEachWithContext(f func(query.GroupKey, execute.Trigg } // DiscardTable removes a table from the output buffer -func (c *MergeJoinCache) DiscardTable(key query.GroupKey) { +func (c *MergeJoinCache) DiscardTable(key flux.GroupKey) { delete(c.tables, key) } @@ -639,7 +639,7 @@ func (c *MergeJoinCache) DiscardTable(key query.GroupKey) { // ExpireTable will be called after the table associated with key has already // been materialized. As a result, it cannot not be materialized again. Each // buffer is cleared of any stale data that arises as a result of this process. -func (c *MergeJoinCache) ExpireTable(key query.GroupKey) { +func (c *MergeJoinCache) ExpireTable(key flux.GroupKey) { // Remove this group key from the cache c.postJoinKeys.Delete(key) delete(c.tables, key) @@ -655,12 +655,12 @@ func (c *MergeJoinCache) ExpireTable(key query.GroupKey) { if c.canEvictTables() { - leftBuffer.clear(func(key query.GroupKey) bool { + leftBuffer.clear(func(key flux.GroupKey) bool { return rightBuffer.ready[key.Value(0)] && rightBuffer.consumed[key.Value(0)] == 0 }) - rightBuffer.clear(func(key query.GroupKey) bool { + rightBuffer.clear(func(key flux.GroupKey) bool { return leftBuffer.ready[key.Value(0)] && leftBuffer.consumed[key.Value(0)] == 0 }) @@ -668,7 +668,7 @@ func (c *MergeJoinCache) ExpireTable(key query.GroupKey) { } // SetTriggerSpec sets the trigger rule for this cache -func (c *MergeJoinCache) SetTriggerSpec(spec query.TriggerSpec) { +func (c *MergeJoinCache) SetTriggerSpec(spec flux.TriggerSpec) { c.triggerSpec = spec } @@ -682,13 +682,13 @@ func (c *MergeJoinCache) canEvictTables() bool { } // insertIntoBuffer adds the rows of an incoming table to one of the Join's internal buffers -func (c *MergeJoinCache) insertIntoBuffer(id execute.DatasetID, tbl query.Table) { +func (c *MergeJoinCache) insertIntoBuffer(id execute.DatasetID, tbl flux.Table) { // Initialize schema if tbl is first from its stream if _, ok := c.schemas[id]; !ok { c.schemas[id] = schema{ - key: make([]query.ColMeta, len(tbl.Key().Cols())), - columns: make([]query.ColMeta, len(tbl.Cols())), + key: make([]flux.ColMeta, len(tbl.Key().Cols())), + columns: make([]flux.ColMeta, len(tbl.Cols())), } for j, column := range tbl.Cols() { @@ -714,15 +714,15 @@ func (c *MergeJoinCache) insertIntoBuffer(id execute.DatasetID, tbl query.Table) // it with all other group keys from the opposing input stream. If it is determined // that two group keys will not join (due to having different values on a join column) // they are skipped. -func (c *MergeJoinCache) registerKey(id execute.DatasetID, key query.GroupKey) { +func (c *MergeJoinCache) registerKey(id execute.DatasetID, key flux.GroupKey) { var empty struct{} switch id { case c.leftID: - c.buffers[c.rightID].iterate(func(groupKey query.GroupKey) { + c.buffers[c.rightID].iterate(func(groupKey flux.GroupKey) { - keys := map[execute.DatasetID]query.GroupKey{ + keys := map[execute.DatasetID]flux.GroupKey{ c.leftID: key, c.rightID: groupKey, } @@ -744,9 +744,9 @@ func (c *MergeJoinCache) registerKey(id execute.DatasetID, key query.GroupKey) { case c.rightID: - c.buffers[c.leftID].iterate(func(groupKey query.GroupKey) { + c.buffers[c.leftID].iterate(func(groupKey flux.GroupKey) { - keys := map[execute.DatasetID]query.GroupKey{ + keys := map[execute.DatasetID]flux.GroupKey{ c.leftID: groupKey, c.rightID: key, } @@ -799,12 +799,12 @@ func (c *MergeJoinCache) buildPostJoinSchema() { ncols := len(left) + len(right) c.schema = schema{ - columns: make([]query.ColMeta, 0, ncols-len(c.on)), - key: make([]query.ColMeta, 0, ncols-len(c.on)), + columns: make([]flux.ColMeta, 0, ncols-len(c.on)), + key: make([]flux.ColMeta, 0, ncols-len(c.on)), } - c.colIndex = make(map[query.ColMeta]int, ncols-len(c.on)) - c.schemaMap = make(map[tableCol]query.ColMeta, ncols) + c.colIndex = make(map[flux.ColMeta]int, ncols-len(c.on)) + c.schemaMap = make(map[tableCol]flux.ColMeta, ncols) added := make(map[string]bool, ncols-len(c.on)) // Build schema for output table @@ -818,7 +818,7 @@ func (c *MergeJoinCache) buildPostJoinSchema() { } } -func (c *MergeJoinCache) join(left, right *execute.ColListTableBuilder) (query.Table, error) { +func (c *MergeJoinCache) join(left, right *execute.ColListTableBuilder) (flux.Table, error) { // Determine sort order for the joining tables on := make([]string, len(c.on)) @@ -831,13 +831,13 @@ func (c *MergeJoinCache) join(left, right *execute.ColListTableBuilder) (query.T right.Sort(on, false) var leftSet, rightSet subset - var leftKey, rightKey query.GroupKey + var leftKey, rightKey flux.GroupKey leftTable, rightTable := left.RawTable(), right.RawTable() leftSet, leftKey = c.advance(leftSet.Stop, leftTable) rightSet, rightKey = c.advance(rightSet.Stop, rightTable) - keys := map[execute.DatasetID]query.GroupKey{ + keys := map[execute.DatasetID]flux.GroupKey{ c.leftID: left.Key(), c.rightID: right.Key(), } @@ -899,9 +899,9 @@ func (c *MergeJoinCache) join(left, right *execute.ColListTableBuilder) (query.T } // postJoinGroupKey produces a new group key value from a left and a right group key value -func (c *MergeJoinCache) postJoinGroupKey(keys map[execute.DatasetID]query.GroupKey) query.GroupKey { +func (c *MergeJoinCache) postJoinGroupKey(keys map[execute.DatasetID]flux.GroupKey) flux.GroupKey { key := groupKey{ - cols: make([]query.ColMeta, 0, len(keys)*5), + cols: make([]flux.ColMeta, 0, len(keys)*5), vals: make([]values.Value, 0, len(keys)*5), } @@ -933,7 +933,7 @@ func (c *MergeJoinCache) postJoinGroupKey(keys map[execute.DatasetID]query.Group } // advance advances the row pointer of a sorted table that is being joined -func (c *MergeJoinCache) advance(offset int, table query.ColReader) (subset, query.GroupKey) { +func (c *MergeJoinCache) advance(offset int, table flux.ColReader) (subset, flux.GroupKey) { if n := table.Len(); n == offset { return subset{Start: n, Stop: n}, nil } @@ -958,33 +958,33 @@ func (s subset) Empty() bool { } // equalRowKeys determines whether two rows of a table are equal on the set of columns defined by on -func equalRowKeys(x, y int, table query.ColReader, on map[string]bool) bool { +func equalRowKeys(x, y int, table flux.ColReader, on map[string]bool) bool { for j, c := range table.Cols() { if !on[c.Label] { continue } switch c.Type { - case query.TBool: + case flux.TBool: if xv, yv := table.Bools(j)[x], table.Bools(j)[y]; xv != yv { return false } - case query.TInt: + case flux.TInt: if xv, yv := table.Ints(j)[x], table.Ints(j)[y]; xv != yv { return false } - case query.TUInt: + case flux.TUInt: if xv, yv := table.UInts(j)[x], table.UInts(j)[y]; xv != yv { return false } - case query.TFloat: + case flux.TFloat: if xv, yv := table.Floats(j)[x], table.Floats(j)[y]; xv != yv { return false } - case query.TString: + case flux.TString: if xv, yv := table.Strings(j)[x], table.Strings(j)[y]; xv != yv { return false } - case query.TTime: + case flux.TTime: if xv, yv := table.Times(j)[x], table.Times(j)[y]; xv != yv { return false } @@ -995,7 +995,7 @@ func equalRowKeys(x, y int, table query.ColReader, on map[string]bool) bool { return true } -func addColumnsToSchema(name string, columns []query.ColMeta, added, shared, on map[string]bool, schema *schema, schemaMap map[tableCol]query.ColMeta) { +func addColumnsToSchema(name string, columns []flux.ColMeta, added, shared, on map[string]bool, schema *schema, schemaMap map[tableCol]flux.ColMeta) { for _, column := range columns { tableAndColumn := tableCol{ @@ -1004,7 +1004,7 @@ func addColumnsToSchema(name string, columns []query.ColMeta, added, shared, on } newLabel := renameColumn(tableAndColumn, shared, on) - newColumn := query.ColMeta{ + newColumn := flux.ColMeta{ Label: newLabel, Type: column.Type, } @@ -1029,7 +1029,7 @@ func renameColumn(col tableCol, share, on map[string]bool) string { } type groupKey struct { - cols []query.ColMeta + cols []flux.ColMeta vals []values.Value } diff --git a/functions/join_test.go b/functions/join_test.go index 927bab7d8d..b3a6877a60 100644 --- a/functions/join_test.go +++ b/functions/join_test.go @@ -6,25 +6,25 @@ import ( "time" "github.com/google/go-cmp/cmp" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/plan/plantest" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/plan/plantest" ) func TestJoin_NewQuery(t *testing.T) { - tests := []querytest.NewQueryTestCase{ + tests := []fluxtest.NewQueryTestCase{ { Name: "basic two-way join", Raw: ` a = from(bucket:"dbA") |> range(start:-1h) b = from(bucket:"dbB") |> range(start:-1h) join(tables:{a:a,b:b}, on:["host"])`, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "from0", Spec: &functions.FromOpSpec{ @@ -34,11 +34,11 @@ func TestJoin_NewQuery(t *testing.T) { { ID: "range1", Spec: &functions.RangeOpSpec{ - Start: query.Time{ + Start: flux.Time{ Relative: -1 * time.Hour, IsRelative: true, }, - Stop: query.Time{ + Stop: flux.Time{ IsRelative: true, }, TimeCol: "_time", @@ -55,11 +55,11 @@ func TestJoin_NewQuery(t *testing.T) { { ID: "range3", Spec: &functions.RangeOpSpec{ - Start: query.Time{ + Start: flux.Time{ Relative: -1 * time.Hour, IsRelative: true, }, - Stop: query.Time{ + Stop: flux.Time{ IsRelative: true, }, TimeCol: "_time", @@ -71,12 +71,12 @@ func TestJoin_NewQuery(t *testing.T) { ID: "join4", Spec: &functions.JoinOpSpec{ On: []string{"host"}, - TableNames: map[query.OperationID]string{"range1": "a", "range3": "b"}, + TableNames: map[flux.OperationID]string{"range1": "a", "range3": "b"}, Method: "inner", }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "from0", Child: "range1"}, {Parent: "from2", Child: "range3"}, {Parent: "range1", Child: "join4"}, @@ -91,8 +91,8 @@ func TestJoin_NewQuery(t *testing.T) { b = from(bucket:"flux") |> range(start:-1h) join(tables:{a:a,b:b}, on:["t1"]) `, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "from0", Spec: &functions.FromOpSpec{ @@ -102,11 +102,11 @@ func TestJoin_NewQuery(t *testing.T) { { ID: "range1", Spec: &functions.RangeOpSpec{ - Start: query.Time{ + Start: flux.Time{ Relative: -1 * time.Hour, IsRelative: true, }, - Stop: query.Time{ + Stop: flux.Time{ IsRelative: true, }, TimeCol: "_time", @@ -123,11 +123,11 @@ func TestJoin_NewQuery(t *testing.T) { { ID: "range3", Spec: &functions.RangeOpSpec{ - Start: query.Time{ + Start: flux.Time{ Relative: -1 * time.Hour, IsRelative: true, }, - Stop: query.Time{ + Stop: flux.Time{ IsRelative: true, }, TimeCol: "_time", @@ -139,12 +139,12 @@ func TestJoin_NewQuery(t *testing.T) { ID: "join4", Spec: &functions.JoinOpSpec{ On: []string{"t1"}, - TableNames: map[query.OperationID]string{"range1": "a", "range3": "b"}, + TableNames: map[flux.OperationID]string{"range1": "a", "range3": "b"}, Method: "inner", }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "from0", Child: "range1"}, {Parent: "from2", Child: "range3"}, {Parent: "range1", Child: "join4"}, @@ -157,7 +157,7 @@ func TestJoin_NewQuery(t *testing.T) { tc := tc t.Run(tc.Name, func(t *testing.T) { t.Parallel() - querytest.NewQueryTestHelper(t, tc) + fluxtest.NewQueryTestHelper(t, tc) }) } } @@ -171,14 +171,14 @@ func TestJoinOperation_Marshaling(t *testing.T) { "tableNames":{"sum1":"a","count3":"b"} } }`) - op := &query.Operation{ + op := &flux.Operation{ ID: "join", Spec: &functions.JoinOpSpec{ On: []string{"t1", "t2"}, - TableNames: map[query.OperationID]string{"sum1": "a", "count3": "b"}, + TableNames: map[flux.OperationID]string{"sum1": "a", "count3": "b"}, }, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestMergeJoin_Process(t *testing.T) { @@ -204,9 +204,9 @@ func TestMergeJoin_Process(t *testing.T) { }, data0: []*executetest.Table{ { - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 1.0}, @@ -217,9 +217,9 @@ func TestMergeJoin_Process(t *testing.T) { }, data1: []*executetest.Table{ { - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 10.0}, @@ -230,10 +230,10 @@ func TestMergeJoin_Process(t *testing.T) { }, want: []*executetest.Table{ { - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "a__value", Type: query.TFloat}, - {Label: "b__value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "a__value", Type: flux.TFloat}, + {Label: "b__value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, 10.0}, @@ -251,9 +251,9 @@ func TestMergeJoin_Process(t *testing.T) { }, data0: []*executetest.Table{ { - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TInt}, }, Data: [][]interface{}{ {execute.Time(1), int64(1)}, @@ -264,9 +264,9 @@ func TestMergeJoin_Process(t *testing.T) { }, data1: []*executetest.Table{ { - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TInt}, }, Data: [][]interface{}{ {execute.Time(1), int64(10)}, @@ -277,10 +277,10 @@ func TestMergeJoin_Process(t *testing.T) { }, want: []*executetest.Table{ { - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "a__value", Type: query.TInt}, - {Label: "b__value", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "a__value", Type: flux.TInt}, + {Label: "b__value", Type: flux.TInt}, }, Data: [][]interface{}{ {execute.Time(1), int64(1), int64(10)}, @@ -298,9 +298,9 @@ func TestMergeJoin_Process(t *testing.T) { }, data0: []*executetest.Table{ { - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(2), 1.0}, @@ -311,9 +311,9 @@ func TestMergeJoin_Process(t *testing.T) { }, data1: []*executetest.Table{ { - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(3), 10.0}, @@ -324,10 +324,10 @@ func TestMergeJoin_Process(t *testing.T) { }, want: []*executetest.Table{ { - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "a__value", Type: query.TFloat}, - {Label: "b__value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "a__value", Type: flux.TFloat}, + {Label: "b__value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 2.0, 20.0}, @@ -345,9 +345,9 @@ func TestMergeJoin_Process(t *testing.T) { }, data0: []*executetest.Table{ { - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 1.0}, @@ -358,9 +358,9 @@ func TestMergeJoin_Process(t *testing.T) { }, data1: []*executetest.Table{ { - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 10.0}, @@ -370,10 +370,10 @@ func TestMergeJoin_Process(t *testing.T) { }, want: []*executetest.Table{ { - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "a__value", Type: query.TFloat}, - {Label: "b__value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "a__value", Type: flux.TFloat}, + {Label: "b__value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, 10.0}, @@ -390,9 +390,9 @@ func TestMergeJoin_Process(t *testing.T) { }, data0: []*executetest.Table{ { - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 1.0}, @@ -403,9 +403,9 @@ func TestMergeJoin_Process(t *testing.T) { }, data1: []*executetest.Table{ { - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 10.0}, @@ -418,10 +418,10 @@ func TestMergeJoin_Process(t *testing.T) { }, want: []*executetest.Table{ { - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "a__value", Type: query.TFloat}, - {Label: "b__value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "a__value", Type: flux.TFloat}, + {Label: "b__value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, 10.0}, @@ -442,10 +442,10 @@ func TestMergeJoin_Process(t *testing.T) { data0: []*executetest.Table{ { KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "a"}, @@ -457,10 +457,10 @@ func TestMergeJoin_Process(t *testing.T) { data1: []*executetest.Table{ { KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 10.0, "a"}, @@ -472,11 +472,11 @@ func TestMergeJoin_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "a__value", Type: query.TFloat}, - {Label: "b__value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "a__value", Type: flux.TFloat}, + {Label: "b__value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, 10.0, "a"}, @@ -494,10 +494,10 @@ func TestMergeJoin_Process(t *testing.T) { }, data0: []*executetest.Table{ { - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "a"}, @@ -511,10 +511,10 @@ func TestMergeJoin_Process(t *testing.T) { }, data1: []*executetest.Table{ { - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 10.0, "a"}, @@ -528,11 +528,11 @@ func TestMergeJoin_Process(t *testing.T) { }, want: []*executetest.Table{ { - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "a__value", Type: query.TFloat}, - {Label: "b__value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "a__value", Type: flux.TFloat}, + {Label: "b__value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, 10.0, "a"}, @@ -554,11 +554,11 @@ func TestMergeJoin_Process(t *testing.T) { data0: []*executetest.Table{ { KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "a", "x"}, @@ -573,11 +573,11 @@ func TestMergeJoin_Process(t *testing.T) { data1: []*executetest.Table{ { KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 10.0, "a", "x"}, @@ -592,12 +592,12 @@ func TestMergeJoin_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "a__value", Type: query.TFloat}, - {Label: "b__value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "a__value", Type: flux.TFloat}, + {Label: "b__value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, 10.0, "a", "x"}, @@ -619,11 +619,11 @@ func TestMergeJoin_Process(t *testing.T) { data0: []*executetest.Table{ { KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "a", "x"}, @@ -636,11 +636,11 @@ func TestMergeJoin_Process(t *testing.T) { data1: []*executetest.Table{ { KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 10.0, "a", "x"}, @@ -655,12 +655,12 @@ func TestMergeJoin_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "a__value", Type: query.TFloat}, - {Label: "b__value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "a__value", Type: flux.TFloat}, + {Label: "b__value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, 10.0, "a", "x"}, @@ -682,9 +682,9 @@ func TestMergeJoin_Process(t *testing.T) { data0: []*executetest.Table{ { KeyCols: []string{"_value"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 1.0}, @@ -692,9 +692,9 @@ func TestMergeJoin_Process(t *testing.T) { }, { KeyCols: []string{"_value"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(2), 2.0}, @@ -702,9 +702,9 @@ func TestMergeJoin_Process(t *testing.T) { }, { KeyCols: []string{"_value"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(3), 3.0}, @@ -714,9 +714,9 @@ func TestMergeJoin_Process(t *testing.T) { data1: []*executetest.Table{ { KeyCols: []string{"_value"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 1.0}, @@ -724,9 +724,9 @@ func TestMergeJoin_Process(t *testing.T) { }, { KeyCols: []string{"_value"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(2), 2.0}, @@ -734,9 +734,9 @@ func TestMergeJoin_Process(t *testing.T) { }, { KeyCols: []string{"_value"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(3), 3.0}, @@ -746,10 +746,10 @@ func TestMergeJoin_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"a__value", "b__value"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "a__value", Type: query.TFloat}, - {Label: "b__value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "a__value", Type: flux.TFloat}, + {Label: "b__value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, 1.0}, @@ -757,10 +757,10 @@ func TestMergeJoin_Process(t *testing.T) { }, { KeyCols: []string{"a__value", "b__value"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "a__value", Type: query.TFloat}, - {Label: "b__value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "a__value", Type: flux.TFloat}, + {Label: "b__value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(2), 2.0, 2.0}, @@ -768,10 +768,10 @@ func TestMergeJoin_Process(t *testing.T) { }, { KeyCols: []string{"a__value", "b__value"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "a__value", Type: query.TFloat}, - {Label: "b__value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "a__value", Type: flux.TFloat}, + {Label: "b__value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(3), 3.0, 3.0}, @@ -788,9 +788,9 @@ func TestMergeJoin_Process(t *testing.T) { data0: []*executetest.Table{ { KeyCols: []string{"_key"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_key", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_key", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(3), "a"}, @@ -799,9 +799,9 @@ func TestMergeJoin_Process(t *testing.T) { }, { KeyCols: []string{"_key"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_key", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_key", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(4), "b"}, @@ -810,9 +810,9 @@ func TestMergeJoin_Process(t *testing.T) { }, { KeyCols: []string{"_key"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_key", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_key", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(5), "c"}, @@ -823,9 +823,9 @@ func TestMergeJoin_Process(t *testing.T) { data1: []*executetest.Table{ { KeyCols: []string{"_key"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_key", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_key", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(8), "a"}, @@ -833,9 +833,9 @@ func TestMergeJoin_Process(t *testing.T) { }, { KeyCols: []string{"_key"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_key", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_key", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(5), "b"}, @@ -845,9 +845,9 @@ func TestMergeJoin_Process(t *testing.T) { }, { KeyCols: []string{"_key"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_key", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_key", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), "c"}, @@ -857,10 +857,10 @@ func TestMergeJoin_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"a__key", "b__key"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "a__key", Type: query.TString}, - {Label: "b__key", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "a__key", Type: flux.TString}, + {Label: "b__key", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), "a", "c"}, @@ -868,10 +868,10 @@ func TestMergeJoin_Process(t *testing.T) { }, { KeyCols: []string{"a__key", "b__key"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "a__key", Type: query.TString}, - {Label: "b__key", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "a__key", Type: flux.TString}, + {Label: "b__key", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(5), "c", "b"}, @@ -888,11 +888,11 @@ func TestMergeJoin_Process(t *testing.T) { data0: []*executetest.Table{ { KeyCols: []string{"t1", "t2"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "a", "x"}, @@ -902,11 +902,11 @@ func TestMergeJoin_Process(t *testing.T) { }, { KeyCols: []string{"t1", "t2"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.5, "a", "y"}, @@ -918,11 +918,11 @@ func TestMergeJoin_Process(t *testing.T) { data1: []*executetest.Table{ { KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 10.0, "a", "x"}, @@ -937,13 +937,13 @@ func TestMergeJoin_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"a_t1", "b_t1", "t2"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "a__value", Type: query.TFloat}, - {Label: "a_t1", Type: query.TString}, - {Label: "b__value", Type: query.TFloat}, - {Label: "b_t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "a__value", Type: flux.TFloat}, + {Label: "a_t1", Type: flux.TString}, + {Label: "b__value", Type: flux.TFloat}, + {Label: "b_t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "a", 10.0, "a", "x"}, @@ -953,13 +953,13 @@ func TestMergeJoin_Process(t *testing.T) { }, { KeyCols: []string{"a_t1", "b_t1", "t2"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "a__value", Type: query.TFloat}, - {Label: "a_t1", Type: query.TString}, - {Label: "b__value", Type: query.TFloat}, - {Label: "b_t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "a__value", Type: flux.TFloat}, + {Label: "a_t1", Type: flux.TString}, + {Label: "b__value", Type: flux.TFloat}, + {Label: "b_t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.5, "a", 10.1, "a", "y"}, @@ -978,11 +978,11 @@ func TestMergeJoin_Process(t *testing.T) { data0: []*executetest.Table{ { KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "a", "x"}, @@ -997,11 +997,11 @@ func TestMergeJoin_Process(t *testing.T) { data1: []*executetest.Table{ { KeyCols: []string{"t2"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 10.0, "a", "x"}, @@ -1011,11 +1011,11 @@ func TestMergeJoin_Process(t *testing.T) { }, { KeyCols: []string{"t2"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 10.1, "a", "y"}, @@ -1027,13 +1027,13 @@ func TestMergeJoin_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"a_t1", "t2"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "a__value", Type: query.TFloat}, - {Label: "a_t1", Type: query.TString}, - {Label: "b__value", Type: query.TFloat}, - {Label: "b_t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "a__value", Type: flux.TFloat}, + {Label: "a_t1", Type: flux.TString}, + {Label: "b__value", Type: flux.TFloat}, + {Label: "b_t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "a", 10.0, "a", "x"}, @@ -1043,13 +1043,13 @@ func TestMergeJoin_Process(t *testing.T) { }, { KeyCols: []string{"a_t1", "t2"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "a__value", Type: query.TFloat}, - {Label: "a_t1", Type: query.TString}, - {Label: "b__value", Type: query.TFloat}, - {Label: "b_t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "a__value", Type: flux.TFloat}, + {Label: "a_t1", Type: flux.TString}, + {Label: "b__value", Type: flux.TFloat}, + {Label: "b_t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.5, "a", 10.1, "a", "y"}, @@ -1068,11 +1068,11 @@ func TestMergeJoin_Process(t *testing.T) { data0: []*executetest.Table{ { KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "a", "x"}, @@ -1084,11 +1084,11 @@ func TestMergeJoin_Process(t *testing.T) { data1: []*executetest.Table{ { KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 10.0, "a", "x"}, @@ -1103,14 +1103,14 @@ func TestMergeJoin_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"a_t1", "b_t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "a__value", Type: query.TFloat}, - {Label: "a_t1", Type: query.TString}, - {Label: "a_t2", Type: query.TString}, - {Label: "b__value", Type: query.TFloat}, - {Label: "b_t1", Type: query.TString}, - {Label: "b_t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "a__value", Type: flux.TFloat}, + {Label: "a_t1", Type: flux.TString}, + {Label: "a_t2", Type: flux.TString}, + {Label: "b__value", Type: flux.TFloat}, + {Label: "b_t1", Type: flux.TString}, + {Label: "b_t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "a", "x", 10.0, "a", "x"}, @@ -1130,10 +1130,10 @@ func TestMergeJoin_Process(t *testing.T) { }, data0: []*executetest.Table{ { - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "a_tag", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "a_tag", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "a"}, @@ -1144,10 +1144,10 @@ func TestMergeJoin_Process(t *testing.T) { }, data1: []*executetest.Table{ { - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "b_tag", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "b_tag", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "b"}, @@ -1158,11 +1158,11 @@ func TestMergeJoin_Process(t *testing.T) { }, want: []*executetest.Table{ { - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "a_tag", Type: query.TString}, - {Label: "b_tag", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "a_tag", Type: flux.TString}, + {Label: "b_tag", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "a", "b"}, @@ -1181,10 +1181,10 @@ func TestMergeJoin_Process(t *testing.T) { data0: []*executetest.Table{ { KeyCols: []string{"tag"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "tag", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "tag", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "a"}, @@ -1192,10 +1192,10 @@ func TestMergeJoin_Process(t *testing.T) { }, { KeyCols: []string{"tag"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "tag", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "tag", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(2), 2.0, "b"}, @@ -1203,10 +1203,10 @@ func TestMergeJoin_Process(t *testing.T) { }, { KeyCols: []string{"tag"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "tag", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "tag", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(3), 3.0, "c"}, @@ -1216,10 +1216,10 @@ func TestMergeJoin_Process(t *testing.T) { data1: []*executetest.Table{ { KeyCols: []string{"tag"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "tag", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "tag", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "a"}, @@ -1227,10 +1227,10 @@ func TestMergeJoin_Process(t *testing.T) { }, { KeyCols: []string{"tag"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "tag", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "tag", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(2), 2.0, "b"}, @@ -1238,10 +1238,10 @@ func TestMergeJoin_Process(t *testing.T) { }, { KeyCols: []string{"tag"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "tag", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "tag", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(3), 3.0, "c"}, @@ -1251,11 +1251,11 @@ func TestMergeJoin_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"tag"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "a__value", Type: query.TFloat}, - {Label: "b__value", Type: query.TFloat}, - {Label: "tag", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "a__value", Type: flux.TFloat}, + {Label: "b__value", Type: flux.TFloat}, + {Label: "tag", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, 1.0, "a"}, @@ -1263,11 +1263,11 @@ func TestMergeJoin_Process(t *testing.T) { }, { KeyCols: []string{"tag"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "a__value", Type: query.TFloat}, - {Label: "b__value", Type: query.TFloat}, - {Label: "tag", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "a__value", Type: flux.TFloat}, + {Label: "b__value", Type: flux.TFloat}, + {Label: "tag", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(2), 2.0, 2.0, "b"}, @@ -1275,11 +1275,11 @@ func TestMergeJoin_Process(t *testing.T) { }, { KeyCols: []string{"tag"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "a__value", Type: query.TFloat}, - {Label: "b__value", Type: query.TFloat}, - {Label: "tag", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "a__value", Type: flux.TFloat}, + {Label: "b__value", Type: flux.TFloat}, + {Label: "tag", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(3), 3.0, 3.0, "c"}, diff --git a/functions/keys.go b/functions/keys.go index b686e56458..dd667327b6 100644 --- a/functions/keys.go +++ b/functions/keys.go @@ -5,11 +5,11 @@ import ( "sort" "strings" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/interpreter" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/interpreter" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" ) const KeysKind = "keys" @@ -22,19 +22,19 @@ type KeysOpSpec struct { Except []string `json:"except"` } -var keysSignature = query.DefaultFunctionSignature() +var keysSignature = flux.DefaultFunctionSignature() func init() { keysSignature.Params["except"] = semantic.NewArrayType(semantic.String) - query.RegisterFunction(KeysKind, createKeysOpSpec, keysSignature) - query.RegisterOpSpec(KeysKind, newKeysOp) + flux.RegisterFunction(KeysKind, createKeysOpSpec, keysSignature) + flux.RegisterOpSpec(KeysKind, newKeysOp) plan.RegisterProcedureSpec(KeysKind, newKeysProcedure, KeysKind) plan.RegisterRewriteRule(KeysPointLimitRewriteRule{}) execute.RegisterTransformation(KeysKind, createKeysTransformation) } -func createKeysOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createKeysOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -54,11 +54,11 @@ func createKeysOpSpec(args query.Arguments, a *query.Administration) (query.Oper return spec, nil } -func newKeysOp() query.OperationSpec { +func newKeysOp() flux.OperationSpec { return new(KeysOpSpec) } -func (s *KeysOpSpec) Kind() query.OperationKind { +func (s *KeysOpSpec) Kind() flux.OperationKind { return KeysKind } @@ -66,7 +66,7 @@ type KeysProcedureSpec struct { Except []string } -func newKeysProcedure(qs query.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { +func newKeysProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*KeysOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -151,18 +151,18 @@ func NewKeysTransformation(d execute.Dataset, cache execute.TableBuilderCache, s } } -func (t *keysTransformation) RetractTable(id execute.DatasetID, key query.GroupKey) error { +func (t *keysTransformation) RetractTable(id execute.DatasetID, key flux.GroupKey) error { return t.d.RetractTable(key) } -func (t *keysTransformation) Process(id execute.DatasetID, tbl query.Table) error { +func (t *keysTransformation) Process(id execute.DatasetID, tbl flux.Table) error { builder, created := t.cache.TableBuilder(tbl.Key()) if !created { return fmt.Errorf("keys found duplicate table with key: %v", tbl.Key()) } execute.AddTableKeyCols(tbl.Key(), builder) - colIdx := builder.AddCol(query.ColMeta{Label: execute.DefaultValueColLabel, Type: query.TString}) + colIdx := builder.AddCol(flux.ColMeta{Label: execute.DefaultValueColLabel, Type: flux.TString}) cols := tbl.Cols() sort.Slice(cols, func(i, j int) bool { @@ -194,7 +194,7 @@ func (t *keysTransformation) Process(id execute.DatasetID, tbl query.Table) erro } // TODO: this is a hack - return tbl.Do(func(query.ColReader) error { + return tbl.Do(func(flux.ColReader) error { return nil }) } diff --git a/functions/keys_test.go b/functions/keys_test.go index 457dcd4414..fababba423 100644 --- a/functions/keys_test.go +++ b/functions/keys_test.go @@ -3,29 +3,29 @@ package functions_test import ( "testing" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/functions" ) func TestKeys_Process(t *testing.T) { testCases := []struct { name string spec *functions.KeysProcedureSpec - data []query.Table + data []flux.Table want []*executetest.Table }{ { name: "one table", spec: &functions.KeysProcedureSpec{}, - data: []query.Table{ + data: []flux.Table{ &executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "tag0", Type: query.TString}, - {Label: "tag1", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "tag0", Type: flux.TString}, + {Label: "tag1", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 2.0}, @@ -33,8 +33,8 @@ func TestKeys_Process(t *testing.T) { }, }, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_value", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_value", Type: flux.TString}, }, Data: [][]interface{}{ {"_time"}, @@ -47,13 +47,13 @@ func TestKeys_Process(t *testing.T) { { name: "one table except", spec: &functions.KeysProcedureSpec{Except: []string{"_value", "_time"}}, - data: []query.Table{ + data: []flux.Table{ &executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "tag0", Type: query.TString}, - {Label: "tag1", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "tag0", Type: flux.TString}, + {Label: "tag1", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 2.0}, @@ -61,8 +61,8 @@ func TestKeys_Process(t *testing.T) { }, }, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_value", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_value", Type: flux.TString}, }, Data: [][]interface{}{ {"tag0"}, @@ -73,14 +73,14 @@ func TestKeys_Process(t *testing.T) { { name: "two tables", spec: &functions.KeysProcedureSpec{}, - data: []query.Table{ + data: []flux.Table{ &executetest.Table{ KeyCols: []string{"tag0", "tag1"}, - ColMeta: []query.ColMeta{ - {Label: "tag0", Type: query.TString}, - {Label: "tag1", Type: query.TString}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "tag0", Type: flux.TString}, + {Label: "tag1", Type: flux.TString}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {"tag0-0", "tag1-0", execute.Time(1), 2.0}, @@ -88,11 +88,11 @@ func TestKeys_Process(t *testing.T) { }, &executetest.Table{ KeyCols: []string{"tag0", "tag2"}, - ColMeta: []query.ColMeta{ - {Label: "tag0", Type: query.TString}, - {Label: "tag2", Type: query.TString}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "tag0", Type: flux.TString}, + {Label: "tag2", Type: flux.TString}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {"tag0-0", "tag2-0", execute.Time(1), 2.0}, @@ -102,10 +102,10 @@ func TestKeys_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"tag0", "tag1"}, - ColMeta: []query.ColMeta{ - {Label: "tag0", Type: query.TString}, - {Label: "tag1", Type: query.TString}, - {Label: "_value", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "tag0", Type: flux.TString}, + {Label: "tag1", Type: flux.TString}, + {Label: "_value", Type: flux.TString}, }, Data: [][]interface{}{ {"tag0-0", "tag1-0", "_time"}, @@ -116,10 +116,10 @@ func TestKeys_Process(t *testing.T) { }, { KeyCols: []string{"tag0", "tag2"}, - ColMeta: []query.ColMeta{ - {Label: "tag0", Type: query.TString}, - {Label: "tag2", Type: query.TString}, - {Label: "_value", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "tag0", Type: flux.TString}, + {Label: "tag2", Type: flux.TString}, + {Label: "_value", Type: flux.TString}, }, Data: [][]interface{}{ {"tag0-0", "tag2-0", "_time"}, diff --git a/functions/last.go b/functions/last.go index a341d90c41..31b6174370 100644 --- a/functions/last.go +++ b/functions/last.go @@ -3,9 +3,9 @@ package functions import ( "fmt" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/plan" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/plan" ) const LastKind = "last" @@ -17,13 +17,13 @@ type LastOpSpec struct { var lastSignature = execute.DefaultSelectorSignature() func init() { - query.RegisterFunction(LastKind, createLastOpSpec, lastSignature) - query.RegisterOpSpec(LastKind, newLastOp) + flux.RegisterFunction(LastKind, createLastOpSpec, lastSignature) + flux.RegisterOpSpec(LastKind, newLastOp) plan.RegisterProcedureSpec(LastKind, newLastProcedure, LastKind) execute.RegisterTransformation(LastKind, createLastTransformation) } -func createLastOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createLastOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -35,11 +35,11 @@ func createLastOpSpec(args query.Arguments, a *query.Administration) (query.Oper return spec, nil } -func newLastOp() query.OperationSpec { +func newLastOp() flux.OperationSpec { return new(LastOpSpec) } -func (s *LastOpSpec) Kind() query.OperationKind { +func (s *LastOpSpec) Kind() flux.OperationKind { return LastKind } @@ -47,7 +47,7 @@ type LastProcedureSpec struct { execute.SelectorConfig } -func newLastProcedure(qs query.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { +func newLastProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*LastOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -78,7 +78,7 @@ func (s *LastProcedureSpec) PushDown(root *plan.Procedure, dup func() *plan.Proc root = dup() selectSpec = root.Spec.(*FromProcedureSpec) selectSpec.BoundsSet = false - selectSpec.Bounds = query.Bounds{} + selectSpec.Bounds = flux.Bounds{} selectSpec.LimitSet = false selectSpec.PointsLimit = 0 selectSpec.SeriesLimit = 0 @@ -88,9 +88,9 @@ func (s *LastProcedureSpec) PushDown(root *plan.Procedure, dup func() *plan.Proc return } selectSpec.BoundsSet = true - selectSpec.Bounds = query.Bounds{ - Start: query.MinTime, - Stop: query.Now, + selectSpec.Bounds = flux.Bounds{ + Start: flux.MinTime, + Stop: flux.Now, } selectSpec.LimitSet = true selectSpec.PointsLimit = 1 @@ -149,24 +149,24 @@ func (s *LastSelector) Rows() []execute.Row { return s.rows } -func (s *LastSelector) selectLast(l int, cr query.ColReader) { +func (s *LastSelector) selectLast(l int, cr flux.ColReader) { if l > 0 { s.rows = []execute.Row{execute.ReadRow(l-1, cr)} } } -func (s *LastSelector) DoBool(vs []bool, cr query.ColReader) { +func (s *LastSelector) DoBool(vs []bool, cr flux.ColReader) { s.selectLast(len(vs), cr) } -func (s *LastSelector) DoInt(vs []int64, cr query.ColReader) { +func (s *LastSelector) DoInt(vs []int64, cr flux.ColReader) { s.selectLast(len(vs), cr) } -func (s *LastSelector) DoUInt(vs []uint64, cr query.ColReader) { +func (s *LastSelector) DoUInt(vs []uint64, cr flux.ColReader) { s.selectLast(len(vs), cr) } -func (s *LastSelector) DoFloat(vs []float64, cr query.ColReader) { +func (s *LastSelector) DoFloat(vs []float64, cr flux.ColReader) { s.selectLast(len(vs), cr) } -func (s *LastSelector) DoString(vs []string, cr query.ColReader) { +func (s *LastSelector) DoString(vs []string, cr flux.ColReader) { s.selectLast(len(vs), cr) } diff --git a/functions/last_test.go b/functions/last_test.go index ccb5861960..301cbbce8f 100644 --- a/functions/last_test.go +++ b/functions/last_test.go @@ -3,18 +3,18 @@ package functions_test import ( "testing" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/plan/plantest" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/plan/plantest" ) func TestLastOperation_Marshaling(t *testing.T) { data := []byte(`{"id":"last","kind":"last","spec":{"column":"bar"}}`) - op := &query.Operation{ + op := &flux.Operation{ ID: "last", Spec: &functions.LastOpSpec{ SelectorConfig: execute.SelectorConfig{ @@ -23,7 +23,7 @@ func TestLastOperation_Marshaling(t *testing.T) { }, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestLast_Process(t *testing.T) { @@ -36,11 +36,11 @@ func TestLast_Process(t *testing.T) { name: "last", data: &executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(0), 0.0, "a", "y"}, @@ -98,9 +98,9 @@ func TestLast_PushDown(t *testing.T) { want := &plan.Procedure{ Spec: &functions.FromProcedureSpec{ BoundsSet: true, - Bounds: query.Bounds{ - Start: query.MinTime, - Stop: query.Now, + Bounds: flux.Bounds{ + Start: flux.MinTime, + Stop: flux.Now, }, LimitSet: true, PointsLimit: 1, @@ -116,9 +116,9 @@ func TestLast_PushDown_Duplicate(t *testing.T) { root := &plan.Procedure{ Spec: &functions.FromProcedureSpec{ BoundsSet: true, - Bounds: query.Bounds{ - Start: query.MinTime, - Stop: query.Now, + Bounds: flux.Bounds{ + Start: flux.MinTime, + Stop: flux.Now, }, LimitSet: true, PointsLimit: 1, diff --git a/functions/limit.go b/functions/limit.go index cdc4544962..25e5e7b2f6 100644 --- a/functions/limit.go +++ b/functions/limit.go @@ -3,10 +3,10 @@ package functions import ( "fmt" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" "github.com/pkg/errors" ) @@ -19,20 +19,20 @@ type LimitOpSpec struct { Offset int64 `json:"offset"` } -var limitSignature = query.DefaultFunctionSignature() +var limitSignature = flux.DefaultFunctionSignature() func init() { limitSignature.Params["n"] = semantic.Int limitSignature.Params["offset"] = semantic.Int - query.RegisterFunction(LimitKind, createLimitOpSpec, limitSignature) - query.RegisterOpSpec(LimitKind, newLimitOp) + flux.RegisterFunction(LimitKind, createLimitOpSpec, limitSignature) + flux.RegisterOpSpec(LimitKind, newLimitOp) plan.RegisterProcedureSpec(LimitKind, newLimitProcedure, LimitKind) // TODO register a range transformation. Currently range is only supported if it is pushed down into a select procedure. execute.RegisterTransformation(LimitKind, createLimitTransformation) } -func createLimitOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createLimitOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -54,11 +54,11 @@ func createLimitOpSpec(args query.Arguments, a *query.Administration) (query.Ope return spec, nil } -func newLimitOp() query.OperationSpec { +func newLimitOp() flux.OperationSpec { return new(LimitOpSpec) } -func (s *LimitOpSpec) Kind() query.OperationKind { +func (s *LimitOpSpec) Kind() flux.OperationKind { return LimitKind } @@ -67,7 +67,7 @@ type LimitProcedureSpec struct { Offset int64 `json:"offset"` } -func newLimitProcedure(qs query.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { +func newLimitProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*LimitOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -139,11 +139,11 @@ func NewLimitTransformation(d execute.Dataset, cache execute.TableBuilderCache, } } -func (t *limitTransformation) RetractTable(id execute.DatasetID, key query.GroupKey) error { +func (t *limitTransformation) RetractTable(id execute.DatasetID, key flux.GroupKey) error { return t.d.RetractTable(key) } -func (t *limitTransformation) Process(id execute.DatasetID, tbl query.Table) error { +func (t *limitTransformation) Process(id execute.DatasetID, tbl flux.Table) error { builder, created := t.cache.TableBuilder(tbl.Key()) if !created { return fmt.Errorf("limit found duplicate table with key: %v", tbl.Key()) @@ -153,7 +153,7 @@ func (t *limitTransformation) Process(id execute.DatasetID, tbl query.Table) err // AppendTable with limit n := t.n offset := t.offset - tbl.Do(func(cr query.ColReader) error { + tbl.Do(func(cr flux.ColReader) error { if n <= 0 { // Returning an error terminates iteration return errors.New("finished") @@ -184,7 +184,7 @@ func (t *limitTransformation) Process(id execute.DatasetID, tbl query.Table) err } type sliceColReader struct { - query.ColReader + flux.ColReader start, stop int } diff --git a/functions/limit_test.go b/functions/limit_test.go index d9f31a8a92..1b78b1edcd 100644 --- a/functions/limit_test.go +++ b/functions/limit_test.go @@ -3,32 +3,32 @@ package functions_test import ( "testing" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/plan/plantest" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/plan/plantest" ) func TestLimitOperation_Marshaling(t *testing.T) { data := []byte(`{"id":"limit","kind":"limit","spec":{"n":10}}`) - op := &query.Operation{ + op := &flux.Operation{ ID: "limit", Spec: &functions.LimitOpSpec{ N: 10, }, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestLimit_Process(t *testing.T) { testCases := []struct { name string spec *functions.LimitProcedureSpec - data []query.Table + data []flux.Table want []*executetest.Table }{ { @@ -36,10 +36,10 @@ func TestLimit_Process(t *testing.T) { spec: &functions.LimitProcedureSpec{ N: 1, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 2.0}, @@ -47,9 +47,9 @@ func TestLimit_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 2.0}, @@ -62,10 +62,10 @@ func TestLimit_Process(t *testing.T) { N: 1, Offset: 1, }, - data: []query.Table{execute.CopyTable(&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{execute.CopyTable(&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 2.0}, @@ -74,9 +74,9 @@ func TestLimit_Process(t *testing.T) { }, }, executetest.UnlimitedAllocator)}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(2), 1.0}, @@ -89,10 +89,10 @@ func TestLimit_Process(t *testing.T) { N: 1, Offset: 1, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 2.0}, @@ -101,9 +101,9 @@ func TestLimit_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(2), 1.0}, @@ -115,13 +115,13 @@ func TestLimit_Process(t *testing.T) { spec: &functions.LimitProcedureSpec{ N: 2, }, - data: []query.Table{ + data: []flux.Table{ &executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "t1", Type: query.TString}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "t1", Type: flux.TString}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {"a", execute.Time(1), 3.0}, @@ -131,10 +131,10 @@ func TestLimit_Process(t *testing.T) { }, &executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "t1", Type: query.TString}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "t1", Type: flux.TString}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {"b", execute.Time(3), 3.0}, @@ -146,10 +146,10 @@ func TestLimit_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "t1", Type: query.TString}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "t1", Type: flux.TString}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {"a", execute.Time(1), 3.0}, @@ -158,10 +158,10 @@ func TestLimit_Process(t *testing.T) { }, { KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "t1", Type: query.TString}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "t1", Type: flux.TString}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {"b", execute.Time(3), 3.0}, diff --git a/functions/map.go b/functions/map.go index e75619f551..61be3c4932 100644 --- a/functions/map.go +++ b/functions/map.go @@ -5,12 +5,12 @@ import ( "log" "sort" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/interpreter" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/interpreter" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" + "github.com/influxdata/flux/values" ) const MapKind = "map" @@ -20,19 +20,19 @@ type MapOpSpec struct { MergeKey bool `json:"mergeKey"` } -var mapSignature = query.DefaultFunctionSignature() +var mapSignature = flux.DefaultFunctionSignature() func init() { mapSignature.Params["fn"] = semantic.Function mapSignature.Params["mergeKey"] = semantic.Bool - query.RegisterFunction(MapKind, createMapOpSpec, mapSignature) - query.RegisterOpSpec(MapKind, newMapOp) + flux.RegisterFunction(MapKind, createMapOpSpec, mapSignature) + flux.RegisterOpSpec(MapKind, newMapOp) plan.RegisterProcedureSpec(MapKind, newMapProcedure, MapKind) execute.RegisterTransformation(MapKind, createMapTransformation) } -func createMapOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createMapOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -59,11 +59,11 @@ func createMapOpSpec(args query.Arguments, a *query.Administration) (query.Opera return spec, nil } -func newMapOp() query.OperationSpec { +func newMapOp() flux.OperationSpec { return new(MapOpSpec) } -func (s *MapOpSpec) Kind() query.OperationKind { +func (s *MapOpSpec) Kind() flux.OperationKind { return MapKind } @@ -72,7 +72,7 @@ type MapProcedureSpec struct { MergeKey bool } -func newMapProcedure(qs query.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { +func newMapProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*MapOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -129,11 +129,11 @@ func NewMapTransformation(d execute.Dataset, cache execute.TableBuilderCache, sp }, nil } -func (t *mapTransformation) RetractTable(id execute.DatasetID, key query.GroupKey) error { +func (t *mapTransformation) RetractTable(id execute.DatasetID, key flux.GroupKey) error { return t.d.RetractTable(key) } -func (t *mapTransformation) Process(id execute.DatasetID, tbl query.Table) error { +func (t *mapTransformation) Process(id execute.DatasetID, tbl flux.Table) error { // Prepare the functions for the column types. cols := tbl.Cols() err := t.fn.Prepare(cols) @@ -155,7 +155,7 @@ func (t *mapTransformation) Process(id execute.DatasetID, tbl query.Table) error on[c.Label] = t.mergeKey || execute.ContainsStr(keys, c.Label) } - return tbl.Do(func(cr query.ColReader) error { + return tbl.Do(func(cr flux.ColReader) error { l := cr.Len() for i := 0; i < l; i++ { m, err := t.fn.Eval(i, cr) @@ -174,7 +174,7 @@ func (t *mapTransformation) Process(id execute.DatasetID, tbl query.Table) error if t.mergeKey && tbl.Key().HasCol(k) { continue } - builder.AddCol(query.ColMeta{ + builder.AddCol(flux.ColMeta{ Label: k, Type: execute.ConvertFromKind(properties[k].Kind()), }) @@ -197,8 +197,8 @@ func (t *mapTransformation) Process(id execute.DatasetID, tbl query.Table) error }) } -func groupKeyForObject(i int, cr query.ColReader, obj values.Object, on map[string]bool) query.GroupKey { - cols := make([]query.ColMeta, 0, len(on)) +func groupKeyForObject(i int, cr flux.ColReader, obj values.Object, on map[string]bool) flux.GroupKey { + cols := make([]flux.ColMeta, 0, len(on)) vs := make([]values.Value, 0, len(on)) for j, c := range cr.Cols() { if !on[c.Label] { @@ -210,17 +210,17 @@ func groupKeyForObject(i int, cr query.ColReader, obj values.Object, on map[stri vs = append(vs, v) } else { switch c.Type { - case query.TBool: + case flux.TBool: vs = append(vs, values.NewBoolValue(cr.Bools(j)[i])) - case query.TInt: + case flux.TInt: vs = append(vs, values.NewIntValue(cr.Ints(j)[i])) - case query.TUInt: + case flux.TUInt: vs = append(vs, values.NewUIntValue(cr.UInts(j)[i])) - case query.TFloat: + case flux.TFloat: vs = append(vs, values.NewFloatValue(cr.Floats(j)[i])) - case query.TString: + case flux.TString: vs = append(vs, values.NewStringValue(cr.Strings(j)[i])) - case query.TTime: + case flux.TTime: vs = append(vs, values.NewTimeValue(cr.Times(j)[i])) } } diff --git a/functions/map_test.go b/functions/map_test.go index 5fdc25195b..2dc401600e 100644 --- a/functions/map_test.go +++ b/functions/map_test.go @@ -3,22 +3,22 @@ package functions_test import ( "testing" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/querytest" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux" + "github.com/influxdata/flux/ast" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" + "github.com/influxdata/flux/semantic" ) func TestMap_NewQuery(t *testing.T) { - tests := []querytest.NewQueryTestCase{ + tests := []fluxtest.NewQueryTestCase{ { Name: "simple static map", Raw: `from(bucket:"mybucket") |> map(fn: (r) => r._value + 1)`, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "from0", Spec: &functions.FromOpSpec{ @@ -45,7 +45,7 @@ func TestMap_NewQuery(t *testing.T) { }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "from0", Child: "map1"}, }, }, @@ -53,8 +53,8 @@ func TestMap_NewQuery(t *testing.T) { { Name: "resolve map", Raw: `x = 2 from(bucket:"mybucket") |> map(fn: (r) => r._value + x)`, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "from0", Spec: &functions.FromOpSpec{ @@ -81,7 +81,7 @@ func TestMap_NewQuery(t *testing.T) { }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "from0", Child: "map1"}, }, }, @@ -91,7 +91,7 @@ func TestMap_NewQuery(t *testing.T) { tc := tc t.Run(tc.Name, func(t *testing.T) { t.Parallel() - querytest.NewQueryTestHelper(t, tc) + fluxtest.NewQueryTestHelper(t, tc) }) } } @@ -123,7 +123,7 @@ func TestMapOperation_Marshaling(t *testing.T) { } } }`) - op := &query.Operation{ + op := &flux.Operation{ ID: "map", Spec: &functions.MapOpSpec{ Fn: &semantic.FunctionExpression{ @@ -141,13 +141,13 @@ func TestMapOperation_Marshaling(t *testing.T) { }, }, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestMap_Process(t *testing.T) { testCases := []struct { name string spec *functions.MapProcedureSpec - data []query.Table + data []flux.Table want []*executetest.Table }{ { @@ -186,10 +186,10 @@ func TestMap_Process(t *testing.T) { }, }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 1.0}, @@ -197,9 +197,9 @@ func TestMap_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 6.0}, @@ -243,13 +243,13 @@ func TestMap_Process(t *testing.T) { }, }, }, - data: []query.Table{&executetest.Table{ + data: []flux.Table{&executetest.Table{ KeyCols: []string{"_measurement", "host"}, - ColMeta: []query.ColMeta{ - {Label: "_measurement", Type: query.TString}, - {Label: "host", Type: query.TString}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_measurement", Type: flux.TString}, + {Label: "host", Type: flux.TString}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {"m", "A", execute.Time(1), 1.0}, @@ -258,11 +258,11 @@ func TestMap_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"_measurement", "host"}, - ColMeta: []query.ColMeta{ - {Label: "_measurement", Type: query.TString}, - {Label: "host", Type: query.TString}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_measurement", Type: flux.TString}, + {Label: "host", Type: flux.TString}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {"m", "A", execute.Time(1), 6.0}, @@ -306,13 +306,13 @@ func TestMap_Process(t *testing.T) { }, }, }, - data: []query.Table{&executetest.Table{ + data: []flux.Table{&executetest.Table{ KeyCols: []string{"_measurement", "host"}, - ColMeta: []query.ColMeta{ - {Label: "_measurement", Type: query.TString}, - {Label: "host", Type: query.TString}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_measurement", Type: flux.TString}, + {Label: "host", Type: flux.TString}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {"m", "A", execute.Time(1), 1.0}, @@ -320,9 +320,9 @@ func TestMap_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 6.0}, @@ -379,13 +379,13 @@ func TestMap_Process(t *testing.T) { }, }, }, - data: []query.Table{&executetest.Table{ + data: []flux.Table{&executetest.Table{ KeyCols: []string{"_measurement", "host"}, - ColMeta: []query.ColMeta{ - {Label: "_measurement", Type: query.TString}, - {Label: "host", Type: query.TString}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_measurement", Type: flux.TString}, + {Label: "host", Type: flux.TString}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {"m", "A", execute.Time(1), 1.0}, @@ -394,11 +394,11 @@ func TestMap_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"_measurement", "host"}, - ColMeta: []query.ColMeta{ - {Label: "_measurement", Type: query.TString}, - {Label: "host", Type: query.TString}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_measurement", Type: flux.TString}, + {Label: "host", Type: flux.TString}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {"m", "A.local", execute.Time(1), 6.0}, @@ -464,14 +464,14 @@ func TestMap_Process(t *testing.T) { }, }, }, - data: []query.Table{&executetest.Table{ + data: []flux.Table{&executetest.Table{ KeyCols: []string{"_measurement", "host"}, - ColMeta: []query.ColMeta{ - {Label: "_measurement", Type: query.TString}, - {Label: "host", Type: query.TString}, - {Label: "domain", Type: query.TString}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_measurement", Type: flux.TString}, + {Label: "host", Type: flux.TString}, + {Label: "domain", Type: flux.TString}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {"m", "A", "example.com", execute.Time(1), 1.0}, @@ -481,11 +481,11 @@ func TestMap_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"_measurement", "host"}, - ColMeta: []query.ColMeta{ - {Label: "_measurement", Type: query.TString}, - {Label: "host", Type: query.TString}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_measurement", Type: flux.TString}, + {Label: "host", Type: flux.TString}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {"m", "A.example.com", execute.Time(1), 6.0}, @@ -493,11 +493,11 @@ func TestMap_Process(t *testing.T) { }, { KeyCols: []string{"_measurement", "host"}, - ColMeta: []query.ColMeta{ - {Label: "_measurement", Type: query.TString}, - {Label: "host", Type: query.TString}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_measurement", Type: flux.TString}, + {Label: "host", Type: flux.TString}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {"m", "A.www.example.com", execute.Time(2), 11.0}, @@ -544,10 +544,10 @@ func TestMap_Process(t *testing.T) { }, }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 1.0}, @@ -555,9 +555,9 @@ func TestMap_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 1.0}, @@ -603,10 +603,10 @@ func TestMap_Process(t *testing.T) { }, }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TInt}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TInt}, }, Data: [][]interface{}{ {execute.Time(1), int64(1)}, @@ -614,9 +614,9 @@ func TestMap_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 1.0}, @@ -662,10 +662,10 @@ func TestMap_Process(t *testing.T) { }, }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TUInt}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TUInt}, }, Data: [][]interface{}{ {execute.Time(1), uint64(1)}, @@ -673,9 +673,9 @@ func TestMap_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 1.0}, diff --git a/functions/max.go b/functions/max.go index 4f9dc737ee..7e68cf20c1 100644 --- a/functions/max.go +++ b/functions/max.go @@ -3,9 +3,9 @@ package functions import ( "fmt" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/plan" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/plan" ) const MaxKind = "max" @@ -17,13 +17,13 @@ type MaxOpSpec struct { var maxSignature = execute.DefaultSelectorSignature() func init() { - query.RegisterFunction(MaxKind, createMaxOpSpec, maxSignature) - query.RegisterOpSpec(MaxKind, newMaxOp) + flux.RegisterFunction(MaxKind, createMaxOpSpec, maxSignature) + flux.RegisterOpSpec(MaxKind, newMaxOp) plan.RegisterProcedureSpec(MaxKind, newMaxProcedure, MaxKind) execute.RegisterTransformation(MaxKind, createMaxTransformation) } -func createMaxOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createMaxOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -36,11 +36,11 @@ func createMaxOpSpec(args query.Arguments, a *query.Administration) (query.Opera return spec, nil } -func newMaxOp() query.OperationSpec { +func newMaxOp() flux.OperationSpec { return new(MaxOpSpec) } -func (s *MaxOpSpec) Kind() query.OperationKind { +func (s *MaxOpSpec) Kind() flux.OperationKind { return MaxKind } @@ -48,7 +48,7 @@ type MaxProcedureSpec struct { execute.SelectorConfig } -func newMaxProcedure(qs query.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { +func newMaxProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*MaxOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -121,14 +121,14 @@ func (s *MaxSelector) Rows() []execute.Row { return s.rows } -func (s *MaxSelector) selectRow(idx int, cr query.ColReader) { +func (s *MaxSelector) selectRow(idx int, cr flux.ColReader) { // Capture row if idx >= 0 { s.rows = []execute.Row{execute.ReadRow(idx, cr)} } } -func (s *MaxIntSelector) DoInt(vs []int64, cr query.ColReader) { +func (s *MaxIntSelector) DoInt(vs []int64, cr flux.ColReader) { maxIdx := -1 for i, v := range vs { if !s.set || v > s.max { @@ -139,7 +139,7 @@ func (s *MaxIntSelector) DoInt(vs []int64, cr query.ColReader) { } s.selectRow(maxIdx, cr) } -func (s *MaxUIntSelector) DoUInt(vs []uint64, cr query.ColReader) { +func (s *MaxUIntSelector) DoUInt(vs []uint64, cr flux.ColReader) { maxIdx := -1 for i, v := range vs { if !s.set || v > s.max { @@ -150,7 +150,7 @@ func (s *MaxUIntSelector) DoUInt(vs []uint64, cr query.ColReader) { } s.selectRow(maxIdx, cr) } -func (s *MaxFloatSelector) DoFloat(vs []float64, cr query.ColReader) { +func (s *MaxFloatSelector) DoFloat(vs []float64, cr flux.ColReader) { maxIdx := -1 for i, v := range vs { if !s.set || v > s.max { diff --git a/functions/max_test.go b/functions/max_test.go index 4dc2af3827..aa0863e133 100644 --- a/functions/max_test.go +++ b/functions/max_test.go @@ -3,16 +3,16 @@ package functions_test import ( "testing" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" ) func TestMaxOperation_Marshaling(t *testing.T) { data := []byte(`{"id":"max","kind":"max","spec":{"column":"baz"}}`) - op := &query.Operation{ + op := &flux.Operation{ ID: "max", Spec: &functions.MaxOpSpec{ SelectorConfig: execute.SelectorConfig{ @@ -21,7 +21,7 @@ func TestMaxOperation_Marshaling(t *testing.T) { }, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestMax_Process(t *testing.T) { @@ -34,11 +34,11 @@ func TestMax_Process(t *testing.T) { name: "first", data: &executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(0), 10.0, "a", "y"}, @@ -61,11 +61,11 @@ func TestMax_Process(t *testing.T) { name: "last", data: &executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(0), 7.0, "a", "y"}, @@ -88,11 +88,11 @@ func TestMax_Process(t *testing.T) { name: "middle", data: &executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(0), 7.0, "a", "y"}, diff --git a/functions/mean.go b/functions/mean.go index 6da32d5316..650f40d3f9 100644 --- a/functions/mean.go +++ b/functions/mean.go @@ -4,9 +4,9 @@ import ( "fmt" "math" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/plan" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/plan" ) const MeanKind = "mean" @@ -18,12 +18,12 @@ type MeanOpSpec struct { var meanSignature = execute.DefaultAggregateSignature() func init() { - query.RegisterFunction(MeanKind, createMeanOpSpec, meanSignature) - query.RegisterOpSpec(MeanKind, newMeanOp) + flux.RegisterFunction(MeanKind, createMeanOpSpec, meanSignature) + flux.RegisterOpSpec(MeanKind, newMeanOp) plan.RegisterProcedureSpec(MeanKind, newMeanProcedure, MeanKind) execute.RegisterTransformation(MeanKind, createMeanTransformation) } -func createMeanOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createMeanOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -35,11 +35,11 @@ func createMeanOpSpec(args query.Arguments, a *query.Administration) (query.Oper return spec, nil } -func newMeanOp() query.OperationSpec { +func newMeanOp() flux.OperationSpec { return new(MeanOpSpec) } -func (s *MeanOpSpec) Kind() query.OperationKind { +func (s *MeanOpSpec) Kind() flux.OperationKind { return MeanKind } @@ -47,7 +47,7 @@ type MeanProcedureSpec struct { execute.AggregateConfig } -func newMeanProcedure(qs query.OperationSpec, a plan.Administration) (plan.ProcedureSpec, error) { +func newMeanProcedure(qs flux.OperationSpec, a plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*MeanOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -120,8 +120,8 @@ func (a *MeanAgg) DoFloat(vs []float64) { a.sum += v } } -func (a *MeanAgg) Type() query.DataType { - return query.TFloat +func (a *MeanAgg) Type() flux.DataType { + return flux.TFloat } func (a *MeanAgg) ValueFloat() float64 { if a.count < 1 { diff --git a/functions/mean_test.go b/functions/mean_test.go index 64efa033d8..698afa34cf 100644 --- a/functions/mean_test.go +++ b/functions/mean_test.go @@ -4,20 +4,20 @@ import ( "math" "testing" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" ) func TestMeanOperation_Marshaling(t *testing.T) { data := []byte(`{"id":"mean","kind":"mean"}`) - op := &query.Operation{ + op := &flux.Operation{ ID: "mean", Spec: &functions.MeanOpSpec{}, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestMean_Process(t *testing.T) { diff --git a/functions/min.go b/functions/min.go index 65235662ba..31c78d98cf 100644 --- a/functions/min.go +++ b/functions/min.go @@ -3,9 +3,9 @@ package functions import ( "fmt" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/plan" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/plan" ) const MinKind = "min" @@ -17,13 +17,13 @@ type MinOpSpec struct { var minSignature = execute.DefaultSelectorSignature() func init() { - query.RegisterFunction(MinKind, createMinOpSpec, minSignature) - query.RegisterOpSpec(MinKind, newMinOp) + flux.RegisterFunction(MinKind, createMinOpSpec, minSignature) + flux.RegisterOpSpec(MinKind, newMinOp) plan.RegisterProcedureSpec(MinKind, newMinProcedure, MinKind) execute.RegisterTransformation(MinKind, createMinTransformation) } -func createMinOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createMinOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -36,11 +36,11 @@ func createMinOpSpec(args query.Arguments, a *query.Administration) (query.Opera return spec, nil } -func newMinOp() query.OperationSpec { +func newMinOp() flux.OperationSpec { return new(MinOpSpec) } -func (s *MinOpSpec) Kind() query.OperationKind { +func (s *MinOpSpec) Kind() flux.OperationKind { return MinKind } @@ -48,7 +48,7 @@ type MinProcedureSpec struct { execute.SelectorConfig } -func newMinProcedure(qs query.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { +func newMinProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*MinOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -121,14 +121,14 @@ func (s *MinSelector) Rows() []execute.Row { return s.rows } -func (s *MinSelector) selectRow(idx int, cr query.ColReader) { +func (s *MinSelector) selectRow(idx int, cr flux.ColReader) { // Capture row if idx >= 0 { s.rows = []execute.Row{execute.ReadRow(idx, cr)} } } -func (s *MinIntSelector) DoInt(vs []int64, cr query.ColReader) { +func (s *MinIntSelector) DoInt(vs []int64, cr flux.ColReader) { minIdx := -1 for i, v := range vs { if !s.set || v < s.min { @@ -139,7 +139,7 @@ func (s *MinIntSelector) DoInt(vs []int64, cr query.ColReader) { } s.selectRow(minIdx, cr) } -func (s *MinUIntSelector) DoUInt(vs []uint64, cr query.ColReader) { +func (s *MinUIntSelector) DoUInt(vs []uint64, cr flux.ColReader) { minIdx := -1 for i, v := range vs { if !s.set || v < s.min { @@ -150,7 +150,7 @@ func (s *MinUIntSelector) DoUInt(vs []uint64, cr query.ColReader) { } s.selectRow(minIdx, cr) } -func (s *MinFloatSelector) DoFloat(vs []float64, cr query.ColReader) { +func (s *MinFloatSelector) DoFloat(vs []float64, cr flux.ColReader) { minIdx := -1 for i, v := range vs { if !s.set || v < s.min { diff --git a/functions/min_test.go b/functions/min_test.go index a50d66756d..ec9fc1601f 100644 --- a/functions/min_test.go +++ b/functions/min_test.go @@ -3,16 +3,16 @@ package functions_test import ( "testing" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" ) func TestMinOperation_Marshaling(t *testing.T) { data := []byte(`{"id":"min","kind":"min","spec":{"column":"min"}}`) - op := &query.Operation{ + op := &flux.Operation{ ID: "min", Spec: &functions.MinOpSpec{ SelectorConfig: execute.SelectorConfig{ @@ -21,7 +21,7 @@ func TestMinOperation_Marshaling(t *testing.T) { }, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestMin_Process(t *testing.T) { @@ -34,11 +34,11 @@ func TestMin_Process(t *testing.T) { name: "first", data: &executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(0), 0.0, "a", "y"}, @@ -61,11 +61,11 @@ func TestMin_Process(t *testing.T) { name: "last", data: &executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(0), 7.0, "a", "y"}, @@ -88,11 +88,11 @@ func TestMin_Process(t *testing.T) { name: "middle", data: &executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(0), 7.0, "a", "y"}, diff --git a/functions/percentile.go b/functions/percentile.go index e30fa17451..e6aeed07fb 100644 --- a/functions/percentile.go +++ b/functions/percentile.go @@ -5,10 +5,10 @@ import ( "math" "sort" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" "github.com/influxdata/tdigest" "github.com/pkg/errors" ) @@ -40,10 +40,10 @@ func init() { percentileSignature.Params["compression"] = semantic.Float percentileSignature.Params["method"] = semantic.String - query.RegisterFunction(PercentileKind, createPercentileOpSpec, percentileSignature) - query.RegisterBuiltIn("median", medianBuiltin) + flux.RegisterFunction(PercentileKind, createPercentileOpSpec, percentileSignature) + flux.RegisterBuiltIn("median", medianBuiltin) - query.RegisterOpSpec(PercentileKind, newPercentileOp) + flux.RegisterOpSpec(PercentileKind, newPercentileOp) plan.RegisterProcedureSpec(PercentileKind, newPercentileProcedure, PercentileKind) execute.RegisterTransformation(PercentileKind, createPercentileTransformation) execute.RegisterTransformation(ExactPercentileAggKind, createExactPercentileAggTransformation) @@ -57,7 +57,7 @@ var medianBuiltin = ` median = (method="estimate_tdigest", compression=0.0, table=<-) => percentile(table:table, percentile:0.5, method:method, compression:compression) ` -func createPercentileOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createPercentileOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -105,11 +105,11 @@ func createPercentileOpSpec(args query.Arguments, a *query.Administration) (quer return spec, nil } -func newPercentileOp() query.OperationSpec { +func newPercentileOp() flux.OperationSpec { return new(PercentileOpSpec) } -func (s *PercentileOpSpec) Kind() query.OperationKind { +func (s *PercentileOpSpec) Kind() flux.OperationKind { return PercentileKind } @@ -154,7 +154,7 @@ func (s *ExactPercentileSelectProcedureSpec) Copy() plan.ProcedureSpec { return &ExactPercentileSelectProcedureSpec{Percentile: s.Percentile} } -func newPercentileProcedure(qs query.OperationSpec, a plan.Administration) (plan.ProcedureSpec, error) { +func newPercentileProcedure(qs flux.OperationSpec, a plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*PercentileOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -234,8 +234,8 @@ func (a *PercentileAgg) DoFloat(vs []float64) { } } -func (a *PercentileAgg) Type() query.DataType { - return query.TFloat +func (a *PercentileAgg) Type() flux.DataType { + return flux.TFloat } func (a *PercentileAgg) ValueFloat() float64 { return a.digest.Quantile(a.Quantile) @@ -288,8 +288,8 @@ func (a *ExactPercentileAgg) DoFloat(vs []float64) { a.data = append(a.data, vs...) } -func (a *ExactPercentileAgg) Type() query.DataType { - return query.TFloat +func (a *ExactPercentileAgg) Type() flux.DataType { + return flux.TFloat } func (a *ExactPercentileAgg) ValueFloat() float64 { @@ -345,7 +345,7 @@ func NewExactPercentileSelectorTransformation(d execute.Dataset, cache execute.T return sel } -func (t *ExactPercentileSelectorTransformation) Process(id execute.DatasetID, tbl query.Table) error { +func (t *ExactPercentileSelectorTransformation) Process(id execute.DatasetID, tbl flux.Table) error { valueIdx := execute.ColIdx(t.spec.Column, tbl.Cols()) if valueIdx < 0 { return fmt.Errorf("no column %q exists", t.spec.Column) @@ -386,7 +386,7 @@ func getQuantileIndex(quantile float64, len int) int { return index } -func (t *ExactPercentileSelectorTransformation) RetractTable(id execute.DatasetID, key query.GroupKey) error { +func (t *ExactPercentileSelectorTransformation) RetractTable(id execute.DatasetID, key flux.GroupKey) error { return t.d.RetractTable(key) } diff --git a/functions/percentile_test.go b/functions/percentile_test.go index 71ff66269d..f959d5a193 100644 --- a/functions/percentile_test.go +++ b/functions/percentile_test.go @@ -4,23 +4,23 @@ import ( "math" "testing" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" ) func TestPercentileOperation_Marshaling(t *testing.T) { data := []byte(`{"id":"percentile","kind":"percentile","spec":{"percentile":0.9}}`) - op := &query.Operation{ + op := &flux.Operation{ ID: "percentile", Spec: &functions.PercentileOpSpec{ Percentile: 0.9, }, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestPercentile_Process(t *testing.T) { @@ -141,20 +141,20 @@ func TestPercentileSelector_Process(t *testing.T) { testCases := []struct { name string quantile float64 - data []query.Table + data []flux.Table want []*executetest.Table }{ { name: "select_10", quantile: 0.1, - data: []query.Table{ + data: []flux.Table{ &executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(0), 1.0, "a", "y"}, @@ -167,11 +167,11 @@ func TestPercentileSelector_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(0), 1.0, "a", "y"}, @@ -182,13 +182,13 @@ func TestPercentileSelector_Process(t *testing.T) { { name: "select_20", quantile: 0.2, - data: []query.Table{&executetest.Table{ + data: []flux.Table{&executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(0), 1.0, "a", "y"}, @@ -201,11 +201,11 @@ func TestPercentileSelector_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(0), 1.0, "a", "y"}, @@ -215,13 +215,13 @@ func TestPercentileSelector_Process(t *testing.T) { { name: "select_40", quantile: 0.4, - data: []query.Table{&executetest.Table{ + data: []flux.Table{&executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(0), 1.0, "a", "y"}, @@ -233,11 +233,11 @@ func TestPercentileSelector_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(10), 2.0, "a", "x"}, @@ -247,13 +247,13 @@ func TestPercentileSelector_Process(t *testing.T) { { name: "select_50", quantile: 0.5, - data: []query.Table{&executetest.Table{ + data: []flux.Table{&executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(0), 1.0, "a", "y"}, @@ -265,11 +265,11 @@ func TestPercentileSelector_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(20), 3.0, "a", "y"}, @@ -279,13 +279,13 @@ func TestPercentileSelector_Process(t *testing.T) { { name: "select_80", quantile: 0.8, - data: []query.Table{&executetest.Table{ + data: []flux.Table{&executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(0), 1.0, "a", "y"}, @@ -297,11 +297,11 @@ func TestPercentileSelector_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(30), 4.0, "a", "x"}, @@ -311,13 +311,13 @@ func TestPercentileSelector_Process(t *testing.T) { { name: "select_90", quantile: 0.9, - data: []query.Table{&executetest.Table{ + data: []flux.Table{&executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(0), 1.0, "a", "y"}, @@ -329,11 +329,11 @@ func TestPercentileSelector_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(40), 5.0, "a", "y"}, @@ -343,13 +343,13 @@ func TestPercentileSelector_Process(t *testing.T) { { name: "select_100", quantile: 1.0, - data: []query.Table{&executetest.Table{ + data: []flux.Table{&executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(0), 1.0, "a", "y"}, @@ -361,11 +361,11 @@ func TestPercentileSelector_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(40), 5.0, "a", "y"}, diff --git a/functions/pivot.go b/functions/pivot.go index 180f5329a7..bec5899492 100644 --- a/functions/pivot.go +++ b/functions/pivot.go @@ -4,12 +4,12 @@ import ( "fmt" "strconv" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/interpreter" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/interpreter" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" + "github.com/influxdata/flux/values" ) const PivotKind = "pivot" @@ -20,7 +20,7 @@ type PivotOpSpec struct { ValueCol string `json:"valueCol"` } -var pivotSignature = query.DefaultFunctionSignature() +var pivotSignature = flux.DefaultFunctionSignature() var fromRowsBuiltin = ` // fromRows will access a database and retrieve data aligned into time-aligned tuples, grouped by measurement. @@ -32,15 +32,15 @@ func init() { pivotSignature.Params["colKey"] = semantic.Array pivotSignature.Params["valueCol"] = semantic.String - query.RegisterFunction(PivotKind, createPivotOpSpec, pivotSignature) - query.RegisterBuiltIn("fromRows", fromRowsBuiltin) - query.RegisterOpSpec(PivotKind, newPivotOp) + flux.RegisterFunction(PivotKind, createPivotOpSpec, pivotSignature) + flux.RegisterBuiltIn("fromRows", fromRowsBuiltin) + flux.RegisterOpSpec(PivotKind, newPivotOp) plan.RegisterProcedureSpec(PivotKind, newPivotProcedure, PivotKind) execute.RegisterTransformation(PivotKind, createPivotTransformation) } -func createPivotOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createPivotOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -87,11 +87,11 @@ func createPivotOpSpec(args query.Arguments, a *query.Administration) (query.Ope return spec, nil } -func newPivotOp() query.OperationSpec { +func newPivotOp() flux.OperationSpec { return new(PivotOpSpec) } -func (s *PivotOpSpec) Kind() query.OperationKind { +func (s *PivotOpSpec) Kind() flux.OperationKind { return PivotKind } @@ -101,7 +101,7 @@ type PivotProcedureSpec struct { ValueCol string } -func newPivotProcedure(qs query.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { +func newPivotProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*PivotOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -163,11 +163,11 @@ func NewPivotTransformation(d execute.Dataset, cache execute.TableBuilderCache, return t } -func (t *pivotTransformation) RetractTable(id execute.DatasetID, key query.GroupKey) error { +func (t *pivotTransformation) RetractTable(id execute.DatasetID, key flux.GroupKey) error { return t.d.RetractTable(key) } -func (t *pivotTransformation) Process(id execute.DatasetID, tbl query.Table) error { +func (t *pivotTransformation) Process(id execute.DatasetID, tbl flux.Table) error { rowKeyIndex := make(map[string]int) for _, v := range t.spec.RowKey { @@ -182,13 +182,13 @@ func (t *pivotTransformation) Process(id execute.DatasetID, tbl query.Table) err // determine the initial column schema colKeyIndex := make(map[string]int) valueColIndex := -1 - var valueColType query.DataType + var valueColType flux.DataType for _, v := range t.spec.ColKey { colKeyIndex[v] = -1 } - cols := make([]query.ColMeta, 0, len(tbl.Cols())) - keyCols := make([]query.ColMeta, 0, len(tbl.Key().Cols())) + cols := make([]flux.ColMeta, 0, len(tbl.Cols())) + keyCols := make([]flux.ColMeta, 0, len(tbl.Key().Cols())) keyValues := make([]values.Value, 0, len(tbl.Key().Cols())) newIDX := 0 colMap := make([]int, len(tbl.Cols())) @@ -235,7 +235,7 @@ func (t *pivotTransformation) Process(id execute.DatasetID, tbl query.Table) err t.nextRow = 0 } - tbl.Do(func(cr query.ColReader) error { + tbl.Do(func(cr flux.ColReader) error { for row := 0; row < cr.Len(); row++ { rowKey := "" colKey := "" @@ -256,7 +256,7 @@ func (t *pivotTransformation) Process(id execute.DatasetID, tbl query.Table) err // we know the col key; // 0. If we've not seen the colKey before, then we need to add a new column and backfill it. if _, ok := t.colKeyMaps[groupKeyString][colKey]; !ok { - newCol := query.ColMeta{ + newCol := flux.ColMeta{ Label: colKey, Type: valueColType, } @@ -296,76 +296,76 @@ func (t *pivotTransformation) Process(id execute.DatasetID, tbl query.Table) err return nil } -func growColumn(builder execute.TableBuilder, colType query.DataType, colIdx, nRows int) { +func growColumn(builder execute.TableBuilder, colType flux.DataType, colIdx, nRows int) { switch colType { - case query.TBool: + case flux.TBool: builder.GrowBools(colIdx, nRows) - case query.TInt: + case flux.TInt: builder.GrowInts(colIdx, nRows) - case query.TUInt: + case flux.TUInt: builder.GrowUInts(colIdx, nRows) - case query.TFloat: + case flux.TFloat: builder.GrowFloats(colIdx, nRows) - case query.TString: + case flux.TString: builder.GrowStrings(colIdx, nRows) - case query.TTime: + case flux.TTime: builder.GrowTimes(colIdx, nRows) default: execute.PanicUnknownType(colType) } } -func setBuilderValue(cr query.ColReader, builder execute.TableBuilder, readerColType query.DataType, readerRowIndex, readerColIndex, builderRow, builderCol int) { +func setBuilderValue(cr flux.ColReader, builder execute.TableBuilder, readerColType flux.DataType, readerRowIndex, readerColIndex, builderRow, builderCol int) { switch readerColType { - case query.TBool: + case flux.TBool: builder.SetBool(builderRow, builderCol, cr.Bools(readerColIndex)[readerRowIndex]) - case query.TInt: + case flux.TInt: builder.SetInt(builderRow, builderCol, cr.Ints(readerColIndex)[readerRowIndex]) - case query.TUInt: + case flux.TUInt: builder.SetUInt(builderRow, builderCol, cr.UInts(readerColIndex)[readerRowIndex]) - case query.TFloat: + case flux.TFloat: builder.SetFloat(builderRow, builderCol, cr.Floats(readerColIndex)[readerRowIndex]) - case query.TString: + case flux.TString: builder.SetString(builderRow, builderCol, cr.Strings(readerColIndex)[readerRowIndex]) - case query.TTime: + case flux.TTime: builder.SetTime(builderRow, builderCol, cr.Times(readerColIndex)[readerRowIndex]) default: execute.PanicUnknownType(readerColType) } } -func appendBuilderValue(cr query.ColReader, builder execute.TableBuilder, readerColType query.DataType, readerRowIndex, readerColIndex, builderColIndex int) { +func appendBuilderValue(cr flux.ColReader, builder execute.TableBuilder, readerColType flux.DataType, readerRowIndex, readerColIndex, builderColIndex int) { switch readerColType { - case query.TBool: + case flux.TBool: builder.AppendBool(builderColIndex, cr.Bools(readerColIndex)[readerRowIndex]) - case query.TInt: + case flux.TInt: builder.AppendInt(builderColIndex, cr.Ints(readerColIndex)[readerRowIndex]) - case query.TUInt: + case flux.TUInt: builder.AppendUInt(builderColIndex, cr.UInts(readerColIndex)[readerRowIndex]) - case query.TFloat: + case flux.TFloat: builder.AppendFloat(builderColIndex, cr.Floats(readerColIndex)[readerRowIndex]) - case query.TString: + case flux.TString: builder.AppendString(builderColIndex, cr.Strings(readerColIndex)[readerRowIndex]) - case query.TTime: + case flux.TTime: builder.AppendTime(builderColIndex, cr.Times(readerColIndex)[readerRowIndex]) default: execute.PanicUnknownType(readerColType) } } -func valueToStr(cr query.ColReader, c query.ColMeta, row, col int) string { +func valueToStr(cr flux.ColReader, c flux.ColMeta, row, col int) string { switch c.Type { - case query.TBool: + case flux.TBool: return strconv.FormatBool(cr.Bools(col)[row]) - case query.TInt: + case flux.TInt: return strconv.FormatInt(cr.Ints(col)[row], 10) - case query.TUInt: + case flux.TUInt: return strconv.FormatUint(cr.UInts(col)[row], 10) - case query.TFloat: + case flux.TFloat: return strconv.FormatFloat(cr.Floats(col)[row], 'E', -1, 64) - case query.TString: + case flux.TString: return cr.Strings(col)[row] - case query.TTime: + case flux.TTime: return cr.Times(col)[row].String() default: execute.PanicUnknownType(c.Type) diff --git a/functions/pivot_test.go b/functions/pivot_test.go index 809b9b0393..c8dfefdb01 100644 --- a/functions/pivot_test.go +++ b/functions/pivot_test.go @@ -5,20 +5,20 @@ import ( "testing" "time" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" ) func TestPivot_NewQuery(t *testing.T) { - tests := []querytest.NewQueryTestCase{ + tests := []fluxtest.NewQueryTestCase{ { Name: "pivot [_measurement, _field] around _time", Raw: `from(bucket:"testdb") |> range(start: -1h) |> pivot(rowKey: ["_time"], colKey: ["_measurement", "_field"], valueCol: "_value")`, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "from0", Spec: &functions.FromOpSpec{ @@ -28,11 +28,11 @@ func TestPivot_NewQuery(t *testing.T) { { ID: "range1", Spec: &functions.RangeOpSpec{ - Start: query.Time{ + Start: flux.Time{ Relative: -1 * time.Hour, IsRelative: true, }, - Stop: query.Time{ + Stop: flux.Time{ IsRelative: true, }, TimeCol: "_time", @@ -49,7 +49,7 @@ func TestPivot_NewQuery(t *testing.T) { }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "from0", Child: "range1"}, {Parent: "range1", Child: "pivot2"}, }, @@ -60,7 +60,7 @@ func TestPivot_NewQuery(t *testing.T) { tc := tc t.Run(tc.Name, func(t *testing.T) { t.Parallel() - querytest.NewQueryTestHelper(t, tc) + fluxtest.NewQueryTestHelper(t, tc) }) } } @@ -75,7 +75,7 @@ func TestPivotOperation_Marshaling(t *testing.T) { "valueCol":"_value" } }`) - op := &query.Operation{ + op := &flux.Operation{ ID: "pivot", Spec: &functions.PivotOpSpec{ RowKey: []string{"_time"}, @@ -83,14 +83,14 @@ func TestPivotOperation_Marshaling(t *testing.T) { ValueCol: "_value", }, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestPivot_Process(t *testing.T) { testCases := []struct { name string spec *functions.PivotProcedureSpec - data []query.Table + data []flux.Table want []*executetest.Table wantErr error }{ @@ -111,14 +111,14 @@ func TestPivot_Process(t *testing.T) { ColKey: []string{"_field"}, ValueCol: "_value", }, - data: []query.Table{ + data: []flux.Table{ &executetest.Table{ KeyCols: []string{"_measurement"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "_measurement", Type: query.TString}, - {Label: "_field", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "_measurement", Type: flux.TString}, + {Label: "_field", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "m1", "f1"}, @@ -131,11 +131,11 @@ func TestPivot_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"_measurement"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_measurement", Type: query.TString}, - {Label: "f1", Type: query.TFloat}, - {Label: "f2", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_measurement", Type: flux.TString}, + {Label: "f1", Type: flux.TFloat}, + {Label: "f2", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), "m1", 1.0, 2.0}, @@ -151,14 +151,14 @@ func TestPivot_Process(t *testing.T) { ColKey: []string{"_field"}, ValueCol: "_value", }, - data: []query.Table{ + data: []flux.Table{ &executetest.Table{ KeyCols: []string{"_measurement"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "_measurement", Type: query.TString}, - {Label: "_field", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "_measurement", Type: flux.TString}, + {Label: "_field", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "m1", "f1"}, @@ -169,11 +169,11 @@ func TestPivot_Process(t *testing.T) { }, &executetest.Table{ KeyCols: []string{"_measurement"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "_measurement", Type: query.TString}, - {Label: "_field", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "_measurement", Type: flux.TString}, + {Label: "_field", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "m2", "f3"}, @@ -186,11 +186,11 @@ func TestPivot_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"_measurement"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_measurement", Type: query.TString}, - {Label: "f1", Type: query.TFloat}, - {Label: "f2", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_measurement", Type: flux.TString}, + {Label: "f1", Type: flux.TFloat}, + {Label: "f2", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), "m1", 1.0, 2.0}, @@ -199,11 +199,11 @@ func TestPivot_Process(t *testing.T) { }, { KeyCols: []string{"_measurement"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_measurement", Type: query.TString}, - {Label: "f3", Type: query.TFloat}, - {Label: "f4", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_measurement", Type: flux.TString}, + {Label: "f3", Type: flux.TFloat}, + {Label: "f4", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), "m2", 1.0, 2.0}, @@ -219,14 +219,14 @@ func TestPivot_Process(t *testing.T) { ColKey: []string{"_measurement", "_field"}, ValueCol: "_value", }, - data: []query.Table{ + data: []flux.Table{ &executetest.Table{ KeyCols: []string{"_measurement"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "_measurement", Type: query.TString}, - {Label: "_field", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "_measurement", Type: flux.TString}, + {Label: "_field", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "m1", "f1"}, @@ -240,10 +240,10 @@ func TestPivot_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: nil, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "m1_f1", Type: query.TFloat}, - {Label: "m1_f2", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "m1_f1", Type: flux.TFloat}, + {Label: "m1_f2", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 5.0, 2.0}, @@ -259,15 +259,15 @@ func TestPivot_Process(t *testing.T) { ColKey: []string{"_measurement", "_field"}, ValueCol: "_value", }, - data: []query.Table{ + data: []flux.Table{ &executetest.Table{ KeyCols: []string{"_measurement"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "_measurement", Type: query.TString}, - {Label: "_field", Type: query.TString}, - {Label: "droppedcol", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "_measurement", Type: flux.TString}, + {Label: "_field", Type: flux.TString}, + {Label: "droppedcol", Type: flux.TInt}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "m1", "f1", 1}, @@ -281,10 +281,10 @@ func TestPivot_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: nil, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "m1_f1", Type: query.TFloat}, - {Label: "m1_f2", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "m1_f1", Type: flux.TFloat}, + {Label: "m1_f2", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 5.0, 2.0}, @@ -300,15 +300,15 @@ func TestPivot_Process(t *testing.T) { ColKey: []string{"_measurement", "_field"}, ValueCol: "_value", }, - data: []query.Table{ + data: []flux.Table{ &executetest.Table{ KeyCols: []string{"grouper"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "_measurement", Type: query.TString}, - {Label: "_field", Type: query.TString}, - {Label: "grouper", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "_measurement", Type: flux.TString}, + {Label: "_field", Type: flux.TString}, + {Label: "grouper", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "m1", "f1", "A"}, @@ -322,11 +322,11 @@ func TestPivot_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"grouper"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "grouper", Type: query.TString}, - {Label: "m1_f1", Type: query.TFloat}, - {Label: "m1_f2", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "grouper", Type: flux.TString}, + {Label: "m1_f1", Type: flux.TFloat}, + {Label: "m1_f2", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), "A", 5.0, 2.0}, @@ -342,15 +342,15 @@ func TestPivot_Process(t *testing.T) { ColKey: []string{"_measurement", "_field"}, ValueCol: "_value", }, - data: []query.Table{ + data: []flux.Table{ &executetest.Table{ KeyCols: []string{"grouper", "_field"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "_measurement", Type: query.TString}, - {Label: "_field", Type: query.TString}, - {Label: "grouper", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "_measurement", Type: flux.TString}, + {Label: "_field", Type: flux.TString}, + {Label: "grouper", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "m1", "f1", "A"}, @@ -359,12 +359,12 @@ func TestPivot_Process(t *testing.T) { }, &executetest.Table{ KeyCols: []string{"grouper", "_field"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "_measurement", Type: query.TString}, - {Label: "_field", Type: query.TString}, - {Label: "grouper", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "_measurement", Type: flux.TString}, + {Label: "_field", Type: flux.TString}, + {Label: "grouper", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 2.0, "m1", "f2", "B"}, @@ -372,12 +372,12 @@ func TestPivot_Process(t *testing.T) { }, &executetest.Table{ KeyCols: []string{"grouper", "_field"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "_measurement", Type: query.TString}, - {Label: "_field", Type: query.TString}, - {Label: "grouper", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "_measurement", Type: flux.TString}, + {Label: "_field", Type: flux.TString}, + {Label: "grouper", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(2), 4.0, "m1", "f2", "A"}, @@ -387,11 +387,11 @@ func TestPivot_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"grouper"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "grouper", Type: query.TString}, - {Label: "m1_f1", Type: query.TFloat}, - {Label: "m1_f2", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "grouper", Type: flux.TString}, + {Label: "m1_f1", Type: flux.TFloat}, + {Label: "m1_f2", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), "A", 1.0, 0.0}, @@ -400,10 +400,10 @@ func TestPivot_Process(t *testing.T) { }, { KeyCols: []string{"grouper"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "grouper", Type: query.TString}, - {Label: "m1_f2", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "grouper", Type: flux.TString}, + {Label: "m1_f2", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), "B", 2.0}, @@ -418,15 +418,15 @@ func TestPivot_Process(t *testing.T) { ColKey: []string{"_measurement", "_field"}, ValueCol: "grouper", }, - data: []query.Table{ + data: []flux.Table{ &executetest.Table{ KeyCols: []string{"grouper", "_field"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "_measurement", Type: query.TString}, - {Label: "_field", Type: query.TString}, - {Label: "grouper", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "_measurement", Type: flux.TString}, + {Label: "_field", Type: flux.TString}, + {Label: "grouper", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "m1", "f1", "A"}, @@ -435,12 +435,12 @@ func TestPivot_Process(t *testing.T) { }, &executetest.Table{ KeyCols: []string{"grouper", "_field"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "_measurement", Type: query.TString}, - {Label: "_field", Type: query.TString}, - {Label: "grouper", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "_measurement", Type: flux.TString}, + {Label: "_field", Type: flux.TString}, + {Label: "grouper", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 2.0, "m1", "f2", "B"}, @@ -448,12 +448,12 @@ func TestPivot_Process(t *testing.T) { }, &executetest.Table{ KeyCols: []string{"grouper", "_field"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "_measurement", Type: query.TString}, - {Label: "_field", Type: query.TString}, - {Label: "grouper", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "_measurement", Type: flux.TString}, + {Label: "_field", Type: flux.TString}, + {Label: "grouper", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(2), 4.0, "m1", "f2", "A"}, @@ -463,10 +463,10 @@ func TestPivot_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: nil, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "m1_f1", Type: query.TString}, - {Label: "m1_f2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "m1_f1", Type: flux.TString}, + {Label: "m1_f2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), "A", "B"}, diff --git a/functions/prepcsvtests/prepcsvtests.go b/functions/prepcsvtests/prepcsvtests.go index 268011f584..5d368b23f4 100644 --- a/functions/prepcsvtests/prepcsvtests.go +++ b/functions/prepcsvtests/prepcsvtests.go @@ -11,11 +11,11 @@ import ( "regexp" "strings" - "github.com/influxdata/platform/query" - _ "github.com/influxdata/platform/query/builtin" - "github.com/influxdata/platform/query/csv" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux" + _ "github.com/influxdata/flux/builtin" + "github.com/influxdata/flux/csv" "golang.org/x/text/unicode/norm" ) @@ -69,11 +69,11 @@ func main() { return } - pqs := querytest.GetProxyQueryServiceBridge() - req := &query.ProxyRequest{ - Request: query.Request{ - Compiler: querytest.FromCSVCompiler{ - Compiler: query.FluxCompiler{ + pqs := fluxtest.GetProxyQueryServiceBridge() + req := &flux.ProxyRequest{ + Request: flux.Request{ + Compiler: fluxtest.FromCSVCompiler{ + Compiler: flux.FluxCompiler{ Query: string(querytext), }, InputFile: incsv, diff --git a/functions/query_test.go b/functions/query_test.go index 21878ab145..0fe39bcf3e 100644 --- a/functions/query_test.go +++ b/functions/query_test.go @@ -9,39 +9,13 @@ import ( "strings" "testing" - "github.com/influxdata/platform" - "github.com/influxdata/platform/mock" - "github.com/influxdata/platform/query" - _ "github.com/influxdata/platform/query/builtin" - "github.com/influxdata/platform/query/csv" - "github.com/influxdata/platform/query/influxql" - "github.com/influxdata/platform/query/querytest" - "github.com/andreyvit/diff" + "github.com/influxdata/flux" + _ "github.com/influxdata/flux/builtin" + "github.com/influxdata/flux/csv" + "github.com/influxdata/flux/fluxtest" ) -var dbrpMappingSvc = mock.NewDBRPMappingService() - -func init() { - mapping := platform.DBRPMapping{ - Cluster: "cluster", - Database: "db0", - RetentionPolicy: "autogen", - Default: true, - OrganizationID: platform.ID("org"), - BucketID: platform.ID("bucket"), - } - dbrpMappingSvc.FindByFn = func(ctx context.Context, cluster string, db string, rp string) (*platform.DBRPMapping, error) { - return &mapping, nil - } - dbrpMappingSvc.FindFn = func(ctx context.Context, filter platform.DBRPMappingFilter) (*platform.DBRPMapping, error) { - return &mapping, nil - } - dbrpMappingSvc.FindManyFn = func(ctx context.Context, filter platform.DBRPMappingFilter, opt ...platform.FindOptions) ([]*platform.DBRPMapping, int, error) { - return []*platform.DBRPMapping{&mapping}, 1, nil - } -} - var skipTests = map[string]string{ "derivative": "derivative not supported by influxql (https://github.com/influxdata/platform/issues/93)", "filter_by_tags": "arbitrary filtering not supported by influxql (https://github.com/influxdata/platform/issues/94)", @@ -52,7 +26,7 @@ var skipTests = map[string]string{ "string_interp": "string interpolation not working as expected in flux (https://github.com/influxdata/platform/issues/404)", } -var pqs = querytest.GetProxyQueryServiceBridge() +var pqs = fluxtest.GetProxyQueryServiceBridge() func withEachFluxFile(t testing.TB, fn func(prefix, caseName string)) { dir, err := os.Getwd() @@ -79,19 +53,12 @@ func Test_QueryEndToEnd(t *testing.T) { reason, skip := skipTests[caseName] fluxName := caseName + ".flux" - influxqlName := caseName + ".influxql" t.Run(fluxName, func(t *testing.T) { if skip { t.Skip(reason) } testFlux(t, pqs, prefix, ".flux") }) - t.Run(influxqlName, func(t *testing.T) { - if skip { - t.Skip(reason) - } - testInfluxQL(t, pqs, prefix, ".influxql") - }) }) } @@ -103,7 +70,6 @@ func Benchmark_QueryEndToEnd(b *testing.B) { } fluxName := caseName + ".flux" - influxqlName := caseName + ".influxql" b.Run(fluxName, func(b *testing.B) { if skip { b.Skip(reason) @@ -114,20 +80,10 @@ func Benchmark_QueryEndToEnd(b *testing.B) { testFlux(b, pqs, prefix, ".flux") } }) - b.Run(influxqlName, func(b *testing.B) { - if skip { - b.Skip(reason) - } - b.ResetTimer() - b.ReportAllocs() - for i := 0; i < b.N; i++ { - testInfluxQL(b, pqs, prefix, ".influxql") - } - }) }) } -func testFlux(t testing.TB, pqs query.ProxyQueryService, prefix, queryExt string) { +func testFlux(t testing.TB, pqs flux.ProxyQueryService, prefix, queryExt string) { q, err := ioutil.ReadFile(prefix + queryExt) if err != nil { t.Fatal(err) @@ -139,12 +95,12 @@ func testFlux(t testing.TB, pqs query.ProxyQueryService, prefix, queryExt string t.Fatal(err) } - compiler := query.FluxCompiler{ + compiler := flux.FluxCompiler{ Query: string(q), } - req := &query.ProxyRequest{ - Request: query.Request{ - Compiler: querytest.FromCSVCompiler{ + req := &flux.ProxyRequest{ + Request: flux.Request{ + Compiler: fluxtest.FromCSVCompiler{ Compiler: compiler, InputFile: csvInFilename, }, @@ -155,50 +111,7 @@ func testFlux(t testing.TB, pqs query.ProxyQueryService, prefix, queryExt string QueryTestCheckSpec(t, pqs, req, string(csvOut)) } -func testInfluxQL(t testing.TB, pqs query.ProxyQueryService, prefix, queryExt string) { - q, err := ioutil.ReadFile(prefix + queryExt) - if err != nil { - if !os.IsNotExist(err) { - t.Fatal(err) - } - t.Skip("influxql query is missing") - } - - csvInFilename := prefix + ".in.csv" - csvOut, err := ioutil.ReadFile(prefix + ".out.csv") - if err != nil { - t.Fatal(err) - } - - compiler := influxql.NewCompiler(dbrpMappingSvc) - compiler.Cluster = "cluster" - compiler.DB = "db0" - compiler.Query = string(q) - req := &query.ProxyRequest{ - Request: query.Request{ - Compiler: querytest.FromCSVCompiler{ - Compiler: compiler, - InputFile: csvInFilename, - }, - }, - Dialect: csv.DefaultDialect(), - } - QueryTestCheckSpec(t, pqs, req, string(csvOut)) - - // Rerun test for InfluxQL JSON dialect - req.Dialect = new(influxql.Dialect) - - jsonOut, err := ioutil.ReadFile(prefix + ".out.json") - if err != nil { - if !os.IsNotExist(err) { - t.Fatal(err) - } - t.Skip("influxql expected json is missing") - } - QueryTestCheckSpec(t, pqs, req, string(jsonOut)) -} - -func QueryTestCheckSpec(t testing.TB, pqs query.ProxyQueryService, req *query.ProxyRequest, want string) { +func QueryTestCheckSpec(t testing.TB, pqs flux.ProxyQueryService, req *flux.ProxyRequest, want string) { t.Helper() var buf bytes.Buffer diff --git a/functions/range.go b/functions/range.go index 682c70e566..01202689bb 100644 --- a/functions/range.go +++ b/functions/range.go @@ -3,25 +3,25 @@ package functions import ( "fmt" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" + "github.com/influxdata/flux/values" "github.com/pkg/errors" ) const RangeKind = "range" type RangeOpSpec struct { - Start query.Time `json:"start"` - Stop query.Time `json:"stop"` - TimeCol string `json:"timeCol"` - StartCol string `json:"startCol"` - StopCol string `json:"stopCol"` + Start flux.Time `json:"start"` + Stop flux.Time `json:"stop"` + TimeCol string `json:"timeCol"` + StartCol string `json:"startCol"` + StopCol string `json:"stopCol"` } -var rangeSignature = query.DefaultFunctionSignature() +var rangeSignature = flux.DefaultFunctionSignature() func init() { rangeSignature.Params["start"] = semantic.Time @@ -30,14 +30,14 @@ func init() { rangeSignature.Params["startCol"] = semantic.String rangeSignature.Params["stopCol"] = semantic.String - query.RegisterFunction(RangeKind, createRangeOpSpec, rangeSignature) - query.RegisterOpSpec(RangeKind, newRangeOp) + flux.RegisterFunction(RangeKind, createRangeOpSpec, rangeSignature) + flux.RegisterOpSpec(RangeKind, newRangeOp) plan.RegisterProcedureSpec(RangeKind, newRangeProcedure, RangeKind) // TODO register a range transformation. Currently range is only supported if it is pushed down into a select procedure. execute.RegisterTransformation(RangeKind, createRangeTransformation) } -func createRangeOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createRangeOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -55,7 +55,7 @@ func createRangeOpSpec(args query.Arguments, a *query.Administration) (query.Ope spec.Stop = stop } else { // Make stop time implicit "now" - spec.Stop = query.Now + spec.Stop = flux.Now } if col, ok, err := args.GetString("timeCol"); err != nil { @@ -85,22 +85,22 @@ func createRangeOpSpec(args query.Arguments, a *query.Administration) (query.Ope return spec, nil } -func newRangeOp() query.OperationSpec { +func newRangeOp() flux.OperationSpec { return new(RangeOpSpec) } -func (s *RangeOpSpec) Kind() query.OperationKind { +func (s *RangeOpSpec) Kind() flux.OperationKind { return RangeKind } type RangeProcedureSpec struct { - Bounds query.Bounds + Bounds flux.Bounds TimeCol string StartCol string StopCol string } -func newRangeProcedure(qs query.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { +func newRangeProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*RangeOpSpec) if !ok { @@ -112,7 +112,7 @@ func newRangeProcedure(qs query.OperationSpec, pa plan.Administration) (plan.Pro } return &RangeProcedureSpec{ - Bounds: query.Bounds{ + Bounds: flux.Bounds{ Start: spec.Start, Stop: spec.Stop, }, @@ -151,14 +151,14 @@ func (s *RangeProcedureSpec) PushDown(root *plan.Procedure, dup func() *plan.Pro root = dup() selectSpec = root.Spec.(*FromProcedureSpec) selectSpec.BoundsSet = false - selectSpec.Bounds = query.Bounds{} + selectSpec.Bounds = flux.Bounds{} return } selectSpec.BoundsSet = true selectSpec.Bounds = s.Bounds } -func (s *RangeProcedureSpec) TimeBounds() query.Bounds { +func (s *RangeProcedureSpec) TimeBounds() flux.Bounds { return s.Bounds } @@ -202,11 +202,11 @@ func NewRangeTransformation(d execute.Dataset, cache execute.TableBuilderCache, }, nil } -func (t *rangeTransformation) RetractTable(id execute.DatasetID, key query.GroupKey) error { +func (t *rangeTransformation) RetractTable(id execute.DatasetID, key flux.GroupKey) error { return t.d.RetractTable(key) } -func (t *rangeTransformation) Process(id execute.DatasetID, tbl query.Table) error { +func (t *rangeTransformation) Process(id execute.DatasetID, tbl flux.Table) error { // Determine index of start and stop columns in group key startColIdx := execute.ColIdx(t.startCol, tbl.Cols()) stopColIdx := execute.ColIdx(t.stopCol, tbl.Cols()) @@ -227,7 +227,7 @@ func (t *rangeTransformation) Process(id execute.DatasetID, tbl query.Table) err return fmt.Errorf("range error: supplied time column %s doesn't exist", t.timeCol) } - if builder.Cols()[timeIdx].Type != query.TTime { + if builder.Cols()[timeIdx].Type != flux.TTime { return fmt.Errorf("range error: provided column %s is not of type time", t.timeCol) } @@ -264,9 +264,9 @@ func (t *rangeTransformation) Process(id execute.DatasetID, tbl query.Table) err if startColIdx < 0 { startColIdx = builder.NCols() - c := query.ColMeta{ + c := flux.ColMeta{ Label: t.startCol, - Type: query.TTime, + Type: flux.TTime, } builder.AddCol(c) startAdded = true @@ -274,15 +274,15 @@ func (t *rangeTransformation) Process(id execute.DatasetID, tbl query.Table) err if stopColIdx < 0 { stopColIdx = builder.NCols() - c := query.ColMeta{ + c := flux.ColMeta{ Label: t.stopCol, - Type: query.TTime, + Type: flux.TTime, } builder.AddCol(c) stopAdded = true } - err := tbl.Do(func(cr query.ColReader) error { + err := tbl.Do(func(cr flux.ColReader) error { l := cr.Len() for i := 0; i < l; i++ { tVal := cr.Times(timeIdx)[i] @@ -319,17 +319,17 @@ func (t *rangeTransformation) Process(id execute.DatasetID, tbl query.Table) err builder.AppendTime(j, stop) default: switch c.Type { - case query.TBool: + case flux.TBool: builder.AppendBool(j, cr.Bools(j)[i]) - case query.TInt: + case flux.TInt: builder.AppendInt(j, cr.Ints(j)[i]) - case query.TUInt: + case flux.TUInt: builder.AppendUInt(j, cr.UInts(j)[i]) - case query.TFloat: + case flux.TFloat: builder.AppendFloat(j, cr.Floats(j)[i]) - case query.TString: + case flux.TString: builder.AppendString(j, cr.Strings(j)[i]) - case query.TTime: + case flux.TTime: builder.AppendTime(j, cr.Times(j)[i]) default: execute.PanicUnknownType(c.Type) diff --git a/functions/range_test.go b/functions/range_test.go index 6aabdaeb1a..55b98692bd 100644 --- a/functions/range_test.go +++ b/functions/range_test.go @@ -4,26 +4,26 @@ import ( "testing" "time" - "github.com/influxdata/platform/query/semantic" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux/semantic" + "github.com/influxdata/flux/values" "github.com/pkg/errors" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/plan/plantest" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/plan/plantest" ) func TestRange_NewQuery(t *testing.T) { - tests := []querytest.NewQueryTestCase{ + tests := []fluxtest.NewQueryTestCase{ { Name: "from with database with range", Raw: `from(bucket:"mybucket") |> range(start:-4h, stop:-2h) |> sum()`, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "from0", Spec: &functions.FromOpSpec{ @@ -33,11 +33,11 @@ func TestRange_NewQuery(t *testing.T) { { ID: "range1", Spec: &functions.RangeOpSpec{ - Start: query.Time{ + Start: flux.Time{ Relative: -4 * time.Hour, IsRelative: true, }, - Stop: query.Time{ + Stop: flux.Time{ Relative: -2 * time.Hour, IsRelative: true, }, @@ -53,7 +53,7 @@ func TestRange_NewQuery(t *testing.T) { }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "from0", Child: "range1"}, {Parent: "range1", Child: "sum2"}, }, @@ -62,8 +62,8 @@ func TestRange_NewQuery(t *testing.T) { { Name: "from csv with range", Raw: `fromCSV(csv: "1,2") |> range(start:-4h, stop:-2h, timeCol: "_start") |> sum()`, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "fromCSV0", Spec: &functions.FromCSVOpSpec{ @@ -73,11 +73,11 @@ func TestRange_NewQuery(t *testing.T) { { ID: "range1", Spec: &functions.RangeOpSpec{ - Start: query.Time{ + Start: flux.Time{ Relative: -4 * time.Hour, IsRelative: true, }, - Stop: query.Time{ + Stop: flux.Time{ Relative: -2 * time.Hour, IsRelative: true, }, @@ -93,7 +93,7 @@ func TestRange_NewQuery(t *testing.T) { }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "fromCSV0", Child: "range1"}, {Parent: "range1", Child: "sum2"}, }, @@ -104,33 +104,33 @@ func TestRange_NewQuery(t *testing.T) { tc := tc t.Run(tc.Name, func(t *testing.T) { t.Parallel() - querytest.NewQueryTestHelper(t, tc) + fluxtest.NewQueryTestHelper(t, tc) }) } } func TestRangeOperation_Marshaling(t *testing.T) { data := []byte(`{"id":"range","kind":"range","spec":{"start":"-1h","stop":"2017-10-10T00:00:00Z"}}`) - op := &query.Operation{ + op := &flux.Operation{ ID: "range", Spec: &functions.RangeOpSpec{ - Start: query.Time{ + Start: flux.Time{ Relative: -1 * time.Hour, IsRelative: true, }, - Stop: query.Time{ + Stop: flux.Time{ Absolute: time.Date(2017, 10, 10, 0, 0, 0, 0, time.UTC), }, }, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestRange_PushDown(t *testing.T) { spec := &functions.RangeProcedureSpec{ - Bounds: query.Bounds{ - Stop: query.Now, + Bounds: flux.Bounds{ + Stop: flux.Now, }, } root := &plan.Procedure{ @@ -139,8 +139,8 @@ func TestRange_PushDown(t *testing.T) { want := &plan.Procedure{ Spec: &functions.FromProcedureSpec{ BoundsSet: true, - Bounds: query.Bounds{ - Stop: query.Now, + Bounds: flux.Bounds{ + Stop: flux.Now, }, }, } @@ -152,21 +152,21 @@ func TestRange_Process(t *testing.T) { testCases := []struct { name string spec *functions.RangeProcedureSpec - data []query.Table + data []flux.Table want []*executetest.Table - groupKey func() query.GroupKey + groupKey func() flux.GroupKey now values.Time wantErr error }{ { name: "from csv", spec: &functions.RangeProcedureSpec{ - Bounds: query.Bounds{ - Start: query.Time{ + Bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: -5 * time.Minute, }, - Stop: query.Time{ + Stop: flux.Time{ IsRelative: true, Relative: -2 * time.Minute, }, @@ -175,10 +175,10 @@ func TestRange_Process(t *testing.T) { StartCol: "_start", StopCol: "_stop", }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(time.Minute.Nanoseconds()), 10.0}, @@ -191,11 +191,11 @@ func TestRange_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, }, Data: [][]interface{}{ {execute.Time(2 * time.Minute.Nanoseconds()), 5.0, execute.Time(2 * time.Minute.Nanoseconds()), execute.Time(5 * time.Minute.Nanoseconds())}, @@ -208,12 +208,12 @@ func TestRange_Process(t *testing.T) { { name: "invalid column", spec: &functions.RangeProcedureSpec{ - Bounds: query.Bounds{ - Start: query.Time{ + Bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: -5 * time.Minute, }, - Stop: query.Time{ + Stop: flux.Time{ IsRelative: true, Relative: -2 * time.Minute, }, @@ -222,10 +222,10 @@ func TestRange_Process(t *testing.T) { StartCol: "_start", StopCol: "_stop", }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(time.Minute.Nanoseconds()), 10.0}, @@ -238,9 +238,9 @@ func TestRange_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}(nil), }}, @@ -250,12 +250,12 @@ func TestRange_Process(t *testing.T) { { name: "specified column", spec: &functions.RangeProcedureSpec{ - Bounds: query.Bounds{ - Start: query.Time{ + Bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: -2 * time.Minute, }, - Stop: query.Time{ + Stop: flux.Time{ IsRelative: true, }, }, @@ -263,11 +263,11 @@ func TestRange_Process(t *testing.T) { StartCol: "_start", StopCol: "_stop", }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(0), execute.Time(time.Minute.Nanoseconds()), 10.0}, @@ -277,11 +277,11 @@ func TestRange_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "_stop", Type: query.TTime}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "_stop", Type: flux.TTime}, }, Data: [][]interface{}{ {execute.Time(time.Minute.Nanoseconds()), execute.Time(3 * time.Minute.Nanoseconds()), 9.0, execute.Time(3 * time.Minute.Nanoseconds())}, @@ -293,12 +293,12 @@ func TestRange_Process(t *testing.T) { { name: "group key no overlap", spec: &functions.RangeProcedureSpec{ - Bounds: query.Bounds{ - Start: query.Time{ + Bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: -2 * time.Minute, }, - Stop: query.Time{ + Stop: flux.Time{ IsRelative: true, }, }, @@ -306,12 +306,12 @@ func TestRange_Process(t *testing.T) { StartCol: "_start", StopCol: "_stop", }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, KeyCols: []string{"_start", "_stop"}, KeyValues: []interface{}{execute.Time(10 * time.Minute.Nanoseconds()), execute.Time(20 * time.Minute.Nanoseconds())}, @@ -323,11 +323,11 @@ func TestRange_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, KeyCols: []string{"_start", "_stop"}, KeyValues: []interface{}{execute.Time(10 * time.Minute.Nanoseconds()), execute.Time(20 * time.Minute.Nanoseconds())}, @@ -338,11 +338,11 @@ func TestRange_Process(t *testing.T) { { name: "group key overlap", spec: &functions.RangeProcedureSpec{ - Bounds: query.Bounds{ - Start: query.Time{ + Bounds: flux.Bounds{ + Start: flux.Time{ Absolute: time.Unix(12*time.Minute.Nanoseconds(), 0), }, - Stop: query.Time{ + Stop: flux.Time{ Absolute: time.Unix(14*time.Minute.Nanoseconds(), 0), }, }, @@ -350,12 +350,12 @@ func TestRange_Process(t *testing.T) { StartCol: "_start", StopCol: "_stop", }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, KeyCols: []string{"_start", "_stop"}, KeyValues: []interface{}{execute.Time(10 * time.Minute.Nanoseconds()), execute.Time(20 * time.Minute.Nanoseconds())}, @@ -367,11 +367,11 @@ func TestRange_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, KeyCols: []string{"_start", "_stop"}, KeyValues: []interface{}{execute.Time(10 * time.Minute.Nanoseconds()), execute.Time(20 * time.Minute.Nanoseconds())}, @@ -380,7 +380,7 @@ func TestRange_Process(t *testing.T) { {execute.Time(12 * time.Minute.Nanoseconds()), execute.Time(14 * time.Minute.Nanoseconds()), execute.Time(13 * time.Minute.Nanoseconds()), 1.0}, }, }}, - groupKey: func() query.GroupKey { + groupKey: func() flux.GroupKey { t1, err := values.NewValue(values.Time(10*time.Minute.Nanoseconds()), semantic.Time) if err != nil { t.Fatal(err) @@ -392,9 +392,9 @@ func TestRange_Process(t *testing.T) { vs := []values.Value{t1, t2} return execute.NewGroupKey( - []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, + []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, }, vs, ) @@ -403,11 +403,11 @@ func TestRange_Process(t *testing.T) { { name: "empty bounds start == stop", spec: &functions.RangeProcedureSpec{ - Bounds: query.Bounds{ - Start: query.Time{ + Bounds: flux.Bounds{ + Start: flux.Time{ Absolute: time.Date(2018, 1, 1, 0, 0, 0, 0, time.UTC), }, - Stop: query.Time{ + Stop: flux.Time{ Absolute: time.Date(2018, 1, 1, 0, 0, 0, 0, time.UTC), }, }, @@ -416,10 +416,10 @@ func TestRange_Process(t *testing.T) { StartCol: "_start", StopCol: "_stop", }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(time.Minute.Nanoseconds()), 10.0}, @@ -432,11 +432,11 @@ func TestRange_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, }, Data: [][]interface{}(nil), }}, @@ -445,12 +445,12 @@ func TestRange_Process(t *testing.T) { { name: "empty bounds start > stop", spec: &functions.RangeProcedureSpec{ - Bounds: query.Bounds{ - Start: query.Time{ + Bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: -2 * time.Minute, }, - Stop: query.Time{ + Stop: flux.Time{ IsRelative: true, Relative: -5 * time.Minute, }, @@ -459,10 +459,10 @@ func TestRange_Process(t *testing.T) { StartCol: "_start", StopCol: "_stop", }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(time.Minute.Nanoseconds()), 10.0}, @@ -475,11 +475,11 @@ func TestRange_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, }, Data: [][]interface{}(nil), }}, @@ -535,16 +535,16 @@ func TestRange_Process(t *testing.T) { } func TestRange_PushDown_Duplicate(t *testing.T) { spec := &functions.RangeProcedureSpec{ - Bounds: query.Bounds{ - Stop: query.Now, + Bounds: flux.Bounds{ + Stop: flux.Now, }, } root := &plan.Procedure{ Spec: &functions.FromProcedureSpec{ BoundsSet: true, - Bounds: query.Bounds{ - Start: query.MinTime, - Stop: query.Now, + Bounds: flux.Bounds{ + Start: flux.MinTime, + Stop: flux.Now, }, }, } @@ -558,8 +558,8 @@ func TestRange_PushDown_Duplicate(t *testing.T) { func TestRange_PushDown_Match(t *testing.T) { spec := &functions.RangeProcedureSpec{ - Bounds: query.Bounds{ - Stop: query.Now, + Bounds: flux.Bounds{ + Stop: flux.Now, }, TimeCol: "_time", } diff --git a/functions/sample.go b/functions/sample.go index 8b52f841fb..58771476d2 100644 --- a/functions/sample.go +++ b/functions/sample.go @@ -5,10 +5,10 @@ import ( "math/rand" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" ) const SampleKind = "sample" @@ -25,13 +25,13 @@ func init() { sampleSignature.Params["n"] = semantic.Int sampleSignature.Params["pos"] = semantic.Int - query.RegisterFunction(SampleKind, createSampleOpSpec, sampleSignature) - query.RegisterOpSpec(SampleKind, newSampleOp) + flux.RegisterFunction(SampleKind, createSampleOpSpec, sampleSignature) + flux.RegisterOpSpec(SampleKind, newSampleOp) plan.RegisterProcedureSpec(SampleKind, newSampleProcedure, SampleKind) execute.RegisterTransformation(SampleKind, createSampleTransformation) } -func createSampleOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createSampleOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -59,11 +59,11 @@ func createSampleOpSpec(args query.Arguments, a *query.Administration) (query.Op return spec, nil } -func newSampleOp() query.OperationSpec { +func newSampleOp() flux.OperationSpec { return new(SampleOpSpec) } -func (s *SampleOpSpec) Kind() query.OperationKind { +func (s *SampleOpSpec) Kind() flux.OperationKind { return SampleKind } @@ -73,7 +73,7 @@ type SampleProcedureSpec struct { execute.SelectorConfig } -func newSampleProcedure(qs query.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { +func newSampleProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*SampleOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) diff --git a/functions/sample_test.go b/functions/sample_test.go index 9b77e99d84..7f59d6865d 100644 --- a/functions/sample_test.go +++ b/functions/sample_test.go @@ -3,16 +3,16 @@ package functions_test import ( "testing" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" ) func TestSampleOperation_Marshaling(t *testing.T) { data := []byte(`{"id":"sample","kind":"sample","spec":{"n":5, "pos":0}}`) - op := &query.Operation{ + op := &flux.Operation{ ID: "sample", Spec: &functions.SampleOpSpec{ N: 5, @@ -20,13 +20,13 @@ func TestSampleOperation_Marshaling(t *testing.T) { }, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestSample_Process(t *testing.T) { testCases := []struct { name string - data query.Table + data flux.Table want [][]int fromor *functions.SampleSelector }{ @@ -38,11 +38,11 @@ func TestSample_Process(t *testing.T) { name: "everything in separate Do calls", data: &executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(0), 7.0, "a", "y"}, @@ -78,11 +78,11 @@ func TestSample_Process(t *testing.T) { name: "everything in single Do call", data: execute.CopyTable(&executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(0), 7.0, "a", "y"}, @@ -118,11 +118,11 @@ func TestSample_Process(t *testing.T) { name: "every-other-even", data: execute.CopyTable(&executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(0), 7.0, "a", "y"}, @@ -153,11 +153,11 @@ func TestSample_Process(t *testing.T) { name: "every-other-odd", data: execute.CopyTable(&executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(0), 7.0, "a", "y"}, @@ -188,11 +188,11 @@ func TestSample_Process(t *testing.T) { name: "every-third-0", data: execute.CopyTable(&executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(0), 7.0, "a", "y"}, @@ -222,11 +222,11 @@ func TestSample_Process(t *testing.T) { name: "every-third-1", data: execute.CopyTable(&executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(0), 7.0, "a", "y"}, @@ -255,11 +255,11 @@ func TestSample_Process(t *testing.T) { name: "every-third-2", data: execute.CopyTable(&executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(0), 7.0, "a", "y"}, @@ -288,11 +288,11 @@ func TestSample_Process(t *testing.T) { name: "every-third-2 in separate Do calls", data: &executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(0), 7.0, "a", "y"}, diff --git a/functions/schema_functions.go b/functions/schema_functions.go index d6de8017c4..33ef5509dc 100644 --- a/functions/schema_functions.go +++ b/functions/schema_functions.go @@ -3,12 +3,12 @@ package functions import ( "fmt" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/interpreter" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/interpreter" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" + "github.com/influxdata/flux/values" "github.com/pkg/errors" ) @@ -42,7 +42,7 @@ const SchemaMutationKind = "SchemaMutation" // A list of all operations which should map to the SchemaMutationProcedure // Added to dynamically upon calls to `Register()` -var SchemaMutationOps = []query.OperationKind{} +var SchemaMutationOps = []flux.OperationKind{} // A MutationRegistrar contains information needed // to register a type of Operation Spec @@ -51,20 +51,20 @@ var SchemaMutationOps = []query.OperationKind{} // Operations with a corresponding MutationRegistrar // should not have their own ProcedureSpec. type MutationRegistrar struct { - Kind query.OperationKind + Kind flux.OperationKind Args map[string]semantic.Type - Create query.CreateOperationSpec - New query.NewOperationSpec + Create flux.CreateOperationSpec + New flux.NewOperationSpec } func (m MutationRegistrar) Register() { - signature := query.DefaultFunctionSignature() + signature := flux.DefaultFunctionSignature() for name, typ := range m.Args { signature.Params[name] = typ } - query.RegisterFunction(string(m.Kind), m.Create, signature) - query.RegisterOpSpec(m.Kind, m.New) + flux.RegisterFunction(string(m.Kind), m.Create, signature) + flux.RegisterOpSpec(m.Kind, m.New) // Add to list of SchemaMutations which should map to a // SchemaMutationProcedureSpec @@ -121,7 +121,7 @@ func init() { execute.RegisterTransformation(SchemaMutationKind, createSchemaMutationTransformation) } -func createRenameOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createRenameOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -178,7 +178,7 @@ func createRenameOpSpec(args query.Arguments, a *query.Administration) (query.Op return spec, nil } -func createDropOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createDropOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -225,7 +225,7 @@ func createDropOpSpec(args query.Arguments, a *query.Administration) (query.Oper }, nil } -func createKeepOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createKeepOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -272,7 +272,7 @@ func createKeepOpSpec(args query.Arguments, a *query.Administration) (query.Oper }, nil } -func createDuplicateOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createDuplicateOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -293,35 +293,35 @@ func createDuplicateOpSpec(args query.Arguments, a *query.Administration) (query }, nil } -func newRenameOp() query.OperationSpec { +func newRenameOp() flux.OperationSpec { return new(RenameOpSpec) } -func (s *RenameOpSpec) Kind() query.OperationKind { +func (s *RenameOpSpec) Kind() flux.OperationKind { return RenameKind } -func newDropOp() query.OperationSpec { +func newDropOp() flux.OperationSpec { return new(DropOpSpec) } -func (s *DropOpSpec) Kind() query.OperationKind { +func (s *DropOpSpec) Kind() flux.OperationKind { return DropKind } -func newKeepOp() query.OperationSpec { +func newKeepOp() flux.OperationSpec { return new(KeepOpSpec) } -func (s *KeepOpSpec) Kind() query.OperationKind { +func (s *KeepOpSpec) Kind() flux.OperationKind { return KeepKind } -func newDuplicateOp() query.OperationSpec { +func newDuplicateOp() flux.OperationSpec { return new(DuplicateOpSpec) } -func (s *DuplicateOpSpec) Kind() query.OperationKind { +func (s *DuplicateOpSpec) Kind() flux.OperationKind { return DuplicateKind } @@ -419,7 +419,7 @@ func (s *SchemaMutationProcedureSpec) Copy() plan.ProcedureSpec { } } -func newSchemaMutationProcedure(qs query.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { +func newSchemaMutationProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { s, ok := qs.(SchemaMutation) if !ok { return nil, fmt.Errorf("invalid spec type %T doesn't implement SchemaMutation", qs) @@ -469,7 +469,7 @@ func NewSchemaMutationTransformation(d execute.Dataset, cache execute.TableBuild }, nil } -func (t *schemaMutationTransformation) Process(id execute.DatasetID, tbl query.Table) error { +func (t *schemaMutationTransformation) Process(id execute.DatasetID, tbl flux.Table) error { ctx := NewBuilderContext(tbl) for _, m := range t.mutators { err := m.Mutate(ctx) @@ -485,7 +485,7 @@ func (t *schemaMutationTransformation) Process(id execute.DatasetID, tbl query.T } } - return tbl.Do(func(cr query.ColReader) error { + return tbl.Do(func(cr flux.ColReader) error { for i := 0; i < cr.Len(); i++ { execute.AppendMappedRecord(i, cr, builder, ctx.ColMap()) } @@ -493,7 +493,7 @@ func (t *schemaMutationTransformation) Process(id execute.DatasetID, tbl query.T }) } -func (t *schemaMutationTransformation) RetractTable(id execute.DatasetID, key query.GroupKey) error { +func (t *schemaMutationTransformation) RetractTable(id execute.DatasetID, key flux.GroupKey) error { return t.d.RetractTable(key) } diff --git a/functions/schema_functions_test.go b/functions/schema_functions_test.go index 5c8f2cfa6f..af3e30f514 100644 --- a/functions/schema_functions_test.go +++ b/functions/schema_functions_test.go @@ -4,26 +4,26 @@ import ( "regexp" "testing" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux/ast" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" + "github.com/influxdata/flux/values" "github.com/pkg/errors" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" ) func TestSchemaMutions_NewQueries(t *testing.T) { - tests := []querytest.NewQueryTestCase{ + tests := []fluxtest.NewQueryTestCase{ { Name: "test rename query", Raw: `from(bucket:"mybucket") |> rename(columns:{old:"new"}) |> sum()`, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "from0", Spec: &functions.FromOpSpec{ @@ -45,7 +45,7 @@ func TestSchemaMutions_NewQueries(t *testing.T) { }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "from0", Child: "rename1"}, {Parent: "rename1", Child: "sum2"}, }, @@ -54,8 +54,8 @@ func TestSchemaMutions_NewQueries(t *testing.T) { { Name: "test drop query", Raw: `from(bucket:"mybucket") |> drop(columns:["col1", "col2", "col3"]) |> sum()`, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "from0", Spec: &functions.FromOpSpec{ @@ -75,7 +75,7 @@ func TestSchemaMutions_NewQueries(t *testing.T) { }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "from0", Child: "drop1"}, {Parent: "drop1", Child: "sum2"}, }, @@ -84,8 +84,8 @@ func TestSchemaMutions_NewQueries(t *testing.T) { { Name: "test keep query", Raw: `from(bucket:"mybucket") |> keep(columns:["col1", "col2", "col3"]) |> sum()`, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "from0", Spec: &functions.FromOpSpec{ @@ -105,7 +105,7 @@ func TestSchemaMutions_NewQueries(t *testing.T) { }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "from0", Child: "keep1"}, {Parent: "keep1", Child: "sum2"}, }, @@ -114,8 +114,8 @@ func TestSchemaMutions_NewQueries(t *testing.T) { { Name: "test duplicate query", Raw: `from(bucket:"mybucket") |> duplicate(column: "col1", as: "col1_new") |> sum()`, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "from0", Spec: &functions.FromOpSpec{ @@ -136,7 +136,7 @@ func TestSchemaMutions_NewQueries(t *testing.T) { }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "from0", Child: "duplicate1"}, {Parent: "duplicate1", Child: "sum2"}, }, @@ -145,8 +145,8 @@ func TestSchemaMutions_NewQueries(t *testing.T) { { Name: "test drop query fn param", Raw: `from(bucket:"mybucket") |> drop(fn: (col) => col =~ /reg*/) |> sum()`, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "from0", Spec: &functions.FromOpSpec{ @@ -177,7 +177,7 @@ func TestSchemaMutions_NewQueries(t *testing.T) { }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "from0", Child: "drop1"}, {Parent: "drop1", Child: "sum2"}, }, @@ -186,8 +186,8 @@ func TestSchemaMutions_NewQueries(t *testing.T) { { Name: "test keep query fn param", Raw: `from(bucket:"mybucket") |> keep(fn: (col) => col =~ /reg*/) |> sum()`, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "from0", Spec: &functions.FromOpSpec{ @@ -218,7 +218,7 @@ func TestSchemaMutions_NewQueries(t *testing.T) { }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "from0", Child: "keep1"}, {Parent: "keep1", Child: "sum2"}, }, @@ -227,8 +227,8 @@ func TestSchemaMutions_NewQueries(t *testing.T) { { Name: "test rename query fn param", Raw: `from(bucket:"mybucket") |> rename(fn: (col) => "new_name") |> sum()`, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "from0", Spec: &functions.FromOpSpec{ @@ -253,7 +253,7 @@ func TestSchemaMutions_NewQueries(t *testing.T) { }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "from0", Child: "rename1"}, {Parent: "rename1", Child: "sum2"}, }, @@ -289,7 +289,7 @@ func TestSchemaMutions_NewQueries(t *testing.T) { tc := tc t.Run(tc.Name, func(t *testing.T) { t.Parallel() - querytest.NewQueryTestHelper(t, tc) + fluxtest.NewQueryTestHelper(t, tc) }) } } @@ -298,7 +298,7 @@ func TestDropRenameKeep_Process(t *testing.T) { testCases := []struct { name string spec plan.ProcedureSpec - data []query.Table + data []flux.Table want []*executetest.Table wantErr error }{ @@ -315,11 +315,11 @@ func TestDropRenameKeep_Process(t *testing.T) { }, }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "1a", Type: query.TFloat}, - {Label: "2a", Type: query.TFloat}, - {Label: "3a", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "1a", Type: flux.TFloat}, + {Label: "2a", Type: flux.TFloat}, + {Label: "3a", Type: flux.TFloat}, }, Data: [][]interface{}{ {1.0, 2.0, 3.0}, @@ -328,10 +328,10 @@ func TestDropRenameKeep_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "1b", Type: query.TFloat}, - {Label: "2b", Type: query.TFloat}, - {Label: "3b", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "1b", Type: flux.TFloat}, + {Label: "2b", Type: flux.TFloat}, + {Label: "3b", Type: flux.TFloat}, }, Data: [][]interface{}{ {1.0, 2.0, 3.0}, @@ -350,11 +350,11 @@ func TestDropRenameKeep_Process(t *testing.T) { }, }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "a", Type: query.TFloat}, - {Label: "b", Type: query.TFloat}, - {Label: "c", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "a", Type: flux.TFloat}, + {Label: "b", Type: flux.TFloat}, + {Label: "c", Type: flux.TFloat}, }, Data: [][]interface{}{ {1.0, 2.0, 3.0}, @@ -363,8 +363,8 @@ func TestDropRenameKeep_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "c", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "c", Type: flux.TFloat}, }, Data: [][]interface{}{ {3.0}, @@ -382,11 +382,11 @@ func TestDropRenameKeep_Process(t *testing.T) { }, }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "a", Type: query.TFloat}, - {Label: "b", Type: query.TFloat}, - {Label: "c", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "a", Type: flux.TFloat}, + {Label: "b", Type: flux.TFloat}, + {Label: "c", Type: flux.TFloat}, }, Data: [][]interface{}{ {1.0, 2.0, 3.0}, @@ -395,8 +395,8 @@ func TestDropRenameKeep_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "a", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "a", Type: flux.TFloat}, }, Data: [][]interface{}{ {1.0}, @@ -415,11 +415,11 @@ func TestDropRenameKeep_Process(t *testing.T) { }, }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "a", Type: query.TFloat}, - {Label: "b", Type: query.TFloat}, - {Label: "c", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "a", Type: flux.TFloat}, + {Label: "b", Type: flux.TFloat}, + {Label: "c", Type: flux.TFloat}, }, Data: [][]interface{}{ {1.0, 2.0, 3.0}, @@ -428,11 +428,11 @@ func TestDropRenameKeep_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "a", Type: query.TFloat}, - {Label: "a_1", Type: query.TFloat}, - {Label: "b", Type: query.TFloat}, - {Label: "c", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "a", Type: flux.TFloat}, + {Label: "a_1", Type: flux.TFloat}, + {Label: "b", Type: flux.TFloat}, + {Label: "c", Type: flux.TFloat}, }, Data: [][]interface{}{ {1.0, 1.0, 2.0, 3.0}, @@ -455,11 +455,11 @@ func TestDropRenameKeep_Process(t *testing.T) { }, }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "1a", Type: query.TFloat}, - {Label: "2a", Type: query.TFloat}, - {Label: "3a", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "1a", Type: flux.TFloat}, + {Label: "2a", Type: flux.TFloat}, + {Label: "3a", Type: flux.TFloat}, }, Data: [][]interface{}{ {1.0, 2.0, 3.0}, @@ -468,10 +468,10 @@ func TestDropRenameKeep_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "new_name", Type: query.TFloat}, - {Label: "new_name", Type: query.TFloat}, - {Label: "new_name", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "new_name", Type: flux.TFloat}, + {Label: "new_name", Type: flux.TFloat}, + {Label: "new_name", Type: flux.TFloat}, }, Data: [][]interface{}{ {1.0, 2.0, 3.0}, @@ -500,11 +500,11 @@ func TestDropRenameKeep_Process(t *testing.T) { }, }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "server1", Type: query.TFloat}, - {Label: "local", Type: query.TFloat}, - {Label: "server2", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "server1", Type: flux.TFloat}, + {Label: "local", Type: flux.TFloat}, + {Label: "server2", Type: flux.TFloat}, }, Data: [][]interface{}{ {1.0, 2.0, 3.0}, @@ -513,8 +513,8 @@ func TestDropRenameKeep_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "local", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "local", Type: flux.TFloat}, }, Data: [][]interface{}{ {2.0}, @@ -543,11 +543,11 @@ func TestDropRenameKeep_Process(t *testing.T) { }, }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "server1", Type: query.TFloat}, - {Label: "local", Type: query.TFloat}, - {Label: "server2", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "server1", Type: flux.TFloat}, + {Label: "local", Type: flux.TFloat}, + {Label: "server2", Type: flux.TFloat}, }, Data: [][]interface{}{ {1.0, 2.0, 3.0}, @@ -556,9 +556,9 @@ func TestDropRenameKeep_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "server1", Type: query.TFloat}, - {Label: "server2", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "server1", Type: flux.TFloat}, + {Label: "server2", Type: flux.TFloat}, }, Data: [][]interface{}{ {1.0, 3.0}, @@ -581,11 +581,11 @@ func TestDropRenameKeep_Process(t *testing.T) { }, }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "server1", Type: query.TFloat}, - {Label: "local", Type: query.TFloat}, - {Label: "server2", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "server1", Type: flux.TFloat}, + {Label: "local", Type: flux.TFloat}, + {Label: "server2", Type: flux.TFloat}, }, Data: [][]interface{}{ {1.0, 2.0, 3.0}, @@ -594,8 +594,8 @@ func TestDropRenameKeep_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "localhost", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "localhost", Type: flux.TFloat}, }, Data: [][]interface{}{ {2.0}, @@ -613,11 +613,11 @@ func TestDropRenameKeep_Process(t *testing.T) { }, }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "server1", Type: query.TFloat}, - {Label: "local", Type: query.TFloat}, - {Label: "server2", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "server1", Type: flux.TFloat}, + {Label: "local", Type: flux.TFloat}, + {Label: "server2", Type: flux.TFloat}, }, Data: [][]interface{}{ {1.0, 2.0, 3.0}, @@ -639,11 +639,11 @@ func TestDropRenameKeep_Process(t *testing.T) { }, }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "server1", Type: query.TFloat}, - {Label: "local", Type: query.TFloat}, - {Label: "server2", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "server1", Type: flux.TFloat}, + {Label: "local", Type: flux.TFloat}, + {Label: "server2", Type: flux.TFloat}, }, Data: [][]interface{}{ {1.0, 2.0, 3.0}, @@ -663,11 +663,11 @@ func TestDropRenameKeep_Process(t *testing.T) { }, }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "server1", Type: query.TFloat}, - {Label: "local", Type: query.TFloat}, - {Label: "server2", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "server1", Type: flux.TFloat}, + {Label: "local", Type: flux.TFloat}, + {Label: "server2", Type: flux.TFloat}, }, Data: [][]interface{}{ {1.0, 2.0, 3.0}, @@ -688,11 +688,11 @@ func TestDropRenameKeep_Process(t *testing.T) { }, }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "server1", Type: query.TFloat}, - {Label: "local", Type: query.TFloat}, - {Label: "server2", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "server1", Type: flux.TFloat}, + {Label: "local", Type: flux.TFloat}, + {Label: "server2", Type: flux.TFloat}, }, Data: [][]interface{}{ {1.0, 2.0, 3.0}, @@ -716,11 +716,11 @@ func TestDropRenameKeep_Process(t *testing.T) { }, }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "1a", Type: query.TFloat}, - {Label: "2a", Type: query.TFloat}, - {Label: "3a", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "1a", Type: flux.TFloat}, + {Label: "2a", Type: flux.TFloat}, + {Label: "3a", Type: flux.TFloat}, }, Data: [][]interface{}{ {1.0, 2.0, 3.0}, @@ -730,18 +730,18 @@ func TestDropRenameKeep_Process(t *testing.T) { KeyCols: []string{"1a"}, KeyValues: []interface{}{1.0}, GroupKey: execute.NewGroupKey( - []query.ColMeta{{ + []flux.ColMeta{{ Label: "1a", - Type: query.TFloat, + Type: flux.TFloat, }}, []values.Value{values.NewFloatValue(1.0)}, ), }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "1b", Type: query.TFloat}, - {Label: "2b", Type: query.TFloat}, - {Label: "3b", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "1b", Type: flux.TFloat}, + {Label: "2b", Type: flux.TFloat}, + {Label: "3b", Type: flux.TFloat}, }, Data: [][]interface{}{ {1.0, 2.0, 3.0}, @@ -751,9 +751,9 @@ func TestDropRenameKeep_Process(t *testing.T) { KeyCols: []string{"1b"}, KeyValues: []interface{}{1.0}, GroupKey: execute.NewGroupKey( - []query.ColMeta{{ + []flux.ColMeta{{ Label: "1b", - Type: query.TFloat, + Type: flux.TFloat, }}, []values.Value{values.NewFloatValue(1.0)}, ), @@ -768,11 +768,11 @@ func TestDropRenameKeep_Process(t *testing.T) { }, }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "1a", Type: query.TFloat}, - {Label: "2a", Type: query.TFloat}, - {Label: "3a", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "1a", Type: flux.TFloat}, + {Label: "2a", Type: flux.TFloat}, + {Label: "3a", Type: flux.TFloat}, }, Data: [][]interface{}{ {1.0, 2.0, 3.0}, @@ -782,17 +782,17 @@ func TestDropRenameKeep_Process(t *testing.T) { KeyCols: []string{"2a"}, KeyValues: []interface{}{2.0}, GroupKey: execute.NewGroupKey( - []query.ColMeta{{ + []flux.ColMeta{{ Label: "2a", - Type: query.TFloat, + Type: flux.TFloat, }}, []values.Value{values.NewFloatValue(2.0)}, ), }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "1a", Type: query.TFloat}, - {Label: "3a", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "1a", Type: flux.TFloat}, + {Label: "3a", Type: flux.TFloat}, }, Data: [][]interface{}{ {1.0, 3.0}, @@ -801,7 +801,7 @@ func TestDropRenameKeep_Process(t *testing.T) { }, KeyCols: []string(nil), KeyValues: []interface{}(nil), - GroupKey: execute.NewGroupKey([]query.ColMeta{}, []values.Value{}), + GroupKey: execute.NewGroupKey([]flux.ColMeta{}, []values.Value{}), }}, }, { @@ -813,11 +813,11 @@ func TestDropRenameKeep_Process(t *testing.T) { }, }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "1a", Type: query.TFloat}, - {Label: "2a", Type: query.TFloat}, - {Label: "3a", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "1a", Type: flux.TFloat}, + {Label: "2a", Type: flux.TFloat}, + {Label: "3a", Type: flux.TFloat}, }, Data: [][]interface{}{ {1.0, 2.0, 3.0}, @@ -827,16 +827,16 @@ func TestDropRenameKeep_Process(t *testing.T) { KeyCols: []string{"1a", "3a"}, KeyValues: []interface{}{1.0, 3.0}, GroupKey: execute.NewGroupKey( - []query.ColMeta{ - {Label: "1a", Type: query.TFloat}, - {Label: "3a", Type: query.TFloat}, + []flux.ColMeta{ + {Label: "1a", Type: flux.TFloat}, + {Label: "3a", Type: flux.TFloat}, }, []values.Value{values.NewFloatValue(1.0), values.NewFloatValue(3.0)}, ), }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "1a", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "1a", Type: flux.TFloat}, }, Data: [][]interface{}{ {1.0}, @@ -846,8 +846,8 @@ func TestDropRenameKeep_Process(t *testing.T) { KeyCols: []string{"1a"}, KeyValues: []interface{}{1.0}, GroupKey: execute.NewGroupKey( - []query.ColMeta{ - {Label: "1a", Type: query.TFloat}, + []flux.ColMeta{ + {Label: "1a", Type: flux.TFloat}, }, []values.Value{values.NewFloatValue(1.0)}, ), diff --git a/functions/schema_mutators.go b/functions/schema_mutators.go index 3503b9a43f..2065264e87 100644 --- a/functions/schema_mutators.go +++ b/functions/schema_mutators.go @@ -3,21 +3,21 @@ package functions import ( "fmt" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/compiler" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/semantic" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux" + "github.com/influxdata/flux/compiler" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/semantic" + "github.com/influxdata/flux/values" "github.com/pkg/errors" ) type BuilderContext struct { - TableColumns []query.ColMeta - TableKey query.GroupKey + TableColumns []flux.ColMeta + TableKey flux.GroupKey ColIdxMap []int } -func NewBuilderContext(tbl query.Table) *BuilderContext { +func NewBuilderContext(tbl flux.Table) *BuilderContext { colMap := make([]int, len(tbl.Cols())) for i := range tbl.Cols() { colMap[i] = i @@ -30,11 +30,11 @@ func NewBuilderContext(tbl query.Table) *BuilderContext { } } -func (b *BuilderContext) Cols() []query.ColMeta { +func (b *BuilderContext) Cols() []flux.ColMeta { return b.TableColumns } -func (b *BuilderContext) Key() query.GroupKey { +func (b *BuilderContext) Key() flux.GroupKey { return b.TableKey } @@ -55,7 +55,7 @@ type SchemaMutation interface { // to the function expression, it takes two types to verify the result against: // a single argument type, and a single return type. func compileFnParam(fn *semantic.FunctionExpression, paramType, returnType semantic.Type) (compiler.Func, string, error) { - scope, decls := query.BuiltIns() + scope, decls := flux.BuiltIns() compileCache := compiler.NewCompilationCache(fn, scope, decls) if len(fn.Params) != 1 { return nil, "", fmt.Errorf("function should only have a single parameter, got %d", len(fn.Params)) @@ -88,7 +88,7 @@ func toStringSet(arr []string) map[string]bool { return set } -func checkCol(label string, cols []query.ColMeta) error { +func checkCol(label string, cols []flux.ColMeta) error { if execute.ColIdx(label, cols) < 0 { return fmt.Errorf(`column "%s" doesn't exist`, label) } @@ -102,7 +102,7 @@ type RenameMutator struct { ParamName string } -func NewRenameMutator(qs query.OperationSpec) (*RenameMutator, error) { +func NewRenameMutator(qs flux.OperationSpec) (*RenameMutator, error) { s, ok := qs.(*RenameOpSpec) m := &RenameMutator{} @@ -127,7 +127,7 @@ func NewRenameMutator(qs query.OperationSpec) (*RenameMutator, error) { return m, nil } -func (m *RenameMutator) renameCol(col *query.ColMeta) error { +func (m *RenameMutator) renameCol(col *flux.ColMeta) error { if col == nil { return errors.New("rename error: cannot rename nil column") } @@ -146,7 +146,7 @@ func (m *RenameMutator) renameCol(col *query.ColMeta) error { return nil } -func (m *RenameMutator) checkColumns(tableCols []query.ColMeta) error { +func (m *RenameMutator) checkColumns(tableCols []flux.ColMeta) error { for c := range m.Cols { if err := checkCol(c, tableCols); err != nil { return errors.Wrap(err, "rename error") @@ -160,7 +160,7 @@ func (m *RenameMutator) Mutate(ctx *BuilderContext) error { return err } - keyCols := make([]query.ColMeta, 0, len(ctx.Cols())) + keyCols := make([]flux.ColMeta, 0, len(ctx.Cols())) keyValues := make([]values.Value, 0, len(ctx.Cols())) for i := range ctx.Cols() { @@ -191,7 +191,7 @@ type DropKeepMutator struct { Scope map[string]values.Value } -func NewDropKeepMutator(qs query.OperationSpec) (*DropKeepMutator, error) { +func NewDropKeepMutator(qs flux.OperationSpec) (*DropKeepMutator, error) { m := &DropKeepMutator{} switch s := qs.(type) { @@ -230,7 +230,7 @@ func NewDropKeepMutator(qs query.OperationSpec) (*DropKeepMutator, error) { return m, nil } -func (m *DropKeepMutator) checkColumns(tableCols []query.ColMeta) error { +func (m *DropKeepMutator) checkColumns(tableCols []flux.ColMeta) error { if m.DropCols != nil { for c := range m.DropCols { if err := checkCol(c, tableCols); err != nil { @@ -272,7 +272,7 @@ func (m *DropKeepMutator) shouldDropCol(col string) (bool, error) { return false, nil } -func (m *DropKeepMutator) keepToDropCols(cols []query.ColMeta) { +func (m *DropKeepMutator) keepToDropCols(cols []flux.ColMeta) { // If we have columns we want to keep, we can accomplish this by inverting the Cols map, // and storing it in Cols. // With a keep operation, Cols may be changed with each call to `Mutate`, but @@ -295,9 +295,9 @@ func (m *DropKeepMutator) Mutate(ctx *BuilderContext) error { m.keepToDropCols(ctx.Cols()) - keyCols := make([]query.ColMeta, 0, len(ctx.Cols())) + keyCols := make([]flux.ColMeta, 0, len(ctx.Cols())) keyValues := make([]values.Value, 0, len(ctx.Cols())) - newCols := make([]query.ColMeta, 0, len(ctx.Cols())) + newCols := make([]flux.ColMeta, 0, len(ctx.Cols())) oldColMap := ctx.ColMap() newColMap := make([]int, 0, len(ctx.Cols())) @@ -330,7 +330,7 @@ type DuplicateMutator struct { As string } -func NewDuplicateMutator(qs query.OperationSpec) (*DuplicateMutator, error) { +func NewDuplicateMutator(qs flux.OperationSpec) (*DuplicateMutator, error) { s, ok := qs.(*DuplicateOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -347,7 +347,7 @@ func (m *DuplicateMutator) Mutate(ctx *BuilderContext) error { return errors.Wrap(err, "duplicate error") } - newCols := make([]query.ColMeta, 0, len(ctx.Cols())+1) + newCols := make([]flux.ColMeta, 0, len(ctx.Cols())+1) newColMap := make([]int, 0, len(ctx.Cols())+1) oldColMap := ctx.ColMap() @@ -367,8 +367,8 @@ func (m *DuplicateMutator) Mutate(ctx *BuilderContext) error { return nil } -func duplicate(col query.ColMeta, dupName string) query.ColMeta { - return query.ColMeta{ +func duplicate(col flux.ColMeta, dupName string) flux.ColMeta { + return flux.ColMeta{ Type: col.Type, Label: dupName, } diff --git a/functions/set.go b/functions/set.go index ab6e3ca035..370196be29 100644 --- a/functions/set.go +++ b/functions/set.go @@ -3,11 +3,11 @@ package functions import ( "fmt" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" + "github.com/influxdata/flux/values" ) const SetKind = "set" @@ -17,19 +17,19 @@ type SetOpSpec struct { Value string `json:"value"` } -var setSignature = query.DefaultFunctionSignature() +var setSignature = flux.DefaultFunctionSignature() func init() { setSignature.Params["key"] = semantic.String setSignature.Params["value"] = semantic.String - query.RegisterFunction(SetKind, createSetOpSpec, setSignature) - query.RegisterOpSpec(SetKind, newSetOp) + flux.RegisterFunction(SetKind, createSetOpSpec, setSignature) + flux.RegisterOpSpec(SetKind, newSetOp) plan.RegisterProcedureSpec(SetKind, newSetProcedure, SetKind) execute.RegisterTransformation(SetKind, createSetTransformation) } -func createSetOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createSetOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -50,11 +50,11 @@ func createSetOpSpec(args query.Arguments, a *query.Administration) (query.Opera return spec, nil } -func newSetOp() query.OperationSpec { +func newSetOp() flux.OperationSpec { return new(SetOpSpec) } -func (s *SetOpSpec) Kind() query.OperationKind { +func (s *SetOpSpec) Kind() flux.OperationKind { return SetKind } @@ -62,7 +62,7 @@ type SetProcedureSpec struct { Key, Value string } -func newSetProcedure(qs query.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { +func newSetProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { s, ok := qs.(*SetOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -115,16 +115,16 @@ func NewSetTransformation( } } -func (t *setTransformation) RetractTable(id execute.DatasetID, key query.GroupKey) error { +func (t *setTransformation) RetractTable(id execute.DatasetID, key flux.GroupKey) error { // TODO return nil } -func (t *setTransformation) Process(id execute.DatasetID, tbl query.Table) error { +func (t *setTransformation) Process(id execute.DatasetID, tbl flux.Table) error { key := tbl.Key() if idx := execute.ColIdx(t.key, key.Cols()); idx >= 0 { // Update key - cols := make([]query.ColMeta, len(key.Cols())) + cols := make([]flux.ColMeta, len(key.Cols())) vs := make([]values.Value, len(key.Cols())) for j, c := range key.Cols() { cols[j] = c @@ -140,14 +140,14 @@ func (t *setTransformation) Process(id execute.DatasetID, tbl query.Table) error if created { execute.AddTableCols(tbl, builder) if !execute.HasCol(t.key, builder.Cols()) { - builder.AddCol(query.ColMeta{ + builder.AddCol(flux.ColMeta{ Label: t.key, - Type: query.TString, + Type: flux.TString, }) } } idx := execute.ColIdx(t.key, builder.Cols()) - return tbl.Do(func(cr query.ColReader) error { + return tbl.Do(func(cr flux.ColReader) error { for j := range cr.Cols() { if j == idx { continue diff --git a/functions/set_test.go b/functions/set_test.go index 2aeca948d7..e5849f9e75 100644 --- a/functions/set_test.go +++ b/functions/set_test.go @@ -3,16 +3,16 @@ package functions_test import ( "testing" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" ) func TestSetOperation_Marshaling(t *testing.T) { data := []byte(`{"id":"set","kind":"set","spec":{"key":"t1","value":"v1"}}`) - op := &query.Operation{ + op := &flux.Operation{ ID: "set", Spec: &functions.SetOpSpec{ Key: "t1", @@ -20,14 +20,14 @@ func TestSetOperation_Marshaling(t *testing.T) { }, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestSet_Process(t *testing.T) { testCases := []struct { name string spec *functions.SetProcedureSpec - data []query.Table + data []flux.Table want []*executetest.Table }{ { @@ -36,10 +36,10 @@ func TestSet_Process(t *testing.T) { Key: "t1", Value: "bob", }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 2.0}, @@ -47,10 +47,10 @@ func TestSet_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 2.0, "bob"}, @@ -64,11 +64,11 @@ func TestSet_Process(t *testing.T) { Key: "t1", Value: "bob", }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "jim"}, @@ -76,10 +76,10 @@ func TestSet_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "bob"}, @@ -93,13 +93,13 @@ func TestSet_Process(t *testing.T) { Key: "t1", Value: "bob", }, - data: []query.Table{&executetest.Table{ + data: []flux.Table{&executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "alice", "a"}, @@ -108,11 +108,11 @@ func TestSet_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "bob", "a"}, @@ -126,13 +126,13 @@ func TestSet_Process(t *testing.T) { Key: "t1", Value: "bob", }, - data: []query.Table{ + data: []flux.Table{ &executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "alice"}, @@ -141,10 +141,10 @@ func TestSet_Process(t *testing.T) { }, &executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(3), 3.0, "sue"}, @@ -154,10 +154,10 @@ func TestSet_Process(t *testing.T) { }, want: []*executetest.Table{{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "bob"}, @@ -173,13 +173,13 @@ func TestSet_Process(t *testing.T) { Key: "t2", Value: "bob", }, - data: []query.Table{ + data: []flux.Table{ &executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "alice"}, @@ -188,10 +188,10 @@ func TestSet_Process(t *testing.T) { }, &executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(3), 3.0, "sue"}, @@ -202,11 +202,11 @@ func TestSet_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "alice", "bob"}, @@ -215,11 +215,11 @@ func TestSet_Process(t *testing.T) { }, { KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "t1", Type: query.TString}, - {Label: "t2", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "t1", Type: flux.TString}, + {Label: "t2", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(3), 3.0, "sue", "bob"}, diff --git a/functions/shift.go b/functions/shift.go index 163c6cc467..8d254aa50c 100644 --- a/functions/shift.go +++ b/functions/shift.go @@ -3,34 +3,34 @@ package functions import ( "fmt" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/interpreter" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/interpreter" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" + "github.com/influxdata/flux/values" ) const ShiftKind = "shift" type ShiftOpSpec struct { - Shift query.Duration `json:"shift"` - Columns []string `json:"columns"` + Shift flux.Duration `json:"shift"` + Columns []string `json:"columns"` } -var shiftSignature = query.DefaultFunctionSignature() +var shiftSignature = flux.DefaultFunctionSignature() func init() { shiftSignature.Params["shift"] = semantic.Duration shiftSignature.Params["columns"] = semantic.NewArrayType(semantic.String) - query.RegisterFunction(ShiftKind, createShiftOpSpec, shiftSignature) - query.RegisterOpSpec(ShiftKind, newShiftOp) + flux.RegisterFunction(ShiftKind, createShiftOpSpec, shiftSignature) + flux.RegisterOpSpec(ShiftKind, newShiftOp) plan.RegisterProcedureSpec(ShiftKind, newShiftProcedure, ShiftKind) execute.RegisterTransformation(ShiftKind, createShiftTransformation) } -func createShiftOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createShiftOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -61,20 +61,20 @@ func createShiftOpSpec(args query.Arguments, a *query.Administration) (query.Ope return spec, nil } -func newShiftOp() query.OperationSpec { +func newShiftOp() flux.OperationSpec { return new(ShiftOpSpec) } -func (s *ShiftOpSpec) Kind() query.OperationKind { +func (s *ShiftOpSpec) Kind() flux.OperationKind { return ShiftKind } type ShiftProcedureSpec struct { - Shift query.Duration + Shift flux.Duration Columns []string } -func newShiftProcedure(qs query.OperationSpec, _ plan.Administration) (plan.ProcedureSpec, error) { +func newShiftProcedure(qs flux.OperationSpec, _ plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*ShiftOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -128,18 +128,18 @@ func NewShiftTransformation(d execute.Dataset, cache execute.TableBuilderCache, } } -func (t *shiftTransformation) RetractTable(id execute.DatasetID, key query.GroupKey) error { +func (t *shiftTransformation) RetractTable(id execute.DatasetID, key flux.GroupKey) error { return t.d.RetractTable(key) } -func (t *shiftTransformation) Process(id execute.DatasetID, tbl query.Table) error { +func (t *shiftTransformation) Process(id execute.DatasetID, tbl flux.Table) error { key := tbl.Key() // Update key - cols := make([]query.ColMeta, len(key.Cols())) + cols := make([]flux.ColMeta, len(key.Cols())) vs := make([]values.Value, len(key.Cols())) for j, c := range key.Cols() { if execute.ContainsStr(t.columns, c.Label) { - if c.Type != query.TTime { + if c.Type != flux.TTime { return fmt.Errorf("column %q is not of type time", c.Label) } cols[j] = c @@ -157,7 +157,7 @@ func (t *shiftTransformation) Process(id execute.DatasetID, tbl query.Table) err } execute.AddTableCols(tbl, builder) - return tbl.Do(func(cr query.ColReader) error { + return tbl.Do(func(cr flux.ColReader) error { for j, c := range cr.Cols() { if execute.ContainsStr(t.columns, c.Label) { l := cr.Len() diff --git a/functions/shift_test.go b/functions/shift_test.go index 95f092ca29..20b8b7210d 100644 --- a/functions/shift_test.go +++ b/functions/shift_test.go @@ -4,44 +4,44 @@ import ( "testing" "time" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" ) func TestShiftOperation_Marshaling(t *testing.T) { data := []byte(`{"id":"shift","kind":"shift","spec":{"shift":"1h"}}`) - op := &query.Operation{ + op := &flux.Operation{ ID: "shift", Spec: &functions.ShiftOpSpec{ - Shift: query.Duration(1 * time.Hour), + Shift: flux.Duration(1 * time.Hour), }, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestShift_Process(t *testing.T) { - cols := []query.ColMeta{ - {Label: "t1", Type: query.TString}, - {Label: execute.DefaultTimeColLabel, Type: query.TTime}, - {Label: execute.DefaultValueColLabel, Type: query.TFloat}, + cols := []flux.ColMeta{ + {Label: "t1", Type: flux.TString}, + {Label: execute.DefaultTimeColLabel, Type: flux.TTime}, + {Label: execute.DefaultValueColLabel, Type: flux.TFloat}, } testCases := []struct { name string spec *functions.ShiftProcedureSpec - data []query.Table + data []flux.Table want []*executetest.Table }{ { name: "one table", spec: &functions.ShiftProcedureSpec{ Columns: []string{execute.DefaultTimeColLabel}, - Shift: query.Duration(1), + Shift: flux.Duration(1), }, - data: []query.Table{ + data: []flux.Table{ &executetest.Table{ KeyCols: []string{"t1"}, ColMeta: cols, @@ -66,9 +66,9 @@ func TestShift_Process(t *testing.T) { name: "multiple tables", spec: &functions.ShiftProcedureSpec{ Columns: []string{execute.DefaultTimeColLabel}, - Shift: query.Duration(2), + Shift: flux.Duration(2), }, - data: []query.Table{ + data: []flux.Table{ &executetest.Table{ KeyCols: []string{"t1"}, ColMeta: cols, diff --git a/functions/skew.go b/functions/skew.go index d8584cee6f..7b710f4009 100644 --- a/functions/skew.go +++ b/functions/skew.go @@ -4,9 +4,9 @@ import ( "fmt" "math" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/plan" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/plan" ) const SkewKind = "skew" @@ -18,12 +18,12 @@ type SkewOpSpec struct { var skewSignature = execute.DefaultAggregateSignature() func init() { - query.RegisterFunction(SkewKind, createSkewOpSpec, skewSignature) - query.RegisterOpSpec(SkewKind, newSkewOp) + flux.RegisterFunction(SkewKind, createSkewOpSpec, skewSignature) + flux.RegisterOpSpec(SkewKind, newSkewOp) plan.RegisterProcedureSpec(SkewKind, newSkewProcedure, SkewKind) execute.RegisterTransformation(SkewKind, createSkewTransformation) } -func createSkewOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createSkewOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -36,11 +36,11 @@ func createSkewOpSpec(args query.Arguments, a *query.Administration) (query.Oper return s, nil } -func newSkewOp() query.OperationSpec { +func newSkewOp() flux.OperationSpec { return new(SkewOpSpec) } -func (s *SkewOpSpec) Kind() query.OperationKind { +func (s *SkewOpSpec) Kind() flux.OperationKind { return SkewKind } @@ -48,7 +48,7 @@ type SkewProcedureSpec struct { execute.AggregateConfig } -func newSkewProcedure(qs query.OperationSpec, a plan.Administration) (plan.ProcedureSpec, error) { +func newSkewProcedure(qs flux.OperationSpec, a plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*SkewOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -147,8 +147,8 @@ func (a *SkewAgg) DoFloat(vs []float64) { a.m1 += deltaN } } -func (a *SkewAgg) Type() query.DataType { - return query.TFloat +func (a *SkewAgg) Type() flux.DataType { + return flux.TFloat } func (a *SkewAgg) ValueFloat() float64 { if a.n < 2 { diff --git a/functions/skew_test.go b/functions/skew_test.go index 39b0e4b54f..883f299b47 100644 --- a/functions/skew_test.go +++ b/functions/skew_test.go @@ -4,20 +4,20 @@ import ( "math" "testing" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" ) func TestSkewOperation_Marshaling(t *testing.T) { data := []byte(`{"id":"skew","kind":"skew"}`) - op := &query.Operation{ + op := &flux.Operation{ ID: "skew", Spec: &functions.SkewOpSpec{}, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestSkew_Process(t *testing.T) { diff --git a/functions/sort.go b/functions/sort.go index cd07a27653..03c02b90aa 100644 --- a/functions/sort.go +++ b/functions/sort.go @@ -3,12 +3,12 @@ package functions import ( "fmt" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/interpreter" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/interpreter" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" + "github.com/influxdata/flux/values" ) const SortKind = "sort" @@ -18,19 +18,19 @@ type SortOpSpec struct { Desc bool `json:"desc"` } -var sortSignature = query.DefaultFunctionSignature() +var sortSignature = flux.DefaultFunctionSignature() func init() { sortSignature.Params["cols"] = semantic.NewArrayType(semantic.String) sortSignature.Params["desc"] = semantic.Bool - query.RegisterFunction(SortKind, createSortOpSpec, sortSignature) - query.RegisterOpSpec(SortKind, newSortOp) + flux.RegisterFunction(SortKind, createSortOpSpec, sortSignature) + flux.RegisterOpSpec(SortKind, newSortOp) plan.RegisterProcedureSpec(SortKind, newSortProcedure, SortKind) execute.RegisterTransformation(SortKind, createSortTransformation) } -func createSortOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createSortOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -58,11 +58,11 @@ func createSortOpSpec(args query.Arguments, a *query.Administration) (query.Oper return spec, nil } -func newSortOp() query.OperationSpec { +func newSortOp() flux.OperationSpec { return new(SortOpSpec) } -func (s *SortOpSpec) Kind() query.OperationKind { +func (s *SortOpSpec) Kind() flux.OperationKind { return SortKind } @@ -71,7 +71,7 @@ type SortProcedureSpec struct { Desc bool } -func newSortProcedure(qs query.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { +func newSortProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*SortOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -124,11 +124,11 @@ func NewSortTransformation(d execute.Dataset, cache execute.TableBuilderCache, s } } -func (t *sortTransformation) RetractTable(id execute.DatasetID, key query.GroupKey) error { +func (t *sortTransformation) RetractTable(id execute.DatasetID, key flux.GroupKey) error { return t.d.RetractTable(key) } -func (t *sortTransformation) Process(id execute.DatasetID, tbl query.Table) error { +func (t *sortTransformation) Process(id execute.DatasetID, tbl flux.Table) error { key := tbl.Key() for _, label := range t.cols { if key.HasCol(label) { @@ -158,8 +158,8 @@ func (t *sortTransformation) Finish(id execute.DatasetID, err error) { t.d.Finish(err) } -func (t *sortTransformation) sortedKey(key query.GroupKey) query.GroupKey { - cols := make([]query.ColMeta, len(key.Cols())) +func (t *sortTransformation) sortedKey(key flux.GroupKey) flux.GroupKey { + cols := make([]flux.ColMeta, len(key.Cols())) vs := make([]values.Value, len(key.Cols())) j := 0 for _, label := range t.cols { diff --git a/functions/sort_test.go b/functions/sort_test.go index 0e4d2f6724..b186797a9e 100644 --- a/functions/sort_test.go +++ b/functions/sort_test.go @@ -3,23 +3,23 @@ package functions_test import ( "testing" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" ) func TestSortOperation_Marshaling(t *testing.T) { data := []byte(`{"id":"sort","kind":"sort","spec":{"cols":["t1","t2"],"desc":true}}`) - op := &query.Operation{ + op := &flux.Operation{ ID: "sort", Spec: &functions.SortOpSpec{ Cols: []string{"t1", "t2"}, Desc: true, }, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestSort_PassThrough(t *testing.T) { @@ -40,7 +40,7 @@ func TestSort_Process(t *testing.T) { testCases := []struct { name string spec *functions.SortProcedureSpec - data []query.Table + data []flux.Table want []*executetest.Table }{ { @@ -49,10 +49,10 @@ func TestSort_Process(t *testing.T) { Cols: []string{"_value"}, Desc: false, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 2.0}, @@ -60,9 +60,9 @@ func TestSort_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(2), 1.0}, @@ -76,10 +76,10 @@ func TestSort_Process(t *testing.T) { Cols: []string{"_value"}, Desc: true, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 1.0}, @@ -87,9 +87,9 @@ func TestSort_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(2), 2.0}, @@ -103,10 +103,10 @@ func TestSort_Process(t *testing.T) { Cols: []string{"_value", "time"}, Desc: false, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(2), 2.0}, @@ -115,9 +115,9 @@ func TestSort_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 1.0}, @@ -132,10 +132,10 @@ func TestSort_Process(t *testing.T) { Cols: []string{"_value", "time"}, Desc: true, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 1.0}, @@ -144,9 +144,9 @@ func TestSort_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(2), 2.0}, @@ -161,13 +161,13 @@ func TestSort_Process(t *testing.T) { Cols: []string{"_time", "_stop"}, Desc: true, }, - data: []query.Table{&executetest.Table{ + data: []flux.Table{&executetest.Table{ KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), execute.Time(1), 1.0}, @@ -177,11 +177,11 @@ func TestSort_Process(t *testing.T) { }}, want: []*executetest.Table{{ KeyCols: []string{"_stop", "_start"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), execute.Time(3), execute.Time(3), 2.0}, @@ -196,13 +196,13 @@ func TestSort_Process(t *testing.T) { Cols: []string{"_value"}, Desc: false, }, - data: []query.Table{ + data: []flux.Table{ &executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "t1", Type: query.TString}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "t1", Type: flux.TString}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {"a", execute.Time(1), 3.0}, @@ -212,10 +212,10 @@ func TestSort_Process(t *testing.T) { }, &executetest.Table{ KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "t1", Type: query.TString}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "t1", Type: flux.TString}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {"b", execute.Time(3), 3.0}, @@ -227,10 +227,10 @@ func TestSort_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "t1", Type: query.TString}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "t1", Type: flux.TString}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {"a", execute.Time(2), 1.0}, @@ -240,10 +240,10 @@ func TestSort_Process(t *testing.T) { }, { KeyCols: []string{"t1"}, - ColMeta: []query.ColMeta{ - {Label: "t1", Type: query.TString}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "t1", Type: flux.TString}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {"b", execute.Time(4), 1.0}, @@ -259,14 +259,14 @@ func TestSort_Process(t *testing.T) { Cols: []string{"_field", "_value"}, Desc: false, }, - data: []query.Table{ + data: []flux.Table{ &executetest.Table{ KeyCols: []string{"host"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "host", Type: query.TString}, - {Label: "_field", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "host", Type: flux.TString}, + {Label: "_field", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "hostA", "F1"}, @@ -279,11 +279,11 @@ func TestSort_Process(t *testing.T) { }, &executetest.Table{ KeyCols: []string{"host"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "host", Type: query.TString}, - {Label: "_field", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "host", Type: flux.TString}, + {Label: "_field", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "hostB", "F1"}, @@ -298,11 +298,11 @@ func TestSort_Process(t *testing.T) { want: []*executetest.Table{ { KeyCols: []string{"host"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "host", Type: query.TString}, - {Label: "_field", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "host", Type: flux.TString}, + {Label: "_field", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "hostA", "F1"}, @@ -315,11 +315,11 @@ func TestSort_Process(t *testing.T) { }, { KeyCols: []string{"host"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "host", Type: query.TString}, - {Label: "_field", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "host", Type: flux.TString}, + {Label: "_field", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(1), 1.0, "hostB", "F1"}, diff --git a/functions/spread.go b/functions/spread.go index c1e774ecc7..5585489588 100644 --- a/functions/spread.go +++ b/functions/spread.go @@ -3,9 +3,9 @@ package functions import ( "fmt" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/plan" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/plan" ) // SpreadKind is the registration name for Flux, query, plan, and execution. @@ -14,13 +14,13 @@ const SpreadKind = "spread" var spreadSignature = execute.DefaultAggregateSignature() func init() { - query.RegisterFunction(SpreadKind, createSpreadOpSpec, spreadSignature) - query.RegisterOpSpec(SpreadKind, newSpreadOp) + flux.RegisterFunction(SpreadKind, createSpreadOpSpec, spreadSignature) + flux.RegisterOpSpec(SpreadKind, newSpreadOp) plan.RegisterProcedureSpec(SpreadKind, newSpreadProcedure, SpreadKind) execute.RegisterTransformation(SpreadKind, createSpreadTransformation) } -func createSpreadOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createSpreadOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -32,7 +32,7 @@ func createSpreadOpSpec(args query.Arguments, a *query.Administration) (query.Op return s, nil } -func newSpreadOp() query.OperationSpec { +func newSpreadOp() flux.OperationSpec { return new(SpreadOpSpec) } @@ -43,11 +43,11 @@ type SpreadOpSpec struct { } // Kind is used to lookup createSpreadOpSpec producing SpreadOpSpec -func (s *SpreadOpSpec) Kind() query.OperationKind { +func (s *SpreadOpSpec) Kind() flux.OperationKind { return SpreadKind } -func newSpreadProcedure(qs query.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { +func newSpreadProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*SpreadOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -138,8 +138,8 @@ func (a *SpreadIntAgg) DoInt(vs []int64) { } } -func (a *SpreadIntAgg) Type() query.DataType { - return query.TInt +func (a *SpreadIntAgg) Type() flux.DataType { + return flux.TInt } // Value returns the difference between max and min @@ -161,8 +161,8 @@ func (a *SpreadUIntAgg) DoUInt(vs []uint64) { } } -func (a *SpreadUIntAgg) Type() query.DataType { - return query.TUInt +func (a *SpreadUIntAgg) Type() flux.DataType { + return flux.TUInt } // Value returns the difference between max and min @@ -184,8 +184,8 @@ func (a *SpreadFloatAgg) DoFloat(vs []float64) { } } -func (a *SpreadFloatAgg) Type() query.DataType { - return query.TFloat +func (a *SpreadFloatAgg) Type() flux.DataType { + return flux.TFloat } // Value returns the difference between max and min diff --git a/functions/spread_test.go b/functions/spread_test.go index 41fc951063..51f49812c8 100644 --- a/functions/spread_test.go +++ b/functions/spread_test.go @@ -3,20 +3,20 @@ package functions_test import ( "testing" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" ) func TestSpreadOperation_Marshaling(t *testing.T) { data := []byte(`{"id":"spread","kind":"spread"}`) - op := &query.Operation{ + op := &flux.Operation{ ID: "spread", Spec: &functions.SpreadOpSpec{}, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestSpread_Process(t *testing.T) { diff --git a/functions/state_tracking.go b/functions/state_tracking.go index d1b4349f7a..3437e2e8c2 100644 --- a/functions/state_tracking.go +++ b/functions/state_tracking.go @@ -5,11 +5,11 @@ import ( "log" "time" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/interpreter" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/interpreter" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" "github.com/pkg/errors" ) @@ -19,11 +19,11 @@ type StateTrackingOpSpec struct { Fn *semantic.FunctionExpression `json:"fn"` CountLabel string `json:"countLabel"` DurationLabel string `json:"durationLabel"` - DurationUnit query.Duration `json:"durationUnit"` + DurationUnit flux.Duration `json:"durationUnit"` TimeCol string `json:"timeCol"` } -var stateTrackingSignature = query.DefaultFunctionSignature() +var stateTrackingSignature = flux.DefaultFunctionSignature() func init() { stateTrackingSignature.Params["fn"] = semantic.Function @@ -32,9 +32,9 @@ func init() { stateTrackingSignature.Params["durationUnit"] = semantic.Duration stateTrackingSignature.Params["timeCol"] = semantic.String - query.RegisterFunction(StateTrackingKind, createStateTrackingOpSpec, stateTrackingSignature) - query.RegisterBuiltIn("state-tracking", stateTrackingBuiltin) - query.RegisterOpSpec(StateTrackingKind, newStateTrackingOp) + flux.RegisterFunction(StateTrackingKind, createStateTrackingOpSpec, stateTrackingSignature) + flux.RegisterBuiltIn("state-tracking", stateTrackingBuiltin) + flux.RegisterOpSpec(StateTrackingKind, newStateTrackingOp) plan.RegisterProcedureSpec(StateTrackingKind, newStateTrackingProcedure, StateTrackingKind) execute.RegisterTransformation(StateTrackingKind, createStateTrackingTransformation) } @@ -71,7 +71,7 @@ stateDuration = (fn, label="stateDuration", unit=1s, table=<-) => stateTracking(table:table, durationLabel:label, fn:fn, durationUnit:unit) ` -func createStateTrackingOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createStateTrackingOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -88,7 +88,7 @@ func createStateTrackingOpSpec(args query.Arguments, a *query.Administration) (q spec := &StateTrackingOpSpec{ Fn: fn, - DurationUnit: query.Duration(time.Second), + DurationUnit: flux.Duration(time.Second), } if label, ok, err := args.GetString("countLabel"); err != nil { @@ -120,11 +120,11 @@ func createStateTrackingOpSpec(args query.Arguments, a *query.Administration) (q return spec, nil } -func newStateTrackingOp() query.OperationSpec { +func newStateTrackingOp() flux.OperationSpec { return new(StateTrackingOpSpec) } -func (s *StateTrackingOpSpec) Kind() query.OperationKind { +func (s *StateTrackingOpSpec) Kind() flux.OperationKind { return StateTrackingKind } @@ -132,11 +132,11 @@ type StateTrackingProcedureSpec struct { Fn *semantic.FunctionExpression CountLabel, DurationLabel string - DurationUnit query.Duration + DurationUnit flux.Duration TimeCol string } -func newStateTrackingProcedure(qs query.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { +func newStateTrackingProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*StateTrackingOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -206,11 +206,11 @@ func NewStateTrackingTransformation(d execute.Dataset, cache execute.TableBuilde }, nil } -func (t *stateTrackingTransformation) RetractTable(id execute.DatasetID, key query.GroupKey) error { +func (t *stateTrackingTransformation) RetractTable(id execute.DatasetID, key flux.GroupKey) error { return t.d.RetractTable(key) } -func (t *stateTrackingTransformation) Process(id execute.DatasetID, tbl query.Table) error { +func (t *stateTrackingTransformation) Process(id execute.DatasetID, tbl flux.Table) error { builder, created := t.cache.TableBuilder(tbl.Key()) if !created { return fmt.Errorf("found duplicate table with key: %v", tbl.Key()) @@ -229,15 +229,15 @@ func (t *stateTrackingTransformation) Process(id execute.DatasetID, tbl query.Ta // Add new value columns if t.countLabel != "" { - countCol = builder.AddCol(query.ColMeta{ + countCol = builder.AddCol(flux.ColMeta{ Label: t.countLabel, - Type: query.TInt, + Type: flux.TInt, }) } if t.durationLabel != "" { - durationCol = builder.AddCol(query.ColMeta{ + durationCol = builder.AddCol(flux.ColMeta{ Label: t.durationLabel, - Type: query.TInt, + Type: flux.TInt, }) } @@ -253,7 +253,7 @@ func (t *stateTrackingTransformation) Process(id execute.DatasetID, tbl query.Ta return fmt.Errorf("no column %q exists", t.timeCol) } // Append modified rows - return tbl.Do(func(cr query.ColReader) error { + return tbl.Do(func(cr flux.ColReader) error { l := cr.Len() for i := 0; i < l; i++ { tm := cr.Times(timeIdx)[i] diff --git a/functions/state_tracking_test.go b/functions/state_tracking_test.go index d2cbd21ce5..af185a390a 100644 --- a/functions/state_tracking_test.go +++ b/functions/state_tracking_test.go @@ -4,26 +4,26 @@ import ( "testing" "time" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/querytest" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux" + "github.com/influxdata/flux/ast" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" + "github.com/influxdata/flux/semantic" ) func TestStateTrackingOperation_Marshaling(t *testing.T) { data := []byte(`{"id":"id","kind":"stateTracking","spec":{"countLabel":"c","durationLabel":"d","durationUnit":"1m"}}`) - op := &query.Operation{ + op := &flux.Operation{ ID: "id", Spec: &functions.StateTrackingOpSpec{ CountLabel: "c", DurationLabel: "d", - DurationUnit: query.Duration(time.Minute), + DurationUnit: flux.Duration(time.Minute), }, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestStateTracking_Process(t *testing.T) { @@ -41,7 +41,7 @@ func TestStateTracking_Process(t *testing.T) { testCases := []struct { name string spec *functions.StateTrackingProcedureSpec - data []query.Table + data []flux.Table want []*executetest.Table }{ { @@ -53,10 +53,10 @@ func TestStateTracking_Process(t *testing.T) { Fn: gt5, TimeCol: "_time", }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 2.0}, @@ -68,11 +68,11 @@ func TestStateTracking_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "count", Type: query.TInt}, - {Label: "duration", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "count", Type: flux.TInt}, + {Label: "duration", Type: flux.TInt}, }, Data: [][]interface{}{ {execute.Time(1), 2.0, int64(-1), int64(-1)}, @@ -92,10 +92,10 @@ func TestStateTracking_Process(t *testing.T) { Fn: gt5, TimeCol: "_time", }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 2.0}, @@ -107,10 +107,10 @@ func TestStateTracking_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "duration", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "duration", Type: flux.TInt}, }, Data: [][]interface{}{ {execute.Time(1), 2.0, int64(-1)}, @@ -129,10 +129,10 @@ func TestStateTracking_Process(t *testing.T) { Fn: gt5, TimeCol: "_time", }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 2.0}, @@ -144,10 +144,10 @@ func TestStateTracking_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "count", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "count", Type: flux.TInt}, }, Data: [][]interface{}{ {execute.Time(1), 2.0, int64(-1)}, diff --git a/functions/stddev.go b/functions/stddev.go index 24eff6f872..0d0d373bd2 100644 --- a/functions/stddev.go +++ b/functions/stddev.go @@ -4,9 +4,9 @@ import ( "fmt" "math" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/plan" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/plan" ) const StddevKind = "stddev" @@ -18,12 +18,12 @@ type StddevOpSpec struct { var stddevSignature = execute.DefaultAggregateSignature() func init() { - query.RegisterFunction(StddevKind, createStddevOpSpec, stddevSignature) - query.RegisterOpSpec(StddevKind, newStddevOp) + flux.RegisterFunction(StddevKind, createStddevOpSpec, stddevSignature) + flux.RegisterOpSpec(StddevKind, newStddevOp) plan.RegisterProcedureSpec(StddevKind, newStddevProcedure, StddevKind) execute.RegisterTransformation(StddevKind, createStddevTransformation) } -func createStddevOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createStddevOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -34,11 +34,11 @@ func createStddevOpSpec(args query.Arguments, a *query.Administration) (query.Op return s, nil } -func newStddevOp() query.OperationSpec { +func newStddevOp() flux.OperationSpec { return new(StddevOpSpec) } -func (s *StddevOpSpec) Kind() query.OperationKind { +func (s *StddevOpSpec) Kind() flux.OperationKind { return StddevKind } @@ -46,7 +46,7 @@ type StddevProcedureSpec struct { execute.AggregateConfig } -func newStddevProcedure(qs query.OperationSpec, a plan.Administration) (plan.ProcedureSpec, error) { +func newStddevProcedure(qs flux.OperationSpec, a plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*StddevOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -129,8 +129,8 @@ func (a *StddevAgg) DoFloat(vs []float64) { a.m2 += delta * delta2 } } -func (a *StddevAgg) Type() query.DataType { - return query.TFloat +func (a *StddevAgg) Type() flux.DataType { + return flux.TFloat } func (a *StddevAgg) ValueFloat() float64 { if a.n < 2 { diff --git a/functions/stddev_test.go b/functions/stddev_test.go index df15b4e1dc..ba8aaa7ecd 100644 --- a/functions/stddev_test.go +++ b/functions/stddev_test.go @@ -4,20 +4,20 @@ import ( "math" "testing" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" ) func TestStddevOperation_Marshaling(t *testing.T) { data := []byte(`{"id":"stddev","kind":"stddev"}`) - op := &query.Operation{ + op := &flux.Operation{ ID: "stddev", Spec: &functions.StddevOpSpec{}, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestStddev_Process(t *testing.T) { diff --git a/functions/storage/pb/predicate.go b/functions/storage/pb/predicate.go deleted file mode 100644 index f98af0fe19..0000000000 --- a/functions/storage/pb/predicate.go +++ /dev/null @@ -1,160 +0,0 @@ -package pb - -import ( - "fmt" - - ostorage "github.com/influxdata/influxdb/services/storage" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/semantic" - "github.com/pkg/errors" -) - -func ToStoragePredicate(f *semantic.FunctionExpression) (*ostorage.Predicate, error) { - if len(f.Params) != 1 { - return nil, errors.New("storage predicate functions must have exactly one parameter") - } - - root, err := toStoragePredicate(f.Body.(semantic.Expression), f.Params[0].Key.Name) - if err != nil { - return nil, err - } - - return &ostorage.Predicate{ - Root: root, - }, nil -} - -func toStoragePredicate(n semantic.Expression, objectName string) (*ostorage.Node, error) { - switch n := n.(type) { - case *semantic.LogicalExpression: - left, err := toStoragePredicate(n.Left, objectName) - if err != nil { - return nil, errors.Wrap(err, "left hand side") - } - right, err := toStoragePredicate(n.Right, objectName) - if err != nil { - return nil, errors.Wrap(err, "right hand side") - } - children := []*ostorage.Node{left, right} - switch n.Operator { - case ast.AndOperator: - return &ostorage.Node{ - NodeType: ostorage.NodeTypeLogicalExpression, - Value: &ostorage.Node_Logical_{Logical: ostorage.LogicalAnd}, - Children: children, - }, nil - case ast.OrOperator: - return &ostorage.Node{ - NodeType: ostorage.NodeTypeLogicalExpression, - Value: &ostorage.Node_Logical_{Logical: ostorage.LogicalOr}, - Children: children, - }, nil - default: - return nil, fmt.Errorf("unknown logical operator %v", n.Operator) - } - case *semantic.BinaryExpression: - left, err := toStoragePredicate(n.Left, objectName) - if err != nil { - return nil, errors.Wrap(err, "left hand side") - } - right, err := toStoragePredicate(n.Right, objectName) - if err != nil { - return nil, errors.Wrap(err, "right hand side") - } - children := []*ostorage.Node{left, right} - op, err := toComparisonOperator(n.Operator) - if err != nil { - return nil, err - } - return &ostorage.Node{ - NodeType: ostorage.NodeTypeComparisonExpression, - Value: &ostorage.Node_Comparison_{Comparison: op}, - Children: children, - }, nil - case *semantic.StringLiteral: - return &ostorage.Node{ - NodeType: ostorage.NodeTypeLiteral, - Value: &ostorage.Node_StringValue{ - StringValue: n.Value, - }, - }, nil - case *semantic.IntegerLiteral: - return &ostorage.Node{ - NodeType: ostorage.NodeTypeLiteral, - Value: &ostorage.Node_IntegerValue{ - IntegerValue: n.Value, - }, - }, nil - case *semantic.BooleanLiteral: - return &ostorage.Node{ - NodeType: ostorage.NodeTypeLiteral, - Value: &ostorage.Node_BooleanValue{ - BooleanValue: n.Value, - }, - }, nil - case *semantic.FloatLiteral: - return &ostorage.Node{ - NodeType: ostorage.NodeTypeLiteral, - Value: &ostorage.Node_FloatValue{ - FloatValue: n.Value, - }, - }, nil - case *semantic.RegexpLiteral: - return &ostorage.Node{ - NodeType: ostorage.NodeTypeLiteral, - Value: &ostorage.Node_RegexValue{ - RegexValue: n.Value.String(), - }, - }, nil - case *semantic.MemberExpression: - // Sanity check that the object is the objectName identifier - if ident, ok := n.Object.(*semantic.IdentifierExpression); !ok || ident.Name != objectName { - return nil, fmt.Errorf("unknown object %q", n.Object) - } - if n.Property == "_value" { - return &ostorage.Node{ - NodeType: ostorage.NodeTypeFieldRef, - Value: &ostorage.Node_FieldRefValue{ - FieldRefValue: "_value", - }, - }, nil - } - return &ostorage.Node{ - NodeType: ostorage.NodeTypeTagRef, - Value: &ostorage.Node_TagRefValue{ - TagRefValue: n.Property, - }, - }, nil - case *semantic.DurationLiteral: - return nil, errors.New("duration literals not supported in storage predicates") - case *semantic.DateTimeLiteral: - return nil, errors.New("time literals not supported in storage predicates") - default: - return nil, fmt.Errorf("unsupported semantic expression type %T", n) - } -} - -func toComparisonOperator(o ast.OperatorKind) (ostorage.Node_Comparison, error) { - switch o { - case ast.EqualOperator: - return ostorage.ComparisonEqual, nil - case ast.NotEqualOperator: - return ostorage.ComparisonNotEqual, nil - case ast.RegexpMatchOperator: - return ostorage.ComparisonRegex, nil - case ast.NotRegexpMatchOperator: - return ostorage.ComparisonNotRegex, nil - case ast.StartsWithOperator: - return ostorage.ComparisonStartsWith, nil - case ast.LessThanOperator: - return ostorage.ComparisonLess, nil - case ast.LessThanEqualOperator: - return ostorage.ComparisonLessEqual, nil - case ast.GreaterThanOperator: - return ostorage.ComparisonGreater, nil - case ast.GreaterThanEqualOperator: - return ostorage.ComparisonGreaterEqual, nil - default: - return 0, fmt.Errorf("unknown operator %v", o) - } -} diff --git a/functions/storage/pb/reader.go b/functions/storage/pb/reader.go deleted file mode 100644 index 99c9d83537..0000000000 --- a/functions/storage/pb/reader.go +++ /dev/null @@ -1,968 +0,0 @@ -package pb - -import ( - "context" - "fmt" - "io" - "sort" - "strings" - - "github.com/gogo/protobuf/types" - "github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc" - ostorage "github.com/influxdata/influxdb/services/storage" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/functions/storage" - "github.com/influxdata/platform/query/values" - opentracing "github.com/opentracing/opentracing-go" - "github.com/pkg/errors" - "google.golang.org/grpc" -) - -func NewReader(hl storage.HostLookup) (*reader, error) { - tracer := opentracing.GlobalTracer() - - // TODO(nathanielc): Watch for host changes - hosts := hl.Hosts() - conns := make([]connection, len(hosts)) - for i, h := range hosts { - conn, err := grpc.Dial( - h, - grpc.WithInsecure(), - grpc.WithUnaryInterceptor(otgrpc.OpenTracingClientInterceptor(tracer)), - grpc.WithStreamInterceptor(otgrpc.OpenTracingStreamClientInterceptor(tracer)), - ) - if err != nil { - return nil, err - } - conns[i] = connection{ - host: h, - conn: conn, - client: ostorage.NewStorageClient(conn), - } - } - return &reader{ - conns: conns, - }, nil -} - -type reader struct { - conns []connection -} - -type connection struct { - host string - conn *grpc.ClientConn - client ostorage.StorageClient -} - -func (sr *reader) Read(ctx context.Context, readSpec storage.ReadSpec, start, stop execute.Time) (query.TableIterator, error) { - var predicate *ostorage.Predicate - if readSpec.Predicate != nil { - p, err := ToStoragePredicate(readSpec.Predicate) - if err != nil { - return nil, err - } - predicate = p - } - - bi := &tableIterator{ - ctx: ctx, - bounds: execute.Bounds{ - Start: start, - Stop: stop, - }, - conns: sr.conns, - readSpec: readSpec, - predicate: predicate, - } - return bi, nil -} - -func (sr *reader) Close() { - for _, conn := range sr.conns { - _ = conn.conn.Close() - } -} - -type tableIterator struct { - ctx context.Context - bounds execute.Bounds - conns []connection - readSpec storage.ReadSpec - predicate *ostorage.Predicate -} - -func (bi *tableIterator) Do(f func(query.Table) error) error { - src := ostorage.ReadSource{Database: string(bi.readSpec.BucketID)} - if i := strings.IndexByte(src.Database, '/'); i > -1 { - src.RetentionPolicy = src.Database[i+1:] - src.Database = src.Database[:i] - } - - // Setup read request - var req ostorage.ReadRequest - if any, err := types.MarshalAny(&src); err != nil { - return err - } else { - req.ReadSource = any - } - req.Predicate = bi.predicate - req.Descending = bi.readSpec.Descending - req.TimestampRange.Start = int64(bi.bounds.Start) - req.TimestampRange.End = int64(bi.bounds.Stop) - req.Group = convertGroupMode(bi.readSpec.GroupMode) - req.GroupKeys = bi.readSpec.GroupKeys - req.SeriesLimit = bi.readSpec.SeriesLimit - req.PointsLimit = bi.readSpec.PointsLimit - req.SeriesOffset = bi.readSpec.SeriesOffset - - if req.PointsLimit == -1 { - req.Hints.SetNoPoints() - } - - if agg, err := determineAggregateMethod(bi.readSpec.AggregateMethod); err != nil { - return err - } else if agg != ostorage.AggregateTypeNone { - req.Aggregate = &ostorage.Aggregate{Type: agg} - } - isGrouping := req.Group != ostorage.GroupAll - streams := make([]*streamState, 0, len(bi.conns)) - for _, c := range bi.conns { - if len(bi.readSpec.Hosts) > 0 { - // Filter down to only hosts provided - found := false - for _, h := range bi.readSpec.Hosts { - if c.host == h { - found = true - break - } - } - if !found { - continue - } - } - stream, err := c.client.Read(bi.ctx, &req) - if err != nil { - return err - } - streams = append(streams, &streamState{ - bounds: bi.bounds, - stream: stream, - readSpec: &bi.readSpec, - group: isGrouping, - }) - } - - ms := &mergedStreams{ - streams: streams, - } - - if isGrouping { - return bi.handleGroupRead(f, ms) - } - return bi.handleRead(f, ms) -} - -func (bi *tableIterator) handleRead(f func(query.Table) error, ms *mergedStreams) error { - for ms.more() { - if p := ms.peek(); readFrameType(p) != seriesType { - //This means the consumer didn't read all the data off the table - return errors.New("internal error: short read") - } - frame := ms.next() - s := frame.GetSeries() - typ := convertDataType(s.DataType) - key := groupKeyForSeries(s, &bi.readSpec, bi.bounds) - cols, defs := determineTableColsForSeries(s, typ) - table := newTable(bi.bounds, key, cols, ms, &bi.readSpec, s.Tags, defs) - - if err := f(table); err != nil { - // TODO(nathanielc): Close streams since we have abandoned the request - return err - } - // Wait until the table has been read. - table.wait() - } - return nil -} - -func (bi *tableIterator) handleGroupRead(f func(query.Table) error, ms *mergedStreams) error { - for ms.more() { - if p := ms.peek(); readFrameType(p) != groupType { - //This means the consumer didn't read all the data off the table - return errors.New("internal error: short read") - } - frame := ms.next() - s := frame.GetGroup() - key := groupKeyForGroup(s, &bi.readSpec, bi.bounds) - - // try to infer type - // TODO(sgc): this is a hack - typ := query.TString - if p := ms.peek(); readFrameType(p) == seriesType { - typ = convertDataType(p.GetSeries().DataType) - } - cols, defs := determineTableColsForGroup(s, typ) - - table := newTable(bi.bounds, key, cols, ms, &bi.readSpec, nil, defs) - - if err := f(table); err != nil { - // TODO(nathanielc): Close streams since we have abandoned the request - return err - } - // Wait until the table has been read. - table.wait() - } - return nil -} - -func determineAggregateMethod(agg string) (ostorage.Aggregate_AggregateType, error) { - if agg == "" { - return ostorage.AggregateTypeNone, nil - } - - if t, ok := ostorage.Aggregate_AggregateType_value[strings.ToUpper(agg)]; ok { - return ostorage.Aggregate_AggregateType(t), nil - } - return 0, fmt.Errorf("unknown aggregate type %q", agg) -} - -func convertGroupMode(m storage.GroupMode) ostorage.ReadRequest_Group { - switch m { - case storage.GroupModeNone: - return ostorage.GroupNone - case storage.GroupModeBy: - return ostorage.GroupBy - case storage.GroupModeExcept: - return ostorage.GroupExcept - - case storage.GroupModeDefault, storage.GroupModeAll: - fallthrough - default: - return ostorage.GroupAll - } -} - -func convertDataType(t ostorage.ReadResponse_DataType) query.DataType { - switch t { - case ostorage.DataTypeFloat: - return query.TFloat - case ostorage.DataTypeInteger: - return query.TInt - case ostorage.DataTypeUnsigned: - return query.TUInt - case ostorage.DataTypeBoolean: - return query.TBool - case ostorage.DataTypeString: - return query.TString - default: - return query.TInvalid - } -} - -const ( - startColIdx = 0 - stopColIdx = 1 - timeColIdx = 2 - valueColIdx = 3 -) - -func determineTableColsForSeries(s *ostorage.ReadResponse_SeriesFrame, typ query.DataType) ([]query.ColMeta, [][]byte) { - cols := make([]query.ColMeta, 4+len(s.Tags)) - defs := make([][]byte, 4+len(s.Tags)) - cols[startColIdx] = query.ColMeta{ - Label: execute.DefaultStartColLabel, - Type: query.TTime, - } - cols[stopColIdx] = query.ColMeta{ - Label: execute.DefaultStopColLabel, - Type: query.TTime, - } - cols[timeColIdx] = query.ColMeta{ - Label: execute.DefaultTimeColLabel, - Type: query.TTime, - } - cols[valueColIdx] = query.ColMeta{ - Label: execute.DefaultValueColLabel, - Type: typ, - } - for j, tag := range s.Tags { - cols[4+j] = query.ColMeta{ - Label: string(tag.Key), - Type: query.TString, - } - defs[4+j] = []byte("") - } - return cols, defs -} - -func groupKeyForSeries(s *ostorage.ReadResponse_SeriesFrame, readSpec *storage.ReadSpec, bnds execute.Bounds) query.GroupKey { - cols := make([]query.ColMeta, 2, len(s.Tags)) - vs := make([]values.Value, 2, len(s.Tags)) - cols[0] = query.ColMeta{ - Label: execute.DefaultStartColLabel, - Type: query.TTime, - } - vs[0] = values.NewTimeValue(bnds.Start) - cols[1] = query.ColMeta{ - Label: execute.DefaultStopColLabel, - Type: query.TTime, - } - vs[1] = values.NewTimeValue(bnds.Stop) - switch readSpec.GroupMode { - case storage.GroupModeBy: - // group key in GroupKeys order, including tags in the GroupKeys slice - for _, k := range readSpec.GroupKeys { - if i := indexOfTag(s.Tags, k); i < len(s.Tags) { - cols = append(cols, query.ColMeta{ - Label: string(s.Tags[i].Key), - Type: query.TString, - }) - vs = append(vs, values.NewStringValue(string(s.Tags[i].Value))) - } - } - case storage.GroupModeExcept: - // group key in GroupKeys order, skipping tags in the GroupKeys slice - for _, k := range readSpec.GroupKeys { - if i := indexOfTag(s.Tags, k); i == len(s.Tags) { - cols = append(cols, query.ColMeta{ - Label: string(s.Tags[i].Key), - Type: query.TString, - }) - vs = append(vs, values.NewStringValue(string(s.Tags[i].Value))) - } - } - case storage.GroupModeDefault, storage.GroupModeAll: - for i := range s.Tags { - cols = append(cols, query.ColMeta{ - Label: string(s.Tags[i].Key), - Type: query.TString, - }) - vs = append(vs, values.NewStringValue(string(s.Tags[i].Value))) - } - } - return execute.NewGroupKey(cols, vs) -} - -func determineTableColsForGroup(f *ostorage.ReadResponse_GroupFrame, typ query.DataType) ([]query.ColMeta, [][]byte) { - cols := make([]query.ColMeta, 4+len(f.TagKeys)) - defs := make([][]byte, 4+len(f.TagKeys)) - cols[startColIdx] = query.ColMeta{ - Label: execute.DefaultStartColLabel, - Type: query.TTime, - } - cols[stopColIdx] = query.ColMeta{ - Label: execute.DefaultStopColLabel, - Type: query.TTime, - } - cols[timeColIdx] = query.ColMeta{ - Label: execute.DefaultTimeColLabel, - Type: query.TTime, - } - cols[valueColIdx] = query.ColMeta{ - Label: execute.DefaultValueColLabel, - Type: typ, - } - for j, tag := range f.TagKeys { - cols[4+j] = query.ColMeta{ - Label: string(tag), - Type: query.TString, - } - defs[4+j] = []byte("") - - } - return cols, defs -} - -func groupKeyForGroup(g *ostorage.ReadResponse_GroupFrame, readSpec *storage.ReadSpec, bnds execute.Bounds) query.GroupKey { - cols := make([]query.ColMeta, 2, len(readSpec.GroupKeys)+2) - vs := make([]values.Value, 2, len(readSpec.GroupKeys)+2) - cols[0] = query.ColMeta{ - Label: execute.DefaultStartColLabel, - Type: query.TTime, - } - vs[0] = values.NewTimeValue(bnds.Start) - cols[1] = query.ColMeta{ - Label: execute.DefaultStopColLabel, - Type: query.TTime, - } - vs[1] = values.NewTimeValue(bnds.Stop) - for i := range readSpec.GroupKeys { - cols = append(cols, query.ColMeta{ - Label: readSpec.GroupKeys[i], - Type: query.TString, - }) - vs = append(vs, values.NewStringValue(string(g.PartitionKeyVals[i]))) - } - return execute.NewGroupKey(cols, vs) -} - -// table implement OneTimeTable as it can only be read once. -// Since it can only be read once it is also a ValueIterator for itself. -type table struct { - bounds execute.Bounds - key query.GroupKey - cols []query.ColMeta - - empty bool - more bool - - // cache of the tags on the current series. - // len(tags) == len(colMeta) - tags [][]byte - defs [][]byte - - readSpec *storage.ReadSpec - - done chan struct{} - - ms *mergedStreams - - // The current number of records in memory - l int - // colBufs are the buffers for the given columns. - colBufs []interface{} - - // resuable buffer for the time column - timeBuf []execute.Time - - // resuable buffers for the different types of values - boolBuf []bool - intBuf []int64 - uintBuf []uint64 - floatBuf []float64 - stringBuf []string - - err error -} - -func newTable( - bounds execute.Bounds, - key query.GroupKey, - cols []query.ColMeta, - ms *mergedStreams, - readSpec *storage.ReadSpec, - tags []ostorage.Tag, - defs [][]byte, -) *table { - b := &table{ - bounds: bounds, - key: key, - tags: make([][]byte, len(cols)), - defs: defs, - colBufs: make([]interface{}, len(cols)), - cols: cols, - readSpec: readSpec, - ms: ms, - done: make(chan struct{}), - empty: true, - } - b.readTags(tags) - // Call advance now so that we know if we are empty or not - b.more = b.advance() - return b -} - -func (t *table) RefCount(n int) { - //TODO(nathanielc): Have the table consume the Allocator, - // once we have zero-copy serialization over the network -} - -func (t *table) Err() error { return t.err } - -func (t *table) wait() { - <-t.done -} - -func (t *table) Key() query.GroupKey { - return t.key -} -func (t *table) Cols() []query.ColMeta { - return t.cols -} - -// onetime satisfies the OneTimeTable interface since this table may only be read once. -func (t *table) onetime() {} -func (t *table) Do(f func(query.ColReader) error) error { - defer close(t.done) - // If the initial advance call indicated we are done, return immediately - if !t.more { - return t.err - } - - f(t) - for t.advance() { - if err := f(t); err != nil { - return err - } - } - return t.err -} - -func (t *table) Len() int { - return t.l -} - -func (t *table) Bools(j int) []bool { - execute.CheckColType(t.cols[j], query.TBool) - return t.colBufs[j].([]bool) -} -func (t *table) Ints(j int) []int64 { - execute.CheckColType(t.cols[j], query.TInt) - return t.colBufs[j].([]int64) -} -func (t *table) UInts(j int) []uint64 { - execute.CheckColType(t.cols[j], query.TUInt) - return t.colBufs[j].([]uint64) -} -func (t *table) Floats(j int) []float64 { - execute.CheckColType(t.cols[j], query.TFloat) - return t.colBufs[j].([]float64) -} -func (t *table) Strings(j int) []string { - execute.CheckColType(t.cols[j], query.TString) - return t.colBufs[j].([]string) -} -func (t *table) Times(j int) []execute.Time { - execute.CheckColType(t.cols[j], query.TTime) - return t.colBufs[j].([]execute.Time) -} - -// readTags populates b.tags with the provided tags -func (t *table) readTags(tags []ostorage.Tag) { - for j := range t.tags { - t.tags[j] = t.defs[j] - } - - if len(tags) == 0 { - return - } - - for _, tag := range tags { - k := string(tag.Key) - j := execute.ColIdx(k, t.cols) - t.tags[j] = tag.Value - } -} - -func (t *table) advance() bool { - for t.ms.more() { - //reset buffers - t.timeBuf = t.timeBuf[0:0] - t.boolBuf = t.boolBuf[0:0] - t.intBuf = t.intBuf[0:0] - t.uintBuf = t.uintBuf[0:0] - t.stringBuf = t.stringBuf[0:0] - t.floatBuf = t.floatBuf[0:0] - - switch p := t.ms.peek(); readFrameType(p) { - case groupType: - return false - case seriesType: - if !t.ms.key().Equal(t.key) { - // We have reached the end of data for this table - return false - } - s := p.GetSeries() - t.readTags(s.Tags) - - // Advance to next frame - t.ms.next() - - if t.readSpec.PointsLimit == -1 { - // do not expect points frames - t.l = 0 - return true - } - case boolPointsType: - if t.cols[valueColIdx].Type != query.TBool { - t.err = fmt.Errorf("value type changed from %s -> %s", t.cols[valueColIdx].Type, query.TBool) - // TODO: Add error handling - // Type changed, - return false - } - t.empty = false - // read next frame - frame := t.ms.next() - p := frame.GetBooleanPoints() - l := len(p.Timestamps) - t.l = l - if l > cap(t.timeBuf) { - t.timeBuf = make([]execute.Time, l) - } else { - t.timeBuf = t.timeBuf[:l] - } - if l > cap(t.boolBuf) { - t.boolBuf = make([]bool, l) - } else { - t.boolBuf = t.boolBuf[:l] - } - - for i, c := range p.Timestamps { - t.timeBuf[i] = execute.Time(c) - t.boolBuf[i] = p.Values[i] - } - t.colBufs[timeColIdx] = t.timeBuf - t.colBufs[valueColIdx] = t.boolBuf - t.appendTags() - t.appendBounds() - return true - case intPointsType: - if t.cols[valueColIdx].Type != query.TInt { - t.err = fmt.Errorf("value type changed from %s -> %s", t.cols[valueColIdx].Type, query.TInt) - // TODO: Add error handling - // Type changed, - return false - } - t.empty = false - // read next frame - frame := t.ms.next() - p := frame.GetIntegerPoints() - l := len(p.Timestamps) - t.l = l - if l > cap(t.timeBuf) { - t.timeBuf = make([]execute.Time, l) - } else { - t.timeBuf = t.timeBuf[:l] - } - if l > cap(t.uintBuf) { - t.intBuf = make([]int64, l) - } else { - t.intBuf = t.intBuf[:l] - } - - for i, c := range p.Timestamps { - t.timeBuf[i] = execute.Time(c) - t.intBuf[i] = p.Values[i] - } - t.colBufs[timeColIdx] = t.timeBuf - t.colBufs[valueColIdx] = t.intBuf - t.appendTags() - t.appendBounds() - return true - case uintPointsType: - if t.cols[valueColIdx].Type != query.TUInt { - t.err = fmt.Errorf("value type changed from %s -> %s", t.cols[valueColIdx].Type, query.TUInt) - // TODO: Add error handling - // Type changed, - return false - } - t.empty = false - // read next frame - frame := t.ms.next() - p := frame.GetUnsignedPoints() - l := len(p.Timestamps) - t.l = l - if l > cap(t.timeBuf) { - t.timeBuf = make([]execute.Time, l) - } else { - t.timeBuf = t.timeBuf[:l] - } - if l > cap(t.intBuf) { - t.uintBuf = make([]uint64, l) - } else { - t.uintBuf = t.uintBuf[:l] - } - - for i, c := range p.Timestamps { - t.timeBuf[i] = execute.Time(c) - t.uintBuf[i] = p.Values[i] - } - t.colBufs[timeColIdx] = t.timeBuf - t.colBufs[valueColIdx] = t.uintBuf - t.appendTags() - t.appendBounds() - return true - case floatPointsType: - if t.cols[valueColIdx].Type != query.TFloat { - t.err = fmt.Errorf("value type changed from %s -> %s", t.cols[valueColIdx].Type, query.TFloat) - // TODO: Add error handling - // Type changed, - return false - } - t.empty = false - // read next frame - frame := t.ms.next() - p := frame.GetFloatPoints() - - l := len(p.Timestamps) - t.l = l - if l > cap(t.timeBuf) { - t.timeBuf = make([]execute.Time, l) - } else { - t.timeBuf = t.timeBuf[:l] - } - if l > cap(t.floatBuf) { - t.floatBuf = make([]float64, l) - } else { - t.floatBuf = t.floatBuf[:l] - } - - for i, c := range p.Timestamps { - t.timeBuf[i] = execute.Time(c) - t.floatBuf[i] = p.Values[i] - } - t.colBufs[timeColIdx] = t.timeBuf - t.colBufs[valueColIdx] = t.floatBuf - t.appendTags() - t.appendBounds() - return true - case stringPointsType: - if t.cols[valueColIdx].Type != query.TString { - t.err = fmt.Errorf("value type changed from %s -> %s", t.cols[valueColIdx].Type, query.TString) - // TODO: Add error handling - // Type changed, - return false - } - t.empty = false - // read next frame - frame := t.ms.next() - p := frame.GetStringPoints() - - l := len(p.Timestamps) - t.l = l - if l > cap(t.timeBuf) { - t.timeBuf = make([]execute.Time, l) - } else { - t.timeBuf = t.timeBuf[:l] - } - if l > cap(t.stringBuf) { - t.stringBuf = make([]string, l) - } else { - t.stringBuf = t.stringBuf[:l] - } - - for i, c := range p.Timestamps { - t.timeBuf[i] = execute.Time(c) - t.stringBuf[i] = p.Values[i] - } - t.colBufs[timeColIdx] = t.timeBuf - t.colBufs[valueColIdx] = t.stringBuf - t.appendTags() - t.appendBounds() - return true - } - } - return false -} - -// appendTags fills the colBufs for the tag columns with the tag value. -func (t *table) appendTags() { - for j := range t.cols { - v := t.tags[j] - if v != nil { - if t.colBufs[j] == nil { - t.colBufs[j] = make([]string, t.l) - } - colBuf := t.colBufs[j].([]string) - if cap(colBuf) < t.l { - colBuf = make([]string, t.l) - } else { - colBuf = colBuf[:t.l] - } - vStr := string(v) - for i := range colBuf { - colBuf[i] = vStr - } - t.colBufs[j] = colBuf - } - } -} - -// appendBounds fills the colBufs for the time bounds -func (t *table) appendBounds() { - bounds := []execute.Time{t.bounds.Start, t.bounds.Stop} - for j := range []int{startColIdx, stopColIdx} { - if t.colBufs[j] == nil { - t.colBufs[j] = make([]execute.Time, t.l) - } - colBuf := t.colBufs[j].([]execute.Time) - if cap(colBuf) < t.l { - colBuf = make([]execute.Time, t.l) - } else { - colBuf = colBuf[:t.l] - } - for i := range colBuf { - colBuf[i] = bounds[j] - } - t.colBufs[j] = colBuf - } -} - -func (t *table) Empty() bool { - return t.empty -} - -type streamState struct { - bounds execute.Bounds - stream ostorage.Storage_ReadClient - rep ostorage.ReadResponse - currentKey query.GroupKey - readSpec *storage.ReadSpec - finished bool - group bool -} - -func (s *streamState) peek() ostorage.ReadResponse_Frame { - return s.rep.Frames[0] -} - -func (s *streamState) more() bool { - if s.finished { - return false - } - if len(s.rep.Frames) > 0 { - return true - } - if err := s.stream.RecvMsg(&s.rep); err != nil { - s.finished = true - if err == io.EOF { - // We are done - return false - } - //TODO add proper error handling - return false - } - if len(s.rep.Frames) == 0 { - return false - } - s.computeKey() - return true -} - -func (s *streamState) key() query.GroupKey { - return s.currentKey -} - -func (s *streamState) computeKey() { - // Determine new currentKey - p := s.peek() - ft := readFrameType(p) - if s.group { - if ft == groupType { - group := p.GetGroup() - s.currentKey = groupKeyForGroup(group, s.readSpec, s.bounds) - } - } else { - if ft == seriesType { - series := p.GetSeries() - s.currentKey = groupKeyForSeries(series, s.readSpec, s.bounds) - } - } -} - -func (s *streamState) next() ostorage.ReadResponse_Frame { - frame := s.rep.Frames[0] - s.rep.Frames = s.rep.Frames[1:] - if len(s.rep.Frames) > 0 { - s.computeKey() - } - return frame -} - -type mergedStreams struct { - streams []*streamState - currentKey query.GroupKey - i int -} - -func (s *mergedStreams) key() query.GroupKey { - if len(s.streams) == 1 { - return s.streams[0].key() - } - return s.currentKey -} -func (s *mergedStreams) peek() ostorage.ReadResponse_Frame { - return s.streams[s.i].peek() -} - -func (s *mergedStreams) next() ostorage.ReadResponse_Frame { - return s.streams[s.i].next() -} - -func (s *mergedStreams) more() bool { - // Optimze for the case of just one stream - if len(s.streams) == 1 { - return s.streams[0].more() - } - if s.i < 0 { - return false - } - if s.currentKey == nil { - return s.determineNewKey() - } - if s.streams[s.i].more() { - if s.streams[s.i].key().Equal(s.currentKey) { - return true - } - return s.advance() - } - return s.advance() -} - -func (s *mergedStreams) advance() bool { - s.i++ - if s.i == len(s.streams) { - if !s.determineNewKey() { - // no new data on any stream - return false - } - } - return s.more() -} - -func (s *mergedStreams) determineNewKey() bool { - minIdx := -1 - var minKey query.GroupKey - for i, stream := range s.streams { - if !stream.more() { - continue - } - k := stream.key() - if minIdx == -1 || k.Less(minKey) { - minIdx = i - minKey = k - } - } - s.currentKey = minKey - s.i = minIdx - return s.i >= 0 -} - -type frameType int - -const ( - seriesType frameType = iota - groupType - boolPointsType - intPointsType - uintPointsType - floatPointsType - stringPointsType -) - -func readFrameType(frame ostorage.ReadResponse_Frame) frameType { - switch frame.Data.(type) { - case *ostorage.ReadResponse_Frame_Series: - return seriesType - case *ostorage.ReadResponse_Frame_Group: - return groupType - case *ostorage.ReadResponse_Frame_BooleanPoints: - return boolPointsType - case *ostorage.ReadResponse_Frame_IntegerPoints: - return intPointsType - case *ostorage.ReadResponse_Frame_UnsignedPoints: - return uintPointsType - case *ostorage.ReadResponse_Frame_FloatPoints: - return floatPointsType - case *ostorage.ReadResponse_Frame_StringPoints: - return stringPointsType - default: - panic(fmt.Errorf("unknown read response frame type: %T", frame.Data)) - } -} - -func indexOfTag(t []ostorage.Tag, k string) int { - return sort.Search(len(t), func(i int) bool { return string(t[i].Key) >= k }) -} diff --git a/functions/storage/storage.go b/functions/storage/storage.go index bc56208016..bbe7f92d6b 100644 --- a/functions/storage/storage.go +++ b/functions/storage/storage.go @@ -6,10 +6,10 @@ import ( "log" "math" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/semantic" "github.com/influxdata/platform" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/semantic" "github.com/pkg/errors" ) @@ -102,7 +102,7 @@ func (s *source) Run(ctx context.Context) { func (s *source) run(ctx context.Context) error { //TODO(nathanielc): Pass through context to actual network I/O. for tables, mark, ok := s.next(ctx); ok; tables, mark, ok = s.next(ctx) { - err := tables.Do(func(tbl query.Table) error { + err := tables.Do(func(tbl flux.Table) error { for _, t := range s.ts { if err := t.Process(s.id, tbl); err != nil { return err @@ -127,7 +127,7 @@ func (s *source) run(ctx context.Context) error { return nil } -func (s *source) next(ctx context.Context) (query.TableIterator, execute.Time, bool) { +func (s *source) next(ctx context.Context) (flux.TableIterator, execute.Time, bool) { if s.overflow { return nil, 0, false } @@ -204,6 +204,6 @@ type ReadSpec struct { } type Reader interface { - Read(ctx context.Context, rs ReadSpec, start, stop execute.Time) (query.TableIterator, error) + Read(ctx context.Context, rs ReadSpec, start, stop execute.Time) (flux.TableIterator, error) Close() } diff --git a/functions/sum.go b/functions/sum.go index 8146f31cf6..0ae48c8bcf 100644 --- a/functions/sum.go +++ b/functions/sum.go @@ -3,9 +3,9 @@ package functions import ( "fmt" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/plan" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/plan" ) const SumKind = "sum" @@ -17,13 +17,13 @@ type SumOpSpec struct { var sumSignature = execute.DefaultAggregateSignature() func init() { - query.RegisterFunction(SumKind, createSumOpSpec, sumSignature) - query.RegisterOpSpec(SumKind, newSumOp) + flux.RegisterFunction(SumKind, createSumOpSpec, sumSignature) + flux.RegisterOpSpec(SumKind, newSumOp) plan.RegisterProcedureSpec(SumKind, newSumProcedure, SumKind) execute.RegisterTransformation(SumKind, createSumTransformation) } -func createSumOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createSumOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -34,11 +34,11 @@ func createSumOpSpec(args query.Arguments, a *query.Administration) (query.Opera return s, nil } -func newSumOp() query.OperationSpec { +func newSumOp() flux.OperationSpec { return new(SumOpSpec) } -func (s *SumOpSpec) Kind() query.OperationKind { +func (s *SumOpSpec) Kind() flux.OperationKind { return SumKind } @@ -46,7 +46,7 @@ type SumProcedureSpec struct { execute.AggregateConfig } -func newSumProcedure(qs query.OperationSpec, a plan.Administration) (plan.ProcedureSpec, error) { +func newSumProcedure(qs flux.OperationSpec, a plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*SumOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -133,8 +133,8 @@ func (a *SumIntAgg) DoInt(vs []int64) { a.sum += v } } -func (a *SumIntAgg) Type() query.DataType { - return query.TInt +func (a *SumIntAgg) Type() flux.DataType { + return flux.TInt } func (a *SumIntAgg) ValueInt() int64 { return a.sum @@ -149,8 +149,8 @@ func (a *SumUIntAgg) DoUInt(vs []uint64) { a.sum += v } } -func (a *SumUIntAgg) Type() query.DataType { - return query.TUInt +func (a *SumUIntAgg) Type() flux.DataType { + return flux.TUInt } func (a *SumUIntAgg) ValueUInt() uint64 { return a.sum @@ -165,8 +165,8 @@ func (a *SumFloatAgg) DoFloat(vs []float64) { a.sum += v } } -func (a *SumFloatAgg) Type() query.DataType { - return query.TFloat +func (a *SumFloatAgg) Type() flux.DataType { + return flux.TFloat } func (a *SumFloatAgg) ValueFloat() float64 { return a.sum diff --git a/functions/sum_test.go b/functions/sum_test.go index 10bb46cd23..0e608d6887 100644 --- a/functions/sum_test.go +++ b/functions/sum_test.go @@ -3,22 +3,22 @@ package functions_test import ( "testing" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/plan/plantest" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/plan/plantest" ) func TestSumOperation_Marshaling(t *testing.T) { data := []byte(`{"id":"sum","kind":"sum"}`) - op := &query.Operation{ + op := &flux.Operation{ ID: "sum", Spec: &functions.SumOpSpec{}, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestSum_Process(t *testing.T) { diff --git a/functions/system_time.go b/functions/system_time.go index 3340efa03a..5d96f9a2e0 100644 --- a/functions/system_time.go +++ b/functions/system_time.go @@ -3,16 +3,16 @@ package functions import ( "time" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/semantic" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux" + "github.com/influxdata/flux/semantic" + "github.com/influxdata/flux/values" ) var systemTimeFuncName = "systemTime" func init() { nowFunc := SystemTime() - query.RegisterBuiltInValue(systemTimeFuncName, nowFunc) + flux.RegisterBuiltInValue(systemTimeFuncName, nowFunc) } // SystemTime return a function value that when called will give the current system time diff --git a/functions/testdata/derivative.influxql b/functions/testdata/derivative.influxql deleted file mode 100644 index 92a1320d76..0000000000 --- a/functions/testdata/derivative.influxql +++ /dev/null @@ -1 +0,0 @@ -select derivative("used_percent") FROM testdb..disk \ No newline at end of file diff --git a/functions/testdata/filter_by_regex.influxql b/functions/testdata/filter_by_regex.influxql deleted file mode 100644 index ae1ac4d55d..0000000000 --- a/functions/testdata/filter_by_regex.influxql +++ /dev/null @@ -1 +0,0 @@ -select io_time from testdb..diskio where "name" =~ /.*0/ \ No newline at end of file diff --git a/functions/testdata/filter_by_tags.influxql b/functions/testdata/filter_by_tags.influxql deleted file mode 100644 index 441655140a..0000000000 --- a/functions/testdata/filter_by_tags.influxql +++ /dev/null @@ -1 +0,0 @@ -select io_time from testdb..diskio where "name" = 'disk0' \ No newline at end of file diff --git a/functions/testdata/group.influxql b/functions/testdata/group.influxql deleted file mode 100644 index f211413896..0000000000 --- a/functions/testdata/group.influxql +++ /dev/null @@ -1 +0,0 @@ -SELECT max(io_time) FROM testdb..diskio GROUP BY "name" diff --git a/functions/testdata/mean.influxql b/functions/testdata/mean.influxql deleted file mode 100644 index 9f03c560e8..0000000000 --- a/functions/testdata/mean.influxql +++ /dev/null @@ -1 +0,0 @@ -select mean("used_percent") from telegraf..disk \ No newline at end of file diff --git a/functions/testdata/percentile.influxql b/functions/testdata/percentile.influxql deleted file mode 100644 index 360f8d84e2..0000000000 --- a/functions/testdata/percentile.influxql +++ /dev/null @@ -1 +0,0 @@ -select percentile("used_percent", 75) from telegraf..disk \ No newline at end of file diff --git a/functions/testdata/select_measurement.influxql b/functions/testdata/select_measurement.influxql deleted file mode 100644 index 56d779345f..0000000000 --- a/functions/testdata/select_measurement.influxql +++ /dev/null @@ -1 +0,0 @@ -select used_percent from testdb..swap \ No newline at end of file diff --git a/functions/testdata/select_measurement_field.influxql b/functions/testdata/select_measurement_field.influxql deleted file mode 100644 index 79affcca2f..0000000000 --- a/functions/testdata/select_measurement_field.influxql +++ /dev/null @@ -1 +0,0 @@ -select load1 from testdb..system \ No newline at end of file diff --git a/functions/testdata/simple_max.influxql b/functions/testdata/simple_max.influxql deleted file mode 100644 index 681c705756..0000000000 --- a/functions/testdata/simple_max.influxql +++ /dev/null @@ -1 +0,0 @@ -select max(f1) from test..m1 where time >= '2018-04-17T00:00:00Z' and time < now() diff --git a/functions/testdata/window.influxql b/functions/testdata/window.influxql deleted file mode 100644 index 5c2516fb88..0000000000 --- a/functions/testdata/window.influxql +++ /dev/null @@ -1 +0,0 @@ -select mean(io_time) from testdb..diskio where time >= '2018-05-22T19:53:26Z' and time < now() group by time(1s) diff --git a/functions/testdata/window_group_mean_ungroup.influxql b/functions/testdata/window_group_mean_ungroup.influxql deleted file mode 100644 index 8ad1f99299..0000000000 --- a/functions/testdata/window_group_mean_ungroup.influxql +++ /dev/null @@ -1 +0,0 @@ -select mean(io_time) from testdb..diskio group by time(1s) \ No newline at end of file diff --git a/functions/testdata/window_offset.influxql b/functions/testdata/window_offset.influxql deleted file mode 100644 index 54ab855a5c..0000000000 --- a/functions/testdata/window_offset.influxql +++ /dev/null @@ -1 +0,0 @@ -select mean(io_time) from testdb..diskio where time >= '2018-05-22T19:53:26Z' and time < now() group by time(1s, 2s) diff --git a/functions/to_http.go b/functions/to_http.go index 5889c6979a..0989ee509c 100644 --- a/functions/to_http.go +++ b/functions/to_http.go @@ -14,11 +14,11 @@ import ( "sync" "time" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" "github.com/influxdata/line-protocol" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" "github.com/pkg/errors" ) @@ -68,7 +68,7 @@ type ToHTTPOpSpec struct { ValueColumns []string `json:"valueColumns"` } -var ToHTTPSignature = query.DefaultFunctionSignature() +var ToHTTPSignature = flux.DefaultFunctionSignature() func init() { ToHTTPSignature.Params["url"] = semantic.String @@ -79,18 +79,18 @@ func init() { ToHTTPSignature.Params["tagColumns"] = semantic.NewArrayType(semantic.String) ToHTTPSignature.Params["valueColumns"] = semantic.NewArrayType(semantic.String) - query.RegisterFunctionWithSideEffect(ToHTTPKind, createToHTTPOpSpec, ToHTTPSignature) - query.RegisterOpSpec(ToHTTPKind, - func() query.OperationSpec { return &ToHTTPOpSpec{} }) + flux.RegisterFunctionWithSideEffect(ToHTTPKind, createToHTTPOpSpec, ToHTTPSignature) + flux.RegisterOpSpec(ToHTTPKind, + func() flux.OperationSpec { return &ToHTTPOpSpec{} }) plan.RegisterProcedureSpec(ToHTTPKind, newToHTTPProcedure, ToHTTPKind) execute.RegisterTransformation(ToHTTPKind, createToHTTPTransformation) } -// ReadArgs loads a query.Arguments into ToHTTPOpSpec. It sets several default values. +// ReadArgs loads a flux.Arguments into ToHTTPOpSpec. It sets several default values. // If the http method isn't set, it defaults to POST, it also uppercases the http method. // If the time_column isn't set, it defaults to execute.TimeColLabel. // If the value_column isn't set it defaults to a []string{execute.DefaultValueColLabel}. -func (o *ToHTTPOpSpec) ReadArgs(args query.Arguments) error { +func (o *ToHTTPOpSpec) ReadArgs(args flux.Arguments) error { var err error o.URL, err = args.GetRequiredString("url") if err != nil { @@ -176,7 +176,7 @@ func (o *ToHTTPOpSpec) ReadArgs(args query.Arguments) error { } -func createToHTTPOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createToHTTPOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -203,7 +203,7 @@ func (o *ToHTTPOpSpec) UnmarshalJSON(b []byte) (err error) { return nil } -func (ToHTTPOpSpec) Kind() query.OperationKind { +func (ToHTTPOpSpec) Kind() flux.OperationKind { return ToHTTPKind } @@ -241,7 +241,7 @@ func (o *ToHTTPProcedureSpec) Copy() plan.ProcedureSpec { return res } -func newToHTTPProcedure(qs query.OperationSpec, a plan.Administration) (plan.ProcedureSpec, error) { +func newToHTTPProcedure(qs flux.OperationSpec, a plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*ToHTTPOpSpec) if !ok && spec != nil { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -266,7 +266,7 @@ type ToHTTPTransformation struct { spec *ToHTTPProcedureSpec } -func (t *ToHTTPTransformation) RetractTable(id execute.DatasetID, key query.GroupKey) error { +func (t *ToHTTPTransformation) RetractTable(id execute.DatasetID, key flux.GroupKey) error { return t.d.RetractTable(key) } @@ -311,10 +311,10 @@ func (m *toHttpMetric) Time() time.Time { type idxType struct { Idx int - Type query.DataType + Type flux.DataType } -func (t *ToHTTPTransformation) Process(id execute.DatasetID, tbl query.Table) error { +func (t *ToHTTPTransformation) Process(id execute.DatasetID, tbl flux.Table) error { pr, pw := io.Pipe() // TODO: replce the pipe with something faster m := &toHttpMetric{} e := protocol.NewEncoder(pw) @@ -333,7 +333,7 @@ func (t *ToHTTPTransformation) Process(id execute.DatasetID, tbl query.Table) er if !ok { return errors.New("Could not get time column") } - if timeColIdx.Type != query.TTime { + if timeColIdx.Type != flux.TTime { return fmt.Errorf("column %s is not of type %s", timeColLabel, timeColIdx.Type) } var measurementNameCol string @@ -355,7 +355,7 @@ func (t *ToHTTPTransformation) Process(id execute.DatasetID, tbl query.Table) er wg.Add(1) go func() { m.name = t.spec.Spec.Name - tbl.Do(func(er query.ColReader) error { + tbl.Do(func(er flux.ColReader) error { l := er.Len() for i := 0; i < l; i++ { m.truncateTagsAndFields() @@ -364,29 +364,29 @@ func (t *ToHTTPTransformation) Process(id execute.DatasetID, tbl query.Table) er case col.Label == timeColLabel: m.t = er.Times(j)[i].Time() case measurementNameCol != "" && measurementNameCol == col.Label: - if col.Type != query.TString { + if col.Type != flux.TString { return errors.New("invalid type for measurement column") } m.name = er.Strings(j)[i] case isTag[j]: - if col.Type != query.TString { + if col.Type != flux.TString { return errors.New("invalid type for measurement column") } m.tags = append(m.tags, &protocol.Tag{Key: col.Label, Value: er.Strings(j)[i]}) case isValue[j]: switch col.Type { - case query.TFloat: + case flux.TFloat: m.fields = append(m.fields, &protocol.Field{Key: col.Label, Value: er.Floats(j)[i]}) - case query.TInt: + case flux.TInt: m.fields = append(m.fields, &protocol.Field{Key: col.Label, Value: er.Ints(j)[i]}) - case query.TUInt: + case flux.TUInt: m.fields = append(m.fields, &protocol.Field{Key: col.Label, Value: er.UInts(j)[i]}) - case query.TString: + case flux.TString: m.fields = append(m.fields, &protocol.Field{Key: col.Label, Value: er.Strings(j)[i]}) - case query.TTime: + case flux.TTime: m.fields = append(m.fields, &protocol.Field{Key: col.Label, Value: er.Times(j)[i]}) - case query.TBool: + case flux.TBool: m.fields = append(m.fields, &protocol.Field{Key: col.Label, Value: er.Bools(j)[i]}) default: return fmt.Errorf("invalid type for column %s", col.Label) diff --git a/functions/to_http_test.go b/functions/to_http_test.go index d769a8404f..31e889f893 100644 --- a/functions/to_http_test.go +++ b/functions/to_http_test.go @@ -8,20 +8,20 @@ import ( "testing" "time" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" ) func TestToHTTP_NewQuery(t *testing.T) { - tests := []querytest.NewQueryTestCase{ + tests := []fluxtest.NewQueryTestCase{ { Name: "from with database with range", Raw: `from(bucket:"mybucket") |> toHTTP(url: "https://localhost:8081", name:"series1", method:"POST", timeout: 50s)`, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "from0", Spec: &functions.FromOpSpec{ @@ -44,7 +44,7 @@ func TestToHTTP_NewQuery(t *testing.T) { }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "from0", Child: "toHTTP1"}, }, }, @@ -54,7 +54,7 @@ func TestToHTTP_NewQuery(t *testing.T) { tc := tc t.Run(tc.Name, func(t *testing.T) { t.Parallel() - querytest.NewQueryTestHelper(t, tc) + fluxtest.NewQueryTestHelper(t, tc) }) } } @@ -116,12 +116,12 @@ func TestToHTTPOpSpec_UnmarshalJSON(t *testing.T) { Timeout: tt.fields.Timeout, NoKeepAlive: tt.fields.NoKeepAlive, } - op := &query.Operation{ + op := &flux.Operation{ ID: "toHTTP", Spec: o, } if !tt.wantErr { - querytest.OperationMarshalingTestHelper(t, tt.bytes, op) + fluxtest.OperationMarshalingTestHelper(t, tt.bytes, op) } else if err := o.UnmarshalJSON(tt.bytes); err == nil { t.Errorf("ToHTTPOpSpec.UnmarshalJSON() error = %v, wantErr %v for test %s", err, tt.wantErr, tt.name) } @@ -148,7 +148,7 @@ func TestToHTTP_Process(t *testing.T) { testCases := []struct { name string spec *functions.ToHTTPProcedureSpec - data []query.Table + data []flux.Table want wanted }{ { @@ -163,12 +163,12 @@ func TestToHTTP_Process(t *testing.T) { NameColumn: "_measurement", }, }, - data: []query.Table{execute.CopyTable(&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_measurement", Type: query.TString}, - {Label: "_value", Type: query.TFloat}, - {Label: "fred", Type: query.TString}, + data: []flux.Table{execute.CopyTable(&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_measurement", Type: flux.TString}, + {Label: "_value", Type: flux.TFloat}, + {Label: "fred", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(11), "a", 2.0, "one"}, @@ -194,12 +194,12 @@ func TestToHTTP_Process(t *testing.T) { NameColumn: "_measurement", }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_measurement", Type: query.TString}, - {Label: "_value", Type: query.TFloat}, - {Label: "fred", Type: query.TString}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_measurement", Type: flux.TString}, + {Label: "_value", Type: flux.TFloat}, + {Label: "fred", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(11), "a", 2.0, "one"}, @@ -226,12 +226,12 @@ func TestToHTTP_Process(t *testing.T) { NameColumn: "_measurement", }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_measurement", Type: query.TString}, - {Label: "_value", Type: query.TFloat}, - {Label: "fred", Type: query.TString}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_measurement", Type: flux.TString}, + {Label: "_value", Type: flux.TFloat}, + {Label: "fred", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(11), "a", 2.0, "one"}, @@ -257,10 +257,10 @@ func TestToHTTP_Process(t *testing.T) { Name: "one_table", }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(11), 2.0}, @@ -286,11 +286,11 @@ func TestToHTTP_Process(t *testing.T) { Name: "one_table_w_unused_tag", }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "fred", Type: query.TString}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "fred", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(11), 2.0, "one"}, @@ -321,11 +321,11 @@ one_table_w_unused_tag _value=4 41 Name: "one_table_w_tag", }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "fred", Type: query.TString}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "fred", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(11), 2.0, "one"}, @@ -356,12 +356,12 @@ one_table_w_tag,fred=elevendyone _value=4 41 Name: "multi_table", }, }, - data: []query.Table{ + data: []flux.Table{ &executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "fred", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "fred", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(11), 2.0, "one"}, @@ -370,10 +370,10 @@ one_table_w_tag,fred=elevendyone _value=4 41 }, }, &executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "fred", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "fred", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(51), 2.0, "one"}, @@ -401,13 +401,13 @@ one_table_w_tag,fred=elevendyone _value=4 41 Name: "multi_collist_tables", }, }, - data: []query.Table{ + data: []flux.Table{ execute.CopyTable( &executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "fred", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "fred", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(11), 2.0, "one"}, @@ -416,10 +416,10 @@ one_table_w_tag,fred=elevendyone _value=4 41 }, }, executetest.UnlimitedAllocator), &executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "fred", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "fred", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(51), 2.0, "one"}, diff --git a/functions/to_kafka.go b/functions/to_kafka.go index bbd1d7087d..7a60920ef1 100644 --- a/functions/to_kafka.go +++ b/functions/to_kafka.go @@ -11,11 +11,11 @@ import ( "time" "github.com/cespare/xxhash" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" "github.com/influxdata/line-protocol" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" "github.com/pkg/errors" kafka "github.com/segmentio/kafka-go" ) @@ -37,7 +37,7 @@ type ToKafkaOpSpec struct { MsgBufSize int `json:"msgBufferSize"` // the maximim number of messages to buffer before sending to kafka, the library we use defaults to 100 } -var ToKafkaSignature = query.DefaultFunctionSignature() +var ToKafkaSignature = flux.DefaultFunctionSignature() func init() { ToKafkaSignature.Params["brokers"] = semantic.NewArrayType(semantic.String) @@ -48,9 +48,9 @@ func init() { ToKafkaSignature.Params["timeColumn"] = semantic.String ToKafkaSignature.Params["tagColumns"] = semantic.NewArrayType(semantic.String) ToKafkaSignature.Params["valueColumns"] = semantic.NewArrayType(semantic.String) - query.RegisterFunctionWithSideEffect(ToKafkaKind, createToKafkaOpSpec, ToKafkaSignature) - query.RegisterOpSpec(ToKafkaKind, - func() query.OperationSpec { return &ToKafkaOpSpec{} }) + flux.RegisterFunctionWithSideEffect(ToKafkaKind, createToKafkaOpSpec, ToKafkaSignature) + flux.RegisterOpSpec(ToKafkaKind, + func() flux.OperationSpec { return &ToKafkaOpSpec{} }) plan.RegisterProcedureSpec(ToKafkaKind, newToKafkaProcedure, ToKafkaKind) execute.RegisterTransformation(ToKafkaKind, createToKafkaTransformation) } @@ -66,10 +66,10 @@ type KafkaWriter interface { WriteMessages(context.Context, ...kafka.Message) error } -// ReadArgs loads a query.Arguments into ToKafkaOpSpec. It sets several default values. +// ReadArgs loads a flux.Arguments into ToKafkaOpSpec. It sets several default values. // If the time_column isn't set, it defaults to execute.TimeColLabel. // If the value_column isn't set it defaults to a []string{execute.DefaultValueColLabel}. -func (o *ToKafkaOpSpec) ReadArgs(args query.Arguments) error { +func (o *ToKafkaOpSpec) ReadArgs(args flux.Arguments) error { var err error var ok bool @@ -156,7 +156,7 @@ func (o *ToKafkaOpSpec) ReadArgs(args query.Arguments) error { return err } -func createToKafkaOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createToKafkaOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -167,7 +167,7 @@ func createToKafkaOpSpec(args query.Arguments, a *query.Administration) (query.O return s, nil } -func (ToKafkaOpSpec) Kind() query.OperationKind { +func (ToKafkaOpSpec) Kind() flux.OperationKind { return ToKafkaKind } @@ -205,7 +205,7 @@ func (o *ToKafkaProcedureSpec) Copy() plan.ProcedureSpec { } return res } -func newToKafkaProcedure(qs query.OperationSpec, a plan.Administration) (plan.ProcedureSpec, error) { +func newToKafkaProcedure(qs flux.OperationSpec, a plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*ToKafkaOpSpec) if !ok && spec != nil { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -229,7 +229,7 @@ type ToKafkaTransformation struct { spec *ToKafkaProcedureSpec } -func (t *ToKafkaTransformation) RetractTable(id execute.DatasetID, key query.GroupKey) error { +func (t *ToKafkaTransformation) RetractTable(id execute.DatasetID, key flux.GroupKey) error { return t.d.RetractTable(key) } func NewToKafkaTransformation(d execute.Dataset, cache execute.TableBuilderCache, spec *ToKafkaProcedureSpec) *ToKafkaTransformation { @@ -264,7 +264,7 @@ func (m *toKafkaMetric) Time() time.Time { return m.t } -func (t *ToKafkaTransformation) Process(id execute.DatasetID, tbl query.Table) (err error) { +func (t *ToKafkaTransformation) Process(id execute.DatasetID, tbl flux.Table) (err error) { w := DefaultKafkaWriterFactory(kafka.WriterConfig{ Brokers: t.spec.Spec.Brokers, Topic: t.spec.Spec.Topic, @@ -302,7 +302,7 @@ func (t *ToKafkaTransformation) Process(id execute.DatasetID, tbl query.Table) ( if !ok { return errors.New("Could not get time column") } - if timeColIdx.Type != query.TTime { + if timeColIdx.Type != flux.TTime { return fmt.Errorf("column %s is not of type %s", timeColLabel, timeColIdx.Type) } var measurementNameCol string @@ -321,7 +321,7 @@ func (t *ToKafkaTransformation) Process(id execute.DatasetID, tbl query.Table) ( wg := sync.WaitGroup{} wg.Add(1) go func() { - err = tbl.Do(func(er query.ColReader) error { + err = tbl.Do(func(er flux.ColReader) error { l := er.Len() for i := 0; i < l; i++ { m.truncateTagsAndFields() @@ -330,28 +330,28 @@ func (t *ToKafkaTransformation) Process(id execute.DatasetID, tbl query.Table) ( case col.Label == timeColLabel: m.t = er.Times(j)[i].Time() case measurementNameCol != "" && measurementNameCol == col.Label: - if col.Type != query.TString { + if col.Type != flux.TString { return errors.New("invalid type for measurement column") } m.name = er.Strings(j)[i] case isTag[j]: - if col.Type != query.TString { + if col.Type != flux.TString { return errors.New("invalid type for measurement column") } m.tags = append(m.tags, &protocol.Tag{Key: col.Label, Value: er.Strings(j)[i]}) case isValue[j]: switch col.Type { - case query.TFloat: + case flux.TFloat: m.fields = append(m.fields, &protocol.Field{Key: col.Label, Value: er.Floats(j)[i]}) - case query.TInt: + case flux.TInt: m.fields = append(m.fields, &protocol.Field{Key: col.Label, Value: er.Ints(j)[i]}) - case query.TUInt: + case flux.TUInt: m.fields = append(m.fields, &protocol.Field{Key: col.Label, Value: er.UInts(j)[i]}) - case query.TString: + case flux.TString: m.fields = append(m.fields, &protocol.Field{Key: col.Label, Value: er.Strings(j)[i]}) - case query.TTime: + case flux.TTime: m.fields = append(m.fields, &protocol.Field{Key: col.Label, Value: er.Times(j)[i]}) - case query.TBool: + case flux.TBool: m.fields = append(m.fields, &protocol.Field{Key: col.Label, Value: er.Bools(j)[i]}) default: return fmt.Errorf("invalid type for column %s", col.Label) diff --git a/functions/to_kafka_test.go b/functions/to_kafka_test.go index 34605166c3..fe0c190590 100644 --- a/functions/to_kafka_test.go +++ b/functions/to_kafka_test.go @@ -7,23 +7,23 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" kafka "github.com/segmentio/kafka-go" ) // type kafkaClientMock = func func TestToKafka_NewQuery(t *testing.T) { - tests := []querytest.NewQueryTestCase{ + tests := []fluxtest.NewQueryTestCase{ { Name: "from with database", Raw: `from(bucket:"mybucket") |> toKafka(brokers:["brokerurl:8989"], name:"series1", topic:"totallynotfaketopic")`, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "from0", Spec: &functions.FromOpSpec{ @@ -41,7 +41,7 @@ func TestToKafka_NewQuery(t *testing.T) { }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "from0", Child: "toKafka1"}, }, }, @@ -51,7 +51,7 @@ func TestToKafka_NewQuery(t *testing.T) { tc := tc t.Run(tc.Name, func(t *testing.T) { t.Parallel() - querytest.NewQueryTestHelper(t, tc) + fluxtest.NewQueryTestHelper(t, tc) }) } } @@ -90,7 +90,7 @@ func TestToKafka_Process(t *testing.T) { testCases := []struct { name string spec *functions.ToKafkaProcedureSpec - data []query.Table + data []flux.Table want wanted }{ { @@ -104,12 +104,12 @@ func TestToKafka_Process(t *testing.T) { NameColumn: "_measurement", }, }, - data: []query.Table{execute.CopyTable(&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_measurement", Type: query.TString}, - {Label: "_value", Type: query.TFloat}, - {Label: "fred", Type: query.TString}, + data: []flux.Table{execute.CopyTable(&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_measurement", Type: flux.TString}, + {Label: "_value", Type: flux.TFloat}, + {Label: "fred", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(11), "a", 2.0, "one"}, @@ -141,12 +141,12 @@ func TestToKafka_Process(t *testing.T) { NameColumn: "_measurement", }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_measurement", Type: query.TString}, - {Label: "_value", Type: query.TFloat}, - {Label: "fred", Type: query.TString}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_measurement", Type: flux.TString}, + {Label: "_value", Type: flux.TFloat}, + {Label: "fred", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(11), "a", 2.0, "one"}, @@ -179,12 +179,12 @@ func TestToKafka_Process(t *testing.T) { NameColumn: "_measurement", }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_measurement", Type: query.TString}, - {Label: "_value", Type: query.TFloat}, - {Label: "fred", Type: query.TString}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_measurement", Type: flux.TString}, + {Label: "_value", Type: flux.TFloat}, + {Label: "fred", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(11), "a", 2.0, "one"}, @@ -216,10 +216,10 @@ func TestToKafka_Process(t *testing.T) { Name: "one_block", }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(11), 2.0}, @@ -249,11 +249,11 @@ func TestToKafka_Process(t *testing.T) { Name: "one_block_w_unused_tag", }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "fred", Type: query.TString}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "fred", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(11), 2.0, "one"}, @@ -284,11 +284,11 @@ func TestToKafka_Process(t *testing.T) { Name: "one_block_w_tag", }, }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "fred", Type: query.TString}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "fred", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(11), 2.0, "one"}, @@ -319,12 +319,12 @@ func TestToKafka_Process(t *testing.T) { Name: "multi_block", }, }, - data: []query.Table{ + data: []flux.Table{ &executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "fred", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "fred", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(11), 2.0, "one"}, @@ -333,10 +333,10 @@ func TestToKafka_Process(t *testing.T) { }, }, &executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "fred", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "fred", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(51), 2.0, "one"}, @@ -370,13 +370,13 @@ func TestToKafka_Process(t *testing.T) { Name: "multi_collist_blocks", }, }, - data: []query.Table{ + data: []flux.Table{ execute.CopyTable( &executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "fred", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "fred", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(11), 2.0, "one"}, @@ -385,10 +385,10 @@ func TestToKafka_Process(t *testing.T) { }, }, executetest.UnlimitedAllocator), &executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, - {Label: "fred", Type: query.TString}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, + {Label: "fred", Type: flux.TString}, }, Data: [][]interface{}{ {execute.Time(51), 2.0, "one"}, diff --git a/functions/top_bottom.go b/functions/top_bottom.go index 2b67773675..345ab3ff88 100644 --- a/functions/top_bottom.go +++ b/functions/top_bottom.go @@ -1,11 +1,11 @@ package functions import ( - "github.com/influxdata/platform/query" + "github.com/influxdata/flux" ) func init() { - query.RegisterBuiltIn("top-bottom", topBottomBuiltIn) + flux.RegisterBuiltIn("top-bottom", topBottomBuiltIn) // TODO(nathanielc): Provide an implementation of top/bottom transformation that can use a more efficient sort based on the limit. // This transformation should be used when ever the planner sees a sort |> limit pair of procedures. } diff --git a/functions/typeconv.go b/functions/typeconv.go index 98ce514bbe..b3f19854ac 100644 --- a/functions/typeconv.go +++ b/functions/typeconv.go @@ -5,20 +5,20 @@ import ( "regexp" "strconv" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/semantic" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux" + "github.com/influxdata/flux/semantic" + "github.com/influxdata/flux/values" ) func init() { - query.RegisterBuiltInValue("string", &stringConv{}) - query.RegisterBuiltInValue("int", &intConv{}) - query.RegisterBuiltInValue("uint", &uintConv{}) - query.RegisterBuiltInValue("float", &floatConv{}) - query.RegisterBuiltInValue("bool", &boolConv{}) - query.RegisterBuiltInValue("time", &timeConv{}) - query.RegisterBuiltInValue("duration", &durationConv{}) - query.RegisterBuiltIn("typeconv", ` + flux.RegisterBuiltInValue("string", &stringConv{}) + flux.RegisterBuiltInValue("int", &intConv{}) + flux.RegisterBuiltInValue("uint", &uintConv{}) + flux.RegisterBuiltInValue("float", &floatConv{}) + flux.RegisterBuiltInValue("bool", &boolConv{}) + flux.RegisterBuiltInValue("time", &timeConv{}) + flux.RegisterBuiltInValue("duration", &durationConv{}) + flux.RegisterBuiltIn("typeconv", ` toString = (table=<-) => table |> map(fn:(r) => string(v:r._value)) toInt = (table=<-) => table |> map(fn:(r) => int(v:r._value)) toUInt = (table=<-) => table |> map(fn:(r) => uint(v:r._value)) diff --git a/functions/unique.go b/functions/unique.go index 73aca2adc3..4f4ba68d5a 100644 --- a/functions/unique.go +++ b/functions/unique.go @@ -3,10 +3,10 @@ package functions import ( "fmt" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" ) const UniqueKind = "unique" @@ -15,18 +15,18 @@ type UniqueOpSpec struct { Column string `json:"column"` } -var uniqueSignature = query.DefaultFunctionSignature() +var uniqueSignature = flux.DefaultFunctionSignature() func init() { uniqueSignature.Params["column"] = semantic.String - query.RegisterFunction(UniqueKind, createUniqueOpSpec, uniqueSignature) - query.RegisterOpSpec(UniqueKind, newUniqueOp) + flux.RegisterFunction(UniqueKind, createUniqueOpSpec, uniqueSignature) + flux.RegisterOpSpec(UniqueKind, newUniqueOp) plan.RegisterProcedureSpec(UniqueKind, newUniqueProcedure, UniqueKind) execute.RegisterTransformation(UniqueKind, createUniqueTransformation) } -func createUniqueOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createUniqueOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -44,11 +44,11 @@ func createUniqueOpSpec(args query.Arguments, a *query.Administration) (query.Op return spec, nil } -func newUniqueOp() query.OperationSpec { +func newUniqueOp() flux.OperationSpec { return new(UniqueOpSpec) } -func (s *UniqueOpSpec) Kind() query.OperationKind { +func (s *UniqueOpSpec) Kind() flux.OperationKind { return UniqueKind } @@ -56,7 +56,7 @@ type UniqueProcedureSpec struct { Column string } -func newUniqueProcedure(qs query.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { +func newUniqueProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { spec, ok := qs.(*UniqueOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -104,11 +104,11 @@ func NewUniqueTransformation(d execute.Dataset, cache execute.TableBuilderCache, } } -func (t *uniqueTransformation) RetractTable(id execute.DatasetID, key query.GroupKey) error { +func (t *uniqueTransformation) RetractTable(id execute.DatasetID, key flux.GroupKey) error { return t.d.RetractTable(key) } -func (t *uniqueTransformation) Process(id execute.DatasetID, tbl query.Table) error { +func (t *uniqueTransformation) Process(id execute.DatasetID, tbl flux.Table) error { builder, created := t.cache.TableBuilder(tbl.Key()) if !created { return fmt.Errorf("unique found duplicate table with key: %v", tbl.Key()) @@ -130,56 +130,56 @@ func (t *uniqueTransformation) Process(id execute.DatasetID, tbl query.Table) er timeUnique map[execute.Time]bool ) switch col.Type { - case query.TBool: + case flux.TBool: boolUnique = make(map[bool]bool) - case query.TInt: + case flux.TInt: intUnique = make(map[int64]bool) - case query.TUInt: + case flux.TUInt: uintUnique = make(map[uint64]bool) - case query.TFloat: + case flux.TFloat: floatUnique = make(map[float64]bool) - case query.TString: + case flux.TString: stringUnique = make(map[string]bool) - case query.TTime: + case flux.TTime: timeUnique = make(map[execute.Time]bool) } - return tbl.Do(func(cr query.ColReader) error { + return tbl.Do(func(cr flux.ColReader) error { l := cr.Len() for i := 0; i < l; i++ { // Check unique switch col.Type { - case query.TBool: + case flux.TBool: v := cr.Bools(colIdx)[i] if boolUnique[v] { continue } boolUnique[v] = true - case query.TInt: + case flux.TInt: v := cr.Ints(colIdx)[i] if intUnique[v] { continue } intUnique[v] = true - case query.TUInt: + case flux.TUInt: v := cr.UInts(colIdx)[i] if uintUnique[v] { continue } uintUnique[v] = true - case query.TFloat: + case flux.TFloat: v := cr.Floats(colIdx)[i] if floatUnique[v] { continue } floatUnique[v] = true - case query.TString: + case flux.TString: v := cr.Strings(colIdx)[i] if stringUnique[v] { continue } stringUnique[v] = true - case query.TTime: + case flux.TTime: v := cr.Times(colIdx)[i] if timeUnique[v] { continue diff --git a/functions/unique_test.go b/functions/unique_test.go index c82235d09d..b5ede303bc 100644 --- a/functions/unique_test.go +++ b/functions/unique_test.go @@ -3,22 +3,22 @@ package functions_test import ( "testing" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" ) func TestUniqueOperation_Marshaling(t *testing.T) { data := []byte(`{"id":"unique","kind":"unique","spec":{"column":"_value"}}`) - op := &query.Operation{ + op := &flux.Operation{ ID: "unique", Spec: &functions.UniqueOpSpec{ Column: "_value", }, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestUnique_PassThrough(t *testing.T) { @@ -38,7 +38,7 @@ func TestUnique_Process(t *testing.T) { testCases := []struct { name string spec *functions.UniqueProcedureSpec - data []query.Table + data []flux.Table want []*executetest.Table }{ { @@ -46,10 +46,10 @@ func TestUnique_Process(t *testing.T) { spec: &functions.UniqueProcedureSpec{ Column: "_value", }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 2.0}, @@ -59,9 +59,9 @@ func TestUnique_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), 2.0}, @@ -75,11 +75,11 @@ func TestUnique_Process(t *testing.T) { spec: &functions.UniqueProcedureSpec{ Column: "t1", }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "t1", Type: query.TString}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "t1", Type: flux.TString}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), "a", 2.0}, @@ -89,10 +89,10 @@ func TestUnique_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "t1", Type: query.TString}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "t1", Type: flux.TString}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), "a", 2.0}, @@ -106,11 +106,11 @@ func TestUnique_Process(t *testing.T) { spec: &functions.UniqueProcedureSpec{ Column: "_time", }, - data: []query.Table{&executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "t1", Type: query.TString}, - {Label: "_value", Type: query.TFloat}, + data: []flux.Table{&executetest.Table{ + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "t1", Type: flux.TString}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), "a", 2.0}, @@ -120,10 +120,10 @@ func TestUnique_Process(t *testing.T) { }, }}, want: []*executetest.Table{{ - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "t1", Type: query.TString}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_time", Type: flux.TTime}, + {Label: "t1", Type: flux.TString}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {execute.Time(1), "a", 2.0}, diff --git a/functions/window.go b/functions/window.go index ee94c6e750..57c7670ee8 100644 --- a/functions/window.go +++ b/functions/window.go @@ -4,31 +4,31 @@ import ( "fmt" "math" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" + "github.com/influxdata/flux/values" "github.com/pkg/errors" ) const WindowKind = "window" type WindowOpSpec struct { - Every query.Duration `json:"every"` - Period query.Duration `json:"period"` - Start query.Time `json:"start"` - Round query.Duration `json:"round"` - Triggering query.TriggerSpec `json:"triggering"` - TimeCol string `json:"time_col"` - StopColLabel string `json:"stop_col_label"` - StartColLabel string `json:"start_col_label"` - CreateEmpty bool `json:"createEmpty"` + Every flux.Duration `json:"every"` + Period flux.Duration `json:"period"` + Start flux.Time `json:"start"` + Round flux.Duration `json:"round"` + Triggering flux.TriggerSpec `json:"triggering"` + TimeCol string `json:"time_col"` + StopColLabel string `json:"stop_col_label"` + StartColLabel string `json:"start_col_label"` + CreateEmpty bool `json:"createEmpty"` } var infinityVar = values.NewDurationValue(math.MaxInt64) -var windowSignature = query.DefaultFunctionSignature() +var windowSignature = flux.DefaultFunctionSignature() func init() { windowSignature.Params["every"] = semantic.Duration @@ -40,14 +40,14 @@ func init() { windowSignature.Params["stopColLabel"] = semantic.String windowSignature.Params["createEmpty"] = semantic.Bool - query.RegisterFunction(WindowKind, createWindowOpSpec, windowSignature) - query.RegisterOpSpec(WindowKind, newWindowOp) - query.RegisterBuiltInValue("inf", infinityVar) + flux.RegisterFunction(WindowKind, createWindowOpSpec, windowSignature) + flux.RegisterOpSpec(WindowKind, newWindowOp) + flux.RegisterBuiltInValue("inf", infinityVar) plan.RegisterProcedureSpec(WindowKind, newWindowProcedure, WindowKind) execute.RegisterTransformation(WindowKind, createWindowTransformation) } -func createWindowOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createWindowOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -58,7 +58,7 @@ func createWindowOpSpec(args query.Arguments, a *query.Administration) (query.Op return nil, err } if everySet { - spec.Every = query.Duration(every) + spec.Every = flux.Duration(every) } period, periodSet, err := args.GetDuration("period") if err != nil { @@ -121,24 +121,24 @@ func createWindowOpSpec(args query.Arguments, a *query.Administration) (query.Op return spec, nil } -func newWindowOp() query.OperationSpec { +func newWindowOp() flux.OperationSpec { return new(WindowOpSpec) } -func (s *WindowOpSpec) Kind() query.OperationKind { +func (s *WindowOpSpec) Kind() flux.OperationKind { return WindowKind } type WindowProcedureSpec struct { Window plan.WindowSpec - Triggering query.TriggerSpec + Triggering flux.TriggerSpec TimeCol, StartColLabel, StopColLabel string CreateEmpty bool } -func newWindowProcedure(qs query.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { +func newWindowProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) { s, ok := qs.(*WindowOpSpec) if !ok { return nil, fmt.Errorf("invalid spec type %T", qs) @@ -157,7 +157,7 @@ func newWindowProcedure(qs query.OperationSpec, pa plan.Administration) (plan.Pr CreateEmpty: s.CreateEmpty, } if p.Triggering == nil { - p.Triggering = query.DefaultTrigger + p.Triggering = flux.DefaultTrigger } return p, nil } @@ -172,7 +172,7 @@ func (s *WindowProcedureSpec) Copy() plan.ProcedureSpec { return ns } -func (s *WindowProcedureSpec) TriggerSpec() query.TriggerSpec { +func (s *WindowProcedureSpec) TriggerSpec() flux.TriggerSpec { return s.Triggering } @@ -185,7 +185,7 @@ func createWindowTransformation(id execute.DatasetID, mode execute.AccumulationM d := execute.NewDataset(id, mode, cache) var start execute.Time if s.Window.Start.IsZero() { - start = a.ResolveTime(query.Now).Truncate(execute.Duration(s.Window.Every)) + start = a.ResolveTime(flux.Now).Truncate(execute.Duration(s.Window.Every)) } else { start = a.ResolveTime(s.Window.Start) } @@ -258,15 +258,15 @@ func NewFixedWindowTransformation( return t } -func (t *fixedWindowTransformation) RetractTable(id execute.DatasetID, key query.GroupKey) (err error) { +func (t *fixedWindowTransformation) RetractTable(id execute.DatasetID, key flux.GroupKey) (err error) { panic("not implemented") } -func (t *fixedWindowTransformation) Process(id execute.DatasetID, tbl query.Table) error { +func (t *fixedWindowTransformation) Process(id execute.DatasetID, tbl flux.Table) error { timeIdx := execute.ColIdx(t.timeCol, tbl.Cols()) - newCols := make([]query.ColMeta, 0, len(tbl.Cols())+2) - keyCols := make([]query.ColMeta, 0, len(tbl.Cols())+2) + newCols := make([]flux.ColMeta, 0, len(tbl.Cols())+2) + keyCols := make([]flux.ColMeta, 0, len(tbl.Cols())+2) keyColMap := make([]int, 0, len(tbl.Cols())+2) startColIdx := -1 stopColIdx := -1 @@ -289,9 +289,9 @@ func (t *fixedWindowTransformation) Process(id execute.DatasetID, tbl query.Tabl } if startColIdx == -1 { startColIdx = len(newCols) - c := query.ColMeta{ + c := flux.ColMeta{ Label: t.startColLabel, - Type: query.TTime, + Type: flux.TTime, } newCols = append(newCols, c) keyCols = append(keyCols, c) @@ -299,9 +299,9 @@ func (t *fixedWindowTransformation) Process(id execute.DatasetID, tbl query.Tabl } if stopColIdx == -1 { stopColIdx = len(newCols) - c := query.ColMeta{ + c := flux.ColMeta{ Label: t.stopColLabel, - Type: query.TTime, + Type: flux.TTime, } newCols = append(newCols, c) keyCols = append(keyCols, c) @@ -323,7 +323,7 @@ func (t *fixedWindowTransformation) Process(id execute.DatasetID, tbl query.Tabl } } - return tbl.Do(func(cr query.ColReader) error { + return tbl.Do(func(cr flux.ColReader) error { l := cr.Len() for i := 0; i < l; i++ { tm := cr.Times(timeIdx)[i] @@ -346,17 +346,17 @@ func (t *fixedWindowTransformation) Process(id execute.DatasetID, tbl query.Tabl builder.AppendTime(stopColIdx, bnds.Stop) default: switch c.Type { - case query.TBool: + case flux.TBool: builder.AppendBool(j, cr.Bools(j)[i]) - case query.TInt: + case flux.TInt: builder.AppendInt(j, cr.Ints(j)[i]) - case query.TUInt: + case flux.TUInt: builder.AppendUInt(j, cr.UInts(j)[i]) - case query.TFloat: + case flux.TFloat: builder.AppendFloat(j, cr.Floats(j)[i]) - case query.TString: + case flux.TString: builder.AppendString(j, cr.Strings(j)[i]) - case query.TTime: + case flux.TTime: builder.AppendTime(j, cr.Times(j)[i]) default: execute.PanicUnknownType(c.Type) @@ -369,8 +369,8 @@ func (t *fixedWindowTransformation) Process(id execute.DatasetID, tbl query.Tabl }) } -func (t *fixedWindowTransformation) newWindowGroupKey(tbl query.Table, keyCols []query.ColMeta, bnds execute.Bounds, keyColMap []int) query.GroupKey { - cols := make([]query.ColMeta, len(keyCols)) +func (t *fixedWindowTransformation) newWindowGroupKey(tbl flux.Table, keyCols []flux.ColMeta, bnds execute.Bounds, keyColMap []int) flux.GroupKey { + cols := make([]flux.ColMeta, len(keyCols)) vs := make([]values.Value, len(keyCols)) for j, c := range keyCols { cols[j] = c diff --git a/functions/window_test.go b/functions/window_test.go index 40339e122f..7018f084d0 100644 --- a/functions/window_test.go +++ b/functions/window_test.go @@ -6,23 +6,23 @@ import ( "testing" "time" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux/values" "github.com/google/go-cmp/cmp" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/querytest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/execute/executetest" + "github.com/influxdata/flux/fluxtest" + "github.com/influxdata/flux/functions" ) func TestWindow_NewQuery(t *testing.T) { - tests := []querytest.NewQueryTestCase{ + tests := []fluxtest.NewQueryTestCase{ { Name: "from with window", Raw: `from(bucket:"mybucket") |> window(start:-4h, every:1h)`, - Want: &query.Spec{ - Operations: []*query.Operation{ + Want: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "from0", Spec: &functions.FromOpSpec{ @@ -32,19 +32,19 @@ func TestWindow_NewQuery(t *testing.T) { { ID: "window1", Spec: &functions.WindowOpSpec{ - Start: query.Time{ + Start: flux.Time{ Relative: -4 * time.Hour, IsRelative: true, }, - Every: query.Duration(time.Hour), - Period: query.Duration(time.Hour), + Every: flux.Duration(time.Hour), + Period: flux.Duration(time.Hour), TimeCol: execute.DefaultTimeColLabel, StartColLabel: execute.DefaultStartColLabel, StopColLabel: execute.DefaultStopColLabel, }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "from0", Child: "window1"}, }, }, @@ -54,7 +54,7 @@ func TestWindow_NewQuery(t *testing.T) { tc := tc t.Run(tc.Name, func(t *testing.T) { t.Parallel() - querytest.NewQueryTestHelper(t, tc) + fluxtest.NewQueryTestHelper(t, tc) }) } } @@ -62,20 +62,20 @@ func TestWindow_NewQuery(t *testing.T) { func TestWindowOperation_Marshaling(t *testing.T) { //TODO: Test marshalling of triggerspec data := []byte(`{"id":"window","kind":"window","spec":{"every":"1m","period":"1h","start":"-4h","round":"1s"}}`) - op := &query.Operation{ + op := &flux.Operation{ ID: "window", Spec: &functions.WindowOpSpec{ - Every: query.Duration(time.Minute), - Period: query.Duration(time.Hour), - Start: query.Time{ + Every: flux.Duration(time.Minute), + Period: flux.Duration(time.Hour), + Start: flux.Time{ Relative: -4 * time.Hour, IsRelative: true, }, - Round: query.Duration(time.Second), + Round: flux.Duration(time.Second), }, } - querytest.OperationMarshalingTestHelper(t, data, op) + fluxtest.OperationMarshalingTestHelper(t, data, op) } func TestFixedWindow_PassThrough(t *testing.T) { @@ -102,16 +102,16 @@ var EmptyBounds = &execute.Bounds{ Stop: execute.Time(0), } -func newEmptyWindowTable(start execute.Time, stop execute.Time, cols []query.ColMeta) *executetest.Table { +func newEmptyWindowTable(start execute.Time, stop execute.Time, cols []flux.ColMeta) *executetest.Table { return &executetest.Table{ KeyCols: []string{"_start", "_stop"}, KeyValues: []interface{}{start, stop}, ColMeta: cols, Data: [][]interface{}(nil), GroupKey: execute.NewGroupKey( - []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, + []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, }, []values.Value{ values.NewTimeValue(start), @@ -123,15 +123,15 @@ func newEmptyWindowTable(start execute.Time, stop execute.Time, cols []query.Col func TestFixedWindow_Process(t *testing.T) { // test columns which all expected data will use - testCols := []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + testCols := []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, } testCases := []struct { name string - valueCol query.ColMeta + valueCol flux.ColMeta start execute.Time every, period execute.Duration createEmpty bool @@ -141,7 +141,7 @@ func TestFixedWindow_Process(t *testing.T) { }{ { name: "nonoverlapping_nonaligned", - valueCol: query.ColMeta{Label: "_value", Type: query.TFloat}, + valueCol: flux.ColMeta{Label: "_value", Type: flux.TFloat}, // Use a time that is *not* aligned with the every/period durations of the window start: execute.Time(time.Date(2017, 10, 10, 10, 10, 10, 10, time.UTC).UnixNano()), every: execute.Duration(time.Minute), @@ -152,11 +152,11 @@ func TestFixedWindow_Process(t *testing.T) { return []*executetest.Table{ { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {start, start + execute.Time(time.Minute), start, 0.0}, @@ -169,11 +169,11 @@ func TestFixedWindow_Process(t *testing.T) { }, { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {start + execute.Time(1*time.Minute), start + execute.Time(2*time.Minute), start + execute.Time(60*time.Second), 6.0}, @@ -186,11 +186,11 @@ func TestFixedWindow_Process(t *testing.T) { }, { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {start + execute.Time(2*time.Minute), start + execute.Time(3*time.Minute), start + execute.Time(120*time.Second), 12.0}, @@ -211,7 +211,7 @@ func TestFixedWindow_Process(t *testing.T) { { name: "nonoverlapping_aligned", - valueCol: query.ColMeta{Label: "_value", Type: query.TFloat}, + valueCol: flux.ColMeta{Label: "_value", Type: flux.TFloat}, // Use a time that is aligned with the every/period durations of the window start: execute.Time(time.Date(2017, 10, 10, 10, 0, 0, 0, time.UTC).UnixNano()), every: execute.Duration(time.Minute), @@ -222,11 +222,11 @@ func TestFixedWindow_Process(t *testing.T) { return []*executetest.Table{ { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {start, start + execute.Time(time.Minute), start, 0.0}, @@ -239,11 +239,11 @@ func TestFixedWindow_Process(t *testing.T) { }, { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {start + execute.Time(1*time.Minute), start + execute.Time(2*time.Minute), start + execute.Time(60*time.Second), 6.0}, @@ -256,11 +256,11 @@ func TestFixedWindow_Process(t *testing.T) { }, { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {start + execute.Time(2*time.Minute), start + execute.Time(3*time.Minute), start + execute.Time(120*time.Second), 12.0}, @@ -271,16 +271,16 @@ func TestFixedWindow_Process(t *testing.T) { { KeyCols: []string{"_start", "_stop"}, KeyValues: []interface{}{start + execute.Time(3*time.Minute), start + execute.Time(4*time.Minute)}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, GroupKey: execute.NewGroupKey( - []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, + []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, }, []values.Value{ values.NewTimeValue(start + execute.Time(3*time.Minute)), @@ -299,7 +299,7 @@ func TestFixedWindow_Process(t *testing.T) { }, { name: "overlapping_nonaligned", - valueCol: query.ColMeta{Label: "_value", Type: query.TFloat}, + valueCol: flux.ColMeta{Label: "_value", Type: flux.TFloat}, // Use a time that is *not* aligned with the every/period durations of the window start: execute.Time(time.Date(2017, 10, 10, 10, 10, 10, 10, time.UTC).UnixNano()), every: execute.Duration(time.Minute), @@ -310,11 +310,11 @@ func TestFixedWindow_Process(t *testing.T) { return []*executetest.Table{ { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {start, start + execute.Time(time.Minute), start, 0.0}, @@ -327,11 +327,11 @@ func TestFixedWindow_Process(t *testing.T) { }, { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {start, start + execute.Time(2*time.Minute), start, 0.0}, @@ -350,11 +350,11 @@ func TestFixedWindow_Process(t *testing.T) { }, { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {start + execute.Time(1*time.Minute), start + execute.Time(3*time.Minute), start + execute.Time(60*time.Second), 6.0}, @@ -370,11 +370,11 @@ func TestFixedWindow_Process(t *testing.T) { }, { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {start + execute.Time(2*time.Minute), start + execute.Time(4*time.Minute), start + execute.Time(120*time.Second), 12.0}, @@ -394,7 +394,7 @@ func TestFixedWindow_Process(t *testing.T) { }, { name: "overlapping_aligned", - valueCol: query.ColMeta{Label: "_value", Type: query.TFloat}, + valueCol: flux.ColMeta{Label: "_value", Type: flux.TFloat}, // Use a time that is aligned with the every/period durations of the window start: execute.Time(time.Date(2017, 10, 10, 10, 0, 0, 0, time.UTC).UnixNano()), every: execute.Duration(time.Minute), @@ -405,11 +405,11 @@ func TestFixedWindow_Process(t *testing.T) { return []*executetest.Table{ { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {start, start + execute.Time(time.Minute), start, 0.0}, @@ -422,11 +422,11 @@ func TestFixedWindow_Process(t *testing.T) { }, { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {start, start + execute.Time(2*time.Minute), start, 0.0}, @@ -445,11 +445,11 @@ func TestFixedWindow_Process(t *testing.T) { }, { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {start + execute.Time(1*time.Minute), start + execute.Time(3*time.Minute), start + execute.Time(60*time.Second), 6.0}, @@ -465,11 +465,11 @@ func TestFixedWindow_Process(t *testing.T) { }, { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {start + execute.Time(2*time.Minute), start + execute.Time(4*time.Minute), start + execute.Time(120*time.Second), 12.0}, @@ -489,7 +489,7 @@ func TestFixedWindow_Process(t *testing.T) { }, { name: "underlapping_nonaligned", - valueCol: query.ColMeta{Label: "_value", Type: query.TFloat}, + valueCol: flux.ColMeta{Label: "_value", Type: flux.TFloat}, // Use a time that is *not* aligned with the every/period durations of the window start: execute.Time(time.Date(2017, 10, 10, 10, 10, 10, 10, time.UTC).UnixNano()), every: execute.Duration(2 * time.Minute), @@ -500,11 +500,11 @@ func TestFixedWindow_Process(t *testing.T) { return []*executetest.Table{ { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {start + 1*execute.Time(time.Minute), start + 2*execute.Time(time.Minute), start + execute.Time(60*time.Second), 6.0}, @@ -517,11 +517,11 @@ func TestFixedWindow_Process(t *testing.T) { }, { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {start + execute.Time(3*time.Minute), start + execute.Time(4*time.Minute), start + execute.Time(180*time.Second), 18.0}, @@ -540,7 +540,7 @@ func TestFixedWindow_Process(t *testing.T) { }, { name: "underlapping_aligned", - valueCol: query.ColMeta{Label: "_value", Type: query.TFloat}, + valueCol: flux.ColMeta{Label: "_value", Type: flux.TFloat}, // Use a time that is aligned with the every/period durations of the window start: execute.Time(time.Date(2017, 10, 10, 10, 0, 0, 0, time.UTC).UnixNano()), every: execute.Duration(2 * time.Minute), @@ -551,11 +551,11 @@ func TestFixedWindow_Process(t *testing.T) { return []*executetest.Table{ { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {start + 1*execute.Time(time.Minute), start + 2*execute.Time(time.Minute), start + execute.Time(60*time.Second), 6.0}, @@ -568,11 +568,11 @@ func TestFixedWindow_Process(t *testing.T) { }, { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TFloat}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TFloat}, }, Data: [][]interface{}{ {start + execute.Time(3*time.Minute), start + execute.Time(4*time.Minute), start + execute.Time(180*time.Second), 18.0}, @@ -591,7 +591,7 @@ func TestFixedWindow_Process(t *testing.T) { }, { name: "nonoverlapping_aligned_int", - valueCol: query.ColMeta{Label: "_value", Type: query.TInt}, + valueCol: flux.ColMeta{Label: "_value", Type: flux.TInt}, // Use a time that is aligned with the every/period durations of the window start: execute.Time(time.Date(2017, 10, 10, 10, 0, 0, 0, time.UTC).UnixNano()), every: execute.Duration(time.Minute), @@ -600,15 +600,15 @@ func TestFixedWindow_Process(t *testing.T) { num: 15, want: func(start execute.Time) []*executetest.Table { testCols := testCols - testCols[3].Type = query.TInt + testCols[3].Type = flux.TInt return []*executetest.Table{ { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TInt}, }, Data: [][]interface{}{ {start, start + execute.Time(time.Minute), start, int64(0.0)}, @@ -621,11 +621,11 @@ func TestFixedWindow_Process(t *testing.T) { }, { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TInt}, }, Data: [][]interface{}{ {start + execute.Time(1*time.Minute), start + execute.Time(2*time.Minute), start + execute.Time(60*time.Second), int64(6)}, @@ -638,11 +638,11 @@ func TestFixedWindow_Process(t *testing.T) { }, { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TInt}, }, Data: [][]interface{}{ {start + execute.Time(2*time.Minute), start + execute.Time(3*time.Minute), start + execute.Time(120*time.Second), int64(12)}, @@ -662,7 +662,7 @@ func TestFixedWindow_Process(t *testing.T) { }, { name: "don't create empty", - valueCol: query.ColMeta{Label: "_value", Type: query.TInt}, + valueCol: flux.ColMeta{Label: "_value", Type: flux.TInt}, // Use a time that is aligned with the every/period durations of the window start: execute.Time(time.Date(2017, 10, 10, 10, 0, 0, 0, time.UTC).UnixNano()), every: execute.Duration(time.Minute), @@ -671,15 +671,15 @@ func TestFixedWindow_Process(t *testing.T) { num: 15, want: func(start execute.Time) []*executetest.Table { testCols := testCols - testCols[3].Type = query.TInt + testCols[3].Type = flux.TInt return []*executetest.Table{ { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TInt}, }, Data: [][]interface{}{ {start, start + execute.Time(time.Minute), start, int64(0.0)}, @@ -692,11 +692,11 @@ func TestFixedWindow_Process(t *testing.T) { }, { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TInt}, }, Data: [][]interface{}{ {start + execute.Time(1*time.Minute), start + execute.Time(2*time.Minute), start + execute.Time(60*time.Second), int64(6)}, @@ -709,11 +709,11 @@ func TestFixedWindow_Process(t *testing.T) { }, { KeyCols: []string{"_start", "_stop"}, - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, - {Label: "_value", Type: query.TInt}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, + {Label: "_value", Type: flux.TInt}, }, Data: [][]interface{}{ {start + execute.Time(2*time.Minute), start + execute.Time(3*time.Minute), start + execute.Time(120*time.Second), int64(12)}, @@ -726,7 +726,7 @@ func TestFixedWindow_Process(t *testing.T) { }, { name: "empty bounds start == stop", - valueCol: query.ColMeta{Label: "_value", Type: query.TInt}, + valueCol: flux.ColMeta{Label: "_value", Type: flux.TInt}, start: execute.Time(time.Date(2017, 10, 10, 10, 0, 0, 0, time.UTC).UnixNano()), every: execute.Duration(time.Minute), period: execute.Duration(time.Minute), @@ -738,7 +738,7 @@ func TestFixedWindow_Process(t *testing.T) { }, { name: "empty bounds start > stop", - valueCol: query.ColMeta{Label: "_value", Type: query.TInt}, + valueCol: flux.ColMeta{Label: "_value", Type: flux.TInt}, start: execute.Time(time.Date(2017, 10, 10, 10, 0, 0, 0, time.UTC).UnixNano()), every: execute.Duration(time.Minute), period: execute.Duration(time.Minute), @@ -788,10 +788,10 @@ func TestFixedWindow_Process(t *testing.T) { ) table0 := &executetest.Table{ - ColMeta: []query.ColMeta{ - {Label: "_start", Type: query.TTime}, - {Label: "_stop", Type: query.TTime}, - {Label: "_time", Type: query.TTime}, + ColMeta: []flux.ColMeta{ + {Label: "_start", Type: flux.TTime}, + {Label: "_stop", Type: flux.TTime}, + {Label: "_time", Type: flux.TTime}, tc.valueCol, }, } @@ -799,15 +799,15 @@ func TestFixedWindow_Process(t *testing.T) { for i := 0; i < tc.num; i++ { var v interface{} switch tc.valueCol.Type { - case query.TBool: + case flux.TBool: v = bool(i%2 == 0) - case query.TInt: + case flux.TInt: v = int64(i) - case query.TUInt: + case flux.TUInt: v = uint64(i) - case query.TFloat: + case flux.TFloat: v = float64(i) - case query.TString: + case flux.TString: v = strconv.Itoa(i) } table0.Data = append(table0.Data, []interface{}{ diff --git a/functions/yield.go b/functions/yield.go index b0f3b49463..832ce4b743 100644 --- a/functions/yield.go +++ b/functions/yield.go @@ -3,9 +3,9 @@ package functions import ( "fmt" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic" ) const YieldKind = "yield" @@ -16,20 +16,20 @@ type YieldOpSpec struct { var yieldSignature = semantic.FunctionSignature{ Params: map[string]semantic.Type{ - query.TableParameter: query.TableObjectType, - "name": semantic.String, + flux.TableParameter: flux.TableObjectType, + "name": semantic.String, }, - ReturnType: query.TableObjectType, - PipeArgument: query.TableParameter, + ReturnType: flux.TableObjectType, + PipeArgument: flux.TableParameter, } func init() { - query.RegisterFunctionWithSideEffect(YieldKind, createYieldOpSpec, yieldSignature) - query.RegisterOpSpec(YieldKind, newYieldOp) + flux.RegisterFunctionWithSideEffect(YieldKind, createYieldOpSpec, yieldSignature) + flux.RegisterOpSpec(YieldKind, newYieldOp) plan.RegisterProcedureSpec(YieldKind, newYieldProcedure, YieldKind) } -func createYieldOpSpec(args query.Arguments, a *query.Administration) (query.OperationSpec, error) { +func createYieldOpSpec(args flux.Arguments, a *flux.Administration) (flux.OperationSpec, error) { if err := a.AddParentFromArgs(args); err != nil { return nil, err } @@ -48,11 +48,11 @@ func createYieldOpSpec(args query.Arguments, a *query.Administration) (query.Ope return spec, nil } -func newYieldOp() query.OperationSpec { +func newYieldOp() flux.OperationSpec { return new(YieldOpSpec) } -func (s *YieldOpSpec) Kind() query.OperationKind { +func (s *YieldOpSpec) Kind() flux.OperationKind { return YieldKind } @@ -60,7 +60,7 @@ type YieldProcedureSpec struct { Name string `json:"name"` } -func newYieldProcedure(qs query.OperationSpec, _ plan.Administration) (plan.ProcedureSpec, error) { +func newYieldProcedure(qs flux.OperationSpec, _ plan.Administration) (plan.ProcedureSpec, error) { if spec, ok := qs.(*YieldOpSpec); ok { return &YieldProcedureSpec{Name: spec.Name}, nil } diff --git a/idfile/idfile_test.go b/idfile/idfile_test.go index cf9842bce1..9059014f40 100644 --- a/idfile/idfile_test.go +++ b/idfile/idfile_test.go @@ -5,7 +5,7 @@ import ( "os" "testing" - "github.com/influxdata/platform/query/idfile" + "github.com/influxdata/flux/idfile" uuid "github.com/satori/go.uuid" ) diff --git a/influxql/README.md b/influxql/README.md deleted file mode 100644 index 8e6a562f35..0000000000 --- a/influxql/README.md +++ /dev/null @@ -1,176 +0,0 @@ -# InfluxQL Transpiler - -The InfluxQL Transpiler exists to rewrite an InfluxQL query into its equivalent query in Flux. The transpiler works off of a few simple rules that match with the equivalent method of constructing queries in InfluxDB. - -**NOTE:** The transpiler code is not finished and may not necessarily reflect what is in this document. When they conflict, this document is considered to be the correct way to do it. If you wish to change how the transpiler works, modify this file first. - -1. [Identify the cursors](#identify-cursors) -2. [Identify the query type](#identify-query-type) -3. [Group the cursors](#group-cursors) -4. [Create the cursors for each group](#create-groups) - 1. [Create cursor](#create-cursor) - 2. [Filter by measurement and fields](#filter-cursor) - 3. [Generate the pivot table](#generate-pivot-table) - 4. [Evaluate the condition](#evaluate-condition) - 5. [Perform the grouping](#perform-grouping) - 6. [Evaluate the function](#evaluate-function) - 7. [Combine windows](#combine-windows) -5. [Join the groups](#join-groups) -6. [Map and eval columns](#map-and-eval) -7. [Encoding the results](#encoding) - -## Identify the cursors - -The InfluxQL query engine works by filling in variables and evaluating the query for the values in each row. The first step of transforming a query is identifying the cursors so we can figure out how to fill them correctly. A cursor is any point in the query that has a **variable or a function call**. Math functions do not count as function calls and are handled in the eval phase. - -For the following query, it is easy to identify the cursors: - - SELECT max(usage_user), usage_system FROM telegraf..cpu - -`max(usage_user)` and `usage_system` are the cursors that we need to fill in for each row. Cursors are global and are not per-field. - -## Identify the query type - -There are three types of queries: raw, aggregate, and selector. A raw query is one where all of the cursors reference a variable. An aggregate is one where all of the cursors reference a function call. A selector is one where there is exactly one function call that is a selector (such as `max()` or `min()`) and the remaining variables, if there are any, are variables. If there is only one function call with no variables and that function is a selector, then the function type is a selector. - -## Group the cursors - -We group the cursors based on the query type. For raw queries and selectors, all of the cursors are put into the same group. For aggregates, each function call is put into a separate group so they can be joined at the end. - -## Create the cursors for each group - -We create the cursors within each group. This process is repeated for every group. - -### Create cursor - -The cursor is generated using the following template: - - create_cursor = (db, rp="autogen", start, stop=now()) => from(bucket: db+"/"+rp) - |> range(start: start, stop: stop) - -This is called once per group. - -### Identify the variables - -Each of the variables in the group are identified. This involves inspecting the condition to collect the common variables in the expression while also retrieving the variables for each expression within the group. For a function call, this retrieves the variable used as a function argument rather than the function itself. - -If a wildcard is identified in the fields, then the field filter is cleared and only the measurement filter is used. If a regex wildcard is identified, it is added as one of the field filters. - -### Filter by measurement and fields - -A filter expression is generated by using the measurement and the fields that were identified. It follows this template: - - ... |> filter(fn: (r) => r._measurement == and ) - -The `` is equal to the measurement name from the `FROM` clause. The `` section is generated differently depending on the fields that were found. If more than one field was selected, then each of the field filters is combined by using `or` and the expression itself is surrounded by parenthesis. For a non-wildcard field, the following expression is used: - - r._field == - -For a regex wildcard, the following is used: - - r._field =~ - -If a star wildcard was used, the `` is omitted from the filter expression. - -### Generate the pivot table - -If there was more than one field selected or if one of the fields was some form of wildcard, a pivot expression is generated. - - ... |> pivot(rowKey: ["_time"], colKey: ["_field"], valueCol: "_value") - -### Evaluate the condition - -At this point, generate the `filter` call to evaluate the condition. If there is no condition outside of the time selector, then this step is skipped. - -### Perform the grouping - -We group together the streams based on the `GROUP BY` clause. As an example: - - > SELECT mean(usage_user) FROM telegraf..cpu WHERE time >= now() - 5m GROUP BY time(5m), host - ... |> group(by: ["_measurement", "_start", "host"]) |> window(every: 5m) - -If the `GROUP BY time(...)` doesn't exist, `window()` is skipped. Grouping will have a default of [`_measurement`, `_start`], regardless of whether a GROUP BY clause is present. -If there are keys in the group by clause, they are concatenated with the default list. If a wildcard is used for grouping, then this step is skipped. - -### Evaluate the function - -If this group contains a function call, the function is evaluated at this stage and invoked on the specific column. As an example: - - > SELECT max(usage_user), usage_system FROM telegraf..cpu - val1 = create_cursor(bucket: "telegraf/autogen", start: -5m, m: "cpu", f: "usage_user") - val1 = create_cursor(bucket: "telegraf/autogen", start: -5m, m: "cpu", f: "usage_system") - inner_join(tables: {val1: val1, val2: val2}, except: ["_field"], fn: (tables) => {val1: tables.val1, val2: tables.val2}) - |> max(column: "val1") - -For an aggregate, the following is used instead: - - > SELECT mean(usage_user) FROM telegraf..cpu - create_cursor(bucket: "telegraf/autogen", start: -5m, m: "cpu", f: "usage_user") - |> group(except: ["_field"]) - |> mean(timeSrc: "_start", columns: ["_value"]) - -If the aggregate is combined with conditions, the column name of `_value` is replaced with whatever the generated column name is. - -### Combine windows - -If there a window operation was added, we then combine each of the function results from the windows back into a single table. - - ... |> window(every: inf) - -This step is skipped if there was no window function. - -## Join the groups - -If there is only one group, this does not need to be done and can be skipped. - -If there are multiple groups, as is the case when there are multiple function calls, then we perform an `outer_join` using the time and any remaining group keys. - -## Map and eval the columns - -After joining the results if a join was required, then a `map` call is used to both evaluate the math functions and name the columns. The time is also passed through the `map()` function so it is available for the encoder. - - result |> map(fn: (r) => {_time: r._time, max: r.val1, usage_system: r.val2}) - -This is the final result. It will also include any tags in the group key and the time will be located in the `_time` variable. - -TODO(jsternberg): The `_time` variable is only needed for selectors and raw queries. We can actually drop this variable for aggregate queries and use the `_start` time from the group key. Consider whether or not we should do this and if it is worth it. - -## Encoding the results - -Each statement will be terminated by a `yield()` call. This call will embed the statement id as the result name. The result name is always of type string, but the transpiler will encode an integer in this field so it can be parsed by the encoder. For example: - - result |> yield(name: "0") - -The edge nodes from the query specification will be used to encode the results back to the user in the JSON format used in 1.x. The JSON format from 1.x is below: - - { - "results": [ - { - "statement_id": 0, - "series": [ - { - "name": "_measurement", - "tags": { - "key": "value" - }, - "columns": [ - "time", - "value" - ], - "values": [ - [ - "2015-01-29T21:55:43.702900257Z", - 2 - ] - ] - } - ] - } - ] - } - -The measurement name is retrieved from the `_measurement` column in the results. For the tags, the values in the group key that are of type string are included with both the keys and the values mapped to each other. Any values in the group key that are not strings, like the start and stop times, are ignored and discarded. If the `_field` key is still present in the group key, it is also discarded. For all normal fields, they are included in the array of values for each row. The `_time` field will be renamed to `time` (or whatever the time alias is set to by the query). - -The chunking options that existed in 1.x are not supported by the encoder and should not be used. To minimize the amount of breaking code, using a chunking option will be ignored and the encoder will operate as normal, but it will include a message in the result so that a user can be informed that an invalid query option was used. The 1.x format has a field for sending back informational messages in it already. - -**TODO(jsternberg):** Find a way for a column to be both used as a tag and a field. This is not currently possible because the encoder can't tell the difference between the two. diff --git a/influxql/compiler.go b/influxql/compiler.go deleted file mode 100644 index b96545dbc3..0000000000 --- a/influxql/compiler.go +++ /dev/null @@ -1,49 +0,0 @@ -package influxql - -import ( - "context" - - "github.com/influxdata/platform" - "github.com/influxdata/platform/query" -) - -const CompilerType = "influxql" - -// AddCompilerMappings adds the influxql specific compiler mappings. -func AddCompilerMappings(mappings query.CompilerMappings, dbrpMappingSvc platform.DBRPMappingService) error { - return mappings.Add(CompilerType, func() query.Compiler { - return NewCompiler(dbrpMappingSvc) - }) -} - -// Compiler is the transpiler to convert InfluxQL to a Flux specification. -type Compiler struct { - Cluster string `json:"cluster,omitempty"` - DB string `json:"db,omitempty"` - RP string `json:"rp,omitempty"` - Query string `json:"query"` - - dbrpMappingSvc platform.DBRPMappingService -} - -func NewCompiler(dbrpMappingSvc platform.DBRPMappingService) *Compiler { - return &Compiler{ - dbrpMappingSvc: dbrpMappingSvc, - } -} - -// Compile tranpiles the query into a specification. -func (c *Compiler) Compile(ctx context.Context) (*query.Spec, error) { - transpiler := NewTranspilerWithConfig( - c.dbrpMappingSvc, - Config{ - Cluster: c.Cluster, - DefaultDatabase: c.DB, - DefaultRetentionPolicy: c.RP, - }, - ) - return transpiler.Transpile(ctx, c.Query) -} -func (c *Compiler) CompilerType() query.CompilerType { - return CompilerType -} diff --git a/influxql/compiler_test.go b/influxql/compiler_test.go deleted file mode 100644 index aabbd810c8..0000000000 --- a/influxql/compiler_test.go +++ /dev/null @@ -1,12 +0,0 @@ -package influxql_test - -import ( - "testing" - - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/influxql" -) - -func TestCompiler(t *testing.T) { - var _ query.Compiler = (*influxql.Compiler)(nil) -} diff --git a/influxql/config.go b/influxql/config.go deleted file mode 100644 index c57a315f92..0000000000 --- a/influxql/config.go +++ /dev/null @@ -1,13 +0,0 @@ -package influxql - -import ( - "time" -) - -// Config modifies the behavior of the Transpiler. -type Config struct { - DefaultDatabase string - DefaultRetentionPolicy string - NowFn func() time.Time - Cluster string -} diff --git a/influxql/cursor.go b/influxql/cursor.go deleted file mode 100644 index f081a49fc4..0000000000 --- a/influxql/cursor.go +++ /dev/null @@ -1,138 +0,0 @@ -package influxql - -import ( - "errors" - - "github.com/influxdata/influxql" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/semantic" -) - -// cursor is holds known information about the current stream. It maps the influxql ast information -// to the attributes on a table. -type cursor interface { - // ID contains the last id that produces this cursor. - ID() query.OperationID - - // Keys returns all of the expressions that this cursor contains. - Keys() []influxql.Expr - - // Value returns the string that can be used to access the computed expression. - // If this cursor does not produce the expression, this returns false for the second - // return argument. - Value(expr influxql.Expr) (string, bool) -} - -// varRefCursor contains a cursor for a single variable. This is usually the raw value -// coming from the database and points to the default value column property. -type varRefCursor struct { - id query.OperationID - ref *influxql.VarRef -} - -// createVarRefCursor creates a new cursor from a variable reference using the sources -// in the transpilerState. -func createVarRefCursor(t *transpilerState, ref *influxql.VarRef) (cursor, error) { - if len(t.stmt.Sources) != 1 { - // TODO(jsternberg): Support multiple sources. - return nil, errors.New("unimplemented: only one source is allowed") - } - - // Only support a direct measurement. Subqueries are not supported yet. - mm, ok := t.stmt.Sources[0].(*influxql.Measurement) - if !ok { - return nil, errors.New("unimplemented: source must be a measurement") - } - - // Create the from spec and add it to the list of operations. - from, err := t.from(mm) - if err != nil { - return nil, err - } - - valuer := influxql.NowValuer{Now: t.spec.Now} - _, tr, err := influxql.ConditionExpr(t.stmt.Condition, &valuer) - if err != nil { - return nil, err - } - - // If the maximum is not set and we have a windowing function, then - // the end time will be set to now. - if tr.Max.IsZero() { - if window, err := t.stmt.GroupByInterval(); err == nil && window > 0 { - tr.Max = t.spec.Now - } - } - - range_ := t.op("range", &functions.RangeOpSpec{ - Start: query.Time{Absolute: tr.MinTime()}, - Stop: query.Time{Absolute: tr.MaxTime()}, - TimeCol: execute.DefaultTimeColLabel, - StartCol: execute.DefaultStartColLabel, - StopCol: execute.DefaultStopColLabel, - }, from) - - id := t.op("filter", &functions.FilterOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{ - {Key: &semantic.Identifier{Name: "r"}}, - }, - Body: &semantic.LogicalExpression{ - Operator: ast.AndOperator, - Left: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{Name: "r"}, - Property: "_measurement", - }, - Right: &semantic.StringLiteral{Value: mm.Name}, - }, - Right: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{Name: "r"}, - Property: "_field", - }, - Right: &semantic.StringLiteral{Value: ref.Val}, - }, - }, - }, - }, range_) - return &varRefCursor{ - id: id, - ref: ref, - }, nil -} - -func (c *varRefCursor) ID() query.OperationID { - return c.id -} - -func (c *varRefCursor) Keys() []influxql.Expr { - return []influxql.Expr{c.ref} -} - -func (c *varRefCursor) Value(expr influxql.Expr) (string, bool) { - ref, ok := expr.(*influxql.VarRef) - if !ok { - return "", false - } - - // If these are the same variable reference (by pointer), then they are equal. - if ref == c.ref || *ref == *c.ref { - return execute.DefaultValueColLabel, true - } - return "", false -} - -// opCursor wraps a cursor with a new id while delegating all calls to the -// wrapped cursor. -type opCursor struct { - id query.OperationID - cursor -} - -func (c *opCursor) ID() query.OperationID { return c.id } diff --git a/influxql/dialect.go b/influxql/dialect.go deleted file mode 100644 index fc52e080c3..0000000000 --- a/influxql/dialect.go +++ /dev/null @@ -1,91 +0,0 @@ -package influxql - -import ( - "net/http" - - "github.com/influxdata/platform/query" -) - -const DialectType = "influxql" - -// AddDialectMappings adds the influxql specific dialect mappings. -func AddDialectMappings(mappings query.DialectMappings) error { - return mappings.Add(DialectType, func() query.Dialect { - return new(Dialect) - }) -} - -// Dialect describes the output format of InfluxQL queries. -type Dialect struct { - TimeFormat TimeFormat // TimeFormat is the format of the timestamp; defaults to RFC3339Nano. - Encoding EncodingFormat // Encoding is the format of the results; defaults to JSON. - ChunkSize int // Chunks is the number of points per chunk encoding batch; defaults to 0 or no chunking. - Compression CompressionFormat // Compression is the compression of the result output; defaults to None. -} - -func (d *Dialect) SetHeaders(w http.ResponseWriter) { - switch d.Encoding { - case JSON, JSONPretty: - w.Header().Set("Content-Type", "application/json") - case CSV: - w.Header().Set("Content-Type", "text/csv") - case Msgpack: - w.Header().Set("Content-Type", "application/x-msgpack") - } -} - -func (d *Dialect) Encoder() query.MultiResultEncoder { - switch d.Encoding { - case JSON, JSONPretty: - return new(MultiResultEncoder) - default: - panic("not implemented") - } -} -func (d *Dialect) DialectType() query.DialectType { - return DialectType -} - -// TimeFormat specifies the format of the timestamp in the query results. -type TimeFormat int - -const ( - // RFC3339Nano is the default format for timestamps for InfluxQL. - RFC3339Nano TimeFormat = iota - // Hour formats time as the number of hours in the unix epoch. - Hour - // Minute formats time as the number of minutes in the unix epoch. - Minute - // Second formats time as the number of seconds in the unix epoch. - Second - // Millisecond formats time as the number of milliseconds in the unix epoch. - Millisecond - // Microsecond formats time as the number of microseconds in the unix epoch. - Microsecond - // Nanosecond formats time as the number of nanoseconds in the unix epoch. - Nanosecond -) - -// CompressionFormat is the format to compress the query results. -type CompressionFormat int - -const ( - // None does not compress the results and is the default. - None CompressionFormat = iota - // Gzip compresses the query results with gzip. - Gzip -) - -// EncodingFormat is the output format for the query response content. -type EncodingFormat int - -const ( - // JSON marshals the response to JSON octets. - JSON EncodingFormat = iota - // JSONPretty marshals the response to JSON octets with idents. - JSONPretty - // CSV marshals the response to CSV. - CSV - // Msgpack has a similar structure as the JSON response. Used? - Msgpack -) diff --git a/influxql/dialect_test.go b/influxql/dialect_test.go deleted file mode 100644 index ae045da88c..0000000000 --- a/influxql/dialect_test.go +++ /dev/null @@ -1,12 +0,0 @@ -package influxql_test - -import ( - "testing" - - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/influxql" -) - -func TestDialect(t *testing.T) { - var _ query.Dialect = (*influxql.Dialect)(nil) -} diff --git a/influxql/function.go b/influxql/function.go deleted file mode 100644 index b609b505ba..0000000000 --- a/influxql/function.go +++ /dev/null @@ -1,275 +0,0 @@ -package influxql - -import ( - "errors" - "fmt" - - "github.com/influxdata/influxql" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/functions" -) - -// function contains the prototype for invoking a function. -// TODO(jsternberg): This should do a lot more heavy lifting, but it mostly just -// pre-validates that we know the function exists. The cursor creation should be -// done by this struct, but it isn't at the moment. -type function struct { - Ref *influxql.VarRef - call *influxql.Call -} - -// parseFunction parses a call AST and creates the function for it. -func parseFunction(expr *influxql.Call) (*function, error) { - switch expr.Name { - case "count": - if exp, got := 1, len(expr.Args); exp != got { - return nil, fmt.Errorf("invalid number of arguments for %s, expected %d, got %d", expr.Name, exp, got) - } - - switch ref := expr.Args[0].(type) { - case *influxql.VarRef: - return &function{ - Ref: ref, - call: expr, - }, nil - case *influxql.Call: - if ref.Name == "distinct" { - return nil, errors.New("unimplemented: count(distinct)") - } - return nil, fmt.Errorf("expected field argument in %s()", expr.Name) - case *influxql.Distinct: - return nil, errors.New("unimplemented: count(distinct)") - case *influxql.Wildcard: - return nil, errors.New("unimplemented: wildcard function") - case *influxql.RegexLiteral: - return nil, errors.New("unimplemented: wildcard regex function") - default: - return nil, fmt.Errorf("expected field argument in %s()", expr.Name) - } - case "min", "max", "sum", "first", "last", "mean": - if exp, got := 1, len(expr.Args); exp != got { - return nil, fmt.Errorf("invalid number of arguments for %s, expected %d, got %d", expr.Name, exp, got) - } - - switch ref := expr.Args[0].(type) { - case *influxql.VarRef: - return &function{ - Ref: ref, - call: expr, - }, nil - case *influxql.Wildcard: - return nil, errors.New("unimplemented: wildcard function") - case *influxql.RegexLiteral: - return nil, errors.New("unimplemented: wildcard regex function") - default: - return nil, fmt.Errorf("expected field argument in %s()", expr.Name) - } - case "percentile": - if exp, got := 2, len(expr.Args); exp != got { - return nil, fmt.Errorf("invalid number of arguments for %s, expected %d, got %d", expr.Name, exp, got) - } - - var functionRef *influxql.VarRef - - switch ref := expr.Args[0].(type) { - case *influxql.VarRef: - functionRef = ref - case *influxql.Wildcard: - return nil, errors.New("unimplemented: wildcard function") - case *influxql.RegexLiteral: - return nil, errors.New("unimplemented: wildcard regex function") - default: - return nil, fmt.Errorf("expected field argument in %s()", expr.Name) - } - - switch expr.Args[1].(type) { - case *influxql.IntegerLiteral: - case *influxql.NumberLiteral: - default: - return nil, fmt.Errorf("expected float argument in %s()", expr.Name) - } - - return &function{ - Ref: functionRef, - call: expr, - }, nil - default: - return nil, fmt.Errorf("unimplemented function: %q", expr.Name) - } - -} - -// createFunctionCursor creates a new cursor that calls a function on one of the columns -// and returns the result. -func createFunctionCursor(t *transpilerState, call *influxql.Call, in cursor) (cursor, error) { - cur := &functionCursor{ - call: call, - parent: in, - } - switch call.Name { - case "count": - value, ok := in.Value(call.Args[0]) - if !ok { - return nil, fmt.Errorf("undefined variable: %s", call.Args[0]) - } - cur.id = t.op("count", &functions.CountOpSpec{ - AggregateConfig: execute.AggregateConfig{ - Columns: []string{value}, - TimeSrc: execute.DefaultStartColLabel, - TimeDst: execute.DefaultTimeColLabel, - }, - }, in.ID()) - cur.value = value - cur.exclude = map[influxql.Expr]struct{}{call.Args[0]: {}} - case "min": - value, ok := in.Value(call.Args[0]) - if !ok { - return nil, fmt.Errorf("undefined variable: %s", call.Args[0]) - } - cur.id = t.op("min", &functions.MinOpSpec{ - SelectorConfig: execute.SelectorConfig{ - Column: value, - }, - }, in.ID()) - cur.value = value - cur.exclude = map[influxql.Expr]struct{}{call.Args[0]: {}} - case "max": - value, ok := in.Value(call.Args[0]) - if !ok { - return nil, fmt.Errorf("undefined variable: %s", call.Args[0]) - } - cur.id = t.op("max", &functions.MaxOpSpec{ - SelectorConfig: execute.SelectorConfig{ - Column: value, - }, - }, in.ID()) - cur.value = value - cur.exclude = map[influxql.Expr]struct{}{call.Args[0]: {}} - case "sum": - value, ok := in.Value(call.Args[0]) - if !ok { - return nil, fmt.Errorf("undefined variable: %s", call.Args[0]) - } - cur.id = t.op("sum", &functions.SumOpSpec{ - AggregateConfig: execute.AggregateConfig{ - Columns: []string{value}, - TimeSrc: execute.DefaultStartColLabel, - TimeDst: execute.DefaultTimeColLabel, - }, - }, in.ID()) - cur.value = value - cur.exclude = map[influxql.Expr]struct{}{call.Args[0]: {}} - case "first": - value, ok := in.Value(call.Args[0]) - if !ok { - return nil, fmt.Errorf("undefined variable: %s", call.Args[0]) - } - cur.id = t.op("first", &functions.FirstOpSpec{ - SelectorConfig: execute.SelectorConfig{ - Column: value, - }, - }, in.ID()) - cur.value = value - cur.exclude = map[influxql.Expr]struct{}{call.Args[0]: {}} - case "last": - value, ok := in.Value(call.Args[0]) - if !ok { - return nil, fmt.Errorf("undefined variable: %s", call.Args[0]) - } - cur.id = t.op("last", &functions.LastOpSpec{ - SelectorConfig: execute.SelectorConfig{ - Column: value, - }, - }, in.ID()) - cur.value = value - cur.exclude = map[influxql.Expr]struct{}{call.Args[0]: {}} - case "mean": - value, ok := in.Value(call.Args[0]) - if !ok { - return nil, fmt.Errorf("undefined variable: %s", call.Args[0]) - } - cur.id = t.op("mean", &functions.MeanOpSpec{ - AggregateConfig: execute.AggregateConfig{ - Columns: []string{value}, - TimeSrc: execute.DefaultStartColLabel, - TimeDst: execute.DefaultTimeColLabel, - }, - }, in.ID()) - cur.value = value - cur.exclude = map[influxql.Expr]struct{}{call.Args[0]: {}} - case "percentile": - if len(call.Args) != 2 { - return nil, errors.New("percentile function requires two arguments field_key and N") - } - - fieldName, ok := in.Value(call.Args[0]) - if !ok { - return nil, fmt.Errorf("undefined variable: %s", call.Args[0]) - } - - var percentile float64 - switch arg := call.Args[1].(type) { - case *influxql.NumberLiteral: - percentile = arg.Val / 100.0 - case *influxql.IntegerLiteral: - percentile = float64(arg.Val) / 100.0 - default: - return nil, errors.New("argument N must be a float type") - } - - if percentile < 0 || percentile > 1 { - return nil, errors.New("argument N must be between 0 and 100") - } - - cur.id = t.op("percentile", &functions.PercentileOpSpec{ - Percentile: percentile, - Compression: 0, - Method: "exact_selector", - AggregateConfig: execute.AggregateConfig{ - Columns: []string{fieldName}, - TimeSrc: execute.DefaultStartColLabel, - TimeDst: execute.DefaultTimeColLabel, - }, - }, in.ID()) - cur.value = fieldName - cur.exclude = map[influxql.Expr]struct{}{call.Args[0]: {}} - default: - return nil, fmt.Errorf("unimplemented function: %q", call.Name) - } - return cur, nil -} - -type functionCursor struct { - id query.OperationID - call *influxql.Call - value string - exclude map[influxql.Expr]struct{} - parent cursor -} - -func (c *functionCursor) ID() query.OperationID { - return c.id -} - -func (c *functionCursor) Keys() []influxql.Expr { - keys := []influxql.Expr{c.call} - if a := c.parent.Keys(); len(a) > 0 { - for _, e := range a { - if _, ok := c.exclude[e]; ok { - continue - } - keys = append(keys, e) - } - } - return keys -} - -func (c *functionCursor) Value(expr influxql.Expr) (string, bool) { - if expr == c.call { - return c.value, true - } else if _, ok := c.exclude[expr]; ok { - return "", false - } - return c.parent.Value(expr) -} diff --git a/influxql/group.go b/influxql/group.go deleted file mode 100644 index 22685772be..0000000000 --- a/influxql/group.go +++ /dev/null @@ -1,399 +0,0 @@ -package influxql - -import ( - "fmt" - "math" - "strings" - "time" - - "github.com/influxdata/influxql" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/semantic" - "github.com/pkg/errors" -) - -type groupInfo struct { - call *influxql.Call - refs []*influxql.VarRef -} - -type groupVisitor struct { - calls []*function - refs []*influxql.VarRef - err error -} - -func (v *groupVisitor) Visit(n influxql.Node) influxql.Visitor { - if v.err != nil { - return nil - } - - // TODO(jsternberg): Identify duplicates so they are a single common instance. - switch expr := n.(type) { - case *influxql.Call: - // TODO(jsternberg): Identify math functions so we visit their arguments instead of recording them. - fn, err := parseFunction(expr) - if err != nil { - v.err = err - return nil - } - v.calls = append(v.calls, fn) - return nil - case *influxql.Distinct: - v.err = errors.New("unimplemented: distinct expression") - return nil - case *influxql.VarRef: - if expr.Val == "time" { - return nil - } - v.refs = append(v.refs, expr) - return nil - case *influxql.Wildcard: - v.err = errors.New("unimplemented: field wildcard") - return nil - case *influxql.RegexLiteral: - v.err = errors.New("unimplemented: field regex wildcard") - return nil - } - return v -} - -// identifyGroups will identify the groups for creating data access cursors. -func identifyGroups(stmt *influxql.SelectStatement) ([]*groupInfo, error) { - v := &groupVisitor{} - influxql.Walk(v, stmt.Fields) - if v.err != nil { - return nil, v.err - } - - // Attempt to take the calls and variables and put them into groups. - if len(v.refs) > 0 { - // If any of the calls are not selectors, we have an error message. - for _, fn := range v.calls { - if !influxql.IsSelector(fn.call) { - return nil, errors.New("mixing aggregate and non-aggregate queries is not supported") - } - } - - // All of the functions are selectors. If we have more than 1, then we have another error message. - if len(v.calls) > 1 { - return nil, errors.New("mixing multiple selector functions with tags or fields is not supported") - } - - // Otherwise, we create a single group. - var call *influxql.Call - if len(v.calls) == 1 { - call = v.calls[0].call - } - return []*groupInfo{{ - call: call, - refs: v.refs, - }}, nil - } - - // We do not have any auxiliary fields so each of the function calls goes into - // its own group. - groups := make([]*groupInfo, 0, len(v.calls)) - for _, fn := range v.calls { - groups = append(groups, &groupInfo{call: fn.call}) - } - return groups, nil -} - -func (gr *groupInfo) createCursor(t *transpilerState) (cursor, error) { - // Create all of the cursors for every variable reference. - // TODO(jsternberg): Determine which of these cursors are from fields and which are tags. - var cursors []cursor - if gr.call != nil { - ref, ok := gr.call.Args[0].(*influxql.VarRef) - if !ok { - // TODO(jsternberg): This should be validated and figured out somewhere else. - return nil, fmt.Errorf("first argument to %q must be a variable", gr.call.Name) - } - cur, err := createVarRefCursor(t, ref) - if err != nil { - return nil, err - } - cursors = append(cursors, cur) - } - - for _, ref := range gr.refs { - cur, err := createVarRefCursor(t, ref) - if err != nil { - return nil, err - } - cursors = append(cursors, cur) - } - - // TODO(jsternberg): Establish which variables in the condition are tags and which are fields. - // We need to create the references to fields here so they can be joined. - var ( - tags map[influxql.VarRef]struct{} - cond influxql.Expr - ) - valuer := influxql.NowValuer{Now: t.spec.Now} - if t.stmt.Condition != nil { - var err error - if cond, _, err = influxql.ConditionExpr(t.stmt.Condition, &valuer); err != nil { - return nil, err - } else if cond != nil { - tags = make(map[influxql.VarRef]struct{}) - - // Walk through the condition for every variable reference. There will be no function - // calls here. - var condErr error - influxql.WalkFunc(cond, func(node influxql.Node) { - if condErr != nil { - return - } - ref, ok := node.(*influxql.VarRef) - if !ok { - return - } - - // If the variable reference is in any of the cursors, it is definitely - // a field and we do not have to inspect it further. - for _, cur := range cursors { - if _, ok := cur.Value(ref); ok { - return - } - } - - // This may be a field or a tag. If it is a field, we need to create the cursor - // and add it to the listing of cursors so it can be joined before we evaluate the condition. - switch typ := t.mapType(ref); typ { - case influxql.Tag: - // Add this variable name to the listing of tags. - tags[*ref] = struct{}{} - default: - cur, err := createVarRefCursor(t, ref) - if err != nil { - condErr = err - return - } - cursors = append(cursors, cur) - } - }) - } - } - - // Join the cursors using an inner join. - // TODO(jsternberg): We need to differentiate between various join types and this needs to be - // except: ["_field"] rather than joining on the _measurement. This also needs to specify what the time - // column should be. - if len(cursors) > 1 { - return nil, errors.New("unimplemented: joining fields within a cursor") - } - - cur := Join(t, cursors, []string{"_measurement"}, nil) - if len(tags) > 0 { - cur = &tagsCursor{cursor: cur, tags: tags} - } - - // Evaluate the conditional and insert a filter if a condition exists. - if cond != nil { - // Generate a filter expression by evaluating the condition and wrapping it in a filter op. - expr, err := t.mapField(cond, cur) - if err != nil { - return nil, errors.Wrap(err, "unable to evaluate condition") - } - id := t.op("filter", &functions.FilterOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{{ - Key: &semantic.Identifier{Name: "r"}, - }}, - Body: expr, - }, - }, cur.ID()) - cur = &opCursor{id: id, cursor: cur} - } - - // Group together the results. - if c, err := gr.group(t, cur); err != nil { - return nil, err - } else { - cur = c - } - - interval, err := t.stmt.GroupByInterval() - if err != nil { - return nil, err - } - - // If a function call is present, evaluate the function call. - if gr.call != nil { - c, err := createFunctionCursor(t, gr.call, cur) - if err != nil { - return nil, err - } - cur = c - - // If there was a window operation, we now need to undo that and sort by the start column - // so they stay in the same table and are joined in the correct order. - if interval > 0 { - cur = &groupCursor{ - id: t.op("window", &functions.WindowOpSpec{ - Every: query.Duration(math.MaxInt64), - Period: query.Duration(math.MaxInt64), - TimeCol: execute.DefaultTimeColLabel, - StartColLabel: execute.DefaultStartColLabel, - StopColLabel: execute.DefaultStopColLabel, - }, cur.ID()), - cursor: cur, - } - } - } else { - // If we do not have a function, but we have a field option, - // return the appropriate error message if there is something wrong with the query. - if interval > 0 { - return nil, errors.New("GROUP BY requires at least one aggregate function") - } - - // TODO(jsternberg): Fill needs to be somewhere and it's probably here somewhere. - // Move this to the correct location once we've figured it out. - switch t.stmt.Fill { - case influxql.NoFill: - return nil, errors.New("fill(none) must be used with a function") - case influxql.LinearFill: - return nil, errors.New("fill(linear) must be used with a function") - } - } - return cur, nil -} - -type groupCursor struct { - cursor - id query.OperationID -} - -func (gr *groupInfo) group(t *transpilerState, in cursor) (cursor, error) { - var windowEvery time.Duration - var windowStart time.Time - tags := []string{"_measurement", "_start"} - if len(t.stmt.Dimensions) > 0 { - // Maintain a set of the dimensions we have encountered. - // This is so we don't duplicate groupings, but we still maintain the - // listing of tags in the tags slice so it is deterministic. - m := make(map[string]struct{}) - for _, d := range t.stmt.Dimensions { - // Reduce the expression before attempting anything. Do not evaluate the call. - expr := influxql.Reduce(d.Expr, nil) - - switch expr := expr.(type) { - case *influxql.VarRef: - if strings.ToLower(expr.Val) == "time" { - return nil, errors.New("time() is a function and expects at least one argument") - } else if _, ok := m[expr.Val]; ok { - continue - } - tags = append(tags, expr.Val) - m[expr.Val] = struct{}{} - case *influxql.Call: - // Ensure the call is time() and it has one or two duration arguments. - if expr.Name != "time" { - return nil, errors.New("only time() calls allowed in dimensions") - } else if got := len(expr.Args); got < 1 || got > 2 { - return nil, errors.New("time dimension expected 1 or 2 arguments") - } else if lit, ok := expr.Args[0].(*influxql.DurationLiteral); !ok { - return nil, errors.New("time dimension must have duration argument") - } else if windowEvery != 0 { - return nil, errors.New("multiple time dimensions not allowed") - } else { - windowEvery = lit.Val - var windowOffset time.Duration - if len(expr.Args) == 2 { - switch lit2 := expr.Args[1].(type) { - case *influxql.DurationLiteral: - windowOffset = lit2.Val % windowEvery - case *influxql.TimeLiteral: - windowOffset = lit2.Val.Sub(lit2.Val.Truncate(windowEvery)) - case *influxql.Call: - if lit2.Name != "now" { - return nil, errors.New("time dimension offset function must be now()") - } else if len(lit2.Args) != 0 { - return nil, errors.New("time dimension offset now() function requires no arguments") - } - now := t.spec.Now - windowOffset = now.Sub(now.Truncate(windowEvery)) - - // Use the evaluated offset to replace the argument. Ideally, we would - // use the interval assigned above, but the query engine hasn't been changed - // to use the compiler information yet. - expr.Args[1] = &influxql.DurationLiteral{Val: windowOffset} - case *influxql.StringLiteral: - // If literal looks like a date time then parse it as a time literal. - if lit2.IsTimeLiteral() { - t, err := lit2.ToTimeLiteral(t.stmt.Location) - if err != nil { - return nil, err - } - windowOffset = t.Val.Sub(t.Val.Truncate(windowEvery)) - } else { - return nil, errors.New("time dimension offset must be duration or now()") - } - default: - return nil, errors.New("time dimension offset must be duration or now()") - } - - //TODO set windowStart - windowStart = time.Unix(0, 0).Add(windowOffset) - } - } - case *influxql.Wildcard: - return nil, errors.New("unimplemented: dimension wildcards") - case *influxql.RegexLiteral: - return nil, errors.New("unimplemented: dimension regex wildcards") - default: - return nil, errors.New("only time and tag dimensions allowed") - } - } - } - - // Perform the grouping by the tags we found. There is always a group by because - // there is always something to group in influxql. - // TODO(jsternberg): A wildcard will skip this step. - id := t.op("group", &functions.GroupOpSpec{ - By: tags, - }, in.ID()) - - if windowEvery > 0 { - windowOp := &functions.WindowOpSpec{ - Every: query.Duration(windowEvery), - Period: query.Duration(windowEvery), - TimeCol: execute.DefaultTimeColLabel, - StartColLabel: execute.DefaultStartColLabel, - StopColLabel: execute.DefaultStopColLabel, - } - - if !windowStart.IsZero() { - windowOp.Start = query.Time{Absolute: windowStart} - } - - id = t.op("window", windowOp, id) - } - - return &groupCursor{id: id, cursor: in}, nil -} - -func (c *groupCursor) ID() query.OperationID { return c.id } - -// tagsCursor is a pseudo-cursor that can be used to access tags within the cursor. -type tagsCursor struct { - cursor - tags map[influxql.VarRef]struct{} -} - -func (c *tagsCursor) Value(expr influxql.Expr) (string, bool) { - if value, ok := c.cursor.Value(expr); ok { - return value, ok - } - - if ref, ok := expr.(*influxql.VarRef); ok { - if _, ok := c.tags[*ref]; ok { - return ref.Val, true - } - } - return "", false -} diff --git a/influxql/join.go b/influxql/join.go deleted file mode 100644 index b43d27961f..0000000000 --- a/influxql/join.go +++ /dev/null @@ -1,94 +0,0 @@ -package influxql - -import ( - "fmt" - - "github.com/influxdata/influxql" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/semantic" -) - -type joinCursor struct { - id query.OperationID - m map[influxql.Expr]string - exprs []influxql.Expr -} - -func Join(t *transpilerState, cursors []cursor, on, except []string) cursor { - if len(cursors) == 1 { - return cursors[0] - } - - // Iterate through each cursor and each expression within each cursor to assign them an id. - var ( - exprs []influxql.Expr - properties []*semantic.Property - ) - m := make(map[influxql.Expr]string) - tables := make(map[query.OperationID]string) - for i, cur := range cursors { - // Record this incoming cursor within the table. - tableName := fmt.Sprintf("t%d", i) - tables[cur.ID()] = tableName - - for _, k := range cur.Keys() { - // Generate a name for accessing this expression and generate the index entries for it. - name := fmt.Sprintf("val%d", len(exprs)) - exprs = append(exprs, k) - m[k] = name - - property := &semantic.Property{ - Key: &semantic.Identifier{Name: name}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "tables", - }, - Property: tableName, - }, - } - if valName, _ := cur.Value(k); valName != execute.DefaultValueColLabel { - property.Value = &semantic.MemberExpression{ - Object: property.Value, - Property: valName, - } - } - properties = append(properties, property) - } - } - - // Retrieve the parent ids from the cursors. - parents := make([]query.OperationID, 0, len(tables)) - for _, cur := range cursors { - parents = append(parents, cur.ID()) - } - id := t.op("join", &functions.JoinOpSpec{ - TableNames: tables, - On: on, - // TODO(jsternberg): This option needs to be included. - //Except: except, - }, parents...) - return &joinCursor{ - id: id, - m: m, - exprs: exprs, - } -} - -func (c *joinCursor) ID() query.OperationID { - return c.id -} - -func (c *joinCursor) Keys() []influxql.Expr { - keys := make([]influxql.Expr, 0, len(c.m)) - for k := range c.m { - keys = append(keys, k) - } - return keys -} - -func (c *joinCursor) Value(expr influxql.Expr) (string, bool) { - value, ok := c.m[expr] - return value, ok -} diff --git a/influxql/map.go b/influxql/map.go deleted file mode 100644 index bebde89d86..0000000000 --- a/influxql/map.go +++ /dev/null @@ -1,198 +0,0 @@ -package influxql - -import ( - "fmt" - "time" - - "github.com/influxdata/influxql" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/semantic" -) - -// mapCursor holds the mapping of expressions to specific fields that happens at the end of -// the transpilation. -// TODO(jsternberg): This abstraction might be useful for subqueries, but we only need the id -// at the moment so just hold that. -type mapCursor struct { - id query.OperationID -} - -func (c *mapCursor) ID() query.OperationID { - return c.id -} - -func (c *mapCursor) Keys() []influxql.Expr { - panic("unimplemented") -} - -func (c *mapCursor) Value(expr influxql.Expr) (string, bool) { - panic("unimplemented") -} - -// mapFields will take the list of symbols and maps each of the operations -// using the column names. -func (t *transpilerState) mapFields(in cursor) (cursor, error) { - columns := t.stmt.ColumnNames() - if len(columns) != len(t.stmt.Fields) { - // TODO(jsternberg): This scenario should not be possible. Replace the use of ColumnNames with a more - // statically verifiable list of columns when we process the fields from the select statement instead - // of doing this in the future. - panic("number of columns does not match the number of fields") - } - - properties := make([]*semantic.Property, 0, len(t.stmt.Fields)+1) - properties = append(properties, &semantic.Property{ - Key: &semantic.Identifier{Name: execute.DefaultTimeColLabel}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: execute.DefaultTimeColLabel, - }, - }) - for i, f := range t.stmt.Fields { - if ref, ok := f.Expr.(*influxql.VarRef); ok && ref.Val == "time" { - // Skip past any time columns. - continue - } - value, err := t.mapField(f.Expr, in) - if err != nil { - return nil, err - } - properties = append(properties, &semantic.Property{ - Key: &semantic.Identifier{Name: columns[i]}, - Value: value, - }) - } - id := t.op("map", &functions.MapOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{{ - Key: &semantic.Identifier{Name: "r"}, - }}, - Body: &semantic.ObjectExpression{ - Properties: properties, - }, - }, - MergeKey: true, - }, in.ID()) - return &mapCursor{id: id}, nil -} - -func (t *transpilerState) mapField(expr influxql.Expr, in cursor) (semantic.Expression, error) { - if sym, ok := in.Value(expr); ok { - return &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: sym, - }, nil - } - - switch expr := expr.(type) { - case *influxql.Call: - if isMathFunction(expr) { - return nil, fmt.Errorf("unimplemented math function: %q", expr.Name) - } - return nil, fmt.Errorf("missing symbol for %s", expr) - case *influxql.VarRef: - return nil, fmt.Errorf("missing symbol for %s", expr) - case *influxql.BinaryExpr: - return t.evalBinaryExpr(expr, in) - case *influxql.ParenExpr: - return t.mapField(expr.Expr, in) - case *influxql.StringLiteral: - if ts, err := expr.ToTimeLiteral(time.UTC); err == nil { - return &semantic.DateTimeLiteral{Value: ts.Val}, nil - } - return &semantic.StringLiteral{Value: expr.Val}, nil - case *influxql.NumberLiteral: - return &semantic.FloatLiteral{Value: expr.Val}, nil - case *influxql.IntegerLiteral: - return &semantic.IntegerLiteral{Value: expr.Val}, nil - case *influxql.BooleanLiteral: - return &semantic.BooleanLiteral{Value: expr.Val}, nil - case *influxql.DurationLiteral: - return &semantic.DurationLiteral{Value: expr.Val}, nil - case *influxql.TimeLiteral: - return &semantic.DateTimeLiteral{Value: expr.Val}, nil - case *influxql.RegexLiteral: - return &semantic.RegexpLiteral{Value: expr.Val}, nil - default: - // TODO(jsternberg): Handle the other expressions by turning them into - // an equivalent expression. - return nil, fmt.Errorf("unimplemented: %T", expr) - } -} - -func (t *transpilerState) evalBinaryExpr(expr *influxql.BinaryExpr, in cursor) (semantic.Expression, error) { - fn := func() func(left, right semantic.Expression) semantic.Expression { - b := evalBuilder{} - switch expr.Op { - case influxql.EQ: - return b.eval(ast.EqualOperator) - case influxql.NEQ: - return b.eval(ast.NotEqualOperator) - case influxql.GT: - return b.eval(ast.GreaterThanOperator) - case influxql.GTE: - return b.eval(ast.GreaterThanEqualOperator) - case influxql.LT: - return b.eval(ast.LessThanOperator) - case influxql.LTE: - return b.eval(ast.LessThanEqualOperator) - case influxql.ADD: - return b.eval(ast.AdditionOperator) - case influxql.SUB: - return b.eval(ast.SubtractionOperator) - case influxql.AND: - return b.logical(ast.AndOperator) - case influxql.OR: - return b.logical(ast.OrOperator) - case influxql.EQREGEX: - return b.eval(ast.RegexpMatchOperator) - case influxql.NEQREGEX: - return b.eval(ast.NotRegexpMatchOperator) - default: - return nil - } - }() - if fn == nil { - return nil, fmt.Errorf("unimplemented binary expression: %s", expr.Op) - } - - lhs, err := t.mapField(expr.LHS, in) - if err != nil { - return nil, err - } - rhs, err := t.mapField(expr.RHS, in) - if err != nil { - return nil, err - } - return fn(lhs, rhs), nil -} - -// evalBuilder is used for namespacing the logical and eval wrapping functions. -type evalBuilder struct{} - -func (evalBuilder) logical(op ast.LogicalOperatorKind) func(left, right semantic.Expression) semantic.Expression { - return func(left, right semantic.Expression) semantic.Expression { - return &semantic.LogicalExpression{ - Operator: op, - Left: left, - Right: right, - } - } -} - -func (evalBuilder) eval(op ast.OperatorKind) func(left, right semantic.Expression) semantic.Expression { - return func(left, right semantic.Expression) semantic.Expression { - return &semantic.BinaryExpression{ - Operator: op, - Left: left, - Right: right, - } - } -} diff --git a/influxql/math.go b/influxql/math.go deleted file mode 100644 index d79e533deb..0000000000 --- a/influxql/math.go +++ /dev/null @@ -1,12 +0,0 @@ -package influxql - -import "github.com/influxdata/influxql" - -// isMathFunction returns true if the call is a math function. -func isMathFunction(expr *influxql.Call) bool { - switch expr.Name { - case "abs", "sin", "cos", "tan", "asin", "acos", "atan", "atan2", "exp", "log", "ln", "log2", "log10", "sqrt", "pow", "floor", "ceil", "round": - return true - } - return false -} diff --git a/influxql/response.go b/influxql/response.go deleted file mode 100644 index 5c45e582f5..0000000000 --- a/influxql/response.go +++ /dev/null @@ -1,44 +0,0 @@ -package influxql - -// all of this code is copied more or less verbatim from the influxdb repo. -// we copy instead of sharing because we want to prevent inadvertent breaking -// changes introduced by the transpiler vs the actual InfluxQL engine. -// By copying the code, we'll be able to detect more explicitly that the -// results generated by the transpiler diverge from InfluxQL. - -type Response struct { - Results []Result `json:"results,omitempty"` - Err string `json:"error,omitempty"` -} - -func (r *Response) error(err error) { - r.Results = nil - r.Err = err.Error() -} - -// Message represents a user-facing message to be included with the result. -type Message struct { - Level string `json:"level"` - Text string `json:"text"` -} - -// Result represents a resultset returned from a single statement. -// Rows represents a list of rows that can be sorted consistently by name/tag. -type Result struct { - // StatementID is just the statement's position in the query. It's used - // to combine statement results if they're being buffered in memory. - StatementID int `json:"statement_id"` - Series []*Row `json:"series,omitempty"` - Messages []*Message `json:"messages,omitempty"` - Partial bool `json:"partial,omitempty"` - Err string `json:"error,omitempty"` -} - -// Row represents a single row returned from the execution of a statement. -type Row struct { - Name string `json:"name,omitempty"` - Tags map[string]string `json:"tags,omitempty"` - Columns []string `json:"columns,omitempty"` - Values [][]interface{} `json:"values,omitempty"` - Partial bool `json:"partial,omitempty"` -} diff --git a/influxql/response_iterator.go b/influxql/response_iterator.go deleted file mode 100644 index f310eee431..0000000000 --- a/influxql/response_iterator.go +++ /dev/null @@ -1,361 +0,0 @@ -package influxql - -import ( - "fmt" - "sort" - "strconv" - "time" - - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/values" -) - -// responseIterator implements query.ResultIterator for a Response. -type responseIterator struct { - response *Response - resultIdx int -} - -// NewresponseIterator constructs a responseIterator from a query.ResultIterator. -func NewResponseIterator(r *Response) query.ResultIterator { - return &responseIterator{ - response: r, - } -} - -// More returns true if there are results left to iterate through. -// It is used to implement query.ResultIterator. -func (r *responseIterator) More() bool { - return r.resultIdx < len(r.response.Results) -} - -// Next retrieves the next query.Result. -// It is used to implement query.ResultIterator. -func (r *responseIterator) Next() query.Result { - res := r.response.Results[r.resultIdx] - r.resultIdx++ - return newQueryResult(&res) -} - -// Cancel is a noop. -// It is used to implement query.ResultIterator. -func (r *responseIterator) Cancel() {} - -// Err returns an error if the response contained an error. -// It is used to implement query.ResultIterator. -func (r *responseIterator) Err() error { - if r.response.Err != "" { - return fmt.Errorf(r.response.Err) - } - - return nil -} - -// seriesIterator is a simple wrapper for Result that implements query.Result and query.TableIterator. -type seriesIterator struct { - result *Result -} - -func newQueryResult(r *Result) *seriesIterator { - return &seriesIterator{ - result: r, - } -} - -// Name returns the results statement id. -// It is used to implement query.Result. -func (r *seriesIterator) Name() string { - return strconv.Itoa(r.result.StatementID) -} - -// Tables returns the original as a query.TableIterator. -// It is used to implement query.Result. -func (r *seriesIterator) Tables() query.TableIterator { - return r -} - -// Do iterates through the series of a Result. -// It is used to implement query.TableIterator. -func (r *seriesIterator) Do(f func(query.Table) error) error { - for _, row := range r.result.Series { - t, err := newQueryTable(row) - if err != nil { - return err - } - if err := f(t); err != nil { - return err - } - } - - return nil -} - -// queryTable implements query.Table and query.ColReader. -type queryTable struct { - row *Row - groupKey query.GroupKey - colMeta []query.ColMeta - cols []interface{} -} - -func newQueryTable(r *Row) (*queryTable, error) { - t := &queryTable{ - row: r, - } - if err := t.translateRowsToColumns(); err != nil { - return nil, err - } - return t, nil -} - -// Data in a column is laid out in the following way: -// [ r.row.Columns... , r.tagKeys()... , r.row.Name ] -func (t *queryTable) translateRowsToColumns() error { - cols := t.Cols() - t.cols = make([]interface{}, len(cols)) - for i, col := range cols { - switch col.Type { - case query.TFloat: - t.cols[i] = make([]float64, 0, t.Len()) - case query.TInt: - t.cols[i] = make([]int64, 0, t.Len()) - case query.TUInt: - t.cols[i] = make([]uint64, 0, t.Len()) - case query.TString: - t.cols[i] = make([]string, 0, t.Len()) - case query.TBool: - t.cols[i] = make([]bool, 0, t.Len()) - case query.TTime: - t.cols[i] = make([]values.Time, 0, t.Len()) - } - } - for _, els := range t.row.Values { - for i, el := range els { - col := cols[i] - switch col.Type { - case query.TFloat: - val, ok := el.(float64) - if !ok { - return fmt.Errorf("unsupported type %T found in column %s of type %s", val, col.Label, col.Type) - } - t.cols[i] = append(t.cols[i].([]float64), val) - case query.TInt: - val, ok := el.(int64) - if !ok { - return fmt.Errorf("unsupported type %T found in column %s of type %s", val, col.Label, col.Type) - } - t.cols[i] = append(t.cols[i].([]int64), val) - case query.TUInt: - val, ok := el.(uint64) - if !ok { - return fmt.Errorf("unsupported type %T found in column %s of type %s", val, col.Label, col.Type) - } - t.cols[i] = append(t.cols[i].([]uint64), val) - case query.TString: - val, ok := el.(string) - if !ok { - return fmt.Errorf("unsupported type %T found in column %s of type %s", val, col.Label, col.Type) - } - t.cols[i] = append(t.cols[i].([]string), val) - case query.TBool: - val, ok := el.(bool) - if !ok { - return fmt.Errorf("unsupported type %T found in column %s of type %s", val, col.Label, col.Type) - } - t.cols[i] = append(t.cols[i].([]bool), val) - case query.TTime: - switch val := el.(type) { - case int64: - t.cols[i] = append(t.cols[i].([]values.Time), values.Time(val)) - case float64: - t.cols[i] = append(t.cols[i].([]values.Time), values.Time(val)) - case string: - tm, err := time.Parse(time.RFC3339, val) - if err != nil { - return fmt.Errorf("could not parse string %q as time: %v", val, err) - } - t.cols[i] = append(t.cols[i].([]values.Time), values.ConvertTime(tm)) - default: - return fmt.Errorf("unsupported type %T found in column %s", val, col.Label) - } - default: - return fmt.Errorf("invalid type %T found in column %s", el, col.Label) - } - } - - j := len(t.row.Columns) - for j < len(t.row.Columns)+len(t.row.Tags) { - col := cols[j] - t.cols[j] = append(t.cols[j].([]string), t.row.Tags[col.Label]) - j++ - } - - t.cols[j] = append(t.cols[j].([]string), t.row.Name) - } - - return nil -} - -// Key constructs the query.GroupKey for a Row from the rows -// tags and measurement. -// It is used to implement query.Table and query.ColReader. -func (r *queryTable) Key() query.GroupKey { - if r.groupKey == nil { - cols := make([]query.ColMeta, len(r.row.Tags)+1) // plus one is for measurement - vs := make([]values.Value, len(r.row.Tags)+1) - kvs := make([]interface{}, len(r.row.Tags)+1) - colMeta := r.Cols() - labels := append(r.tagKeys(), "_measurement") - for j, label := range labels { - idx := execute.ColIdx(label, colMeta) - if idx < 0 { - panic(fmt.Errorf("table invalid: missing group column %q", label)) - } - cols[j] = colMeta[idx] - kvs[j] = "string" - v, err := values.NewValue(kvs[j], execute.ConvertToKind(cols[j].Type)) - if err != nil { - panic(err) - } - vs[j] = v - } - r.groupKey = execute.NewGroupKey(cols, vs) - } - - return r.groupKey -} - -// tags returns the tag keys for a Row. -func (r *queryTable) tagKeys() []string { - tags := []string{} - for t := range r.row.Tags { - tags = append(tags, t) - } - sort.Strings(tags) - return tags -} - -// Cols returns the columns for a row where the data is laid out in the following way: -// [ r.row.Columns... , r.tagKeys()... , r.row.Name ] -// It is used to implement query.Table and query.ColReader. -func (r *queryTable) Cols() []query.ColMeta { - if r.colMeta == nil { - colMeta := make([]query.ColMeta, len(r.row.Columns)+len(r.row.Tags)+1) - for i, col := range r.row.Columns { - colMeta[i] = query.ColMeta{ - Label: col, - Type: query.TInvalid, - } - if col == "time" { - // rename the time column - colMeta[i].Label = "_time" - colMeta[i].Type = query.TTime - } - } - - if len(r.row.Values) < 1 { - panic("must have at least one value") - } - data := r.row.Values[0] - for i := range r.row.Columns { - v := data[i] - if colMeta[i].Label == "_time" { - continue - } - switch v.(type) { - case float64: - colMeta[i].Type = query.TFloat - case int64: - colMeta[i].Type = query.TInt - case uint64: - colMeta[i].Type = query.TUInt - case bool: - colMeta[i].Type = query.TBool - case string: - colMeta[i].Type = query.TString - } - } - - tags := r.tagKeys() - - leng := len(r.row.Columns) - for i, tag := range tags { - colMeta[leng+i] = query.ColMeta{ - Label: tag, - Type: query.TString, - } - } - - leng = leng + len(tags) - colMeta[leng] = query.ColMeta{ - Label: "_measurement", - Type: query.TString, - } - r.colMeta = colMeta - } - - return r.colMeta -} - -// Do applies f to itself. This is because Row is a query.ColReader. -// It is used to implement query.Table. -func (r *queryTable) Do(f func(query.ColReader) error) error { - return f(r) -} - -// RefCount is a noop. -// It is used to implement query.ColReader. -func (r *queryTable) RefCount(n int) {} - -// Empty returns true if a Row has no values. -// It is used to implement query.Table. -func (r *queryTable) Empty() bool { return r.Len() == 0 } - -// Len returns the length or r.row.Values -// It is used to implement query.ColReader. -func (r *queryTable) Len() int { - return len(r.row.Values) -} - -// Bools returns the values in column index j as bools. -// It will panic if the column is not a []bool. -// It is used to implement query.ColReader. -func (r *queryTable) Bools(j int) []bool { - return r.cols[j].([]bool) -} - -// Ints returns the values in column index j as ints. -// It will panic if the column is not a []int64. -// It is used to implement query.ColReader. -func (r *queryTable) Ints(j int) []int64 { - return r.cols[j].([]int64) -} - -// UInts returns the values in column index j as ints. -// It will panic if the column is not a []uint64. -// It is used to implement query.ColReader. -func (r *queryTable) UInts(j int) []uint64 { - return r.cols[j].([]uint64) -} - -// Floats returns the values in column index j as floats. -// It will panic if the column is not a []float64. -// It is used to implement query.ColReader. -func (r *queryTable) Floats(j int) []float64 { - return r.cols[j].([]float64) -} - -// Strings returns the values in column index j as strings. -// It will panic if the column is not a []string. -// It is used to implement query.ColReader. -func (r *queryTable) Strings(j int) []string { - return r.cols[j].([]string) -} - -// Times returns the values in column index j as values.Times. -// It will panic if the column is not a []values.Time. -// It is used to implement query.ColReader. -func (r *queryTable) Times(j int) []values.Time { - return r.cols[j].([]values.Time) -} diff --git a/influxql/response_test.go b/influxql/response_test.go deleted file mode 100644 index 6d25dcdc3f..0000000000 --- a/influxql/response_test.go +++ /dev/null @@ -1,285 +0,0 @@ -package influxql_test - -import ( - "bytes" - "regexp" - "testing" - - "github.com/andreyvit/diff" - "github.com/google/go-cmp/cmp" - "github.com/influxdata/platform/query/csv" - "github.com/influxdata/platform/query/influxql" -) - -var crlfPattern = regexp.MustCompile(`\r?\n`) - -func toCRLF(data string) []byte { - return []byte(crlfPattern.ReplaceAllString(data, "\r\n")) -} - -func TestResponse_ResultIterator(t *testing.T) { - type testCase struct { - name string - encoded []byte - response *influxql.Response - err error - } - tests := []testCase{ - { - name: "single series", - encoded: toCRLF(`#datatype,string,long,dateTime:RFC3339,double,long,string,boolean,string,string,string -#group,false,false,false,false,false,false,false,true,true,true -#default,0,,,,,,,,, -,result,table,_time,usage_user,test,mystr,this,cpu,host,_measurement -,,0,2018-08-29T13:08:47Z,10.2,10,yay,true,cpu-total,a,cpu -,,0,2018-08-29T13:08:48Z,12.1,20,nay,false,cpu-total,a,cpu -,,0,2018-08-29T13:08:47Z,112,30,way,false,cpu-total,a,cpu -,,0,2018-08-29T13:08:48Z,123.2,40,pay,true,cpu-total,a,cpu - -`), - response: &influxql.Response{ - Results: []influxql.Result{ - { - StatementID: 0, - Series: []*influxql.Row{ - { - Name: "cpu", - Tags: map[string]string{ - "cpu": "cpu-total", - "host": "a", - }, - Columns: []string{"time", "usage_user", "test", "mystr", "this"}, - Values: [][]interface{}{ - {int64(1535548127000000000), 10.2, int64(10), "yay", true}, - {int64(1535548128000000000), 12.1, int64(20), "nay", false}, - {int64(1535548127000000000), 112.0, int64(30), "way", false}, - {int64(1535548128000000000), 123.2, int64(40), "pay", true}, - }, - }, - }, - }, - }, - }, - }, - { - name: "multiple series", - encoded: toCRLF(`#datatype,string,long,dateTime:RFC3339,double,long,string,string,string,string -#group,false,false,false,false,false,false,true,true,true -#default,0,,,,,,,, -,result,table,_time,usage_user,test,mystr,cpu,host,_measurement -,,0,2018-08-29T13:08:47Z,10.2,10,yay,cpu-total,a,cpu -,,0,2018-08-29T13:08:48Z,12.1,20,nay,cpu-total,a,cpu -,,0,2018-08-29T13:08:47Z,112,30,way,cpu-total,a,cpu -,,0,2018-08-29T13:08:48Z,123.2,40,pay,cpu-total,a,cpu -,,1,2018-08-29T18:27:31Z,10.2,10,yay,cpu-total,b,cpu -,,1,2018-08-29T18:27:31Z,12.1,20,nay,cpu-total,b,cpu -,,1,2018-08-29T18:27:31Z,112,30,way,cpu-total,b,cpu -,,1,2018-08-29T18:27:31Z,123.2,40,pay,cpu-total,b,cpu - -`), - response: &influxql.Response{ - Results: []influxql.Result{ - { - StatementID: 0, - Series: []*influxql.Row{ - { - Name: "cpu", - Tags: map[string]string{ - "cpu": "cpu-total", - "host": "a", - }, - Columns: []string{"time", "usage_user", "test", "mystr"}, - Values: [][]interface{}{ - {float64(1535548127000000000), 10.2, int64(10), "yay"}, - {float64(1535548128000000000), 12.1, int64(20), "nay"}, - {float64(1535548127000000000), 112.0, int64(30), "way"}, - {float64(1535548128000000000), 123.2, int64(40), "pay"}, - }, - }, - { - Name: "cpu", - Tags: map[string]string{ - "cpu": "cpu-total", - "host": "b", - }, - Columns: []string{"time", "usage_user", "test", "mystr"}, - Values: [][]interface{}{ - {"2018-08-29T18:27:31Z", 10.2, int64(10), "yay"}, - {"2018-08-29T18:27:31Z", 12.1, int64(20), "nay"}, - {"2018-08-29T18:27:31Z", 112.0, int64(30), "way"}, - {"2018-08-29T18:27:31Z", 123.2, int64(40), "pay"}, - }, - }, - }, - }, - }, - }, - }, - { - name: "multiple series with same columns but different types", - encoded: toCRLF(`#datatype,string,long,dateTime:RFC3339,double,long,string,string,string,string -#group,false,false,false,false,false,false,true,true,true -#default,0,,,,,,,, -,result,table,_time,usage_user,test,mystr,cpu,host,_measurement -,,0,2018-08-29T13:08:47Z,10.2,1,yay,cpu-total,a,cpu -,,0,2018-08-29T13:08:48Z,12.1,2,nay,cpu-total,a,cpu -,,0,2018-08-29T13:08:47Z,112,3,way,cpu-total,a,cpu -,,0,2018-08-29T13:08:48Z,123.2,4,pay,cpu-total,a,cpu - -#datatype,string,long,dateTime:RFC3339,double,double,string,string,string,string -#group,false,false,false,false,false,false,true,true,true -#default,0,,,,,,,, -,result,table,_time,usage_user,test,mystr,cpu,host,_measurement -,,1,2018-08-29T13:08:47Z,10.2,10,yay,cpu-total,a,cpu -,,1,2018-08-29T13:08:48Z,12.1,20,nay,cpu-total,a,cpu -,,1,2018-08-29T13:08:47Z,112,30,way,cpu-total,a,cpu -,,1,2018-08-29T13:08:48Z,123.2,40,pay,cpu-total,a,cpu - -`), - response: &influxql.Response{ - Results: []influxql.Result{ - { - StatementID: 0, - Series: []*influxql.Row{ - { - Name: "cpu", - Tags: map[string]string{ - "cpu": "cpu-total", - "host": "a", - }, - Columns: []string{"time", "usage_user", "test", "mystr"}, - Values: [][]interface{}{ - {int64(1535548127000000000), 10.2, int64(1), "yay"}, - {int64(1535548128000000000), 12.1, int64(2), "nay"}, - {int64(1535548127000000000), 112.0, int64(3), "way"}, - {int64(1535548128000000000), 123.2, int64(4), "pay"}, - }, - }, - { - Name: "cpu", - Tags: map[string]string{ - "cpu": "cpu-total", - "host": "a", - }, - Columns: []string{"time", "usage_user", "test", "mystr"}, - Values: [][]interface{}{ - {int64(1535548127000000000), 10.2, float64(10), "yay"}, - {int64(1535548128000000000), 12.1, float64(20), "nay"}, - {int64(1535548127000000000), 112.0, float64(30), "way"}, - {int64(1535548128000000000), 123.2, float64(40), "pay"}, - }, - }, - }, - }, - }, - }, - }, - { - name: "multiple results", - encoded: toCRLF(`#datatype,string,long,dateTime:RFC3339,double,long,string,string,string,string -#group,false,false,false,false,false,false,true,true,true -#default,0,,,,,,,, -,result,table,_time,usage_user,test,mystr,cpu,host,_measurement -,,0,2018-08-29T13:08:47Z,10.2,10,yay,cpu-total,a,cpu -,,0,2018-08-29T13:08:48Z,12.1,20,nay,cpu-total,a,cpu -,,0,2018-08-29T13:08:47Z,112,30,way,cpu-total,a,cpu -,,0,2018-08-29T13:08:48Z,123.2,40,pay,cpu-total,a,cpu -,,1,2018-08-29T13:08:47Z,10.2,10,yay,cpu-total,b,cpu -,,1,2018-08-29T13:08:48Z,12.1,20,nay,cpu-total,b,cpu -,,1,2018-08-29T13:08:47Z,112,30,way,cpu-total,b,cpu -,,1,2018-08-29T13:08:48Z,123.2,40,pay,cpu-total,b,cpu - -#datatype,string,long,dateTime:RFC3339,double,long,string,string,string,string -#group,false,false,false,false,false,false,true,true,true -#default,1,,,,,,,, -,result,table,_time,usage_user,test,mystr,cpu,host,_measurement -,,0,2018-08-29T13:08:47Z,10.2,10,yay,cpu-total,a,cpu -,,0,2018-08-29T13:08:48Z,12.1,20,nay,cpu-total,a,cpu -,,0,2018-08-29T13:08:47Z,112,30,way,cpu-total,a,cpu -,,0,2018-08-29T13:08:48Z,123.2,40,pay,cpu-total,a,cpu - -`), - response: &influxql.Response{ - Results: []influxql.Result{ - { - StatementID: 0, - Series: []*influxql.Row{ - { - Name: "cpu", - Tags: map[string]string{ - "cpu": "cpu-total", - "host": "a", - }, - Columns: []string{"time", "usage_user", "test", "mystr"}, - Values: [][]interface{}{ - {int64(1535548127000000000), 10.2, int64(10), "yay"}, - {int64(1535548128000000000), 12.1, int64(20), "nay"}, - {int64(1535548127000000000), 112.0, int64(30), "way"}, - {int64(1535548128000000000), 123.2, int64(40), "pay"}, - }, - }, - { - Name: "cpu", - Tags: map[string]string{ - "cpu": "cpu-total", - "host": "b", - }, - Columns: []string{"time", "usage_user", "test", "mystr"}, - Values: [][]interface{}{ - {int64(1535548127000000000), 10.2, int64(10), "yay"}, - {int64(1535548128000000000), 12.1, int64(20), "nay"}, - {int64(1535548127000000000), 112.0, int64(30), "way"}, - {int64(1535548128000000000), 123.2, int64(40), "pay"}, - }, - }, - }, - }, - { - StatementID: 1, - Series: []*influxql.Row{ - { - Name: "cpu", - Tags: map[string]string{ - "cpu": "cpu-total", - "host": "a", - }, - Columns: []string{"time", "usage_user", "test", "mystr"}, - Values: [][]interface{}{ - {int64(1535548127000000000), 10.2, int64(10), "yay"}, - {int64(1535548128000000000), 12.1, int64(20), "nay"}, - {int64(1535548127000000000), 112.0, int64(30), "way"}, - {int64(1535548128000000000), 123.2, int64(40), "pay"}, - }, - }, - }, - }, - }, - }, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - encoderConfig := csv.DefaultEncoderConfig() - encoder := csv.NewMultiResultEncoder(encoderConfig) - var got bytes.Buffer - n, err := encoder.Encode(&got, influxql.NewResponseIterator(tt.response)) - if err != nil && tt.err != nil { - if err.Error() != tt.err.Error() { - t.Errorf("unexpected error want: %s\n got: %s\n", tt.err.Error(), err.Error()) - } - } else if err != nil { - t.Errorf("unexpected error want: none\n got: %s\n", err.Error()) - } else if tt.err != nil { - t.Errorf("unexpected error want: %s\n got: none", tt.err.Error()) - } - - if g, w := got.String(), string(tt.encoded); g != w { - t.Errorf("unexpected encoding -want/+got:\n%s", diff.LineDiff(w, g)) - } - if g, w := n, int64(len(tt.encoded)); g != w { - t.Errorf("unexpected encoding count -want/+got:\n%s", cmp.Diff(w, g)) - } - }) - } -} diff --git a/influxql/result.go b/influxql/result.go deleted file mode 100644 index cf7397c4aa..0000000000 --- a/influxql/result.go +++ /dev/null @@ -1,166 +0,0 @@ -package influxql - -import ( - "encoding/json" - "fmt" - "io" - "strconv" - "time" - - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/iocounter" -) - -// MultiResultEncoder encodes results as InfluxQL JSON format. -type MultiResultEncoder struct{} - -// Encode writes a collection of results to the influxdb 1.X http response format. -// Expectations/Assumptions: -// 1. Each result will be published as a 'statement' in the top-level list of results. The result name -// will be interpreted as an integer and used as the statement id. -// 2. If the _measurement name is present in the group key, it will be used as the result name instead -// of as a normal tag. -// 3. All columns in the group key must be strings and they will be used as tags. There is no current way -// to have a tag and field be the same name in the results. -// TODO(jsternberg): For full compatibility, the above must be possible. -// 4. All other columns are fields and will be output in the order they are found. -// TODO(jsternberg): This function currently requires the first column to be a time field, but this isn't -// a strict requirement and will be lifted when we begin to work on transpiling meta queries. -func (e *MultiResultEncoder) Encode(w io.Writer, results query.ResultIterator) (int64, error) { - resp := Response{} - wc := &iocounter.Writer{Writer: w} - - for results.More() { - res := results.Next() - name := res.Name() - id, err := strconv.Atoi(name) - if err != nil { - resp.error(fmt.Errorf("unable to parse statement id from result name: %s", err)) - results.Cancel() - break - } - - tables := res.Tables() - - result := Result{StatementID: id} - if err := tables.Do(func(tbl query.Table) error { - var row Row - - for j, c := range tbl.Key().Cols() { - if c.Type != query.TString { - // Skip any columns that aren't strings. They are extra ones that - // flux includes by default like the start and end times that we do not - // care about. - continue - } - v := tbl.Key().Value(j).Str() - if c.Label == "_measurement" { - row.Name = v - } else if c.Label == "_field" { - // If the field key was not removed by a previous operation, we explicitly - // ignore it here when encoding the result back. - } else { - if row.Tags == nil { - row.Tags = make(map[string]string) - } - row.Tags[c.Label] = v - } - } - - // TODO: resultColMap should be constructed from query metadata once it is provided. - // for now we know that an influxql query ALWAYS has time first, so we put this placeholder - // here to catch this most obvious requirement. Column orderings should be explicitly determined - // from the ordering given in the original query. - resultColMap := map[string]int{} - j := 1 - for _, c := range tbl.Cols() { - if c.Label == execute.DefaultTimeColLabel { - resultColMap[c.Label] = 0 - } else if !tbl.Key().HasCol(c.Label) { - resultColMap[c.Label] = j - j++ - } - } - - row.Columns = make([]string, len(resultColMap)) - for k, v := range resultColMap { - if k == execute.DefaultTimeColLabel { - k = "time" - } - row.Columns[v] = k - } - - if err := tbl.Do(func(cr query.ColReader) error { - // Preallocate the number of rows for the response to make this section - // of code easier to read. Find a time column which should exist - // in the output. - values := make([][]interface{}, cr.Len()) - for j := range values { - values[j] = make([]interface{}, len(row.Columns)) - } - - j := 0 - for idx, c := range tbl.Cols() { - if cr.Key().HasCol(c.Label) { - continue - } - - j = resultColMap[c.Label] - // Fill in the values for each column. - switch c.Type { - case query.TFloat: - for i, v := range cr.Floats(idx) { - values[i][j] = v - } - case query.TInt: - for i, v := range cr.Ints(idx) { - values[i][j] = v - } - case query.TString: - for i, v := range cr.Strings(idx) { - values[i][j] = v - } - case query.TUInt: - for i, v := range cr.UInts(idx) { - values[i][j] = v - } - case query.TBool: - for i, v := range cr.Bools(idx) { - values[i][j] = v - } - case query.TTime: - for i, v := range cr.Times(idx) { - values[i][j] = v.Time().Format(time.RFC3339) - } - default: - return fmt.Errorf("unsupported column type: %s", c.Type) - } - - } - row.Values = append(row.Values, values...) - return nil - }); err != nil { - return err - } - - result.Series = append(result.Series, &row) - return nil - }); err != nil { - resp.error(err) - results.Cancel() - break - } - resp.Results = append(resp.Results, result) - } - - if err := results.Err(); err != nil && resp.Err == "" { - resp.error(err) - } - - err := json.NewEncoder(wc).Encode(resp) - return wc.Count(), err -} -func NewMultiResultEncoder() *MultiResultEncoder { - return new(MultiResultEncoder) -} diff --git a/influxql/result_test.go b/influxql/result_test.go deleted file mode 100644 index 7ad157c167..0000000000 --- a/influxql/result_test.go +++ /dev/null @@ -1,95 +0,0 @@ -package influxql_test - -import ( - "bytes" - "errors" - "testing" - - "time" - - "github.com/google/go-cmp/cmp" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/execute/executetest" - "github.com/influxdata/platform/query/influxql" -) - -func TestMultiResultEncoder_Encode(t *testing.T) { - for _, tt := range []struct { - name string - in query.ResultIterator - out string - }{ - { - name: "Default", - in: query.NewSliceResultIterator( - []query.Result{&executetest.Result{ - Nm: "0", - Tbls: []*executetest.Table{{ - KeyCols: []string{"_measurement", "host"}, - ColMeta: []query.ColMeta{ - {Label: "_time", Type: query.TTime}, - {Label: "_measurement", Type: query.TString}, - {Label: "host", Type: query.TString}, - {Label: "value", Type: query.TFloat}, - }, - Data: [][]interface{}{ - {ts("2018-05-24T09:00:00Z"), "m0", "server01", float64(2)}, - }, - }}, - }}, - ), - out: `{"results":[{"statement_id":0,"series":[{"name":"m0","tags":{"host":"server01"},"columns":["time","value"],"values":[["2018-05-24T09:00:00Z",2]]}]}]}`, - }, - { - name: "Error", - in: &resultErrorIterator{Error: "expected"}, - out: `{"error":"expected"}`, - }, - } { - tt := tt - t.Run(tt.name, func(t *testing.T) { - // Add expected newline to end of output - tt.out += "\n" - - var buf bytes.Buffer - enc := influxql.NewMultiResultEncoder() - n, err := enc.Encode(&buf, tt.in) - if err != nil { - t.Fatalf("unexpected error: %s", err) - } - - if got, exp := buf.String(), tt.out; got != exp { - t.Fatalf("unexpected output:\nexp=%s\ngot=%s", exp, got) - } - if g, w := n, int64(len(tt.out)); g != w { - t.Errorf("unexpected encoding count -want/+got:\n%s", cmp.Diff(w, g)) - } - }) - } -} - -type resultErrorIterator struct { - Error string -} - -func (*resultErrorIterator) Cancel() {} -func (*resultErrorIterator) More() bool { return false } -func (*resultErrorIterator) Next() query.Result { panic("no results") } - -func (ri *resultErrorIterator) Err() error { - return errors.New(ri.Error) -} - -func mustParseTime(s string) time.Time { - t, err := time.Parse(time.RFC3339, s) - if err != nil { - panic(err) - } - return t -} - -// ts takes an RFC3339 time string and returns an execute.Time from it using the unix timestamp. -func ts(s string) execute.Time { - return execute.Time(mustParseTime(s).UnixNano()) -} diff --git a/influxql/spectests/aggregates.go b/influxql/spectests/aggregates.go deleted file mode 100644 index 31dc8636d1..0000000000 --- a/influxql/spectests/aggregates.go +++ /dev/null @@ -1,170 +0,0 @@ -package spectests - -import ( - "fmt" - "path/filepath" - "runtime" - "time" - - "github.com/influxdata/influxql" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/semantic" -) - -var aggregateCreateFuncs = []func(config execute.AggregateConfig) query.OperationSpec{ - func(config execute.AggregateConfig) query.OperationSpec { - return &functions.CountOpSpec{AggregateConfig: config} - }, - func(config execute.AggregateConfig) query.OperationSpec { - return &functions.MeanOpSpec{AggregateConfig: config} - }, - func(config execute.AggregateConfig) query.OperationSpec { - return &functions.SumOpSpec{AggregateConfig: config} - }, -} - -func AggregateTest(fn func(aggregate query.Operation) (string, *query.Spec)) Fixture { - _, file, line, _ := runtime.Caller(1) - fixture := &collection{ - file: filepath.Base(file), - line: line, - } - - for _, aggregateSpecFn := range aggregateCreateFuncs { - spec := aggregateSpecFn(execute.AggregateConfig{ - TimeSrc: execute.DefaultStartColLabel, - TimeDst: execute.DefaultTimeColLabel, - Columns: []string{execute.DefaultValueColLabel}, - }) - op := query.Operation{ - ID: query.OperationID(fmt.Sprintf("%s0", spec.Kind())), - Spec: spec, - } - - fixture.Add(fn(op)) - } - return fixture -} - -func init() { - RegisterFixture( - AggregateTest(func(aggregate query.Operation) (stmt string, spec *query.Spec) { - return fmt.Sprintf(`SELECT %s(value) FROM db0..cpu`, aggregate.Spec.Kind()), - &query.Spec{ - Operations: []*query.Operation{ - { - ID: "from0", - Spec: &functions.FromOpSpec{ - BucketID: bucketID, - }, - }, - { - ID: "range0", - Spec: &functions.RangeOpSpec{ - Start: query.Time{Absolute: time.Unix(0, influxql.MinTime)}, - Stop: query.Time{Absolute: time.Unix(0, influxql.MaxTime)}, - TimeCol: execute.DefaultTimeColLabel, - StartCol: execute.DefaultStartColLabel, - StopCol: execute.DefaultStopColLabel, - }, - }, - { - ID: "filter0", - Spec: &functions.FilterOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{ - {Key: &semantic.Identifier{Name: "r"}}, - }, - Body: &semantic.LogicalExpression{ - Operator: ast.AndOperator, - Left: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_measurement", - }, - Right: &semantic.StringLiteral{ - Value: "cpu", - }, - }, - Right: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_field", - }, - Right: &semantic.StringLiteral{ - Value: "value", - }, - }, - }, - }, - }, - }, - { - ID: "group0", - Spec: &functions.GroupOpSpec{ - By: []string{"_measurement", "_start"}, - }, - }, - &aggregate, - { - ID: "map0", - Spec: &functions.MapOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{{ - Key: &semantic.Identifier{Name: "r"}, - }}, - Body: &semantic.ObjectExpression{ - Properties: []*semantic.Property{ - { - Key: &semantic.Identifier{Name: "_time"}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_time", - }, - }, - { - Key: &semantic.Identifier{Name: string(aggregate.Spec.Kind())}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_value", - }, - }, - }, - }, - }, - MergeKey: true, - }, - }, - { - ID: "yield0", - Spec: &functions.YieldOpSpec{ - Name: "0", - }, - }, - }, - Edges: []query.Edge{ - {Parent: "from0", Child: "range0"}, - {Parent: "range0", Child: "filter0"}, - {Parent: "filter0", Child: "group0"}, - {Parent: "group0", Child: aggregate.ID}, - {Parent: aggregate.ID, Child: "map0"}, - {Parent: "map0", Child: "yield0"}, - }, - Now: Now(), - } - }), - ) -} diff --git a/influxql/spectests/aggregates_with_condition.go b/influxql/spectests/aggregates_with_condition.go deleted file mode 100644 index 03441f0d9b..0000000000 --- a/influxql/spectests/aggregates_with_condition.go +++ /dev/null @@ -1,156 +0,0 @@ -package spectests - -import ( - "fmt" - "time" - - "github.com/influxdata/influxql" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/semantic" -) - -func init() { - RegisterFixture( - AggregateTest(func(aggregate query.Operation) (stmt string, spec *query.Spec) { - return fmt.Sprintf(`SELECT %s(value) FROM db0..cpu WHERE host = 'server01'`, aggregate.Spec.Kind()), - &query.Spec{ - Operations: []*query.Operation{ - { - ID: "from0", - Spec: &functions.FromOpSpec{ - BucketID: bucketID, - }, - }, - { - ID: "range0", - Spec: &functions.RangeOpSpec{ - Start: query.Time{Absolute: time.Unix(0, influxql.MinTime)}, - Stop: query.Time{Absolute: time.Unix(0, influxql.MaxTime)}, - TimeCol: execute.DefaultTimeColLabel, - StartCol: execute.DefaultStartColLabel, - StopCol: execute.DefaultStopColLabel, - }, - }, - { - ID: "filter0", - Spec: &functions.FilterOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{ - {Key: &semantic.Identifier{Name: "r"}}, - }, - Body: &semantic.LogicalExpression{ - Operator: ast.AndOperator, - Left: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_measurement", - }, - Right: &semantic.StringLiteral{ - Value: "cpu", - }, - }, - Right: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_field", - }, - Right: &semantic.StringLiteral{ - Value: "value", - }, - }, - }, - }, - }, - }, - { - ID: "filter1", - Spec: &functions.FilterOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{ - {Key: &semantic.Identifier{Name: "r"}}, - }, - Body: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "host", - }, - Right: &semantic.StringLiteral{ - Value: "server01", - }, - }, - }, - }, - }, - { - ID: "group0", - Spec: &functions.GroupOpSpec{ - By: []string{"_measurement", "_start"}, - }, - }, - &aggregate, - { - ID: "map0", - Spec: &functions.MapOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{{ - Key: &semantic.Identifier{Name: "r"}, - }}, - Body: &semantic.ObjectExpression{ - Properties: []*semantic.Property{ - { - Key: &semantic.Identifier{Name: "_time"}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_time", - }, - }, - { - Key: &semantic.Identifier{Name: string(aggregate.Spec.Kind())}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_value", - }, - }, - }, - }, - }, - MergeKey: true, - }, - }, - { - ID: "yield0", - Spec: &functions.YieldOpSpec{ - Name: "0", - }, - }, - }, - Edges: []query.Edge{ - {Parent: "from0", Child: "range0"}, - {Parent: "range0", Child: "filter0"}, - {Parent: "filter0", Child: "filter1"}, - {Parent: "filter1", Child: "group0"}, - {Parent: "group0", Child: aggregate.ID}, - {Parent: aggregate.ID, Child: "map0"}, - {Parent: "map0", Child: "yield0"}, - }, - Now: Now(), - } - }), - ) -} diff --git a/influxql/spectests/aggregates_with_groupby.go b/influxql/spectests/aggregates_with_groupby.go deleted file mode 100644 index 1e6e808c73..0000000000 --- a/influxql/spectests/aggregates_with_groupby.go +++ /dev/null @@ -1,133 +0,0 @@ -package spectests - -import ( - "fmt" - "time" - - "github.com/influxdata/influxql" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/semantic" -) - -func init() { - RegisterFixture( - AggregateTest(func(aggregate query.Operation) (stmt string, spec *query.Spec) { - return fmt.Sprintf(`SELECT %s(value) FROM db0..cpu GROUP BY host`, aggregate.Spec.Kind()), - &query.Spec{ - Operations: []*query.Operation{ - { - ID: "from0", - Spec: &functions.FromOpSpec{ - BucketID: bucketID, - }, - }, - { - ID: "range0", - Spec: &functions.RangeOpSpec{ - Start: query.Time{Absolute: time.Unix(0, influxql.MinTime)}, - Stop: query.Time{Absolute: time.Unix(0, influxql.MaxTime)}, - TimeCol: execute.DefaultTimeColLabel, - StartCol: execute.DefaultStartColLabel, - StopCol: execute.DefaultStopColLabel, - }, - }, - { - ID: "filter0", - Spec: &functions.FilterOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{ - {Key: &semantic.Identifier{Name: "r"}}, - }, - Body: &semantic.LogicalExpression{ - Operator: ast.AndOperator, - Left: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_measurement", - }, - Right: &semantic.StringLiteral{ - Value: "cpu", - }, - }, - Right: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_field", - }, - Right: &semantic.StringLiteral{ - Value: "value", - }, - }, - }, - }, - }, - }, - { - ID: "group0", - Spec: &functions.GroupOpSpec{ - By: []string{"_measurement", "_start", "host"}, - }, - }, - &aggregate, - { - ID: "map0", - Spec: &functions.MapOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{{ - Key: &semantic.Identifier{Name: "r"}, - }}, - Body: &semantic.ObjectExpression{ - Properties: []*semantic.Property{ - { - Key: &semantic.Identifier{Name: "_time"}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_time", - }, - }, - { - Key: &semantic.Identifier{Name: string(aggregate.Spec.Kind())}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_value", - }, - }, - }, - }, - }, - MergeKey: true, - }, - }, - { - ID: "yield0", - Spec: &functions.YieldOpSpec{ - Name: "0", - }, - }, - }, - Edges: []query.Edge{ - {Parent: "from0", Child: "range0"}, - {Parent: "range0", Child: "filter0"}, - {Parent: "filter0", Child: "group0"}, - {Parent: "group0", Child: aggregate.ID}, - {Parent: aggregate.ID, Child: "map0"}, - {Parent: "map0", Child: "yield0"}, - }, - Now: Now(), - } - }), - ) -} diff --git a/influxql/spectests/aggregates_with_window.go b/influxql/spectests/aggregates_with_window.go deleted file mode 100644 index bde4d2d069..0000000000 --- a/influxql/spectests/aggregates_with_window.go +++ /dev/null @@ -1,155 +0,0 @@ -package spectests - -import ( - "fmt" - "math" - "time" - - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/semantic" -) - -func init() { - RegisterFixture( - AggregateTest(func(aggregate query.Operation) (stmt string, spec *query.Spec) { - return fmt.Sprintf(`SELECT %s(value) FROM db0..cpu WHERE time >= now() - 10m GROUP BY time(1m)`, aggregate.Spec.Kind()), - &query.Spec{ - Operations: []*query.Operation{ - { - ID: "from0", - Spec: &functions.FromOpSpec{ - BucketID: bucketID, - }, - }, - { - ID: "range0", - Spec: &functions.RangeOpSpec{ - Start: query.Time{Absolute: Now().Add(-10 * time.Minute)}, - Stop: query.Time{Absolute: Now()}, - TimeCol: execute.DefaultTimeColLabel, - StartCol: execute.DefaultStartColLabel, - StopCol: execute.DefaultStopColLabel, - }, - }, - { - ID: "filter0", - Spec: &functions.FilterOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{ - {Key: &semantic.Identifier{Name: "r"}}, - }, - Body: &semantic.LogicalExpression{ - Operator: ast.AndOperator, - Left: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_measurement", - }, - Right: &semantic.StringLiteral{ - Value: "cpu", - }, - }, - Right: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_field", - }, - Right: &semantic.StringLiteral{ - Value: "value", - }, - }, - }, - }, - }, - }, - { - ID: "group0", - Spec: &functions.GroupOpSpec{ - By: []string{"_measurement", "_start"}, - }, - }, - { - ID: "window0", - Spec: &functions.WindowOpSpec{ - Every: query.Duration(time.Minute), - Period: query.Duration(time.Minute), - TimeCol: execute.DefaultTimeColLabel, - StartColLabel: execute.DefaultStartColLabel, - StopColLabel: execute.DefaultStopColLabel, - }, - }, - &aggregate, - { - ID: "window1", - Spec: &functions.WindowOpSpec{ - Every: query.Duration(math.MaxInt64), - Period: query.Duration(math.MaxInt64), - TimeCol: execute.DefaultTimeColLabel, - StartColLabel: execute.DefaultStartColLabel, - StopColLabel: execute.DefaultStopColLabel, - }, - }, - { - ID: "map0", - Spec: &functions.MapOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{{ - Key: &semantic.Identifier{Name: "r"}, - }}, - Body: &semantic.ObjectExpression{ - Properties: []*semantic.Property{ - { - Key: &semantic.Identifier{Name: "_time"}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_time", - }, - }, - { - Key: &semantic.Identifier{Name: string(aggregate.Spec.Kind())}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_value", - }, - }, - }, - }, - }, - MergeKey: true, - }, - }, - { - ID: "yield0", - Spec: &functions.YieldOpSpec{ - Name: "0", - }, - }, - }, - Edges: []query.Edge{ - {Parent: "from0", Child: "range0"}, - {Parent: "range0", Child: "filter0"}, - {Parent: "filter0", Child: "group0"}, - {Parent: "group0", Child: "window0"}, - {Parent: "window0", Child: aggregate.ID}, - {Parent: aggregate.ID, Child: "window1"}, - {Parent: "window1", Child: "map0"}, - {Parent: "map0", Child: "yield0"}, - }, - Now: Now(), - } - }), - ) -} diff --git a/influxql/spectests/aggregates_with_window_offset.go b/influxql/spectests/aggregates_with_window_offset.go deleted file mode 100644 index 67f8359402..0000000000 --- a/influxql/spectests/aggregates_with_window_offset.go +++ /dev/null @@ -1,156 +0,0 @@ -package spectests - -import ( - "fmt" - "math" - "time" - - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/semantic" -) - -func init() { - RegisterFixture( - AggregateTest(func(aggregate query.Operation) (stmt string, spec *query.Spec) { - return fmt.Sprintf(`SELECT %s(value) FROM db0..cpu WHERE time >= now() - 10m GROUP BY time(5m, 12m)`, aggregate.Spec.Kind()), - &query.Spec{ - Operations: []*query.Operation{ - { - ID: "from0", - Spec: &functions.FromOpSpec{ - BucketID: bucketID, - }, - }, - { - ID: "range0", - Spec: &functions.RangeOpSpec{ - Start: query.Time{Absolute: Now().Add(-10 * time.Minute)}, - Stop: query.Time{Absolute: Now()}, - TimeCol: execute.DefaultTimeColLabel, - StartCol: execute.DefaultStartColLabel, - StopCol: execute.DefaultStopColLabel, - }, - }, - { - ID: "filter0", - Spec: &functions.FilterOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{ - {Key: &semantic.Identifier{Name: "r"}}, - }, - Body: &semantic.LogicalExpression{ - Operator: ast.AndOperator, - Left: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_measurement", - }, - Right: &semantic.StringLiteral{ - Value: "cpu", - }, - }, - Right: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_field", - }, - Right: &semantic.StringLiteral{ - Value: "value", - }, - }, - }, - }, - }, - }, - { - ID: "group0", - Spec: &functions.GroupOpSpec{ - By: []string{"_measurement", "_start"}, - }, - }, - { - ID: "window0", - Spec: &functions.WindowOpSpec{ - Every: query.Duration(5 * time.Minute), - Period: query.Duration(5 * time.Minute), - Start: query.Time{Absolute: time.Unix(0, 0).Add(time.Minute * 2)}, - TimeCol: execute.DefaultTimeColLabel, - StartColLabel: execute.DefaultStartColLabel, - StopColLabel: execute.DefaultStopColLabel, - }, - }, - &aggregate, - { - ID: "window1", - Spec: &functions.WindowOpSpec{ - Every: query.Duration(math.MaxInt64), - Period: query.Duration(math.MaxInt64), - TimeCol: execute.DefaultTimeColLabel, - StartColLabel: execute.DefaultStartColLabel, - StopColLabel: execute.DefaultStopColLabel, - }, - }, - { - ID: "map0", - Spec: &functions.MapOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{{ - Key: &semantic.Identifier{Name: "r"}, - }}, - Body: &semantic.ObjectExpression{ - Properties: []*semantic.Property{ - { - Key: &semantic.Identifier{Name: "_time"}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_time", - }, - }, - { - Key: &semantic.Identifier{Name: string(aggregate.Spec.Kind())}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_value", - }, - }, - }, - }, - }, - MergeKey: true, - }, - }, - { - ID: "yield0", - Spec: &functions.YieldOpSpec{ - Name: "0", - }, - }, - }, - Edges: []query.Edge{ - {Parent: "from0", Child: "range0"}, - {Parent: "range0", Child: "filter0"}, - {Parent: "filter0", Child: "group0"}, - {Parent: "group0", Child: "window0"}, - {Parent: "window0", Child: aggregate.ID}, - {Parent: aggregate.ID, Child: "window1"}, - {Parent: "window1", Child: "map0"}, - {Parent: "map0", Child: "yield0"}, - }, - Now: Now(), - } - }), - ) -} diff --git a/influxql/spectests/doc.go b/influxql/spectests/doc.go deleted file mode 100644 index 86a9ded55c..0000000000 --- a/influxql/spectests/doc.go +++ /dev/null @@ -1,2 +0,0 @@ -// Package spectests the influxql transpiler specification tests. -package spectests diff --git a/influxql/spectests/math.go b/influxql/spectests/math.go deleted file mode 100644 index 32a7b4dd6f..0000000000 --- a/influxql/spectests/math.go +++ /dev/null @@ -1,208 +0,0 @@ -//+build todo - -package spectests - -import ( - "time" - - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/influxql" - "github.com/influxdata/platform/query/semantic" -) - -func init() { - RegisterFixture( - NewFixture( - `SELECT a + b FROM db0..cpu`, - &query.Spec{ - Operations: []*query.Operation{ - { - ID: "from0", - Spec: &functions.FromOpSpec{ - BucketID: bucketID, - }, - }, - { - ID: "range0", - Spec: &functions.RangeOpSpec{ - Start: query.Time{Absolute: time.Unix(0, influxql.MinTime)}, - Stop: query.Time{Absolute: time.Unix(0, influxql.MaxTime)}, - TimeCol: execute.DefaultTimeColLabel, - StartCol: execute.DefaultStartColLabel, - StopCol: execute.DefaultStopColLabel, - }, - }, - { - ID: "filter0", - Spec: &functions.FilterOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{ - {Key: &semantic.Identifier{Name: "r"}}, - }, - Body: &semantic.LogicalExpression{ - Operator: ast.AndOperator, - Left: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_measurement", - }, - Right: &semantic.StringLiteral{ - Value: "cpu", - }, - }, - Right: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_field", - }, - Right: &semantic.StringLiteral{ - Value: "a", - }, - }, - }, - }, - }, - }, - { - ID: "from1", - Spec: &functions.FromOpSpec{ - BucketID: bucketID, - }, - }, - { - ID: "range1", - Spec: &functions.RangeOpSpec{ - Start: query.Time{Absolute: time.Unix(0, influxql.MinTime)}, - Stop: query.Time{Absolute: time.Unix(0, influxql.MaxTime)}, - TimeCol: execute.DefaultTimeColLabel, - StartCol: execute.DefaultStartColLabel, - StopCol: execute.DefaultStopColLabel, - }, - }, - { - ID: "filter1", - Spec: &functions.FilterOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{ - {Key: &semantic.Identifier{Name: "r"}}, - }, - Body: &semantic.LogicalExpression{ - Operator: ast.AndOperator, - Left: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_measurement", - }, - Right: &semantic.StringLiteral{ - Value: "cpu", - }, - }, - Right: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_field", - }, - Right: &semantic.StringLiteral{ - Value: "b", - }, - }, - }, - }, - }, - }, - { - ID: "join0", - Spec: &functions.JoinOpSpec{ - On: []string{"_measurement"}, - TableNames: map[query.OperationID]string{ - "filter0": "t0", - "filter1": "t1", - }, - }, - }, - { - ID: "group0", - Spec: &functions.GroupOpSpec{ - By: []string{"_measurement", "_start"}, - }, - }, - { - ID: "map0", - Spec: &functions.MapOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{{ - Key: &semantic.Identifier{Name: "r"}, - }}, - Body: &semantic.ObjectExpression{ - Properties: []*semantic.Property{ - { - Key: &semantic.Identifier{Name: "_time"}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_time", - }, - }, - { - Key: &semantic.Identifier{Name: "a_b"}, - Value: &semantic.BinaryExpression{ - Operator: ast.AdditionOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "val0", - }, - Right: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "val1", - }, - }, - }, - }, - }, - }, - MergeKey: true, - }, - }, - { - ID: "yield0", - Spec: &functions.YieldOpSpec{ - Name: "0", - }, - }, - }, - Edges: []query.Edge{ - {Parent: "from0", Child: "range0"}, - {Parent: "range0", Child: "filter0"}, - {Parent: "from1", Child: "range1"}, - {Parent: "range1", Child: "filter1"}, - {Parent: "filter0", Child: "join0"}, - {Parent: "filter1", Child: "join0"}, - {Parent: "join0", Child: "group0"}, - {Parent: "group0", Child: "map0"}, - {Parent: "map0", Child: "yield0"}, - }, - Now: Now(), - }, - ), - ) -} diff --git a/influxql/spectests/multiple_aggregates.go b/influxql/spectests/multiple_aggregates.go deleted file mode 100644 index 6de5836da0..0000000000 --- a/influxql/spectests/multiple_aggregates.go +++ /dev/null @@ -1,235 +0,0 @@ -//+build todo - -package spectests - -import ( - "time" - - "github.com/influxdata/influxql" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/semantic" -) - -func init() { - RegisterFixture( - NewFixture( - `SELECT mean(value), max(value) FROM db0..cpu`, - &query.Spec{ - Operations: []*query.Operation{ - { - ID: "from0", - Spec: &functions.FromOpSpec{ - BucketID: bucketID, - }, - }, - { - ID: "range0", - Spec: &functions.RangeOpSpec{ - Start: query.Time{Absolute: time.Unix(0, influxql.MinTime)}, - Stop: query.Time{Absolute: time.Unix(0, influxql.MaxTime)}, - TimeCol: execute.DefaultTimeColLabel, - StartCol: execute.DefaultStartColLabel, - StopCol: execute.DefaultStopColLabel, - }, - }, - { - ID: "filter0", - Spec: &functions.FilterOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{ - {Key: &semantic.Identifier{Name: "r"}}, - }, - Body: &semantic.LogicalExpression{ - Operator: ast.AndOperator, - Left: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_measurement", - }, - Right: &semantic.StringLiteral{ - Value: "cpu", - }, - }, - Right: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_field", - }, - Right: &semantic.StringLiteral{ - Value: "value", - }, - }, - }, - }, - }, - }, - { - ID: "group0", - Spec: &functions.GroupOpSpec{ - By: []string{"_measurement", "_start"}, - }, - }, - { - ID: "mean0", - Spec: &functions.MeanOpSpec{ - AggregateConfig: execute.AggregateConfig{ - TimeSrc: execute.DefaultStartColLabel, - TimeDst: execute.DefaultTimeColLabel, - Columns: []string{execute.DefaultValueColLabel}, - }, - }, - }, - { - ID: "from1", - Spec: &functions.FromOpSpec{ - BucketID: bucketID, - }, - }, - { - ID: "range1", - Spec: &functions.RangeOpSpec{ - Start: query.Time{Absolute: time.Unix(0, influxql.MinTime)}, - Stop: query.Time{Absolute: time.Unix(0, influxql.MaxTime)}, - TimeCol: execute.DefaultTimeColLabel, - StartCol: execute.DefaultStartColLabel, - StopCol: execute.DefaultStopColLabel, - }, - }, - { - ID: "filter1", - Spec: &functions.FilterOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{ - {Key: &semantic.Identifier{Name: "r"}}, - }, - Body: &semantic.LogicalExpression{ - Operator: ast.AndOperator, - Left: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_measurement", - }, - Right: &semantic.StringLiteral{ - Value: "cpu", - }, - }, - Right: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_field", - }, - Right: &semantic.StringLiteral{ - Value: "value", - }, - }, - }, - }, - }, - }, - { - ID: "group1", - Spec: &functions.GroupOpSpec{ - By: []string{"_measurement", "_start"}, - }, - }, - { - ID: "max0", - Spec: &functions.MaxOpSpec{ - SelectorConfig: execute.SelectorConfig{ - Column: execute.DefaultValueColLabel, - }, - }, - }, - { - ID: "join0", - Spec: &functions.JoinOpSpec{ - On: []string{"_measurement"}, - TableNames: map[query.OperationID]string{ - "mean0": "t0", - "max0": "t1", - }, - }, - }, - { - ID: "map0", - Spec: &functions.MapOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{{ - Key: &semantic.Identifier{Name: "r"}, - }}, - Body: &semantic.ObjectExpression{ - Properties: []*semantic.Property{ - { - Key: &semantic.Identifier{Name: "_time"}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_time", - }, - }, - { - Key: &semantic.Identifier{Name: "mean"}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "val0", - }, - }, - { - Key: &semantic.Identifier{Name: "max"}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "val1", - }, - }, - }, - }, - }, - MergeKey: true, - }, - }, - { - ID: "yield0", - Spec: &functions.YieldOpSpec{ - Name: "0", - }, - }, - }, - Edges: []query.Edge{ - {Parent: "from0", Child: "range0"}, - {Parent: "range0", Child: "filter0"}, - {Parent: "filter0", Child: "group0"}, - {Parent: "group0", Child: "mean0"}, - {Parent: "from1", Child: "range1"}, - {Parent: "range1", Child: "filter1"}, - {Parent: "filter1", Child: "group1"}, - {Parent: "group1", Child: "max0"}, - {Parent: "mean0", Child: "join0"}, - {Parent: "max0", Child: "join0"}, - {Parent: "join0", Child: "map0"}, - {Parent: "map0", Child: "yield0"}, - }, - Now: Now(), - }, - ), - ) -} diff --git a/influxql/spectests/multiple_statements.go b/influxql/spectests/multiple_statements.go deleted file mode 100644 index 3412ab7354..0000000000 --- a/influxql/spectests/multiple_statements.go +++ /dev/null @@ -1,253 +0,0 @@ -package spectests - -import ( - "time" - - "github.com/influxdata/influxql" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/semantic" -) - -func init() { - RegisterFixture( - NewFixture( - `SELECT mean(value) FROM db0..cpu; SELECT max(value) FROM db0..cpu`, - &query.Spec{ - Operations: []*query.Operation{ - { - ID: "from0", - Spec: &functions.FromOpSpec{ - BucketID: bucketID, - }, - }, - { - ID: "range0", - Spec: &functions.RangeOpSpec{ - Start: query.Time{Absolute: time.Unix(0, influxql.MinTime)}, - Stop: query.Time{Absolute: time.Unix(0, influxql.MaxTime)}, - TimeCol: execute.DefaultTimeColLabel, - StartCol: execute.DefaultStartColLabel, - StopCol: execute.DefaultStopColLabel, - }, - }, - { - ID: "filter0", - Spec: &functions.FilterOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{ - {Key: &semantic.Identifier{Name: "r"}}, - }, - Body: &semantic.LogicalExpression{ - Operator: ast.AndOperator, - Left: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_measurement", - }, - Right: &semantic.StringLiteral{ - Value: "cpu", - }, - }, - Right: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_field", - }, - Right: &semantic.StringLiteral{ - Value: "value", - }, - }, - }, - }, - }, - }, - { - ID: "group0", - Spec: &functions.GroupOpSpec{ - By: []string{"_measurement", "_start"}, - }, - }, - { - ID: "mean0", - Spec: &functions.MeanOpSpec{ - AggregateConfig: execute.AggregateConfig{ - TimeSrc: execute.DefaultStartColLabel, - TimeDst: execute.DefaultTimeColLabel, - Columns: []string{execute.DefaultValueColLabel}, - }, - }, - }, - { - ID: "map0", - Spec: &functions.MapOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{{ - Key: &semantic.Identifier{Name: "r"}, - }}, - Body: &semantic.ObjectExpression{ - Properties: []*semantic.Property{ - { - Key: &semantic.Identifier{Name: "_time"}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_time", - }, - }, - { - Key: &semantic.Identifier{Name: "mean"}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_value", - }, - }, - }, - }, - }, - MergeKey: true, - }, - }, - { - ID: "yield0", - Spec: &functions.YieldOpSpec{ - Name: "0", - }, - }, - { - ID: "from1", - Spec: &functions.FromOpSpec{ - BucketID: bucketID, - }, - }, - { - ID: "range1", - Spec: &functions.RangeOpSpec{ - Start: query.Time{Absolute: time.Unix(0, influxql.MinTime)}, - Stop: query.Time{Absolute: time.Unix(0, influxql.MaxTime)}, - TimeCol: execute.DefaultTimeColLabel, - StartCol: execute.DefaultStartColLabel, - StopCol: execute.DefaultStopColLabel, - }, - }, - { - ID: "filter1", - Spec: &functions.FilterOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{ - {Key: &semantic.Identifier{Name: "r"}}, - }, - Body: &semantic.LogicalExpression{ - Operator: ast.AndOperator, - Left: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_measurement", - }, - Right: &semantic.StringLiteral{ - Value: "cpu", - }, - }, - Right: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_field", - }, - Right: &semantic.StringLiteral{ - Value: "value", - }, - }, - }, - }, - }, - }, - { - ID: "group1", - Spec: &functions.GroupOpSpec{ - By: []string{"_measurement", "_start"}, - }, - }, - { - ID: "max0", - Spec: &functions.MaxOpSpec{ - SelectorConfig: execute.SelectorConfig{ - Column: execute.DefaultValueColLabel, - }, - }, - }, - { - ID: "map1", - Spec: &functions.MapOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{{ - Key: &semantic.Identifier{Name: "r"}, - }}, - Body: &semantic.ObjectExpression{ - Properties: []*semantic.Property{ - { - Key: &semantic.Identifier{Name: "_time"}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_time", - }, - }, - { - Key: &semantic.Identifier{Name: "max"}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_value", - }, - }, - }, - }, - }, - MergeKey: true, - }, - }, - { - ID: "yield1", - Spec: &functions.YieldOpSpec{ - Name: "1", - }, - }, - }, - Edges: []query.Edge{ - {Parent: "from0", Child: "range0"}, - {Parent: "range0", Child: "filter0"}, - {Parent: "filter0", Child: "group0"}, - {Parent: "group0", Child: "mean0"}, - {Parent: "mean0", Child: "map0"}, - {Parent: "map0", Child: "yield0"}, - {Parent: "from1", Child: "range1"}, - {Parent: "range1", Child: "filter1"}, - {Parent: "filter1", Child: "group1"}, - {Parent: "group1", Child: "max0"}, - {Parent: "max0", Child: "map1"}, - {Parent: "map1", Child: "yield1"}, - }, - Now: Now(), - }, - ), - ) -} diff --git a/influxql/spectests/raw.go b/influxql/spectests/raw.go deleted file mode 100644 index 93362124c7..0000000000 --- a/influxql/spectests/raw.go +++ /dev/null @@ -1,130 +0,0 @@ -package spectests - -import ( - "time" - - "github.com/influxdata/influxql" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/semantic" -) - -func init() { - RegisterFixture( - NewFixture( - `SELECT value FROM db0..cpu`, - &query.Spec{ - Operations: []*query.Operation{ - { - ID: "from0", - Spec: &functions.FromOpSpec{ - BucketID: bucketID, - }, - }, - { - ID: "range0", - Spec: &functions.RangeOpSpec{ - Start: query.Time{Absolute: time.Unix(0, influxql.MinTime)}, - Stop: query.Time{Absolute: time.Unix(0, influxql.MaxTime)}, - TimeCol: execute.DefaultTimeColLabel, - StartCol: execute.DefaultStartColLabel, - StopCol: execute.DefaultStopColLabel, - }, - }, - { - ID: "filter0", - Spec: &functions.FilterOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{ - {Key: &semantic.Identifier{Name: "r"}}, - }, - Body: &semantic.LogicalExpression{ - Operator: ast.AndOperator, - Left: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_measurement", - }, - Right: &semantic.StringLiteral{ - Value: "cpu", - }, - }, - Right: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_field", - }, - Right: &semantic.StringLiteral{ - Value: "value", - }, - }, - }, - }, - }, - }, - { - ID: "group0", - Spec: &functions.GroupOpSpec{ - By: []string{"_measurement", "_start"}, - }, - }, - { - ID: "map0", - Spec: &functions.MapOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{{ - Key: &semantic.Identifier{Name: "r"}, - }}, - Body: &semantic.ObjectExpression{ - Properties: []*semantic.Property{ - { - Key: &semantic.Identifier{Name: "_time"}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_time", - }, - }, - { - Key: &semantic.Identifier{Name: "value"}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_value", - }, - }, - }, - }, - }, - MergeKey: true, - }, - }, - { - ID: "yield0", - Spec: &functions.YieldOpSpec{ - Name: "0", - }, - }, - }, - Edges: []query.Edge{ - {Parent: "from0", Child: "range0"}, - {Parent: "range0", Child: "filter0"}, - {Parent: "filter0", Child: "group0"}, - {Parent: "group0", Child: "map0"}, - {Parent: "map0", Child: "yield0"}, - }, - Now: Now(), - }, - ), - ) -} diff --git a/influxql/spectests/raw_with_condition.go b/influxql/spectests/raw_with_condition.go deleted file mode 100644 index 33e44a9172..0000000000 --- a/influxql/spectests/raw_with_condition.go +++ /dev/null @@ -1,153 +0,0 @@ -package spectests - -import ( - "time" - - "github.com/influxdata/influxql" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/semantic" -) - -func init() { - RegisterFixture( - NewFixture( - `SELECT value FROM db0..cpu WHERE host = 'server01'`, - &query.Spec{ - Operations: []*query.Operation{ - { - ID: "from0", - Spec: &functions.FromOpSpec{ - BucketID: bucketID, - }, - }, - { - ID: "range0", - Spec: &functions.RangeOpSpec{ - Start: query.Time{Absolute: time.Unix(0, influxql.MinTime)}, - Stop: query.Time{Absolute: time.Unix(0, influxql.MaxTime)}, - TimeCol: execute.DefaultTimeColLabel, - StartCol: execute.DefaultStartColLabel, - StopCol: execute.DefaultStopColLabel, - }, - }, - { - ID: "filter0", - Spec: &functions.FilterOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{ - {Key: &semantic.Identifier{Name: "r"}}, - }, - Body: &semantic.LogicalExpression{ - Operator: ast.AndOperator, - Left: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_measurement", - }, - Right: &semantic.StringLiteral{ - Value: "cpu", - }, - }, - Right: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_field", - }, - Right: &semantic.StringLiteral{ - Value: "value", - }, - }, - }, - }, - }, - }, - { - ID: "filter1", - Spec: &functions.FilterOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{ - {Key: &semantic.Identifier{Name: "r"}}, - }, - Body: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "host", - }, - Right: &semantic.StringLiteral{ - Value: "server01", - }, - }, - }, - }, - }, - { - ID: "group0", - Spec: &functions.GroupOpSpec{ - By: []string{"_measurement", "_start"}, - }, - }, - { - ID: "map0", - Spec: &functions.MapOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{{ - Key: &semantic.Identifier{Name: "r"}, - }}, - Body: &semantic.ObjectExpression{ - Properties: []*semantic.Property{ - { - Key: &semantic.Identifier{Name: "_time"}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_time", - }, - }, - { - Key: &semantic.Identifier{Name: "value"}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_value", - }, - }, - }, - }, - }, - MergeKey: true, - }, - }, - { - ID: "yield0", - Spec: &functions.YieldOpSpec{ - Name: "0", - }, - }, - }, - Edges: []query.Edge{ - {Parent: "from0", Child: "range0"}, - {Parent: "range0", Child: "filter0"}, - {Parent: "filter0", Child: "filter1"}, - {Parent: "filter1", Child: "group0"}, - {Parent: "group0", Child: "map0"}, - {Parent: "map0", Child: "yield0"}, - }, - Now: Now(), - }, - ), - ) -} diff --git a/influxql/spectests/raw_with_regex_condition.go b/influxql/spectests/raw_with_regex_condition.go deleted file mode 100644 index 3f887181b4..0000000000 --- a/influxql/spectests/raw_with_regex_condition.go +++ /dev/null @@ -1,293 +0,0 @@ -package spectests - -import ( - "regexp" - "time" - - "github.com/influxdata/influxql" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/semantic" -) - -func init() { - RegisterFixture( - NewFixture( - `SELECT value FROM db0..cpu WHERE host =~ /.*er01/`, - &query.Spec{ - Operations: []*query.Operation{ - { - ID: "from0", - Spec: &functions.FromOpSpec{ - BucketID: bucketID, - }, - }, - { - ID: "range0", - Spec: &functions.RangeOpSpec{ - Start: query.Time{Absolute: time.Unix(0, influxql.MinTime)}, - Stop: query.Time{Absolute: time.Unix(0, influxql.MaxTime)}, - TimeCol: execute.DefaultTimeColLabel, - StartCol: execute.DefaultStartColLabel, - StopCol: execute.DefaultStopColLabel, - }, - }, - { - ID: "filter0", - Spec: &functions.FilterOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{ - {Key: &semantic.Identifier{Name: "r"}}, - }, - Body: &semantic.LogicalExpression{ - Operator: ast.AndOperator, - Left: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_measurement", - }, - Right: &semantic.StringLiteral{ - Value: "cpu", - }, - }, - Right: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_field", - }, - Right: &semantic.StringLiteral{ - Value: "value", - }, - }, - }, - }, - }, - }, - { - ID: "filter1", - Spec: &functions.FilterOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{ - {Key: &semantic.Identifier{Name: "r"}}, - }, - Body: &semantic.BinaryExpression{ - Operator: ast.RegexpMatchOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "host", - }, - Right: &semantic.RegexpLiteral{ - Value: regexp.MustCompile(`.*er01`), - }, - }, - }, - }, - }, - { - ID: "group0", - Spec: &functions.GroupOpSpec{ - By: []string{"_measurement", "_start"}, - }, - }, - { - ID: "map0", - Spec: &functions.MapOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{{ - Key: &semantic.Identifier{Name: "r"}, - }}, - Body: &semantic.ObjectExpression{ - Properties: []*semantic.Property{ - { - Key: &semantic.Identifier{Name: "_time"}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_time", - }, - }, - { - Key: &semantic.Identifier{Name: "value"}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_value", - }, - }, - }, - }, - }, - MergeKey: true, - }, - }, - { - ID: "yield0", - Spec: &functions.YieldOpSpec{ - Name: "0", - }, - }, - }, - Edges: []query.Edge{ - {Parent: "from0", Child: "range0"}, - {Parent: "range0", Child: "filter0"}, - {Parent: "filter0", Child: "filter1"}, - {Parent: "filter1", Child: "group0"}, - {Parent: "group0", Child: "map0"}, - {Parent: "map0", Child: "yield0"}, - }, - Now: Now(), - }, - ), - ) - - RegisterFixture( - NewFixture( - `SELECT value FROM db0..cpu WHERE host !~ /.*er01/`, - &query.Spec{ - Operations: []*query.Operation{ - { - ID: "from0", - Spec: &functions.FromOpSpec{ - BucketID: bucketID, - }, - }, - { - ID: "range0", - Spec: &functions.RangeOpSpec{ - Start: query.Time{Absolute: time.Unix(0, influxql.MinTime)}, - Stop: query.Time{Absolute: time.Unix(0, influxql.MaxTime)}, - TimeCol: execute.DefaultTimeColLabel, - StartCol: execute.DefaultStartColLabel, - StopCol: execute.DefaultStopColLabel, - }, - }, - { - ID: "filter0", - Spec: &functions.FilterOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{ - {Key: &semantic.Identifier{Name: "r"}}, - }, - Body: &semantic.LogicalExpression{ - Operator: ast.AndOperator, - Left: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_measurement", - }, - Right: &semantic.StringLiteral{ - Value: "cpu", - }, - }, - Right: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_field", - }, - Right: &semantic.StringLiteral{ - Value: "value", - }, - }, - }, - }, - }, - }, - { - ID: "filter1", - Spec: &functions.FilterOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{ - {Key: &semantic.Identifier{Name: "r"}}, - }, - Body: &semantic.BinaryExpression{ - Operator: ast.NotRegexpMatchOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "host", - }, - Right: &semantic.RegexpLiteral{ - Value: regexp.MustCompile(`.*er01`), - }, - }, - }, - }, - }, - { - ID: "group0", - Spec: &functions.GroupOpSpec{ - By: []string{"_measurement", "_start"}, - }, - }, - { - ID: "map0", - Spec: &functions.MapOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{{ - Key: &semantic.Identifier{Name: "r"}, - }}, - Body: &semantic.ObjectExpression{ - Properties: []*semantic.Property{ - { - Key: &semantic.Identifier{Name: "_time"}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_time", - }, - }, - { - Key: &semantic.Identifier{Name: "value"}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_value", - }, - }, - }, - }, - }, - MergeKey: true, - }, - }, - { - ID: "yield0", - Spec: &functions.YieldOpSpec{ - Name: "0", - }, - }, - }, - Edges: []query.Edge{ - {Parent: "from0", Child: "range0"}, - {Parent: "range0", Child: "filter0"}, - {Parent: "filter0", Child: "filter1"}, - {Parent: "filter1", Child: "group0"}, - {Parent: "group0", Child: "map0"}, - {Parent: "map0", Child: "yield0"}, - }, - Now: Now(), - }, - ), - ) -} diff --git a/influxql/spectests/retention_policy.go b/influxql/spectests/retention_policy.go deleted file mode 100644 index 1f4ef2adf5..0000000000 --- a/influxql/spectests/retention_policy.go +++ /dev/null @@ -1,130 +0,0 @@ -package spectests - -import ( - "time" - - "github.com/influxdata/influxql" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/semantic" -) - -func init() { - RegisterFixture( - NewFixture( - `SELECT value FROM db0.alternate.cpu`, - &query.Spec{ - Operations: []*query.Operation{ - { - ID: "from0", - Spec: &functions.FromOpSpec{ - BucketID: altBucketID, - }, - }, - { - ID: "range0", - Spec: &functions.RangeOpSpec{ - Start: query.Time{Absolute: time.Unix(0, influxql.MinTime)}, - Stop: query.Time{Absolute: time.Unix(0, influxql.MaxTime)}, - TimeCol: execute.DefaultTimeColLabel, - StartCol: execute.DefaultStartColLabel, - StopCol: execute.DefaultStopColLabel, - }, - }, - { - ID: "filter0", - Spec: &functions.FilterOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{ - {Key: &semantic.Identifier{Name: "r"}}, - }, - Body: &semantic.LogicalExpression{ - Operator: ast.AndOperator, - Left: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_measurement", - }, - Right: &semantic.StringLiteral{ - Value: "cpu", - }, - }, - Right: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_field", - }, - Right: &semantic.StringLiteral{ - Value: "value", - }, - }, - }, - }, - }, - }, - { - ID: "group0", - Spec: &functions.GroupOpSpec{ - By: []string{"_measurement", "_start"}, - }, - }, - { - ID: "map0", - Spec: &functions.MapOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{{ - Key: &semantic.Identifier{Name: "r"}, - }}, - Body: &semantic.ObjectExpression{ - Properties: []*semantic.Property{ - { - Key: &semantic.Identifier{Name: "_time"}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_time", - }, - }, - { - Key: &semantic.Identifier{Name: "value"}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_value", - }, - }, - }, - }, - }, - MergeKey: true, - }, - }, - { - ID: "yield0", - Spec: &functions.YieldOpSpec{ - Name: "0", - }, - }, - }, - Edges: []query.Edge{ - {Parent: "from0", Child: "range0"}, - {Parent: "range0", Child: "filter0"}, - {Parent: "filter0", Child: "group0"}, - {Parent: "group0", Child: "map0"}, - {Parent: "map0", Child: "yield0"}, - }, - Now: Now(), - }, - ), - ) -} diff --git a/influxql/spectests/selectors.go b/influxql/spectests/selectors.go deleted file mode 100644 index 9e62f4e921..0000000000 --- a/influxql/spectests/selectors.go +++ /dev/null @@ -1,171 +0,0 @@ -package spectests - -import ( - "fmt" - "path/filepath" - "runtime" - "time" - - "github.com/influxdata/influxql" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/semantic" -) - -var selectorCreateFuncs = []func(config execute.SelectorConfig) query.OperationSpec{ - func(config execute.SelectorConfig) query.OperationSpec { - return &functions.FirstOpSpec{SelectorConfig: config} - }, - func(config execute.SelectorConfig) query.OperationSpec { - return &functions.LastOpSpec{SelectorConfig: config} - }, - func(config execute.SelectorConfig) query.OperationSpec { - return &functions.MaxOpSpec{SelectorConfig: config} - }, - func(config execute.SelectorConfig) query.OperationSpec { - return &functions.MinOpSpec{SelectorConfig: config} - }, -} - -func SelectorTest(fn func(selector query.Operation) (string, *query.Spec)) Fixture { - _, file, line, _ := runtime.Caller(1) - fixture := &collection{ - file: filepath.Base(file), - line: line, - } - - for _, selectorSpecFn := range selectorCreateFuncs { - spec := selectorSpecFn(execute.SelectorConfig{ - Column: execute.DefaultValueColLabel, - }) - op := query.Operation{ - ID: query.OperationID(fmt.Sprintf("%s0", spec.Kind())), - Spec: spec, - } - - fixture.Add(fn(op)) - } - return fixture -} - -func init() { - RegisterFixture( - SelectorTest(func(selector query.Operation) (stmt string, spec *query.Spec) { - return fmt.Sprintf(`SELECT %s(value) FROM db0..cpu`, selector.Spec.Kind()), - &query.Spec{ - Operations: []*query.Operation{ - { - ID: "from0", - Spec: &functions.FromOpSpec{ - BucketID: bucketID, - }, - }, - { - ID: "range0", - Spec: &functions.RangeOpSpec{ - Start: query.Time{Absolute: time.Unix(0, influxql.MinTime)}, - Stop: query.Time{Absolute: time.Unix(0, influxql.MaxTime)}, - TimeCol: execute.DefaultTimeColLabel, - StartCol: execute.DefaultStartColLabel, - StopCol: execute.DefaultStopColLabel, - }, - }, - { - ID: "filter0", - Spec: &functions.FilterOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{ - {Key: &semantic.Identifier{Name: "r"}}, - }, - Body: &semantic.LogicalExpression{ - Operator: ast.AndOperator, - Left: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_measurement", - }, - Right: &semantic.StringLiteral{ - Value: "cpu", - }, - }, - Right: &semantic.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_field", - }, - Right: &semantic.StringLiteral{ - Value: "value", - }, - }, - }, - }, - }, - }, - { - ID: "group0", - Spec: &functions.GroupOpSpec{ - By: []string{"_measurement", "_start"}, - }, - }, - &selector, - { - ID: "map0", - Spec: &functions.MapOpSpec{ - Fn: &semantic.FunctionExpression{ - Params: []*semantic.FunctionParam{{ - Key: &semantic.Identifier{Name: "r"}, - }}, - Body: &semantic.ObjectExpression{ - Properties: []*semantic.Property{ - { - Key: &semantic.Identifier{Name: "_time"}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_time", - }, - }, - { - Key: &semantic.Identifier{Name: string(selector.Spec.Kind())}, - Value: &semantic.MemberExpression{ - Object: &semantic.IdentifierExpression{ - Name: "r", - }, - Property: "_value", - }, - }, - }, - }, - }, - MergeKey: true, - }, - }, - { - ID: "yield0", - Spec: &functions.YieldOpSpec{ - Name: "0", - }, - }, - }, - Edges: []query.Edge{ - {Parent: "from0", Child: "range0"}, - {Parent: "range0", Child: "filter0"}, - {Parent: "filter0", Child: "group0"}, - {Parent: "group0", Child: selector.ID}, - {Parent: selector.ID, Child: "map0"}, - {Parent: "map0", Child: "yield0"}, - }, - Now: Now(), - } - }), - ) -} diff --git a/influxql/spectests/testing.go b/influxql/spectests/testing.go deleted file mode 100644 index 45753de4ff..0000000000 --- a/influxql/spectests/testing.go +++ /dev/null @@ -1,163 +0,0 @@ -package spectests - -import ( - "bytes" - "context" - "encoding/json" - "path/filepath" - "runtime" - "testing" - "time" - - "github.com/google/go-cmp/cmp" - "github.com/influxdata/platform" - "github.com/influxdata/platform/mock" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/influxql" -) - -var dbrpMappingSvc = mock.NewDBRPMappingService() -var organizationID = platform.ID("aaaa") -var bucketID = platform.ID("bbbb") -var altBucketID = platform.ID("cccc") - -func init() { - mapping := platform.DBRPMapping{ - Cluster: "cluster", - Database: "db0", - RetentionPolicy: "autogen", - Default: true, - OrganizationID: organizationID, - BucketID: bucketID, - } - altMapping := platform.DBRPMapping{ - Cluster: "cluster", - Database: "db0", - RetentionPolicy: "autogen", - Default: true, - OrganizationID: organizationID, - BucketID: altBucketID, - } - dbrpMappingSvc.FindByFn = func(ctx context.Context, cluster string, db string, rp string) (*platform.DBRPMapping, error) { - if rp == "alternate" { - return &altMapping, nil - } - return &mapping, nil - } - dbrpMappingSvc.FindFn = func(ctx context.Context, filter platform.DBRPMappingFilter) (*platform.DBRPMapping, error) { - if filter.RetentionPolicy != nil && *filter.RetentionPolicy == "alternate" { - return &altMapping, nil - } - return &mapping, nil - } - dbrpMappingSvc.FindManyFn = func(ctx context.Context, filter platform.DBRPMappingFilter, opt ...platform.FindOptions) ([]*platform.DBRPMapping, int, error) { - m := &mapping - if filter.RetentionPolicy != nil && *filter.RetentionPolicy == "alternate" { - m = &altMapping - } - return []*platform.DBRPMapping{m}, 1, nil - } -} - -// Fixture is a structure that will run tests. -type Fixture interface { - Run(t *testing.T) -} - -type fixture struct { - stmt string - spec *query.Spec - - file string - line int -} - -func NewFixture(stmt string, spec *query.Spec) Fixture { - _, file, line, _ := runtime.Caller(1) - return &fixture{ - stmt: stmt, - spec: spec, - file: filepath.Base(file), - line: line, - } -} - -func (f *fixture) Run(t *testing.T) { - t.Run(f.stmt, func(t *testing.T) { - if err := f.spec.Validate(); err != nil { - t.Fatalf("%s:%d: expected spec is not valid: %s", f.file, f.line, err) - } - - transpiler := influxql.NewTranspilerWithConfig( - dbrpMappingSvc, - influxql.Config{ - NowFn: Now, - }, - ) - spec, err := transpiler.Transpile(context.Background(), f.stmt) - if err != nil { - t.Fatalf("%s:%d: unexpected error: %s", f.file, f.line, err) - } else if err := spec.Validate(); err != nil { - t.Fatalf("%s:%d: spec is not valid: %s", f.file, f.line, err) - } - - // Encode both of these to JSON and compare the results. - exp, _ := json.Marshal(f.spec) - got, _ := json.Marshal(spec) - if !bytes.Equal(exp, got) { - // Unmarshal into objects so we can compare the key/value pairs. - var expObj, gotObj interface{} - json.Unmarshal(exp, &expObj) - json.Unmarshal(got, &gotObj) - - // If there is no diff, then they were trivial byte differences and - // there is no error. - if diff := cmp.Diff(expObj, gotObj); diff != "" { - t.Fatalf("unexpected spec in test at %s:%d\n%s", f.file, f.line, diff) - } - } - }) -} - -type collection struct { - stmts []string - specs []*query.Spec - - file string - line int -} - -func (c *collection) Add(stmt string, spec *query.Spec) { - c.stmts = append(c.stmts, stmt) - c.specs = append(c.specs, spec) -} - -func (c *collection) Run(t *testing.T) { - for i, stmt := range c.stmts { - f := fixture{ - stmt: stmt, - spec: c.specs[i], - file: c.file, - line: c.line, - } - f.Run(t) - } -} - -var allFixtures []Fixture - -func RegisterFixture(fixtures ...Fixture) { - allFixtures = append(allFixtures, fixtures...) -} - -func All() []Fixture { - return allFixtures -} - -func Now() time.Time { - t, err := time.Parse(time.RFC3339, "2010-09-15T09:00:00Z") - if err != nil { - panic(err) - } - return t -} diff --git a/influxql/transpiler.go b/influxql/transpiler.go deleted file mode 100644 index 62536f5380..0000000000 --- a/influxql/transpiler.go +++ /dev/null @@ -1,177 +0,0 @@ -// Package influxql implements the transpiler for executing influxql queries in the 2.0 query engine. -package influxql - -import ( - "context" - "errors" - "fmt" - "strconv" - "time" - - "github.com/influxdata/influxql" - "github.com/influxdata/platform" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/functions" -) - -// Transpiler converts InfluxQL queries into a query spec. -type Transpiler struct { - Config *Config - dbrpMappingSvc platform.DBRPMappingService -} - -func NewTranspiler(dbrpMappingSvc platform.DBRPMappingService) *Transpiler { - return NewTranspilerWithConfig(dbrpMappingSvc, Config{}) -} - -func NewTranspilerWithConfig(dbrpMappingSvc platform.DBRPMappingService, cfg Config) *Transpiler { - return &Transpiler{ - Config: &cfg, - dbrpMappingSvc: dbrpMappingSvc, - } -} - -func (t *Transpiler) Transpile(ctx context.Context, txt string) (*query.Spec, error) { - // Parse the text of the query. - q, err := influxql.ParseQuery(txt) - if err != nil { - return nil, err - } - - transpiler := newTranspilerState(t.dbrpMappingSvc, t.Config) - for i, s := range q.Statements { - stmt, ok := s.(*influxql.SelectStatement) - if !ok { - // TODO(jsternberg): Support meta queries. - return nil, fmt.Errorf("only supports select statements: %T", s) - } else if err := transpiler.Transpile(ctx, i, stmt); err != nil { - return nil, err - } - } - return transpiler.spec, nil -} - -type transpilerState struct { - id int - stmt *influxql.SelectStatement - config Config - spec *query.Spec - nextID map[string]int - dbrpMappingSvc platform.DBRPMappingService -} - -func newTranspilerState(dbrpMappingSvc platform.DBRPMappingService, config *Config) *transpilerState { - state := &transpilerState{ - spec: &query.Spec{}, - nextID: make(map[string]int), - dbrpMappingSvc: dbrpMappingSvc, - } - if config != nil { - state.config = *config - } - if state.config.NowFn == nil { - state.config.NowFn = time.Now - } - - // Stamp the current time using the now function from the config or the default. - state.spec.Now = state.config.NowFn() - return state -} - -func (t *transpilerState) Transpile(ctx context.Context, id int, stmt *influxql.SelectStatement) error { - // Clone the select statement and omit the time from the list of column names. - t.stmt = stmt.Clone() - t.stmt.OmitTime = true - t.id = id - - groups, err := identifyGroups(t.stmt) - if err != nil { - return err - } else if len(groups) == 0 { - return errors.New("at least 1 non-time field must be queried") - } - - cursors := make([]cursor, 0, len(groups)) - for _, gr := range groups { - cur, err := gr.createCursor(t) - if err != nil { - return err - } - cursors = append(cursors, cur) - } - - // Join the cursors together on the measurement name. - // TODO(jsternberg): This needs to join on all remaining group keys. - if len(cursors) > 1 { - return errors.New("unimplemented: joining multiple group cursors") - } - cur := Join(t, cursors, []string{"_measurement"}, nil) - - // Map each of the fields into another cursor. This evaluates any lingering expressions. - cur, err = t.mapFields(cur) - if err != nil { - return err - } - - // Yield the cursor from the last cursor to a stream with the name of the statement id. - // TODO(jsternberg): Include the statement id in the transpiler state when we create - // the state so we can yield to something other than zero. - t.op("yield", &functions.YieldOpSpec{Name: strconv.Itoa(t.id)}, cur.ID()) - return nil -} - -func (t *transpilerState) mapType(ref *influxql.VarRef) influxql.DataType { - // TODO(jsternberg): Actually evaluate the type against the schema. - return influxql.Tag -} - -func (t *transpilerState) from(m *influxql.Measurement) (query.OperationID, error) { - db, rp := m.Database, m.RetentionPolicy - if db == "" { - if t.config.DefaultDatabase == "" { - return "", errors.New("database is required") - } - db = t.config.DefaultDatabase - } - if rp == "" { - if t.config.DefaultRetentionPolicy != "" { - rp = t.config.DefaultRetentionPolicy - } - } - - var filter platform.DBRPMappingFilter - filter.Cluster = &t.config.Cluster - if db != "" { - filter.Database = &db - } - if rp != "" { - filter.RetentionPolicy = &rp - } - defaultRP := rp == "" - filter.Default = &defaultRP - mapping, err := t.dbrpMappingSvc.Find(context.TODO(), filter) - if err != nil { - return "", err - } - - spec := &functions.FromOpSpec{ - BucketID: mapping.BucketID, - } - return t.op("from", spec), nil -} - -func (t *transpilerState) op(name string, spec query.OperationSpec, parents ...query.OperationID) query.OperationID { - op := query.Operation{ - ID: query.OperationID(fmt.Sprintf("%s%d", name, t.nextID[name])), - Spec: spec, - } - t.spec.Operations = append(t.spec.Operations, &op) - for _, pid := range parents { - t.spec.Edges = append(t.spec.Edges, query.Edge{ - Parent: pid, - Child: op.ID, - }) - } - t.nextID[name]++ - return op.ID -} diff --git a/influxql/transpiler_test.go b/influxql/transpiler_test.go deleted file mode 100644 index 0ef493af7e..0000000000 --- a/influxql/transpiler_test.go +++ /dev/null @@ -1,406 +0,0 @@ -package influxql_test - -import ( - "context" - "strings" - "testing" - - "github.com/influxdata/platform" - "github.com/influxdata/platform/mock" - "github.com/influxdata/platform/query/influxql" - "github.com/influxdata/platform/query/influxql/spectests" - "github.com/pkg/errors" -) - -var dbrpMappingSvc = mock.NewDBRPMappingService() - -func init() { - mapping := platform.DBRPMapping{ - Cluster: "cluster", - Database: "db0", - RetentionPolicy: "autogen", - Default: true, - OrganizationID: platform.ID("aaaa"), - BucketID: platform.ID("bbbb"), - } - dbrpMappingSvc.FindByFn = func(ctx context.Context, cluster string, db string, rp string) (*platform.DBRPMapping, error) { - return &mapping, nil - } - dbrpMappingSvc.FindFn = func(ctx context.Context, filter platform.DBRPMappingFilter) (*platform.DBRPMapping, error) { - return &mapping, nil - } - dbrpMappingSvc.FindManyFn = func(ctx context.Context, filter platform.DBRPMappingFilter, opt ...platform.FindOptions) ([]*platform.DBRPMapping, int, error) { - return []*platform.DBRPMapping{&mapping}, 1, nil - } -} - -func TestTranspiler(t *testing.T) { - for _, fixture := range spectests.All() { - fixture.Run(t) - } -} - -// TestTranspiler_Compile contains the compilation tests from influxdb. It only verifies if -// each of these queries either succeeds or it fails with the proper message for compatibility. -func TestTranspiler_Compile(t *testing.T) { - for _, tt := range []struct { - s string - err string // if empty, no error is expected - }{ - {s: `SELECT time, value FROM cpu`}, - {s: `SELECT value FROM cpu`}, - {s: `SELECT value, host FROM cpu`}, - {s: `SELECT * FROM cpu`}, - {s: `SELECT time, * FROM cpu`}, - {s: `SELECT value, * FROM cpu`}, - {s: `SELECT max(value) FROM cpu`}, - {s: `SELECT max(value), host FROM cpu`}, - {s: `SELECT max(value), * FROM cpu`}, - {s: `SELECT max(*) FROM cpu`}, - {s: `SELECT max(/val/) FROM cpu`}, - {s: `SELECT min(value) FROM cpu`}, - {s: `SELECT min(value), host FROM cpu`}, - {s: `SELECT min(value), * FROM cpu`}, - {s: `SELECT min(*) FROM cpu`}, - {s: `SELECT min(/val/) FROM cpu`}, - {s: `SELECT first(value) FROM cpu`}, - {s: `SELECT first(value), host FROM cpu`}, - {s: `SELECT first(value), * FROM cpu`}, - {s: `SELECT first(*) FROM cpu`}, - {s: `SELECT first(/val/) FROM cpu`}, - {s: `SELECT last(value) FROM cpu`}, - {s: `SELECT last(value), host FROM cpu`}, - {s: `SELECT last(value), * FROM cpu`}, - {s: `SELECT last(*) FROM cpu`}, - {s: `SELECT last(/val/) FROM cpu`}, - {s: `SELECT count(value) FROM cpu`}, - {s: `SELECT count(distinct(value)) FROM cpu`}, - {s: `SELECT count(distinct value) FROM cpu`}, - {s: `SELECT count(*) FROM cpu`}, - {s: `SELECT count(/val/) FROM cpu`}, - {s: `SELECT mean(value) FROM cpu`}, - {s: `SELECT mean(*) FROM cpu`}, - {s: `SELECT mean(/val/) FROM cpu`}, - {s: `SELECT min(value), max(value) FROM cpu`}, - {s: `SELECT min(*), max(*) FROM cpu`}, - {s: `SELECT min(/val/), max(/val/) FROM cpu`}, - {s: `SELECT first(value), last(value) FROM cpu`}, - {s: `SELECT first(*), last(*) FROM cpu`}, - {s: `SELECT first(/val/), last(/val/) FROM cpu`}, - {s: `SELECT count(value) FROM cpu WHERE time >= now() - 1h GROUP BY time(10m)`}, - {s: `SELECT distinct value FROM cpu`}, - {s: `SELECT distinct(value) FROM cpu`}, - {s: `SELECT value / total FROM cpu`}, - {s: `SELECT min(value) / total FROM cpu`}, - {s: `SELECT max(value) / total FROM cpu`}, - {s: `SELECT top(value, 1) FROM cpu`}, - {s: `SELECT top(value, host, 1) FROM cpu`}, - {s: `SELECT top(value, 1), host FROM cpu`}, - {s: `SELECT min(top) FROM (SELECT top(value, host, 1) FROM cpu) GROUP BY region`}, - {s: `SELECT bottom(value, 1) FROM cpu`}, - {s: `SELECT bottom(value, host, 1) FROM cpu`}, - {s: `SELECT bottom(value, 1), host FROM cpu`}, - {s: `SELECT max(bottom) FROM (SELECT bottom(value, host, 1) FROM cpu) GROUP BY region`}, - {s: `SELECT percentile(value, 75) FROM cpu`}, - {s: `SELECT percentile(value, 75.0) FROM cpu`}, - {s: `SELECT sample(value, 2) FROM cpu`}, - {s: `SELECT sample(*, 2) FROM cpu`}, - {s: `SELECT sample(/val/, 2) FROM cpu`}, - {s: `SELECT elapsed(value) FROM cpu`}, - {s: `SELECT elapsed(value, 10s) FROM cpu`}, - {s: `SELECT integral(value) FROM cpu`}, - {s: `SELECT integral(value, 10s) FROM cpu`}, - {s: `SELECT max(value) FROM cpu WHERE time >= now() - 1m GROUP BY time(10s, 5s)`}, - {s: `SELECT max(value) FROM cpu WHERE time >= now() - 1m GROUP BY time(10s, '2000-01-01T00:00:05Z')`}, - {s: `SELECT max(value) FROM cpu WHERE time >= now() - 1m GROUP BY time(10s, now())`}, - {s: `SELECT max(mean) FROM (SELECT mean(value) FROM cpu GROUP BY host)`}, - {s: `SELECT max(derivative) FROM (SELECT derivative(mean(value)) FROM cpu) WHERE time >= now() - 1m GROUP BY time(10s)`}, - {s: `SELECT max(value) FROM (SELECT value + total FROM cpu) WHERE time >= now() - 1m GROUP BY time(10s)`}, - {s: `SELECT value FROM cpu WHERE time >= '2000-01-01T00:00:00Z' AND time <= '2000-01-01T01:00:00Z'`}, - {s: `SELECT value FROM (SELECT value FROM cpu) ORDER BY time DESC`}, - {s: `SELECT count(distinct(value)), max(value) FROM cpu`}, - {s: `SELECT derivative(distinct(value)), difference(distinct(value)) FROM cpu WHERE time >= now() - 1m GROUP BY time(5s)`}, - {s: `SELECT moving_average(distinct(value), 3) FROM cpu WHERE time >= now() - 5m GROUP BY time(1m)`}, - {s: `SELECT elapsed(distinct(value)) FROM cpu WHERE time >= now() - 5m GROUP BY time(1m)`}, - {s: `SELECT cumulative_sum(distinct(value)) FROM cpu WHERE time >= now() - 5m GROUP BY time(1m)`}, - {s: `SELECT last(value) / (1 - 0) FROM cpu`}, - {s: `SELECT abs(value) FROM cpu`}, - {s: `SELECT sin(value) FROM cpu`}, - {s: `SELECT cos(value) FROM cpu`}, - {s: `SELECT tan(value) FROM cpu`}, - {s: `SELECT asin(value) FROM cpu`}, - {s: `SELECT acos(value) FROM cpu`}, - {s: `SELECT atan(value) FROM cpu`}, - {s: `SELECT sqrt(value) FROM cpu`}, - {s: `SELECT pow(value, 2) FROM cpu`}, - {s: `SELECT pow(value, 3.14) FROM cpu`}, - {s: `SELECT pow(2, value) FROM cpu`}, - {s: `SELECT pow(3.14, value) FROM cpu`}, - {s: `SELECT exp(value) FROM cpu`}, - {s: `SELECT atan2(value, 0.1) FROM cpu`}, - {s: `SELECT atan2(0.2, value) FROM cpu`}, - {s: `SELECT atan2(value, 1) FROM cpu`}, - {s: `SELECT atan2(2, value) FROM cpu`}, - {s: `SELECT ln(value) FROM cpu`}, - {s: `SELECT log(value, 2) FROM cpu`}, - {s: `SELECT log2(value) FROM cpu`}, - {s: `SELECT log10(value) FROM cpu`}, - {s: `SELECT sin(value) - sin(1.3) FROM cpu`}, - {s: `SELECT value FROM cpu WHERE sin(value) > 0.5`}, - {s: `SELECT time FROM cpu`, err: `at least 1 non-time field must be queried`}, - {s: `SELECT value, mean(value) FROM cpu`, err: `mixing aggregate and non-aggregate queries is not supported`}, - {s: `SELECT value, max(value), min(value) FROM cpu`, err: `mixing multiple selector functions with tags or fields is not supported`}, - {s: `SELECT top(value, 10), max(value) FROM cpu`, err: `selector function top() cannot be combined with other functions`}, - {s: `SELECT bottom(value, 10), max(value) FROM cpu`, err: `selector function bottom() cannot be combined with other functions`}, - {s: `SELECT count() FROM cpu`, err: `invalid number of arguments for count, expected 1, got 0`}, - {s: `SELECT count(value, host) FROM cpu`, err: `invalid number of arguments for count, expected 1, got 2`}, - {s: `SELECT min() FROM cpu`, err: `invalid number of arguments for min, expected 1, got 0`}, - {s: `SELECT min(value, host) FROM cpu`, err: `invalid number of arguments for min, expected 1, got 2`}, - {s: `SELECT max() FROM cpu`, err: `invalid number of arguments for max, expected 1, got 0`}, - {s: `SELECT max(value, host) FROM cpu`, err: `invalid number of arguments for max, expected 1, got 2`}, - {s: `SELECT sum() FROM cpu`, err: `invalid number of arguments for sum, expected 1, got 0`}, - {s: `SELECT sum(value, host) FROM cpu`, err: `invalid number of arguments for sum, expected 1, got 2`}, - {s: `SELECT first() FROM cpu`, err: `invalid number of arguments for first, expected 1, got 0`}, - {s: `SELECT first(value, host) FROM cpu`, err: `invalid number of arguments for first, expected 1, got 2`}, - {s: `SELECT last() FROM cpu`, err: `invalid number of arguments for last, expected 1, got 0`}, - {s: `SELECT last(value, host) FROM cpu`, err: `invalid number of arguments for last, expected 1, got 2`}, - {s: `SELECT mean() FROM cpu`, err: `invalid number of arguments for mean, expected 1, got 0`}, - {s: `SELECT mean(value, host) FROM cpu`, err: `invalid number of arguments for mean, expected 1, got 2`}, - {s: `SELECT distinct(value), max(value) FROM cpu`, err: `aggregate function distinct() cannot be combined with other functions or fields`}, - {s: `SELECT count(distinct()) FROM cpu`, err: `distinct function requires at least one argument`}, - {s: `SELECT count(distinct(value, host)) FROM cpu`, err: `distinct function can only have one argument`}, - {s: `SELECT count(distinct(2)) FROM cpu`, err: `expected field argument in distinct()`}, - {s: `SELECT value FROM cpu GROUP BY now()`, err: `only time() calls allowed in dimensions`}, - {s: `SELECT value FROM cpu GROUP BY time()`, err: `time dimension expected 1 or 2 arguments`}, - {s: `SELECT value FROM cpu GROUP BY time(5m, 30s, 1ms)`, err: `time dimension expected 1 or 2 arguments`}, - {s: `SELECT value FROM cpu GROUP BY time('unexpected')`, err: `time dimension must have duration argument`}, - {s: `SELECT value FROM cpu GROUP BY time(5m), time(1m)`, err: `multiple time dimensions not allowed`}, - {s: `SELECT value FROM cpu GROUP BY time(5m, unexpected())`, err: `time dimension offset function must be now()`}, - {s: `SELECT value FROM cpu GROUP BY time(5m, now(1m))`, err: `time dimension offset now() function requires no arguments`}, - {s: `SELECT value FROM cpu GROUP BY time(5m, 'unexpected')`, err: `time dimension offset must be duration or now()`}, - {s: `SELECT value FROM cpu GROUP BY 'unexpected'`, err: `only time and tag dimensions allowed`}, - {s: `SELECT top(value) FROM cpu`, err: `invalid number of arguments for top, expected at least 2, got 1`}, - {s: `SELECT top('unexpected', 5) FROM cpu`, err: `expected first argument to be a field in top(), found 'unexpected'`}, - {s: `SELECT top(value, 'unexpected', 5) FROM cpu`, err: `only fields or tags are allowed in top(), found 'unexpected'`}, - {s: `SELECT top(value, 2.5) FROM cpu`, err: `expected integer as last argument in top(), found 2.500`}, - {s: `SELECT top(value, -1) FROM cpu`, err: `limit (-1) in top function must be at least 1`}, - {s: `SELECT top(value, 3) FROM cpu LIMIT 2`, err: `limit (3) in top function can not be larger than the LIMIT (2) in the select statement`}, - {s: `SELECT bottom(value) FROM cpu`, err: `invalid number of arguments for bottom, expected at least 2, got 1`}, - {s: `SELECT bottom('unexpected', 5) FROM cpu`, err: `expected first argument to be a field in bottom(), found 'unexpected'`}, - {s: `SELECT bottom(value, 'unexpected', 5) FROM cpu`, err: `only fields or tags are allowed in bottom(), found 'unexpected'`}, - {s: `SELECT bottom(value, 2.5) FROM cpu`, err: `expected integer as last argument in bottom(), found 2.500`}, - {s: `SELECT bottom(value, -1) FROM cpu`, err: `limit (-1) in bottom function must be at least 1`}, - {s: `SELECT bottom(value, 3) FROM cpu LIMIT 2`, err: `limit (3) in bottom function can not be larger than the LIMIT (2) in the select statement`}, - // TODO(jsternberg): This query is wrong, but we cannot enforce this because of previous behavior: https://github.com/influxdata/influxdb/pull/8771 - //{s: `SELECT value FROM cpu WHERE time >= now() - 10m OR time < now() - 5m`, err: `cannot use OR with time conditions`}, - {s: `SELECT value FROM cpu WHERE value`, err: `invalid condition expression: value`}, - {s: `SELECT count(value), * FROM cpu`, err: `mixing aggregate and non-aggregate queries is not supported`}, - {s: `SELECT max(*), host FROM cpu`, err: `mixing aggregate and non-aggregate queries is not supported`}, - {s: `SELECT count(value), /ho/ FROM cpu`, err: `mixing aggregate and non-aggregate queries is not supported`}, - {s: `SELECT max(/val/), * FROM cpu`, err: `mixing aggregate and non-aggregate queries is not supported`}, - {s: `SELECT a(value) FROM cpu`, err: `undefined function a()`}, - {s: `SELECT count(max(value)) FROM myseries`, err: `expected field argument in count()`}, - {s: `SELECT count(distinct('value')) FROM myseries`, err: `expected field argument in distinct()`}, - {s: `SELECT distinct('value') FROM myseries`, err: `expected field argument in distinct()`}, - {s: `SELECT min(max(value)) FROM myseries`, err: `expected field argument in min()`}, - {s: `SELECT min(distinct(value)) FROM myseries`, err: `expected field argument in min()`}, - {s: `SELECT max(max(value)) FROM myseries`, err: `expected field argument in max()`}, - {s: `SELECT sum(max(value)) FROM myseries`, err: `expected field argument in sum()`}, - {s: `SELECT first(max(value)) FROM myseries`, err: `expected field argument in first()`}, - {s: `SELECT last(max(value)) FROM myseries`, err: `expected field argument in last()`}, - {s: `SELECT mean(max(value)) FROM myseries`, err: `expected field argument in mean()`}, - {s: `SELECT median(max(value)) FROM myseries`, err: `expected field argument in median()`}, - {s: `SELECT mode(max(value)) FROM myseries`, err: `expected field argument in mode()`}, - {s: `SELECT stddev(max(value)) FROM myseries`, err: `expected field argument in stddev()`}, - {s: `SELECT spread(max(value)) FROM myseries`, err: `expected field argument in spread()`}, - {s: `SELECT top() FROM myseries`, err: `invalid number of arguments for top, expected at least 2, got 0`}, - {s: `SELECT top(field1) FROM myseries`, err: `invalid number of arguments for top, expected at least 2, got 1`}, - {s: `SELECT top(field1,foo) FROM myseries`, err: `expected integer as last argument in top(), found foo`}, - {s: `SELECT top(field1,host,'server',foo) FROM myseries`, err: `expected integer as last argument in top(), found foo`}, - {s: `SELECT top(field1,5,'server',2) FROM myseries`, err: `only fields or tags are allowed in top(), found 5`}, - {s: `SELECT top(field1,max(foo),'server',2) FROM myseries`, err: `only fields or tags are allowed in top(), found max(foo)`}, - {s: `SELECT top(value, 10) + count(value) FROM myseries`, err: `selector function top() cannot be combined with other functions`}, - {s: `SELECT top(max(value), 10) FROM myseries`, err: `expected first argument to be a field in top(), found max(value)`}, - {s: `SELECT bottom() FROM myseries`, err: `invalid number of arguments for bottom, expected at least 2, got 0`}, - {s: `SELECT bottom(field1) FROM myseries`, err: `invalid number of arguments for bottom, expected at least 2, got 1`}, - {s: `SELECT bottom(field1,foo) FROM myseries`, err: `expected integer as last argument in bottom(), found foo`}, - {s: `SELECT bottom(field1,host,'server',foo) FROM myseries`, err: `expected integer as last argument in bottom(), found foo`}, - {s: `SELECT bottom(field1,5,'server',2) FROM myseries`, err: `only fields or tags are allowed in bottom(), found 5`}, - {s: `SELECT bottom(field1,max(foo),'server',2) FROM myseries`, err: `only fields or tags are allowed in bottom(), found max(foo)`}, - {s: `SELECT bottom(value, 10) + count(value) FROM myseries`, err: `selector function bottom() cannot be combined with other functions`}, - {s: `SELECT bottom(max(value), 10) FROM myseries`, err: `expected first argument to be a field in bottom(), found max(value)`}, - {s: `SELECT top(value, 10), bottom(value, 10) FROM cpu`, err: `selector function top() cannot be combined with other functions`}, - {s: `SELECT bottom(value, 10), top(value, 10) FROM cpu`, err: `selector function bottom() cannot be combined with other functions`}, - {s: `SELECT sample(value) FROM myseries`, err: `invalid number of arguments for sample, expected 2, got 1`}, - {s: `SELECT sample(value, 2, 3) FROM myseries`, err: `invalid number of arguments for sample, expected 2, got 3`}, - {s: `SELECT sample(value, 0) FROM myseries`, err: `sample window must be greater than 1, got 0`}, - {s: `SELECT sample(value, 2.5) FROM myseries`, err: `expected integer argument in sample()`}, - {s: `SELECT percentile() FROM myseries`, err: `invalid number of arguments for percentile, expected 2, got 0`}, - {s: `SELECT percentile(field1) FROM myseries`, err: `invalid number of arguments for percentile, expected 2, got 1`}, - {s: `SELECT percentile(field1, foo) FROM myseries`, err: `expected float argument in percentile()`}, - {s: `SELECT percentile(max(field1), 75) FROM myseries`, err: `expected field argument in percentile()`}, - {s: `SELECT field1 FROM foo group by time(1s)`, err: `GROUP BY requires at least one aggregate function`}, - {s: `SELECT field1 FROM foo fill(none)`, err: `fill(none) must be used with a function`}, - {s: `SELECT field1 FROM foo fill(linear)`, err: `fill(linear) must be used with a function`}, - {s: `SELECT count(value), value FROM foo`, err: `mixing aggregate and non-aggregate queries is not supported`}, - {s: `SELECT count(value) FROM foo group by time`, err: `time() is a function and expects at least one argument`}, - {s: `SELECT count(value) FROM foo group by 'time'`, err: `only time and tag dimensions allowed`}, - {s: `SELECT count(value) FROM foo where time > now() and time < now() group by time()`, err: `time dimension expected 1 or 2 arguments`}, - {s: `SELECT count(value) FROM foo where time > now() and time < now() group by time(b)`, err: `time dimension must have duration argument`}, - {s: `SELECT count(value) FROM foo where time > now() and time < now() group by time(1s), time(2s)`, err: `multiple time dimensions not allowed`}, - {s: `SELECT count(value) FROM foo where time > now() and time < now() group by time(1s, b)`, err: `time dimension offset must be duration or now()`}, - {s: `SELECT count(value) FROM foo where time > now() and time < now() group by time(1s, '5s')`, err: `time dimension offset must be duration or now()`}, - {s: `SELECT distinct(field1), sum(field1) FROM myseries`, err: `aggregate function distinct() cannot be combined with other functions or fields`}, - {s: `SELECT distinct(field1), field2 FROM myseries`, err: `aggregate function distinct() cannot be combined with other functions or fields`}, - {s: `SELECT distinct(field1, field2) FROM myseries`, err: `distinct function can only have one argument`}, - {s: `SELECT distinct() FROM myseries`, err: `distinct function requires at least one argument`}, - {s: `SELECT distinct field1, field2 FROM myseries`, err: `aggregate function distinct() cannot be combined with other functions or fields`}, - {s: `SELECT count(distinct field1, field2) FROM myseries`, err: `invalid number of arguments for count, expected 1, got 2`}, - {s: `select count(distinct(too, many, arguments)) from myseries`, err: `distinct function can only have one argument`}, - {s: `select count() from myseries`, err: `invalid number of arguments for count, expected 1, got 0`}, - {s: `SELECT derivative(field1), field1 FROM myseries`, err: `mixing aggregate and non-aggregate queries is not supported`}, - {s: `select derivative() from myseries`, err: `invalid number of arguments for derivative, expected at least 1 but no more than 2, got 0`}, - {s: `select derivative(mean(value), 1h, 3) from myseries`, err: `invalid number of arguments for derivative, expected at least 1 but no more than 2, got 3`}, - {s: `SELECT derivative(value) FROM myseries group by time(1h)`, err: `aggregate function required inside the call to derivative`}, - {s: `SELECT derivative(top(value)) FROM myseries where time < now() and time > now() - 1d group by time(1h)`, err: `invalid number of arguments for top, expected at least 2, got 1`}, - {s: `SELECT derivative(bottom(value)) FROM myseries where time < now() and time > now() - 1d group by time(1h)`, err: `invalid number of arguments for bottom, expected at least 2, got 1`}, - {s: `SELECT derivative(max()) FROM myseries where time < now() and time > now() - 1d group by time(1h)`, err: `invalid number of arguments for max, expected 1, got 0`}, - {s: `SELECT derivative(percentile(value)) FROM myseries where time < now() and time > now() - 1d group by time(1h)`, err: `invalid number of arguments for percentile, expected 2, got 1`}, - {s: `SELECT derivative(mean(value), 1h) FROM myseries where time < now() and time > now() - 1d`, err: `derivative aggregate requires a GROUP BY interval`}, - {s: `SELECT derivative(value, -2h) FROM myseries`, err: `duration argument must be positive, got -2h`}, - {s: `SELECT derivative(value, 10) FROM myseries`, err: `second argument to derivative must be a duration, got *influxql.IntegerLiteral`}, - {s: `SELECT derivative(f, true) FROM myseries`, err: `second argument to derivative must be a duration, got *influxql.BooleanLiteral`}, - {s: `SELECT non_negative_derivative(field1), field1 FROM myseries`, err: `mixing aggregate and non-aggregate queries is not supported`}, - {s: `select non_negative_derivative() from myseries`, err: `invalid number of arguments for non_negative_derivative, expected at least 1 but no more than 2, got 0`}, - {s: `select non_negative_derivative(mean(value), 1h, 3) from myseries`, err: `invalid number of arguments for non_negative_derivative, expected at least 1 but no more than 2, got 3`}, - {s: `SELECT non_negative_derivative(value) FROM myseries group by time(1h)`, err: `aggregate function required inside the call to non_negative_derivative`}, - {s: `SELECT non_negative_derivative(top(value)) FROM myseries where time < now() and time > now() - 1d group by time(1h)`, err: `invalid number of arguments for top, expected at least 2, got 1`}, - {s: `SELECT non_negative_derivative(bottom(value)) FROM myseries where time < now() and time > now() - 1d group by time(1h)`, err: `invalid number of arguments for bottom, expected at least 2, got 1`}, - {s: `SELECT non_negative_derivative(max()) FROM myseries where time < now() and time > now() - 1d group by time(1h)`, err: `invalid number of arguments for max, expected 1, got 0`}, - {s: `SELECT non_negative_derivative(mean(value), 1h) FROM myseries where time < now() and time > now() - 1d`, err: `non_negative_derivative aggregate requires a GROUP BY interval`}, - {s: `SELECT non_negative_derivative(percentile(value)) FROM myseries where time < now() and time > now() - 1d group by time(1h)`, err: `invalid number of arguments for percentile, expected 2, got 1`}, - {s: `SELECT non_negative_derivative(value, -2h) FROM myseries`, err: `duration argument must be positive, got -2h`}, - {s: `SELECT non_negative_derivative(value, 10) FROM myseries`, err: `second argument to non_negative_derivative must be a duration, got *influxql.IntegerLiteral`}, - {s: `SELECT difference(field1), field1 FROM myseries`, err: `mixing aggregate and non-aggregate queries is not supported`}, - {s: `SELECT difference() from myseries`, err: `invalid number of arguments for difference, expected 1, got 0`}, - {s: `SELECT difference(value) FROM myseries group by time(1h)`, err: `aggregate function required inside the call to difference`}, - {s: `SELECT difference(top(value)) FROM myseries where time < now() and time > now() - 1d group by time(1h)`, err: `invalid number of arguments for top, expected at least 2, got 1`}, - {s: `SELECT difference(bottom(value)) FROM myseries where time < now() and time > now() - 1d group by time(1h)`, err: `invalid number of arguments for bottom, expected at least 2, got 1`}, - {s: `SELECT difference(max()) FROM myseries where time < now() and time > now() - 1d group by time(1h)`, err: `invalid number of arguments for max, expected 1, got 0`}, - {s: `SELECT difference(percentile(value)) FROM myseries where time < now() and time > now() - 1d group by time(1h)`, err: `invalid number of arguments for percentile, expected 2, got 1`}, - {s: `SELECT difference(mean(value)) FROM myseries where time < now() and time > now() - 1d`, err: `difference aggregate requires a GROUP BY interval`}, - {s: `SELECT non_negative_difference(field1), field1 FROM myseries`, err: `mixing aggregate and non-aggregate queries is not supported`}, - {s: `SELECT non_negative_difference() from myseries`, err: `invalid number of arguments for non_negative_difference, expected 1, got 0`}, - {s: `SELECT non_negative_difference(value) FROM myseries group by time(1h)`, err: `aggregate function required inside the call to non_negative_difference`}, - {s: `SELECT non_negative_difference(top(value)) FROM myseries where time < now() and time > now() - 1d group by time(1h)`, err: `invalid number of arguments for top, expected at least 2, got 1`}, - {s: `SELECT non_negative_difference(bottom(value)) FROM myseries where time < now() and time > now() - 1d group by time(1h)`, err: `invalid number of arguments for bottom, expected at least 2, got 1`}, - {s: `SELECT non_negative_difference(max()) FROM myseries where time < now() and time > now() - 1d group by time(1h)`, err: `invalid number of arguments for max, expected 1, got 0`}, - {s: `SELECT non_negative_difference(percentile(value)) FROM myseries where time < now() and time > now() - 1d group by time(1h)`, err: `invalid number of arguments for percentile, expected 2, got 1`}, - {s: `SELECT non_negative_difference(mean(value)) FROM myseries where time < now() and time > now() - 1d`, err: `non_negative_difference aggregate requires a GROUP BY interval`}, - {s: `SELECT elapsed() FROM myseries`, err: `invalid number of arguments for elapsed, expected at least 1 but no more than 2, got 0`}, - {s: `SELECT elapsed(value) FROM myseries group by time(1h)`, err: `aggregate function required inside the call to elapsed`}, - {s: `SELECT elapsed(value, 1s, host) FROM myseries`, err: `invalid number of arguments for elapsed, expected at least 1 but no more than 2, got 3`}, - {s: `SELECT elapsed(value, 0s) FROM myseries`, err: `duration argument must be positive, got 0s`}, - {s: `SELECT elapsed(value, -10s) FROM myseries`, err: `duration argument must be positive, got -10s`}, - {s: `SELECT elapsed(value, 10) FROM myseries`, err: `second argument to elapsed must be a duration, got *influxql.IntegerLiteral`}, - {s: `SELECT elapsed(top(value)) FROM myseries where time < now() and time > now() - 1d group by time(1h)`, err: `invalid number of arguments for top, expected at least 2, got 1`}, - {s: `SELECT elapsed(bottom(value)) FROM myseries where time < now() and time > now() - 1d group by time(1h)`, err: `invalid number of arguments for bottom, expected at least 2, got 1`}, - {s: `SELECT elapsed(max()) FROM myseries where time < now() and time > now() - 1d group by time(1h)`, err: `invalid number of arguments for max, expected 1, got 0`}, - {s: `SELECT elapsed(percentile(value)) FROM myseries where time < now() and time > now() - 1d group by time(1h)`, err: `invalid number of arguments for percentile, expected 2, got 1`}, - {s: `SELECT elapsed(mean(value)) FROM myseries where time < now() and time > now() - 1d`, err: `elapsed aggregate requires a GROUP BY interval`}, - {s: `SELECT moving_average(field1, 2), field1 FROM myseries`, err: `mixing aggregate and non-aggregate queries is not supported`}, - {s: `SELECT moving_average(field1, 1), field1 FROM myseries`, err: `moving_average window must be greater than 1, got 1`}, - {s: `SELECT moving_average(field1, 0), field1 FROM myseries`, err: `moving_average window must be greater than 1, got 0`}, - {s: `SELECT moving_average(field1, -1), field1 FROM myseries`, err: `moving_average window must be greater than 1, got -1`}, - {s: `SELECT moving_average(field1, 2.0), field1 FROM myseries`, err: `second argument for moving_average must be an integer, got *influxql.NumberLiteral`}, - {s: `SELECT moving_average() from myseries`, err: `invalid number of arguments for moving_average, expected 2, got 0`}, - {s: `SELECT moving_average(value) FROM myseries`, err: `invalid number of arguments for moving_average, expected 2, got 1`}, - {s: `SELECT moving_average(value, 2) FROM myseries group by time(1h)`, err: `aggregate function required inside the call to moving_average`}, - {s: `SELECT moving_average(top(value), 2) FROM myseries where time < now() and time > now() - 1d group by time(1h)`, err: `invalid number of arguments for top, expected at least 2, got 1`}, - {s: `SELECT moving_average(bottom(value), 2) FROM myseries where time < now() and time > now() - 1d group by time(1h)`, err: `invalid number of arguments for bottom, expected at least 2, got 1`}, - {s: `SELECT moving_average(max(), 2) FROM myseries where time < now() and time > now() - 1d group by time(1h)`, err: `invalid number of arguments for max, expected 1, got 0`}, - {s: `SELECT moving_average(percentile(value), 2) FROM myseries where time < now() and time > now() - 1d group by time(1h)`, err: `invalid number of arguments for percentile, expected 2, got 1`}, - {s: `SELECT moving_average(mean(value), 2) FROM myseries where time < now() and time > now() - 1d`, err: `moving_average aggregate requires a GROUP BY interval`}, - {s: `SELECT cumulative_sum(field1), field1 FROM myseries`, err: `mixing aggregate and non-aggregate queries is not supported`}, - {s: `SELECT cumulative_sum() from myseries`, err: `invalid number of arguments for cumulative_sum, expected 1, got 0`}, - {s: `SELECT cumulative_sum(value) FROM myseries group by time(1h)`, err: `aggregate function required inside the call to cumulative_sum`}, - {s: `SELECT cumulative_sum(top(value)) FROM myseries where time < now() and time > now() - 1d group by time(1h)`, err: `invalid number of arguments for top, expected at least 2, got 1`}, - {s: `SELECT cumulative_sum(bottom(value)) FROM myseries where time < now() and time > now() - 1d group by time(1h)`, err: `invalid number of arguments for bottom, expected at least 2, got 1`}, - {s: `SELECT cumulative_sum(max()) FROM myseries where time < now() and time > now() - 1d group by time(1h)`, err: `invalid number of arguments for max, expected 1, got 0`}, - {s: `SELECT cumulative_sum(percentile(value)) FROM myseries where time < now() and time > now() - 1d group by time(1h)`, err: `invalid number of arguments for percentile, expected 2, got 1`}, - {s: `SELECT cumulative_sum(mean(value)) FROM myseries where time < now() and time > now() - 1d`, err: `cumulative_sum aggregate requires a GROUP BY interval`}, - {s: `SELECT integral() FROM myseries`, err: `invalid number of arguments for integral, expected at least 1 but no more than 2, got 0`}, - {s: `SELECT integral(value, 10s, host) FROM myseries`, err: `invalid number of arguments for integral, expected at least 1 but no more than 2, got 3`}, - {s: `SELECT integral(value, -10s) FROM myseries`, err: `duration argument must be positive, got -10s`}, - {s: `SELECT integral(value, 10) FROM myseries`, err: `second argument must be a duration`}, - {s: `SELECT holt_winters(value) FROM myseries where time < now() and time > now() - 1d`, err: `invalid number of arguments for holt_winters, expected 3, got 1`}, - {s: `SELECT holt_winters(value, 10, 2) FROM myseries where time < now() and time > now() - 1d`, err: `must use aggregate function with holt_winters`}, - {s: `SELECT holt_winters(min(value), 10, 2) FROM myseries where time < now() and time > now() - 1d`, err: `holt_winters aggregate requires a GROUP BY interval`}, - {s: `SELECT holt_winters(min(value), 0, 2) FROM myseries where time < now() and time > now() - 1d GROUP BY time(1d)`, err: `second arg to holt_winters must be greater than 0, got 0`}, - {s: `SELECT holt_winters(min(value), false, 2) FROM myseries where time < now() and time > now() - 1d GROUP BY time(1d)`, err: `expected integer argument as second arg in holt_winters`}, - {s: `SELECT holt_winters(min(value), 10, 'string') FROM myseries where time < now() and time > now() - 1d GROUP BY time(1d)`, err: `expected integer argument as third arg in holt_winters`}, - {s: `SELECT holt_winters(min(value), 10, -1) FROM myseries where time < now() and time > now() - 1d GROUP BY time(1d)`, err: `third arg to holt_winters cannot be negative, got -1`}, - {s: `SELECT holt_winters_with_fit(value) FROM myseries where time < now() and time > now() - 1d`, err: `invalid number of arguments for holt_winters_with_fit, expected 3, got 1`}, - {s: `SELECT holt_winters_with_fit(value, 10, 2) FROM myseries where time < now() and time > now() - 1d`, err: `must use aggregate function with holt_winters_with_fit`}, - {s: `SELECT holt_winters_with_fit(min(value), 10, 2) FROM myseries where time < now() and time > now() - 1d`, err: `holt_winters_with_fit aggregate requires a GROUP BY interval`}, - {s: `SELECT holt_winters_with_fit(min(value), 0, 2) FROM myseries where time < now() and time > now() - 1d GROUP BY time(1d)`, err: `second arg to holt_winters_with_fit must be greater than 0, got 0`}, - {s: `SELECT holt_winters_with_fit(min(value), false, 2) FROM myseries where time < now() and time > now() - 1d GROUP BY time(1d)`, err: `expected integer argument as second arg in holt_winters_with_fit`}, - {s: `SELECT holt_winters_with_fit(min(value), 10, 'string') FROM myseries where time < now() and time > now() - 1d GROUP BY time(1d)`, err: `expected integer argument as third arg in holt_winters_with_fit`}, - {s: `SELECT holt_winters_with_fit(min(value), 10, -1) FROM myseries where time < now() and time > now() - 1d GROUP BY time(1d)`, err: `third arg to holt_winters_with_fit cannot be negative, got -1`}, - {s: `SELECT mean(value) + value FROM cpu WHERE time < now() and time > now() - 1h GROUP BY time(10m)`, err: `mixing aggregate and non-aggregate queries is not supported`}, - // TODO: Remove this restriction in the future: https://github.com/influxdata/influxdb/issues/5968 - {s: `SELECT mean(cpu_total - cpu_idle) FROM cpu`, err: `expected field argument in mean()`}, - {s: `SELECT derivative(mean(cpu_total - cpu_idle), 1s) FROM cpu WHERE time < now() AND time > now() - 1d GROUP BY time(1h)`, err: `expected field argument in mean()`}, - // TODO: The error message will change when math is allowed inside an aggregate: https://github.com/influxdata/influxdb/pull/5990#issuecomment-195565870 - {s: `SELECT count(foo + sum(bar)) FROM cpu`, err: `expected field argument in count()`}, - {s: `SELECT (count(foo + sum(bar))) FROM cpu`, err: `expected field argument in count()`}, - {s: `SELECT sum(value) + count(foo + sum(bar)) FROM cpu`, err: `expected field argument in count()`}, - {s: `SELECT top(value, 2), max(value) FROM cpu`, err: `selector function top() cannot be combined with other functions`}, - {s: `SELECT bottom(value, 2), max(value) FROM cpu`, err: `selector function bottom() cannot be combined with other functions`}, - {s: `SELECT min(derivative) FROM (SELECT derivative(mean(value), 1h) FROM myseries) where time < now() and time > now() - 1d`, err: `derivative aggregate requires a GROUP BY interval`}, - {s: `SELECT min(mean) FROM (SELECT mean(value) FROM myseries GROUP BY time)`, err: `time() is a function and expects at least one argument`}, - {s: `SELECT value FROM myseries WHERE value OR time >= now() - 1m`, err: `invalid condition expression: value`}, - {s: `SELECT value FROM myseries WHERE time >= now() - 1m OR value`, err: `invalid condition expression: value`}, - {s: `SELECT value FROM (SELECT value FROM cpu ORDER BY time DESC) ORDER BY time ASC`, err: `subqueries must be ordered in the same direction as the query itself`}, - {s: `SELECT sin(value, 3) FROM cpu`, err: `invalid number of arguments for sin, expected 1, got 2`}, - {s: `SELECT cos(2.3, value, 3) FROM cpu`, err: `invalid number of arguments for cos, expected 1, got 3`}, - {s: `SELECT tan(value, 3) FROM cpu`, err: `invalid number of arguments for tan, expected 1, got 2`}, - {s: `SELECT asin(value, 3) FROM cpu`, err: `invalid number of arguments for asin, expected 1, got 2`}, - {s: `SELECT acos(value, 3.2) FROM cpu`, err: `invalid number of arguments for acos, expected 1, got 2`}, - {s: `SELECT atan() FROM cpu`, err: `invalid number of arguments for atan, expected 1, got 0`}, - {s: `SELECT sqrt(42, 3, 4) FROM cpu`, err: `invalid number of arguments for sqrt, expected 1, got 3`}, - {s: `SELECT abs(value, 3) FROM cpu`, err: `invalid number of arguments for abs, expected 1, got 2`}, - {s: `SELECT ln(value, 3) FROM cpu`, err: `invalid number of arguments for ln, expected 1, got 2`}, - {s: `SELECT log2(value, 3) FROM cpu`, err: `invalid number of arguments for log2, expected 1, got 2`}, - {s: `SELECT log10(value, 3) FROM cpu`, err: `invalid number of arguments for log10, expected 1, got 2`}, - {s: `SELECT pow(value, 3, 3) FROM cpu`, err: `invalid number of arguments for pow, expected 2, got 3`}, - {s: `SELECT atan2(value, 3, 3) FROM cpu`, err: `invalid number of arguments for atan2, expected 2, got 3`}, - {s: `SELECT sin(1.3) FROM cpu`, err: `field must contain at least one variable`}, - {s: `SELECT nofunc(1.3) FROM cpu`, err: `undefined function nofunc()`}, - } { - t.Run(tt.s, func(t *testing.T) { - defer func() { - if err := recover(); err != nil { - t.Errorf("panic: %s", err) - } - }() - - transpiler := influxql.NewTranspilerWithConfig( - dbrpMappingSvc, - influxql.Config{ - DefaultDatabase: "db0", - }, - ) - if _, err := transpiler.Transpile(context.Background(), tt.s); err != nil { - if got, want := err.Error(), tt.err; got != want { - if cause := errors.Cause(err); strings.HasPrefix(cause.Error(), "unimplemented") { - t.Skip(got) - } - t.Errorf("unexpected error: got=%q want=%q", got, want) - } - } else if tt.err != "" { - t.Errorf("expected error: %s", tt.err) - } - }) - } -} diff --git a/interpreter/interpreter.go b/interpreter/interpreter.go index 2bec88fe18..fb861a06ed 100644 --- a/interpreter/interpreter.go +++ b/interpreter/interpreter.go @@ -4,9 +4,9 @@ import ( "fmt" "regexp" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/semantic" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux/ast" + "github.com/influxdata/flux/semantic" + "github.com/influxdata/flux/values" "github.com/pkg/errors" ) diff --git a/interpreter/interpreter_test.go b/interpreter/interpreter_test.go index d03fe89b9b..03b7f6e4e7 100644 --- a/interpreter/interpreter_test.go +++ b/interpreter/interpreter_test.go @@ -6,12 +6,12 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/interpreter" - "github.com/influxdata/platform/query/parser" - "github.com/influxdata/platform/query/semantic" - "github.com/influxdata/platform/query/semantic/semantictest" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux/ast" + "github.com/influxdata/flux/interpreter" + "github.com/influxdata/flux/parser" + "github.com/influxdata/flux/semantic" + "github.com/influxdata/flux/semantic/semantictest" + "github.com/influxdata/flux/values" ) var testScope = make(map[string]values.Value) diff --git a/logger.go b/logger.go index a75acbf9a2..a41518e94d 100644 --- a/logger.go +++ b/logger.go @@ -1,4 +1,4 @@ -package query +package flux import ( "time" diff --git a/logging.go b/logging.go index 246e9a77b8..7305f1c165 100644 --- a/logging.go +++ b/logging.go @@ -1,4 +1,4 @@ -package query +package flux import ( "context" diff --git a/mock/compiler.go b/mock/compiler.go index c8c1da7291..1de79fb702 100644 --- a/mock/compiler.go +++ b/mock/compiler.go @@ -3,18 +3,18 @@ package mock import ( "context" - "github.com/influxdata/platform/query" + "github.com/influxdata/flux" ) type Compiler struct { - CompileFn func(ctx context.Context) (*query.Spec, error) - Type query.CompilerType + CompileFn func(ctx context.Context) (*flux.Spec, error) + Type flux.CompilerType } -func (c Compiler) Compile(ctx context.Context) (*query.Spec, error) { +func (c Compiler) Compile(ctx context.Context) (*flux.Spec, error) { return c.CompileFn(ctx) } -func (c Compiler) CompilerType() query.CompilerType { +func (c Compiler) CompilerType() flux.CompilerType { if c.Type == "" { return "mockCompiler" } diff --git a/mock/executor.go b/mock/executor.go index 8d502bdb19..89cc594dda 100644 --- a/mock/executor.go +++ b/mock/executor.go @@ -3,28 +3,28 @@ package mock import ( "context" + "github.com/influxdata/flux" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/plan" "github.com/influxdata/platform" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/plan" ) var _ execute.Executor = (*Executor)(nil) // Executor is a mock implementation of an execute.Executor. type Executor struct { - ExecuteFn func(ctx context.Context, orgID platform.ID, p *plan.PlanSpec, a *execute.Allocator) (map[string]query.Result, error) + ExecuteFn func(ctx context.Context, orgID platform.ID, p *plan.PlanSpec, a *execute.Allocator) (map[string]flux.Result, error) } // NewExecutor returns a mock Executor where its methods will return zero values. func NewExecutor() *Executor { return &Executor{ - ExecuteFn: func(context.Context, platform.ID, *plan.PlanSpec, *execute.Allocator) (map[string]query.Result, error) { + ExecuteFn: func(context.Context, platform.ID, *plan.PlanSpec, *execute.Allocator) (map[string]flux.Result, error) { return nil, nil }, } } -func (e *Executor) Execute(ctx context.Context, orgID platform.ID, p *plan.PlanSpec, a *execute.Allocator) (map[string]query.Result, error) { +func (e *Executor) Execute(ctx context.Context, orgID platform.ID, p *plan.PlanSpec, a *execute.Allocator) (map[string]flux.Result, error) { return e.ExecuteFn(ctx, orgID, p, a) } diff --git a/mock/service.go b/mock/service.go index 85908eb677..830c2bbe80 100644 --- a/mock/service.go +++ b/mock/service.go @@ -4,35 +4,35 @@ import ( "context" "io" - "github.com/influxdata/platform/query" + "github.com/influxdata/flux" ) // ProxyQueryService mocks the idep QueryService for testing. type ProxyQueryService struct { - QueryF func(ctx context.Context, w io.Writer, req *query.ProxyRequest) (int64, error) + QueryF func(ctx context.Context, w io.Writer, req *flux.ProxyRequest) (int64, error) } // Query writes the results of the query request. -func (s *ProxyQueryService) Query(ctx context.Context, w io.Writer, req *query.ProxyRequest) (int64, error) { +func (s *ProxyQueryService) Query(ctx context.Context, w io.Writer, req *flux.ProxyRequest) (int64, error) { return s.QueryF(ctx, w, req) } // QueryService mocks the idep QueryService for testing. type QueryService struct { - QueryF func(ctx context.Context, req *query.Request) (query.ResultIterator, error) + QueryF func(ctx context.Context, req *flux.Request) (flux.ResultIterator, error) } // Query writes the results of the query request. -func (s *QueryService) Query(ctx context.Context, req *query.Request) (query.ResultIterator, error) { +func (s *QueryService) Query(ctx context.Context, req *flux.Request) (flux.ResultIterator, error) { return s.QueryF(ctx, req) } // AsyncQueryService mocks the idep QueryService for testing. type AsyncQueryService struct { - QueryF func(ctx context.Context, req *query.Request) (query.Query, error) + QueryF func(ctx context.Context, req *flux.Request) (flux.Query, error) } // Query writes the results of the query request. -func (s *AsyncQueryService) Query(ctx context.Context, req *query.Request) (query.Query, error) { +func (s *AsyncQueryService) Query(ctx context.Context, req *flux.Request) (flux.Query, error) { return s.QueryF(ctx, req) } diff --git a/operation.go b/operation.go index 6770218ad8..2de071ed29 100644 --- a/operation.go +++ b/operation.go @@ -1,11 +1,11 @@ -package query +package flux import ( "encoding/json" "fmt" - "github.com/pkg/errors" "github.com/influxdata/platform" + "github.com/pkg/errors" ) // Operation denotes a single operation in a query. diff --git a/options/now.go b/options/now.go index 2ac9f8124e..0e23f47513 100644 --- a/options/now.go +++ b/options/now.go @@ -1,10 +1,10 @@ package options import ( - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/functions" + "github.com/influxdata/flux" + "github.com/influxdata/flux/functions" ) func init() { - query.RegisterBuiltInOption("now", functions.SystemTime()) + flux.RegisterBuiltInOption("now", functions.SystemTime()) } diff --git a/options/task.go b/options/task.go index c5d93e8e4a..1ab36de634 100644 --- a/options/task.go +++ b/options/task.go @@ -2,12 +2,12 @@ package options import ( - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux" + "github.com/influxdata/flux/values" ) func init() { - query.RegisterBuiltInOption("task", taskObject()) + flux.RegisterBuiltInOption("task", taskObject()) } func taskObject() values.Object { diff --git a/parser/parser.go b/parser/parser.go index 55f2b3bf50..13115844b9 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -5,7 +5,7 @@ package parser //go:generate pigeon -optimize-parser -o flux.go flux.peg import ( - "github.com/influxdata/platform/query/ast" + "github.com/influxdata/flux/ast" ) // NewAST parses Flux query and produces an ast.Program diff --git a/parser/parser_debug.go b/parser/parser_debug.go index a352ff23a8..fd3de28658 100644 --- a/parser/parser_debug.go +++ b/parser/parser_debug.go @@ -5,7 +5,7 @@ package parser //go:generate pigeon -optimize-grammar -o flux.go flux.peg import ( - "github.com/influxdata/platform/query/ast" + "github.com/influxdata/flux/ast" ) // NewAST parses Flux query and produces an ast.Program diff --git a/parser/parser_test.go b/parser/parser_test.go index a735640147..7d18227269 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -5,9 +5,9 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/ast/asttest" - "github.com/influxdata/platform/query/parser" + "github.com/influxdata/flux/ast" + "github.com/influxdata/flux/ast/asttest" + "github.com/influxdata/flux/parser" ) func TestParse(t *testing.T) { diff --git a/parser/types.go b/parser/types.go index 468606686c..eacc6f7bbe 100644 --- a/parser/types.go +++ b/parser/types.go @@ -6,7 +6,7 @@ import ( "strings" "time" - "github.com/influxdata/platform/query/ast" + "github.com/influxdata/flux/ast" ) func toIfaceSlice(v interface{}) []interface{} { @@ -344,7 +344,7 @@ func durationLiteral(durations interface{}, text []byte, pos position) (*ast.Dur literals := durations.([]*singleDurationLiteral) // The slice built by the parser goes from smallest units to largest (opposite of syntax), // reverse it for the AST produced. - for i := 0; i < len(literals) / 2; i++ { + for i := 0; i < len(literals)/2; i++ { j := len(literals) - i - 1 literals[i], literals[j] = literals[j], literals[i] } @@ -363,7 +363,7 @@ type singleDurationLiteral struct { func appendSingleDurations(mag, unit, otherParts interface{}, text []byte, pos position) ([]*singleDurationLiteral, error) { sdl := &singleDurationLiteral{ magnitude: mag.(*ast.IntegerLiteral), - unit: string(unit.([]byte)), + unit: string(unit.([]byte)), } if otherParts == nil { diff --git a/plan/bounds_test.go b/plan/bounds_test.go index e20ac023d6..3ccf2b148d 100644 --- a/plan/bounds_test.go +++ b/plan/bounds_test.go @@ -6,9 +6,9 @@ import ( "github.com/google/go-cmp/cmp" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/plan/plantest" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/plan/plantest" + "github.com/influxdata/flux/values" ) func TestBoundsIntersect(t *testing.T) { @@ -254,14 +254,14 @@ func TestPlanner_ResolveBounds(t *testing.T) { tests := []struct { name string now time.Time - bounds query.Bounds + bounds flux.Bounds want plan.BoundsSpec }{ { name: "relative bounds", now: time.Date(2018, time.August, 14, 11, 0, 0, 0, time.UTC), - bounds: query.Bounds{ - Start: query.Time{ + bounds: flux.Bounds{ + Start: flux.Time{ Relative: true, Start: -1 * time.Hour, }, diff --git a/plan/logical.go b/plan/logical.go index 7375876b7e..92a4d7ba10 100644 --- a/plan/logical.go +++ b/plan/logical.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "github.com/influxdata/platform/query" + "github.com/influxdata/flux" uuid "github.com/satori/go.uuid" ) @@ -14,7 +14,7 @@ var RootUUID = NilUUID type LogicalPlanSpec struct { Procedures map[ProcedureID]*Procedure Order []ProcedureID - Resources query.ResourceManagement + Resources flux.ResourceManagement Now time.Time } @@ -29,19 +29,19 @@ func (lp *LogicalPlanSpec) lookup(id ProcedureID) *Procedure { } type LogicalPlanner interface { - Plan(*query.Spec) (*LogicalPlanSpec, error) + Plan(*flux.Spec) (*LogicalPlanSpec, error) } type logicalPlanner struct { plan *LogicalPlanSpec - q *query.Spec + q *flux.Spec } func NewLogicalPlanner() LogicalPlanner { return new(logicalPlanner) } -func (p *logicalPlanner) Plan(q *query.Spec) (*LogicalPlanSpec, error) { +func (p *logicalPlanner) Plan(q *flux.Spec) (*LogicalPlanSpec, error) { p.q = q p.plan = &LogicalPlanSpec{ Procedures: make(map[ProcedureID]*Procedure), @@ -55,14 +55,14 @@ func (p *logicalPlanner) Plan(q *query.Spec) (*LogicalPlanSpec, error) { return p.plan, nil } -func ProcedureIDFromOperationID(id query.OperationID) ProcedureID { +func ProcedureIDFromOperationID(id flux.OperationID) ProcedureID { return ProcedureID(uuid.NewV5(RootUUID, string(id))) } func ProcedureIDFromParentID(id ProcedureID) ProcedureID { return ProcedureID(uuid.NewV5(RootUUID, id.String())) } -func (p *logicalPlanner) walkQuery(o *query.Operation) error { +func (p *logicalPlanner) walkQuery(o *flux.Operation) error { spec, err := p.createSpec(o.Spec.Kind(), o.Spec) if err != nil { return err @@ -87,7 +87,7 @@ func (p *logicalPlanner) walkQuery(o *query.Operation) error { return nil } -func (p *logicalPlanner) createSpec(qk query.OperationKind, spec query.OperationSpec) (ProcedureSpec, error) { +func (p *logicalPlanner) createSpec(qk flux.OperationKind, spec flux.OperationSpec) (ProcedureSpec, error) { createPs, ok := queryOpToProcedure[qk] if !ok { return nil, fmt.Errorf("unknown query operation %v", qk) @@ -96,6 +96,6 @@ func (p *logicalPlanner) createSpec(qk query.OperationKind, spec query.Operation return createPs[0](spec, p) } -func (p *logicalPlanner) ConvertID(qid query.OperationID) ProcedureID { +func (p *logicalPlanner) ConvertID(qid flux.OperationID) ProcedureID { return ProcedureIDFromOperationID(qid) } diff --git a/plan/logical_test.go b/plan/logical_test.go index 0a8ccf2a22..c5fe5fab2a 100644 --- a/plan/logical_test.go +++ b/plan/logical_test.go @@ -6,20 +6,20 @@ import ( "time" "github.com/google/go-cmp/cmp" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/plan/plantest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/functions" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/plan/plantest" ) func TestLogicalPlanner_Plan(t *testing.T) { testCases := []struct { - q *query.Spec + q *flux.Spec ap *plan.LogicalPlanSpec }{ { - q: &query.Spec{ - Operations: []*query.Operation{ + q: &flux.Spec{ + Operations: []*flux.Operation{ { ID: "0", Spec: &functions.FromOpSpec{ @@ -29,8 +29,8 @@ func TestLogicalPlanner_Plan(t *testing.T) { { ID: "1", Spec: &functions.RangeOpSpec{ - Start: query.Time{Relative: -1 * time.Hour}, - Stop: query.Time{}, + Start: flux.Time{Relative: -1 * time.Hour}, + Stop: flux.Time{}, }, }, { @@ -38,7 +38,7 @@ func TestLogicalPlanner_Plan(t *testing.T) { Spec: &functions.CountOpSpec{}, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "0", Child: "1"}, {Parent: "1", Child: "2"}, }, @@ -56,8 +56,8 @@ func TestLogicalPlanner_Plan(t *testing.T) { plan.ProcedureIDFromOperationID("1"): { ID: plan.ProcedureIDFromOperationID("1"), Spec: &functions.RangeProcedureSpec{ - Bounds: query.Bounds{ - Start: query.Time{Relative: -1 * time.Hour}, + Bounds: flux.Bounds{ + Start: flux.Time{Relative: -1 * time.Hour}, }, TimeCol: "_time", }, @@ -97,8 +97,8 @@ func TestLogicalPlanner_Plan(t *testing.T) { plan.ProcedureIDFromOperationID("range0"): { ID: plan.ProcedureIDFromOperationID("range0"), Spec: &functions.RangeProcedureSpec{ - Bounds: query.Bounds{ - Start: query.Time{Relative: -1 * time.Hour}, + Bounds: flux.Bounds{ + Start: flux.Time{Relative: -1 * time.Hour}, }, TimeCol: "_time", }, @@ -126,8 +126,8 @@ func TestLogicalPlanner_Plan(t *testing.T) { plan.ProcedureIDFromOperationID("range1"): { ID: plan.ProcedureIDFromOperationID("range1"), Spec: &functions.RangeProcedureSpec{ - Bounds: query.Bounds{ - Start: query.Time{Relative: -1 * time.Hour}, + Bounds: flux.Bounds{ + Start: flux.Time{Relative: -1 * time.Hour}, }, TimeCol: "_time", }, @@ -190,8 +190,8 @@ func TestLogicalPlanner_Plan(t *testing.T) { } } -var benchmarkQuery = &query.Spec{ - Operations: []*query.Operation{ +var benchmarkQuery = &flux.Spec{ + Operations: []*flux.Operation{ { ID: "select0", Spec: &functions.FromOpSpec{ @@ -201,8 +201,8 @@ var benchmarkQuery = &query.Spec{ { ID: "range0", Spec: &functions.RangeOpSpec{ - Start: query.Time{Relative: -1 * time.Hour}, - Stop: query.Time{}, + Start: flux.Time{Relative: -1 * time.Hour}, + Stop: flux.Time{}, }, }, { @@ -218,8 +218,8 @@ var benchmarkQuery = &query.Spec{ { ID: "range1", Spec: &functions.RangeOpSpec{ - Start: query.Time{Relative: -1 * time.Hour}, - Stop: query.Time{}, + Start: flux.Time{Relative: -1 * time.Hour}, + Stop: flux.Time{}, }, }, { @@ -229,14 +229,14 @@ var benchmarkQuery = &query.Spec{ { ID: "join", Spec: &functions.JoinOpSpec{ - TableNames: map[query.OperationID]string{ + TableNames: map[flux.OperationID]string{ "count0": "count", "sum1": "sum", }, }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "select0", Child: "range0"}, {Parent: "range0", Child: "count0"}, {Parent: "select1", Child: "range1"}, diff --git a/plan/options_test.go b/plan/options_test.go index 0d8da9433e..6ec84800c0 100644 --- a/plan/options_test.go +++ b/plan/options_test.go @@ -4,16 +4,16 @@ import ( "testing" "time" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/plan" + "github.com/influxdata/flux" + "github.com/influxdata/flux/functions" + "github.com/influxdata/flux/plan" ) func TestPhysicalPlanner_DefaultMemoryLimit(t *testing.T) { // Simple logical plan taken from the planner tests. lp := &plan.LogicalPlanSpec{ Now: time.Now(), - Resources: query.ResourceManagement{ + Resources: flux.ResourceManagement{ ConcurrencyQuota: 1, }, Procedures: map[plan.ProcedureID]*plan.Procedure{ @@ -28,12 +28,12 @@ func TestPhysicalPlanner_DefaultMemoryLimit(t *testing.T) { plan.ProcedureIDFromOperationID("range"): { ID: plan.ProcedureIDFromOperationID("range"), Spec: &functions.RangeProcedureSpec{ - Bounds: query.Bounds{ - Start: query.Time{ + Bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: -1 * time.Hour, }, - Stop: query.Now, + Stop: flux.Now, }, TimeCol: "_time", }, diff --git a/plan/physical.go b/plan/physical.go index 375099dd39..4a57e1af6b 100644 --- a/plan/physical.go +++ b/plan/physical.go @@ -5,9 +5,9 @@ import ( "math" "time" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux/values" - "github.com/influxdata/platform/query" + "github.com/influxdata/flux" "github.com/pkg/errors" uuid "github.com/satori/go.uuid" ) @@ -16,8 +16,8 @@ import ( const DefaultYieldName = "_result" var ( - MinTime = values.ConvertTime(query.MinTime.Absolute) - MaxTime = values.ConvertTime(query.MaxTime.Absolute) + MinTime = values.ConvertTime(flux.MinTime.Absolute) + MaxTime = values.ConvertTime(flux.MaxTime.Absolute) ) type PlanSpec struct { @@ -29,7 +29,7 @@ type PlanSpec struct { // Results is a list of datasets that are the result of the plan Results map[string]YieldSpec - Resources query.ResourceManagement + Resources flux.ResourceManagement } // YieldSpec defines how data should be yielded. @@ -75,11 +75,11 @@ func NewPlanner(opts ...Option) Planner { return p } -func resolveTime(qt query.Time, now time.Time) values.Time { +func resolveTime(qt flux.Time, now time.Time) values.Time { return values.ConvertTime(qt.Time(now)) } -func ToBoundsSpec(bounds query.Bounds, now time.Time) (*BoundsSpec, error) { +func ToBoundsSpec(bounds flux.Bounds, now time.Time) (*BoundsSpec, error) { if bounds.HasZero() { return nil, errors.New("bounds contain zero time") } diff --git a/plan/physical_test.go b/plan/physical_test.go index 85140322e2..dac0b4e3cb 100644 --- a/plan/physical_test.go +++ b/plan/physical_test.go @@ -5,13 +5,13 @@ import ( "testing" "time" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux/values" "github.com/google/go-cmp/cmp" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/plan/plantest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/functions" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/plan/plantest" ) func TestPhysicalPlanner_Plan(t *testing.T) { @@ -25,7 +25,7 @@ func TestPhysicalPlanner_Plan(t *testing.T) { name: "single push down", lp: &plan.LogicalPlanSpec{ Now: now, - Resources: query.ResourceManagement{ + Resources: flux.ResourceManagement{ ConcurrencyQuota: 1, MemoryBytesQuota: 10000, }, @@ -41,12 +41,12 @@ func TestPhysicalPlanner_Plan(t *testing.T) { plan.ProcedureIDFromOperationID("range"): { ID: plan.ProcedureIDFromOperationID("range"), Spec: &functions.RangeProcedureSpec{ - Bounds: query.Bounds{ - Start: query.Time{ + Bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: -1 * time.Hour, }, - Stop: query.Now, + Stop: flux.Now, }, TimeCol: "_time", }, @@ -72,7 +72,7 @@ func TestPhysicalPlanner_Plan(t *testing.T) { }, pp: &plan.PlanSpec{ Now: time.Date(2017, 8, 8, 0, 0, 0, 0, time.UTC), - Resources: query.ResourceManagement{ + Resources: flux.ResourceManagement{ ConcurrencyQuota: 1, MemoryBytesQuota: 10000, }, @@ -82,12 +82,12 @@ func TestPhysicalPlanner_Plan(t *testing.T) { Spec: &functions.FromProcedureSpec{ Bucket: "mybucket", BoundsSet: true, - Bounds: query.Bounds{ - Start: query.Time{ + Bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: -1 * time.Hour, }, - Stop: query.Now, + Stop: flux.Now, }, AggregateSet: true, AggregateMethod: "count", @@ -136,7 +136,7 @@ func TestPhysicalPlanner_Plan(t *testing.T) { }, }, pp: &plan.PlanSpec{ - Resources: query.ResourceManagement{ + Resources: flux.ResourceManagement{ ConcurrencyQuota: 1, MemoryBytesQuota: math.MaxInt64, }, @@ -147,9 +147,9 @@ func TestPhysicalPlanner_Plan(t *testing.T) { Spec: &functions.FromProcedureSpec{ Bucket: "mybucket", BoundsSet: true, - Bounds: query.Bounds{ - Start: query.MinTime, - Stop: query.Now, + Bounds: flux.Bounds{ + Start: flux.MinTime, + Stop: flux.Now, }, LimitSet: true, PointsLimit: 1, @@ -188,12 +188,12 @@ func TestPhysicalPlanner_Plan(t *testing.T) { plan.ProcedureIDFromOperationID("range"): { ID: plan.ProcedureIDFromOperationID("range"), Spec: &functions.RangeProcedureSpec{ - Bounds: query.Bounds{ - Start: query.Time{ + Bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: -1 * time.Hour, }, - Stop: query.Now, + Stop: flux.Now, }, TimeCol: "_time", }, @@ -230,7 +230,7 @@ func TestPhysicalPlanner_Plan(t *testing.T) { }, pp: &plan.PlanSpec{ Now: time.Date(2017, 8, 8, 0, 0, 0, 0, time.UTC), - Resources: query.ResourceManagement{ + Resources: flux.ResourceManagement{ ConcurrencyQuota: 2, MemoryBytesQuota: math.MaxInt64, }, @@ -240,12 +240,12 @@ func TestPhysicalPlanner_Plan(t *testing.T) { Spec: &functions.FromProcedureSpec{ Bucket: "mybucket", BoundsSet: true, - Bounds: query.Bounds{ - Start: query.Time{ + Bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: -1 * time.Hour, }, - Stop: query.Now, + Stop: flux.Now, }, LimitSet: true, PointsLimit: 10, @@ -283,7 +283,7 @@ func TestPhysicalPlanner_Plan(t *testing.T) { name: "multiple yield", lp: &plan.LogicalPlanSpec{ Now: now, - Resources: query.ResourceManagement{ + Resources: flux.ResourceManagement{ ConcurrencyQuota: 1, MemoryBytesQuota: 10000, }, @@ -299,12 +299,12 @@ func TestPhysicalPlanner_Plan(t *testing.T) { plan.ProcedureIDFromOperationID("range"): { ID: plan.ProcedureIDFromOperationID("range"), Spec: &functions.RangeProcedureSpec{ - Bounds: query.Bounds{ - Start: query.Time{ + Bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: -1 * time.Hour, }, - Stop: query.Now, + Stop: flux.Now, }, TimeCol: "_time", }, @@ -350,7 +350,7 @@ func TestPhysicalPlanner_Plan(t *testing.T) { }, pp: &plan.PlanSpec{ Now: time.Date(2017, 8, 8, 0, 0, 0, 0, time.UTC), - Resources: query.ResourceManagement{ + Resources: flux.ResourceManagement{ ConcurrencyQuota: 1, MemoryBytesQuota: 10000, }, @@ -360,12 +360,12 @@ func TestPhysicalPlanner_Plan(t *testing.T) { Spec: &functions.FromProcedureSpec{ Bucket: "mybucket", BoundsSet: true, - Bounds: query.Bounds{ - Start: query.Time{ + Bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: -1 * time.Hour, }, - Stop: query.Now, + Stop: flux.Now, }, }, Bounds: &plan.BoundsSpec{ @@ -414,7 +414,7 @@ func TestPhysicalPlanner_Plan(t *testing.T) { name: "group with aggregate", lp: &plan.LogicalPlanSpec{ Now: now, - Resources: query.ResourceManagement{ + Resources: flux.ResourceManagement{ ConcurrencyQuota: 1, MemoryBytesQuota: 10000, }, @@ -430,12 +430,12 @@ func TestPhysicalPlanner_Plan(t *testing.T) { plan.ProcedureIDFromOperationID("range"): { ID: plan.ProcedureIDFromOperationID("range"), Spec: &functions.RangeProcedureSpec{ - Bounds: query.Bounds{ - Start: query.Time{ + Bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: -1 * time.Hour, }, - Stop: query.Now, + Stop: flux.Now, }, TimeCol: "_time", }, @@ -468,7 +468,7 @@ func TestPhysicalPlanner_Plan(t *testing.T) { }, pp: &plan.PlanSpec{ Now: time.Date(2017, 8, 8, 0, 0, 0, 0, time.UTC), - Resources: query.ResourceManagement{ + Resources: flux.ResourceManagement{ ConcurrencyQuota: 1, MemoryBytesQuota: 10000, }, @@ -478,12 +478,12 @@ func TestPhysicalPlanner_Plan(t *testing.T) { Spec: &functions.FromProcedureSpec{ Bucket: "mybucket", BoundsSet: true, - Bounds: query.Bounds{ - Start: query.Time{ + Bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: -1 * time.Hour, }, - Stop: query.Now, + Stop: flux.Now, }, GroupingSet: true, GroupMode: functions.GroupModeBy, @@ -523,7 +523,7 @@ func TestPhysicalPlanner_Plan(t *testing.T) { name: "group with distinct on tag", lp: &plan.LogicalPlanSpec{ Now: now, - Resources: query.ResourceManagement{ + Resources: flux.ResourceManagement{ ConcurrencyQuota: 1, MemoryBytesQuota: 10000, }, @@ -539,12 +539,12 @@ func TestPhysicalPlanner_Plan(t *testing.T) { plan.ProcedureIDFromOperationID("range"): { ID: plan.ProcedureIDFromOperationID("range"), Spec: &functions.RangeProcedureSpec{ - Bounds: query.Bounds{ - Start: query.Time{ + Bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: -1 * time.Hour, }, - Stop: query.Now, + Stop: flux.Now, }, TimeCol: "_time", }, @@ -579,7 +579,7 @@ func TestPhysicalPlanner_Plan(t *testing.T) { }, pp: &plan.PlanSpec{ Now: time.Date(2017, 8, 8, 0, 0, 0, 0, time.UTC), - Resources: query.ResourceManagement{ + Resources: flux.ResourceManagement{ ConcurrencyQuota: 1, MemoryBytesQuota: 10000, }, @@ -589,12 +589,12 @@ func TestPhysicalPlanner_Plan(t *testing.T) { Spec: &functions.FromProcedureSpec{ Bucket: "mybucket", BoundsSet: true, - Bounds: query.Bounds{ - Start: query.Time{ + Bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: -1 * time.Hour, }, - Stop: query.Now, + Stop: flux.Now, }, GroupingSet: true, GroupMode: functions.GroupModeBy, @@ -634,7 +634,7 @@ func TestPhysicalPlanner_Plan(t *testing.T) { name: "group with distinct on _value does not optimize", lp: &plan.LogicalPlanSpec{ Now: now, - Resources: query.ResourceManagement{ + Resources: flux.ResourceManagement{ ConcurrencyQuota: 1, MemoryBytesQuota: 10000, }, @@ -650,12 +650,12 @@ func TestPhysicalPlanner_Plan(t *testing.T) { plan.ProcedureIDFromOperationID("range"): { ID: plan.ProcedureIDFromOperationID("range"), Spec: &functions.RangeProcedureSpec{ - Bounds: query.Bounds{ - Start: query.Time{ + Bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: -1 * time.Hour, }, - Stop: query.Now, + Stop: flux.Now, }, TimeCol: "_time", }, @@ -690,7 +690,7 @@ func TestPhysicalPlanner_Plan(t *testing.T) { }, pp: &plan.PlanSpec{ Now: time.Date(2017, 8, 8, 0, 0, 0, 0, time.UTC), - Resources: query.ResourceManagement{ + Resources: flux.ResourceManagement{ ConcurrencyQuota: 1, MemoryBytesQuota: 10000, }, @@ -700,12 +700,12 @@ func TestPhysicalPlanner_Plan(t *testing.T) { Spec: &functions.FromProcedureSpec{ Bucket: "mybucket", BoundsSet: true, - Bounds: query.Bounds{ - Start: query.Time{ + Bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: -1 * time.Hour, }, - Stop: query.Now, + Stop: flux.Now, }, GroupingSet: true, GroupMode: functions.GroupModeBy, @@ -743,7 +743,7 @@ func TestPhysicalPlanner_Plan(t *testing.T) { name: "group with distinct on non-grouped does not optimize", lp: &plan.LogicalPlanSpec{ Now: now, - Resources: query.ResourceManagement{ + Resources: flux.ResourceManagement{ ConcurrencyQuota: 1, MemoryBytesQuota: 10000, }, @@ -759,12 +759,12 @@ func TestPhysicalPlanner_Plan(t *testing.T) { plan.ProcedureIDFromOperationID("range"): { ID: plan.ProcedureIDFromOperationID("range"), Spec: &functions.RangeProcedureSpec{ - Bounds: query.Bounds{ - Start: query.Time{ + Bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: -1 * time.Hour, }, - Stop: query.Now, + Stop: flux.Now, }, TimeCol: "_time", }, @@ -799,7 +799,7 @@ func TestPhysicalPlanner_Plan(t *testing.T) { }, pp: &plan.PlanSpec{ Now: time.Date(2017, 8, 8, 0, 0, 0, 0, time.UTC), - Resources: query.ResourceManagement{ + Resources: flux.ResourceManagement{ ConcurrencyQuota: 1, MemoryBytesQuota: 10000, }, @@ -809,12 +809,12 @@ func TestPhysicalPlanner_Plan(t *testing.T) { Spec: &functions.FromProcedureSpec{ Bucket: "mybucket", BoundsSet: true, - Bounds: query.Bounds{ - Start: query.Time{ + Bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: -1 * time.Hour, }, - Stop: query.Now, + Stop: flux.Now, }, GroupingSet: true, GroupMode: functions.GroupModeBy, @@ -864,12 +864,12 @@ func TestPhysicalPlanner_Plan(t *testing.T) { plan.ProcedureIDFromOperationID("range1"): { ID: plan.ProcedureIDFromOperationID("range1"), Spec: &functions.RangeProcedureSpec{ - Bounds: query.Bounds{ - Start: query.Time{ + Bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: -1 * time.Hour, }, - Stop: query.Now, + Stop: flux.Now, }, TimeCol: "_time", }, @@ -881,12 +881,12 @@ func TestPhysicalPlanner_Plan(t *testing.T) { plan.ProcedureIDFromOperationID("range2"): { ID: plan.ProcedureIDFromOperationID("range2"), Spec: &functions.RangeProcedureSpec{ - Bounds: query.Bounds{ - Start: query.Time{ + Bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: -30 * time.Minute, }, - Stop: query.Now, + Stop: flux.Now, }, }, Parents: []plan.ProcedureID{ @@ -923,7 +923,7 @@ func TestPhysicalPlanner_Plan(t *testing.T) { }, pp: &plan.PlanSpec{ Now: now, - Resources: query.ResourceManagement{ + Resources: flux.ResourceManagement{ ConcurrencyQuota: 5, MemoryBytesQuota: math.MaxInt64, }, @@ -939,12 +939,12 @@ func TestPhysicalPlanner_Plan(t *testing.T) { plan.ProcedureIDFromOperationID("range1"): { ID: plan.ProcedureIDFromOperationID("range1"), Spec: &functions.RangeProcedureSpec{ - Bounds: query.Bounds{ - Start: query.Time{ + Bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: -1 * time.Hour, }, - Stop: query.Now, + Stop: flux.Now, }, TimeCol: "_time", }, @@ -960,12 +960,12 @@ func TestPhysicalPlanner_Plan(t *testing.T) { plan.ProcedureIDFromOperationID("range2"): { ID: plan.ProcedureIDFromOperationID("range2"), Spec: &functions.RangeProcedureSpec{ - Bounds: query.Bounds{ - Start: query.Time{ + Bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: -30 * time.Minute, }, - Stop: query.Now, + Stop: flux.Now, }, }, Bounds: &plan.BoundsSpec{ @@ -1079,7 +1079,7 @@ func TestPhysicalPlanner_Plan_PushDown_Branch(t *testing.T) { fromIDDup := plan.ProcedureIDForDuplicate(fromID) want := &plan.PlanSpec{ Now: now, - Resources: query.ResourceManagement{ + Resources: flux.ResourceManagement{ ConcurrencyQuota: 2, MemoryBytesQuota: math.MaxInt64, }, @@ -1089,9 +1089,9 @@ func TestPhysicalPlanner_Plan_PushDown_Branch(t *testing.T) { Spec: &functions.FromProcedureSpec{ Bucket: "mybucket", BoundsSet: true, - Bounds: query.Bounds{ - Start: query.MinTime, - Stop: query.Now, + Bounds: flux.Bounds{ + Start: flux.MinTime, + Stop: flux.Now, }, LimitSet: true, PointsLimit: 1, @@ -1109,9 +1109,9 @@ func TestPhysicalPlanner_Plan_PushDown_Branch(t *testing.T) { Spec: &functions.FromProcedureSpec{ Bucket: "mybucket", BoundsSet: true, - Bounds: query.Bounds{ - Start: query.MinTime, - Stop: query.Now, + Bounds: flux.Bounds{ + Start: flux.MinTime, + Stop: flux.Now, }, LimitSet: true, PointsLimit: 1, @@ -1155,12 +1155,12 @@ func TestPhysicalPlanner_Plan_PushDown_Mixed(t *testing.T) { plan.ProcedureIDFromOperationID("range"): { ID: plan.ProcedureIDFromOperationID("range"), Spec: &functions.RangeProcedureSpec{ - Bounds: query.Bounds{ - Start: query.Time{ + Bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: -1 * time.Hour, }, - Stop: query.Now, + Stop: flux.Now, }, TimeCol: "_time", }, @@ -1211,7 +1211,7 @@ func TestPhysicalPlanner_Plan_PushDown_Mixed(t *testing.T) { fromIDDup := plan.ProcedureIDForDuplicate(fromID) want := &plan.PlanSpec{ Now: now, - Resources: query.ResourceManagement{ + Resources: flux.ResourceManagement{ ConcurrencyQuota: 3, MemoryBytesQuota: math.MaxInt64, }, @@ -1221,12 +1221,12 @@ func TestPhysicalPlanner_Plan_PushDown_Mixed(t *testing.T) { Spec: &functions.FromProcedureSpec{ Bucket: "mybucket", BoundsSet: true, - Bounds: query.Bounds{ - Start: query.Time{ + Bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: -1 * time.Hour, }, - Stop: query.Now, + Stop: flux.Now, }, AggregateSet: true, AggregateMethod: "sum", @@ -1243,12 +1243,12 @@ func TestPhysicalPlanner_Plan_PushDown_Mixed(t *testing.T) { Spec: &functions.FromProcedureSpec{ Bucket: "mybucket", BoundsSet: true, - Bounds: query.Bounds{ - Start: query.Time{ + Bounds: flux.Bounds{ + Start: flux.Time{ IsRelative: true, Relative: -1 * time.Hour, }, - Stop: query.Now, + Stop: flux.Now, }, }, Bounds: &plan.BoundsSpec{ diff --git a/plan/plantest/logical.go b/plan/plantest/logical.go index 6483559475..a5f1e045b4 100644 --- a/plan/plantest/logical.go +++ b/plan/plantest/logical.go @@ -1,7 +1,7 @@ package plantest import ( - "github.com/influxdata/platform/query/plan" + "github.com/influxdata/flux/plan" uuid "github.com/satori/go.uuid" ) diff --git a/plan/plantest/physical.go b/plan/plantest/physical.go index 6e9bd2bd7c..cba5407572 100644 --- a/plan/plantest/physical.go +++ b/plan/plantest/physical.go @@ -5,8 +5,8 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/influxdata/platform/query/plan" - "github.com/influxdata/platform/query/semantic/semantictest" + "github.com/influxdata/flux/plan" + "github.com/influxdata/flux/semantic/semantictest" ) var CmpOptions = []cmp.Option{ diff --git a/plan/procedure.go b/plan/procedure.go index 576b3aa2f7..65e1d14350 100644 --- a/plan/procedure.go +++ b/plan/procedure.go @@ -3,9 +3,9 @@ package plan import ( "fmt" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux/values" - "github.com/influxdata/platform/query" + "github.com/influxdata/flux" uuid "github.com/satori/go.uuid" ) @@ -63,10 +63,10 @@ func (p *Procedure) Child(i int) *Procedure { } type Administration interface { - ConvertID(query.OperationID) ProcedureID + ConvertID(flux.OperationID) ProcedureID } -type CreateProcedureSpec func(query.OperationSpec, Administration) (ProcedureSpec, error) +type CreateProcedureSpec func(flux.OperationSpec, Administration) (ProcedureSpec, error) // ProcedureSpec specifies an operation as part of a query. type ProcedureSpec interface { @@ -81,7 +81,7 @@ type PushDownProcedureSpec interface { } type BoundedProcedureSpec interface { - TimeBounds() query.Bounds + TimeBounds() flux.Bounds } type YieldProcedureSpec interface { @@ -183,18 +183,18 @@ func (b *BoundsSpec) Intersect(o *BoundsSpec) *BoundsSpec { } type WindowSpec struct { - Every query.Duration - Period query.Duration - Round query.Duration - Start query.Time + Every flux.Duration + Period flux.Duration + Round flux.Duration + Start flux.Time } var kindToProcedure = make(map[ProcedureKind]CreateProcedureSpec) -var queryOpToProcedure = make(map[query.OperationKind][]CreateProcedureSpec) +var queryOpToProcedure = make(map[flux.OperationKind][]CreateProcedureSpec) // RegisterProcedureSpec registers a new procedure with the specified kind. // The call panics if the kind is not unique. -func RegisterProcedureSpec(k ProcedureKind, c CreateProcedureSpec, qks ...query.OperationKind) { +func RegisterProcedureSpec(k ProcedureKind, c CreateProcedureSpec, qks ...flux.OperationKind) { if kindToProcedure[k] != nil { panic(fmt.Errorf("duplicate registration for procedure kind %v", k)) } diff --git a/preauthorizer.go b/preauthorizer.go deleted file mode 100644 index f51258a515..0000000000 --- a/preauthorizer.go +++ /dev/null @@ -1,63 +0,0 @@ -package query - -import ( - "github.com/pkg/errors" - "github.com/influxdata/platform" - "context" -) - -// PreAuthorizer provides a method for ensuring that the buckets accessed by a query spec -// are allowed access by the given Authorization. This is a pre-check provided as a way for -// callers to fail early for operations that are not allowed. However, it's still possible -// for authorization to be denied at runtime even if this check passes. -type PreAuthorizer interface { - PreAuthorize(ctx context.Context, spec *Spec, auth *platform.Authorization) error -} - -// NewPreAuthorizer creates a new PreAuthorizer -func NewPreAuthorizer(bucketService platform.BucketService) PreAuthorizer { - return &preAuthorizer{bucketService: bucketService} -} - -type preAuthorizer struct { - bucketService platform.BucketService -} - -// PreAuthorize finds all the buckets read and written by the given spec, and ensures that execution is allowed -// given the Authorization. Returns nil on success, and an error with an appropriate message otherwise. -func (a *preAuthorizer) PreAuthorize(ctx context.Context, spec *Spec, auth *platform.Authorization) error { - - readBuckets, writeBuckets, err := spec.BucketsAccessed() - - if err != nil { - return errors.Wrap(err, "Could not retrieve buckets for query.Spec") - } - - for _, readBucketFilter := range readBuckets { - bucket, err := a.bucketService.FindBucket(ctx, readBucketFilter) - if err != nil { - return errors.Wrapf(err, "Bucket service error") - } else if bucket == nil { - return errors.New("Bucket service returned nil bucket") - } - - reqPerm := platform.ReadBucketPermission(bucket.ID) - if ! platform.Allowed(reqPerm, auth) { - return errors.New("No read permission for bucket: \"" + bucket.Name + "\"") - } - } - - for _, writeBucketFilter := range writeBuckets { - bucket, err := a.bucketService.FindBucket(context.Background(), writeBucketFilter) - if err != nil { - return errors.Wrapf(err, "Could not find bucket %v", writeBucketFilter) - } - - reqPerm := platform.WriteBucketPermission(bucket.ID) - if ! platform.Allowed(reqPerm, auth) { - return errors.New("No write permission for bucket: \"" + bucket.Name + "\"") - } - } - - return nil -} diff --git a/preauthorizer_test.go b/preauthorizer_test.go deleted file mode 100644 index c60880ae2a..0000000000 --- a/preauthorizer_test.go +++ /dev/null @@ -1,71 +0,0 @@ -package query - -import ( - "testing" - "time" - "context" - "github.com/influxdata/platform" - "github.com/influxdata/platform/mock" - "github.com/google/go-cmp/cmp" - "github.com/influxdata/platform/kit/errors" -) - -func newBucketServiceWithOneBucket(bucket platform.Bucket) platform.BucketService { - bs := mock.NewBucketService() - bs.FindBucketFn = func(ctx context.Context, bucketFilter platform.BucketFilter) (*platform.Bucket, error) { - if *bucketFilter.Name == bucket.Name { - return &bucket, nil - } - - return nil, errors.New("Unknown bucket") - } - - return bs -} - -func TestPreAuthorizer_PreAuthorize(t *testing.T) { - ctx := context.Background() - now := time.Now().UTC() - - q := `from(bucket:"my_bucket") |> range(start:-2h) |> yield()` - spec, err := Compile(ctx, q, now) - if err != nil { - t.Errorf("Error compiling query: %v", q) - } - - // Try to pre-authorize with bucket service with no buckets - // and no authorization - auth := &platform.Authorization{Status:platform.Active} - emptyBucketService := mock.NewBucketService() - preAuthorizer := NewPreAuthorizer(emptyBucketService) - - err = preAuthorizer.PreAuthorize(ctx, spec, auth) - if diagnostic := cmp.Diff("Bucket service returned nil bucket", err.Error()); diagnostic != "" { - t.Errorf("Authorize message mismatch: -want/+got:\n%v", diagnostic) - } - - // Try to authorize with a bucket service that knows about one bucket - // (still no authorization) - id, _ := platform.IDFromString("DEADBEEF") - bucketService := newBucketServiceWithOneBucket(platform.Bucket{ - Name: "my_bucket", - ID: *id, - }) - - preAuthorizer = NewPreAuthorizer(bucketService) - err = preAuthorizer.PreAuthorize(ctx, spec, auth) - if diagnostic := cmp.Diff(`No read permission for bucket: "my_bucket"`, err.Error()); diagnostic != "" { - t.Errorf("Authorize message mismatch: -want/+got:\n%v", diagnostic) - } - - // Try to authorize with read permission on bucket - auth = &platform.Authorization{ - Status:platform.Active, - Permissions: []platform.Permission{platform.ReadBucketPermission(*id)}, - } - - err = preAuthorizer.PreAuthorize(ctx, spec, auth) - if err != nil { - t.Errorf("Expected successful authorization, but got error: \"%v\"", err.Error()) - } -} diff --git a/promql/query.go b/promql/query.go index 7dfc207114..949998f949 100644 --- a/promql/query.go +++ b/promql/query.go @@ -3,7 +3,7 @@ package promql import ( "fmt" - "github.com/influxdata/platform/query" + "github.com/influxdata/flux" ) func ParsePromQL(promql string, opts ...Option) (interface{}, error) { @@ -14,7 +14,7 @@ func ParsePromQL(promql string, opts ...Option) (interface{}, error) { return f, nil } -func Build(promql string, opts ...Option) (*query.Spec, error) { +func Build(promql string, opts ...Option) (*flux.Spec, error) { parsed, err := ParsePromQL(promql, opts...) if err != nil { return nil, err diff --git a/promql/query_test.go b/promql/query_test.go index 9c2d0eb97e..7cbed62dbe 100644 --- a/promql/query_test.go +++ b/promql/query_test.go @@ -6,11 +6,11 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/semantic" - "github.com/influxdata/platform/query/semantic/semantictest" + "github.com/influxdata/flux" + "github.com/influxdata/flux/ast" + "github.com/influxdata/flux/functions" + "github.com/influxdata/flux/semantic" + "github.com/influxdata/flux/semantic/semantictest" ) func TestParsePromQL(t *testing.T) { @@ -353,16 +353,16 @@ func TestBuild(t *testing.T) { name string promql string opts []Option - want *query.Spec + want *flux.Spec wantErr bool }{ { name: "aggregate with count without a group by", promql: `count(node_cpu{mode="user",cpu="cpu2"})`, - want: &query.Spec{ - Operations: []*query.Operation{ + want: &flux.Spec{ + Operations: []*flux.Operation{ { - ID: query.OperationID("from"), + ID: flux.OperationID("from"), Spec: &functions.FromOpSpec{Bucket: "prometheus"}, }, { @@ -416,17 +416,17 @@ func TestBuild(t *testing.T) { }, }, { - ID: query.OperationID("count"), Spec: &functions.CountOpSpec{}, + ID: flux.OperationID("count"), Spec: &functions.CountOpSpec{}, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ { - Parent: query.OperationID("from"), - Child: query.OperationID("where"), + Parent: flux.OperationID("from"), + Child: flux.OperationID("where"), }, { - Parent: query.OperationID("where"), - Child: query.OperationID("count"), + Parent: flux.OperationID("where"), + Child: flux.OperationID("count"), }, }, }, @@ -434,16 +434,16 @@ func TestBuild(t *testing.T) { { name: "range of time but no aggregates", promql: `node_cpu{mode="user"}[2m] offset 5m`, - want: &query.Spec{ - Operations: []*query.Operation{ + want: &flux.Spec{ + Operations: []*flux.Operation{ { - ID: query.OperationID("from"), + ID: flux.OperationID("from"), Spec: &functions.FromOpSpec{Bucket: "prometheus"}, }, { - ID: query.OperationID("range"), + ID: flux.OperationID("range"), Spec: &functions.RangeOpSpec{ - Start: query.Time{Relative: -time.Minute * 7}, + Start: flux.Time{Relative: -time.Minute * 7}, }, }, { @@ -482,14 +482,14 @@ func TestBuild(t *testing.T) { }, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ { - Parent: query.OperationID("from"), - Child: query.OperationID("range"), + Parent: flux.OperationID("from"), + Child: flux.OperationID("range"), }, { - Parent: query.OperationID("range"), - Child: query.OperationID("where"), + Parent: flux.OperationID("range"), + Child: flux.OperationID("where"), }, }, }, @@ -498,16 +498,16 @@ func TestBuild(t *testing.T) { { name: "sum over a range", promql: `sum(node_cpu{_measurement="m0"}[170h])`, - want: &query.Spec{ - Operations: []*query.Operation{ + want: &flux.Spec{ + Operations: []*flux.Operation{ { - ID: query.OperationID("from"), + ID: flux.OperationID("from"), Spec: &functions.FromOpSpec{Bucket: "prometheus"}, }, { - ID: query.OperationID("range"), + ID: flux.OperationID("range"), Spec: &functions.RangeOpSpec{ - Start: query.Time{Relative: -170 * time.Hour}, + Start: flux.Time{Relative: -170 * time.Hour}, }, }, { @@ -546,21 +546,21 @@ func TestBuild(t *testing.T) { }, }, { - ID: query.OperationID("sum"), Spec: &functions.SumOpSpec{}, + ID: flux.OperationID("sum"), Spec: &functions.SumOpSpec{}, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ { - Parent: query.OperationID("from"), - Child: query.OperationID("range"), + Parent: flux.OperationID("from"), + Child: flux.OperationID("range"), }, { - Parent: query.OperationID("range"), - Child: query.OperationID("where"), + Parent: flux.OperationID("range"), + Child: flux.OperationID("where"), }, { - Parent: query.OperationID("where"), - Child: query.OperationID("sum"), + Parent: flux.OperationID("where"), + Child: flux.OperationID("sum"), }, }, }, @@ -574,7 +574,7 @@ func TestBuild(t *testing.T) { t.Errorf("Build() %s error = %v, wantErr %v", tt.promql, err, tt.wantErr) return } - opts := append(semantictest.CmpOptions, []cmp.Option{cmp.AllowUnexported(query.Spec{}), cmpopts.IgnoreUnexported(query.Spec{})}...) + opts := append(semantictest.CmpOptions, []cmp.Option{cmp.AllowUnexported(flux.Spec{}), cmpopts.IgnoreUnexported(flux.Spec{})}...) if !cmp.Equal(tt.want, got, opts...) { t.Errorf("Build() = %s -want/+got\n%s", tt.promql, cmp.Diff(tt.want, got, opts...)) } diff --git a/promql/types.go b/promql/types.go index 2c5984edb7..fd13b4291b 100644 --- a/promql/types.go +++ b/promql/types.go @@ -6,10 +6,10 @@ import ( "strings" "time" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux" + "github.com/influxdata/flux/ast" + "github.com/influxdata/flux/functions" + "github.com/influxdata/flux/semantic" ) type ArgKind int @@ -24,7 +24,7 @@ const ( ) type QueryBuilder interface { - QuerySpec() (*query.Spec, error) + QuerySpec() (*flux.Spec, error) } type Arg interface { @@ -140,9 +140,9 @@ type Selector struct { LabelMatchers []*LabelMatcher `json:"label_matchers,omitempty"` } -func (s *Selector) QuerySpec() (*query.Spec, error) { +func (s *Selector) QuerySpec() (*flux.Spec, error) { parent := "from" - ops := []*query.Operation{ + ops := []*flux.Operation{ { ID: "from", // TODO: Change this to a UUID Spec: &functions.FromOpSpec{ @@ -150,7 +150,7 @@ func (s *Selector) QuerySpec() (*query.Spec, error) { }, }, } - edges := []query.Edge{} + edges := []flux.Edge{} rng, err := NewRangeOp(s.Range, s.Offset) if err != nil { @@ -159,8 +159,8 @@ func (s *Selector) QuerySpec() (*query.Spec, error) { if rng != nil { ops = append(ops, rng) - edge := query.Edge{ - Parent: query.OperationID(parent), + edge := flux.Edge{ + Parent: flux.OperationID(parent), Child: "range", } parent = "range" @@ -173,27 +173,27 @@ func (s *Selector) QuerySpec() (*query.Spec, error) { } ops = append(ops, where) - edge := query.Edge{ - Parent: query.OperationID(parent), + edge := flux.Edge{ + Parent: flux.OperationID(parent), Child: "where", } parent = "where" edges = append(edges, edge) - return &query.Spec{ + return &flux.Spec{ Operations: ops, Edges: edges, }, nil } -func NewRangeOp(rng, offset time.Duration) (*query.Operation, error) { +func NewRangeOp(rng, offset time.Duration) (*flux.Operation, error) { if rng == 0 && offset == 0 { return nil, nil } - return &query.Operation{ + return &flux.Operation{ ID: "range", // TODO: Change this to a UUID Spec: &functions.RangeOpSpec{ - Start: query.Time{ + Start: flux.Time{ Relative: -rng - offset, }, }, @@ -207,7 +207,7 @@ var operatorLookup = map[MatchKind]ast.OperatorKind{ RegexNoMatch: ast.NotEqualOperator, } -func NewWhereOperation(metricName string, labels []*LabelMatcher) (*query.Operation, error) { +func NewWhereOperation(metricName string, labels []*LabelMatcher) (*flux.Operation, error) { var node semantic.Expression node = &semantic.BinaryExpression{ Operator: ast.EqualOperator, @@ -253,7 +253,7 @@ func NewWhereOperation(metricName string, labels []*LabelMatcher) (*query.Operat } } - return &query.Operation{ + return &flux.Operation{ ID: "where", // TODO: Change this to a UUID Spec: &functions.FilterOpSpec{ Fn: &semantic.FunctionExpression{ @@ -298,7 +298,7 @@ type Aggregate struct { Labels []*Identifier `json:"labels,omitempty"` } -func (a *Aggregate) QuerySpec() (*query.Operation, error) { +func (a *Aggregate) QuerySpec() (*flux.Operation, error) { if a.Without { return nil, fmt.Errorf("Unable to merge using `without`") } @@ -306,7 +306,7 @@ func (a *Aggregate) QuerySpec() (*query.Operation, error) { for i := range a.Labels { keys[i] = a.Labels[i].Name } - return &query.Operation{ + return &flux.Operation{ ID: "merge", Spec: &functions.GroupOpSpec{ By: keys, @@ -366,42 +366,42 @@ type Operator struct { Arg Arg `json:"arg,omitempty"` } -func (o *Operator) QuerySpec() (*query.Operation, error) { +func (o *Operator) QuerySpec() (*flux.Operation, error) { switch o.Kind { case CountValuesKind, BottomKind, QuantileKind, StdVarKind: return nil, fmt.Errorf("Unable to run %d yet", o.Kind) case CountKind: - return &query.Operation{ + return &flux.Operation{ ID: "count", Spec: &functions.CountOpSpec{}, }, nil //case TopKind: - // return &query.Operation{ + // return &flux.Operation{ // ID: "top", // Spec: &functions.TopOpSpec{}, // TODO: Top doesn't have arg yet // }, nil case SumKind: - return &query.Operation{ + return &flux.Operation{ ID: "sum", Spec: &functions.SumOpSpec{}, }, nil //case MinKind: - // return &query.Operation{ + // return &flux.Operation{ // ID: "min", // Spec: &functions.MinOpSpec{}, // }, nil //case MaxKind: - // return &query.Operation{ + // return &flux.Operation{ // ID: "max", // Spec: &functions.MaxOpSpec{}, // }, nil //case AvgKind: - // return &query.Operation{ + // return &flux.Operation{ // ID: "mean", // Spec: &functions.MeanOpSpec{}, // }, nil //case StdevKind: - // return &query.Operation{ + // return &flux.Operation{ // ID: "stddev", // Spec: &functions.StddevOpSpec{}, // }, nil @@ -416,7 +416,7 @@ type AggregateExpr struct { Aggregate *Aggregate `json:"aggregate,omitempty"` } -func (a *AggregateExpr) QuerySpec() (*query.Spec, error) { +func (a *AggregateExpr) QuerySpec() (*flux.Spec, error) { spec, err := a.Selector.QuerySpec() if err != nil { return nil, err @@ -428,14 +428,14 @@ func (a *AggregateExpr) QuerySpec() (*query.Spec, error) { return nil, err } - parent := query.OperationID("from") + parent := flux.OperationID("from") if len(spec.Edges) > 0 { tail := spec.Edges[len(spec.Edges)-1] parent = tail.Child } spec.Operations = append(spec.Operations, agg) - spec.Edges = append(spec.Edges, query.Edge{ + spec.Edges = append(spec.Edges, flux.Edge{ Parent: parent, Child: agg.ID, }) @@ -446,13 +446,13 @@ func (a *AggregateExpr) QuerySpec() (*query.Spec, error) { return nil, err } - parent := query.OperationID("from") + parent := flux.OperationID("from") if len(spec.Edges) > 0 { tail := spec.Edges[len(spec.Edges)-1] parent = tail.Child } spec.Operations = append(spec.Operations, op) - spec.Edges = append(spec.Edges, query.Edge{ + spec.Edges = append(spec.Edges, flux.Edge{ Parent: parent, Child: op.ID, }) @@ -474,7 +474,7 @@ type Comment struct { Source string `json:"source,omitempty"` } -func (c *Comment) QuerySpec() (*query.Spec, error) { +func (c *Comment) QuerySpec() (*flux.Spec, error) { return nil, fmt.Errorf("Unable to represent comments in the AST") } diff --git a/promql/unicode.go b/promql/unicode.go index fc11a531f9..465ba2415f 100644 --- a/promql/unicode.go +++ b/promql/unicode.go @@ -19,118 +19,118 @@ func validateUnicodeEscape(escape, errMsg string) (interface{}, error) { } var unicodeClasses = map[string]bool{ - "ASCII_Hex_Digit": true, - "Arabic": true, - "Armenian": true, - "Avestan": true, - "Balinese": true, - "Bamum": true, - "Bassa_Vah": true, - "Batak": true, - "Bengali": true, - "Bidi_Control": true, - "Bopomofo": true, - "Brahmi": true, - "Braille": true, - "Buginese": true, - "Buhid": true, - "C": true, - "Canadian_Aboriginal": true, - "Carian": true, - "Caucasian_Albanian": true, - "Cc": true, - "Cf": true, - "Chakma": true, - "Cham": true, - "Cherokee": true, - "Co": true, - "Common": true, - "Coptic": true, - "Cs": true, - "Cuneiform": true, - "Cypriot": true, - "Cyrillic": true, - "Dash": true, - "Deprecated": true, - "Deseret": true, - "Devanagari": true, - "Diacritic": true, - "Duployan": true, - "Egyptian_Hieroglyphs": true, - "Elbasan": true, - "Ethiopic": true, - "Extender": true, - "Georgian": true, - "Glagolitic": true, - "Gothic": true, - "Grantha": true, - "Greek": true, - "Gujarati": true, - "Gurmukhi": true, - "Han": true, - "Hangul": true, - "Hanunoo": true, - "Hebrew": true, - "Hex_Digit": true, - "Hiragana": true, - "Hyphen": true, - "IDS_Binary_Operator": true, - "IDS_Trinary_Operator": true, - "Ideographic": true, - "Imperial_Aramaic": true, - "Inherited": true, - "Inscriptional_Pahlavi": true, - "Inscriptional_Parthian": true, - "Javanese": true, - "Join_Control": true, - "Kaithi": true, - "Kannada": true, - "Katakana": true, - "Kayah_Li": true, - "Kharoshthi": true, - "Khmer": true, - "Khojki": true, - "Khudawadi": true, - "L": true, - "Lao": true, - "Latin": true, - "Lepcha": true, - "Limbu": true, - "Linear_A": true, - "Linear_B": true, - "Lisu": true, - "Ll": true, - "Lm": true, - "Lo": true, - "Logical_Order_Exception": true, - "Lt": true, - "Lu": true, - "Lycian": true, - "Lydian": true, - "M": true, - "Mahajani": true, - "Malayalam": true, - "Mandaic": true, - "Manichaean": true, - "Mc": true, - "Me": true, - "Meetei_Mayek": true, - "Mende_Kikakui": true, - "Meroitic_Cursive": true, - "Meroitic_Hieroglyphs": true, - "Miao": true, - "Mn": true, - "Modi": true, - "Mongolian": true, - "Mro": true, - "Myanmar": true, - "N": true, - "Nabataean": true, - "Nd": true, - "New_Tai_Lue": true, - "Nko": true, - "Nl": true, - "No": true, + "ASCII_Hex_Digit": true, + "Arabic": true, + "Armenian": true, + "Avestan": true, + "Balinese": true, + "Bamum": true, + "Bassa_Vah": true, + "Batak": true, + "Bengali": true, + "Bidi_Control": true, + "Bopomofo": true, + "Brahmi": true, + "Braille": true, + "Buginese": true, + "Buhid": true, + "C": true, + "Canadian_Aboriginal": true, + "Carian": true, + "Caucasian_Albanian": true, + "Cc": true, + "Cf": true, + "Chakma": true, + "Cham": true, + "Cherokee": true, + "Co": true, + "Common": true, + "Coptic": true, + "Cs": true, + "Cuneiform": true, + "Cypriot": true, + "Cyrillic": true, + "Dash": true, + "Deprecated": true, + "Deseret": true, + "Devanagari": true, + "Diacritic": true, + "Duployan": true, + "Egyptian_Hieroglyphs": true, + "Elbasan": true, + "Ethiopic": true, + "Extender": true, + "Georgian": true, + "Glagolitic": true, + "Gothic": true, + "Grantha": true, + "Greek": true, + "Gujarati": true, + "Gurmukhi": true, + "Han": true, + "Hangul": true, + "Hanunoo": true, + "Hebrew": true, + "Hex_Digit": true, + "Hiragana": true, + "Hyphen": true, + "IDS_Binary_Operator": true, + "IDS_Trinary_Operator": true, + "Ideographic": true, + "Imperial_Aramaic": true, + "Inherited": true, + "Inscriptional_Pahlavi": true, + "Inscriptional_Parthian": true, + "Javanese": true, + "Join_Control": true, + "Kaithi": true, + "Kannada": true, + "Katakana": true, + "Kayah_Li": true, + "Kharoshthi": true, + "Khmer": true, + "Khojki": true, + "Khudawadi": true, + "L": true, + "Lao": true, + "Latin": true, + "Lepcha": true, + "Limbu": true, + "Linear_A": true, + "Linear_B": true, + "Lisu": true, + "Ll": true, + "Lm": true, + "Lo": true, + "Logical_Order_Exception": true, + "Lt": true, + "Lu": true, + "Lycian": true, + "Lydian": true, + "M": true, + "Mahajani": true, + "Malayalam": true, + "Mandaic": true, + "Manichaean": true, + "Mc": true, + "Me": true, + "Meetei_Mayek": true, + "Mende_Kikakui": true, + "Meroitic_Cursive": true, + "Meroitic_Hieroglyphs": true, + "Miao": true, + "Mn": true, + "Modi": true, + "Mongolian": true, + "Mro": true, + "Myanmar": true, + "N": true, + "Nabataean": true, + "Nd": true, + "New_Tai_Lue": true, + "Nko": true, + "Nl": true, + "No": true, "Noncharacter_Code_Point": true, "Ogham": true, "Ol_Chiki": true, diff --git a/query.go b/query.go index 076b0fd097..add10b6b5b 100644 --- a/query.go +++ b/query.go @@ -1,5 +1,5 @@ // Package query contains the InfluxDB 2.0 query engine. -package query +package flux import ( "context" diff --git a/query_test.go b/query_test.go index 01b1898a26..c628933f25 100644 --- a/query_test.go +++ b/query_test.go @@ -1,4 +1,4 @@ -package query_test +package flux_test import ( "context" @@ -7,57 +7,57 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" + "github.com/influxdata/flux" "github.com/influxdata/platform" - "github.com/influxdata/platform/query" ) var CmpOpts = []cmp.Option{ - cmpopts.IgnoreUnexported(query.ProxyRequest{}), - cmpopts.IgnoreUnexported(query.Request{}), + cmpopts.IgnoreUnexported(flux.ProxyRequest{}), + cmpopts.IgnoreUnexported(flux.Request{}), } type compilerA struct { A string `json:"a"` } -func (c compilerA) Compile(ctx context.Context) (*query.Spec, error) { +func (c compilerA) Compile(ctx context.Context) (*flux.Spec, error) { panic("not implemented") } -func (c compilerA) CompilerType() query.CompilerType { +func (c compilerA) CompilerType() flux.CompilerType { return "compilerA" } -var compilerMappings = query.CompilerMappings{ - "compilerA": func() query.Compiler { return new(compilerA) }, +var compilerMappings = flux.CompilerMappings{ + "compilerA": func() flux.Compiler { return new(compilerA) }, } type dialectB struct { B int `json:"b"` } -func (d dialectB) Encoder() query.MultiResultEncoder { +func (d dialectB) Encoder() flux.MultiResultEncoder { panic("not implemented") } -func (d dialectB) DialectType() query.DialectType { +func (d dialectB) DialectType() flux.DialectType { return "dialectB" } -var dialectMappings = query.DialectMappings{ - "dialectB": func() query.Dialect { return new(dialectB) }, +var dialectMappings = flux.DialectMappings{ + "dialectB": func() flux.Dialect { return new(dialectB) }, } func TestRequest_JSON(t *testing.T) { testCases := []struct { name string data string - want query.Request + want flux.Request }{ { name: "simple", data: `{"organization_id":"aaaaaaaaaaaaaaaa","compiler":{"a":"my custom compiler"},"compiler_type":"compilerA"}`, - want: query.Request{ + want: flux.Request{ OrganizationID: platform.ID{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, Compiler: &compilerA{ A: "my custom compiler", @@ -66,7 +66,7 @@ func TestRequest_JSON(t *testing.T) { }, } for _, tc := range testCases { - var r query.Request + var r flux.Request r.WithCompilerMappings(compilerMappings) if err := json.Unmarshal([]byte(tc.data), &r); err != nil { @@ -89,13 +89,13 @@ func TestProxyRequest_JSON(t *testing.T) { testCases := []struct { name string data string - want query.ProxyRequest + want flux.ProxyRequest }{ { name: "simple", data: `{"request":{"organization_id":"aaaaaaaaaaaaaaaa","compiler":{"a":"my custom compiler"},"compiler_type":"compilerA"},"dialect":{"b":42},"dialect_type":"dialectB"}`, - want: query.ProxyRequest{ - Request: query.Request{ + want: flux.ProxyRequest{ + Request: flux.Request{ OrganizationID: platform.ID{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, Compiler: &compilerA{ A: "my custom compiler", @@ -108,7 +108,7 @@ func TestProxyRequest_JSON(t *testing.T) { }, } for _, tc := range testCases { - var pr query.ProxyRequest + var pr flux.ProxyRequest pr.WithCompilerMappings(compilerMappings) pr.WithDialectMappings(dialectMappings) diff --git a/querytest/doc.go b/querytest/doc.go deleted file mode 100644 index f3f3402f90..0000000000 --- a/querytest/doc.go +++ /dev/null @@ -1,2 +0,0 @@ -// Package querytest contains utilities for testing the query end-to-end. -package querytest diff --git a/repl/repl.go b/repl/repl.go index db4c3abfff..334a8aa4b0 100644 --- a/repl/repl.go +++ b/repl/repl.go @@ -14,15 +14,15 @@ import ( "syscall" prompt "github.com/c-bata/go-prompt" + "github.com/influxdata/flux" + "github.com/influxdata/flux/control" + "github.com/influxdata/flux/execute" + "github.com/influxdata/flux/functions" + "github.com/influxdata/flux/interpreter" + "github.com/influxdata/flux/parser" + "github.com/influxdata/flux/semantic" + "github.com/influxdata/flux/values" "github.com/influxdata/platform" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/control" - "github.com/influxdata/platform/query/execute" - "github.com/influxdata/platform/query/functions" - "github.com/influxdata/platform/query/interpreter" - "github.com/influxdata/platform/query/parser" - "github.com/influxdata/platform/query/semantic" - "github.com/influxdata/platform/query/values" "github.com/pkg/errors" ) @@ -54,8 +54,8 @@ func addBuiltIn(script string, itrp *interpreter.Interpreter, declarations seman } func New(c *control.Controller, orgID platform.ID) *REPL { - itrp := query.NewInterpreter() - _, decls := query.BuiltIns() + itrp := flux.NewInterpreter() + _, decls := flux.BuiltIns() addBuiltIn("run = () => yield(table:_)", itrp, decls) return &REPL{ @@ -177,10 +177,10 @@ func (r *REPL) executeLine(t string, expectYield bool) (values.Value, error) { v := r.interpreter.Return() // Check for yield and execute query - if v.Type() == query.TableObjectType { - t := v.(*query.TableObject) + if v.Type() == flux.TableObjectType { + t := v.(*flux.TableObject) if !expectYield || (expectYield && t.Kind == functions.YieldKind) { - spec := query.ToSpec(r.interpreter, t) + spec := flux.ToSpec(r.interpreter, t) return nil, r.doQuery(spec) } } @@ -194,16 +194,16 @@ func (r *REPL) executeLine(t string, expectYield bool) (values.Value, error) { return nil, nil } -func (r *REPL) doQuery(spec *query.Spec) error { +func (r *REPL) doQuery(spec *flux.Spec) error { // Setup cancel context ctx, cancelFunc := context.WithCancel(context.Background()) r.setCancel(cancelFunc) defer cancelFunc() defer r.clearCancel() - req := &query.Request{ + req := &flux.Request{ OrganizationID: r.orgID, - Compiler: query.SpecCompiler{ + Compiler: flux.SpecCompiler{ Spec: spec, }, } @@ -230,7 +230,7 @@ func (r *REPL) doQuery(spec *query.Spec) error { r := results[name] tables := r.Tables() fmt.Println("Result:", name) - err := tables.Do(func(tbl query.Table) error { + err := tables.Do(func(tbl flux.Table) error { _, err := execute.NewFormatter(tbl, nil).WriteTo(os.Stdout) return err }) diff --git a/resource_management.go b/resource_management.go index 2660aac8ac..9bf0a45b5a 100644 --- a/resource_management.go +++ b/resource_management.go @@ -1,4 +1,4 @@ -package query +package flux import ( "math" diff --git a/result.go b/result.go index 0c4ad26bc4..1c7b2d5be0 100644 --- a/result.go +++ b/result.go @@ -1,10 +1,10 @@ -package query +package flux import ( "io" - "github.com/influxdata/platform/query/iocounter" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux/iocounter" + "github.com/influxdata/flux/values" "github.com/pkg/errors" ) diff --git a/semantic/binary_types.go b/semantic/binary_types.go index 60f548161a..e34d05cb82 100644 --- a/semantic/binary_types.go +++ b/semantic/binary_types.go @@ -1,6 +1,6 @@ package semantic -import "github.com/influxdata/platform/query/ast" +import "github.com/influxdata/flux/ast" type binarySignature struct { operator ast.OperatorKind diff --git a/semantic/graph.go b/semantic/graph.go index 64d57cf509..416d6f0fe7 100644 --- a/semantic/graph.go +++ b/semantic/graph.go @@ -9,7 +9,7 @@ import ( "sync/atomic" "time" - "github.com/influxdata/platform/query/ast" + "github.com/influxdata/flux/ast" ) type Node interface { diff --git a/semantic/graph_test.go b/semantic/graph_test.go index 86324bc6a2..59e74fe6fe 100644 --- a/semantic/graph_test.go +++ b/semantic/graph_test.go @@ -5,9 +5,9 @@ import ( "time" "github.com/google/go-cmp/cmp" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/semantic" - "github.com/influxdata/platform/query/semantic/semantictest" + "github.com/influxdata/flux/ast" + "github.com/influxdata/flux/semantic" + "github.com/influxdata/flux/semantic/semantictest" ) func TestNew(t *testing.T) { diff --git a/semantic/json_test.go b/semantic/json_test.go index a70f43e0a3..1fa8830d35 100644 --- a/semantic/json_test.go +++ b/semantic/json_test.go @@ -8,9 +8,9 @@ import ( "time" "github.com/google/go-cmp/cmp" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/semantic" - "github.com/influxdata/platform/query/semantic/semantictest" + "github.com/influxdata/flux/ast" + "github.com/influxdata/flux/semantic" + "github.com/influxdata/flux/semantic/semantictest" ) func TestJSONMarshal(t *testing.T) { diff --git a/semantic/semantictest/cmp.go b/semantic/semantictest/cmp.go index 8826eb448d..4b8d0c2dc4 100644 --- a/semantic/semantictest/cmp.go +++ b/semantic/semantictest/cmp.go @@ -5,7 +5,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux/semantic" ) var CmpOptions = []cmp.Option{ diff --git a/semantic/types_test.go b/semantic/types_test.go index 0a8ab53e55..ab511db5b3 100644 --- a/semantic/types_test.go +++ b/semantic/types_test.go @@ -3,7 +3,7 @@ package semantic_test import ( "testing" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux/semantic" ) func TestTypes_Comparable(t *testing.T) { diff --git a/spec.go b/spec.go index 0f638396b9..3b326db30d 100644 --- a/spec.go +++ b/spec.go @@ -1,11 +1,11 @@ -package query +package flux import ( "fmt" "time" - "github.com/pkg/errors" "github.com/influxdata/platform" + "github.com/pkg/errors" ) // Spec specifies a query. @@ -188,7 +188,7 @@ func (q *Spec) BucketsAccessed() (readBuckets, writeBuckets []platform.BucketFil if ok { opBucketsRead, opBucketsWritten := bucketAwareOpSpec.BucketsAccessed() readBuckets = append(readBuckets, opBucketsRead...) - writeBuckets = append(writeBuckets, opBucketsWritten...) + writeBuckets = append(writeBuckets, opBucketsWritten...) } return nil }) diff --git a/spec_test.go b/spec_test.go index 6da3b607b5..bfa9d71421 100644 --- a/spec_test.go +++ b/spec_test.go @@ -1,4 +1,4 @@ -package query_test +package flux_test import ( "encoding/json" @@ -11,19 +11,19 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/influxdata/platform/query" - "github.com/influxdata/platform/query/functions" - _ "github.com/influxdata/platform/query/options" - "github.com/influxdata/platform/query/parser" - "github.com/influxdata/platform/query/semantic" - "github.com/influxdata/platform/query/values" + "github.com/influxdata/flux" + "github.com/influxdata/flux/functions" + _ "github.com/influxdata/flux/options" + "github.com/influxdata/flux/parser" + "github.com/influxdata/flux/semantic" + "github.com/influxdata/flux/values" ) func init() { - query.FinalizeBuiltIns() + flux.FinalizeBuiltIns() } -var ignoreUnexportedQuerySpec = cmpopts.IgnoreUnexported(query.Spec{}) +var ignoreUnexportedQuerySpec = cmpopts.IgnoreUnexported(flux.Spec{}) func TestSpec_JSON(t *testing.T) { srcData := []byte(` @@ -57,12 +57,12 @@ func TestSpec_JSON(t *testing.T) { `) // Ensure we can properly unmarshal a query - gotQ := query.Spec{} + gotQ := flux.Spec{} if err := json.Unmarshal(srcData, &gotQ); err != nil { t.Fatal(err) } - expQ := query.Spec{ - Operations: []*query.Operation{ + expQ := flux.Spec{ + Operations: []*flux.Operation{ { ID: "from", Spec: &functions.FromOpSpec{ @@ -72,11 +72,11 @@ func TestSpec_JSON(t *testing.T) { { ID: "range", Spec: &functions.RangeOpSpec{ - Start: query.Time{ + Start: flux.Time{ Relative: -4 * time.Hour, IsRelative: true, }, - Stop: query.Time{ + Stop: flux.Time{ IsRelative: true, }, }, @@ -86,7 +86,7 @@ func TestSpec_JSON(t *testing.T) { Spec: &functions.SumOpSpec{}, }, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "from", Child: "range"}, {Parent: "range", Child: "sum"}, }, @@ -110,21 +110,21 @@ func TestSpec_JSON(t *testing.T) { func TestSpec_Walk(t *testing.T) { testCases := []struct { - query *query.Spec - walkOrder []query.OperationID + query *flux.Spec + walkOrder []flux.OperationID err error }{ { - query: &query.Spec{}, + query: &flux.Spec{}, err: errors.New("query has no root nodes"), }, { - query: &query.Spec{ - Operations: []*query.Operation{ + query: &flux.Spec{ + Operations: []*flux.Operation{ {ID: "a"}, {ID: "b"}, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "a", Child: "b"}, {Parent: "a", Child: "c"}, }, @@ -132,13 +132,13 @@ func TestSpec_Walk(t *testing.T) { err: errors.New("edge references unknown child operation \"c\""), }, { - query: &query.Spec{ - Operations: []*query.Operation{ + query: &flux.Spec{ + Operations: []*flux.Operation{ {ID: "a"}, {ID: "b"}, {ID: "b"}, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "a", Child: "b"}, {Parent: "a", Child: "b"}, }, @@ -146,13 +146,13 @@ func TestSpec_Walk(t *testing.T) { err: errors.New("found duplicate operation ID \"b\""), }, { - query: &query.Spec{ - Operations: []*query.Operation{ + query: &flux.Spec{ + Operations: []*flux.Operation{ {ID: "a"}, {ID: "b"}, {ID: "c"}, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "a", Child: "b"}, {Parent: "b", Child: "c"}, {Parent: "c", Child: "b"}, @@ -161,14 +161,14 @@ func TestSpec_Walk(t *testing.T) { err: errors.New("found cycle in query"), }, { - query: &query.Spec{ - Operations: []*query.Operation{ + query: &flux.Spec{ + Operations: []*flux.Operation{ {ID: "a"}, {ID: "b"}, {ID: "c"}, {ID: "d"}, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "a", Child: "b"}, {Parent: "b", Child: "c"}, {Parent: "c", Child: "d"}, @@ -178,74 +178,74 @@ func TestSpec_Walk(t *testing.T) { err: errors.New("found cycle in query"), }, { - query: &query.Spec{ - Operations: []*query.Operation{ + query: &flux.Spec{ + Operations: []*flux.Operation{ {ID: "a"}, {ID: "b"}, {ID: "c"}, {ID: "d"}, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "a", Child: "b"}, {Parent: "b", Child: "c"}, {Parent: "c", Child: "d"}, }, }, - walkOrder: []query.OperationID{ + walkOrder: []flux.OperationID{ "a", "b", "c", "d", }, }, { - query: &query.Spec{ - Operations: []*query.Operation{ + query: &flux.Spec{ + Operations: []*flux.Operation{ {ID: "a"}, {ID: "b"}, {ID: "c"}, {ID: "d"}, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "a", Child: "b"}, {Parent: "a", Child: "c"}, {Parent: "b", Child: "d"}, {Parent: "c", Child: "d"}, }, }, - walkOrder: []query.OperationID{ + walkOrder: []flux.OperationID{ "a", "c", "b", "d", }, }, { - query: &query.Spec{ - Operations: []*query.Operation{ + query: &flux.Spec{ + Operations: []*flux.Operation{ {ID: "a"}, {ID: "b"}, {ID: "c"}, {ID: "d"}, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "a", Child: "c"}, {Parent: "b", Child: "c"}, {Parent: "c", Child: "d"}, }, }, - walkOrder: []query.OperationID{ + walkOrder: []flux.OperationID{ "b", "a", "c", "d", }, }, { - query: &query.Spec{ - Operations: []*query.Operation{ + query: &flux.Spec{ + Operations: []*flux.Operation{ {ID: "a"}, {ID: "b"}, {ID: "c"}, {ID: "d"}, }, - Edges: []query.Edge{ + Edges: []flux.Edge{ {Parent: "a", Child: "c"}, {Parent: "b", Child: "d"}, }, }, - walkOrder: []query.OperationID{ + walkOrder: []flux.OperationID{ "b", "d", "a", "c", }, }, @@ -253,8 +253,8 @@ func TestSpec_Walk(t *testing.T) { for i, tc := range testCases { tc := tc t.Run(strconv.Itoa(i), func(t *testing.T) { - var gotOrder []query.OperationID - err := tc.query.Walk(func(o *query.Operation) error { + var gotOrder []flux.OperationID + err := tc.query.Walk(func(o *flux.Operation) error { gotOrder = append(gotOrder, o.ID) return nil }) @@ -280,7 +280,7 @@ func TestSpec_Walk(t *testing.T) { // Example_option demonstrates retrieving an option from the Flux interpreter func Example_option() { // Instantiate a new Flux interpreter with pre-populated option and global scopes - itrp := query.NewInterpreter() + itrp := flux.NewInterpreter() // Retrieve the default value for an option nowFunc := itrp.Option("now") @@ -296,7 +296,7 @@ func Example_option() { // Example_setOption demonstrates setting an option from the Flux interpreter func Example_setOption() { // Instantiate a new Flux interpreter with pre-populated option and global scopes - itrp := query.NewInterpreter() + itrp := flux.NewInterpreter() // Set a new option from the interpreter itrp.SetOption("dummy_option", values.NewIntValue(3)) @@ -312,8 +312,8 @@ func Example_overrideDefaultOptionExternally() { now = () => 2018-07-13T00:00:00Z what_time_is_it = now()` - itrp := query.NewInterpreter() - _, declarations := query.BuiltIns() + itrp := flux.NewInterpreter() + _, declarations := flux.BuiltIns() ast, _ := parser.NewAST(queryString) semanticProgram, _ := semantic.New(ast, declarations) @@ -334,8 +334,8 @@ func Example_overrideDefaultOptionExternally() { func Example_overrideDefaultOptionInternally() { queryString := `what_time_is_it = now()` - itrp := query.NewInterpreter() - _, declarations := query.BuiltIns() + itrp := flux.NewInterpreter() + _, declarations := flux.BuiltIns() ast, _ := parser.NewAST(queryString) semanticProgram, _ := semantic.New(ast, declarations) diff --git a/time.go b/time.go index a83a8d30d1..894b42045b 100644 --- a/time.go +++ b/time.go @@ -1,4 +1,4 @@ -package query +package flux import ( "math" diff --git a/trigger.go b/trigger.go index 778452108e..641ee3d859 100644 --- a/trigger.go +++ b/trigger.go @@ -1,4 +1,4 @@ -package query +package flux type TriggerSpec interface { Kind() TriggerKind diff --git a/values/array.go b/values/array.go index 4d94f387f8..7d079ffb87 100644 --- a/values/array.go +++ b/values/array.go @@ -5,7 +5,7 @@ import ( "regexp" "sort" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux/semantic" ) // Array represents an sequence of elements @@ -113,7 +113,7 @@ func (a *array) Equal(rhs Value) bool { return false } r := rhs.Array() - if (a.Len() != r.Len()) { + if a.Len() != r.Len() { return false } length := a.Len() diff --git a/values/binary.go b/values/binary.go index 9117cc8f3d..969a10c645 100644 --- a/values/binary.go +++ b/values/binary.go @@ -3,8 +3,8 @@ package values import ( "fmt" - "github.com/influxdata/platform/query/ast" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux/ast" + "github.com/influxdata/flux/semantic" ) type BinaryFunction func(l, r Value) Value diff --git a/values/function.go b/values/function.go index 0168b92d86..c613a13247 100644 --- a/values/function.go +++ b/values/function.go @@ -3,7 +3,7 @@ package values import ( "regexp" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux/semantic" ) // Function represents a callable type diff --git a/values/object.go b/values/object.go index dbcff5df52..912234c06e 100644 --- a/values/object.go +++ b/values/object.go @@ -4,7 +4,7 @@ import ( "regexp" "sync/atomic" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux/semantic" ) type Object interface { diff --git a/values/values.go b/values/values.go index 18ca7fa78d..7c218f46dc 100644 --- a/values/values.go +++ b/values/values.go @@ -5,7 +5,7 @@ import ( "fmt" "regexp" - "github.com/influxdata/platform/query/semantic" + "github.com/influxdata/flux/semantic" ) type Typer interface {