From 47eaa98b4e22ecc978ffc8210af2e1c1c1f3c26a Mon Sep 17 00:00:00 2001 From: arnikola Date: Thu, 10 Sep 2020 18:18:01 -0400 Subject: [PATCH] [query] Expose Graphite Compile method. (#2624) --- src/query/graphite/native/aggregation_functions_test.go | 6 +++--- src/query/graphite/native/compiler.go | 6 +++--- src/query/graphite/native/compiler_test.go | 4 ++-- src/query/graphite/native/engine.go | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/query/graphite/native/aggregation_functions_test.go b/src/query/graphite/native/aggregation_functions_test.go index cb19232d5b..8ea1343ee4 100644 --- a/src/query/graphite/native/aggregation_functions_test.go +++ b/src/query/graphite/native/aggregation_functions_test.go @@ -151,7 +151,7 @@ func (e mockEngine) FetchByQuery( } func TestVariadicSumSeries(t *testing.T) { - expr, err := compile("sumSeries(foo.bar.*, foo.baz.*)") + expr, err := Compile("sumSeries(foo.bar.*, foo.baz.*)") require.NoError(t, err) ctx := common.NewTestContext() ctx.Engine = mockEngine{fn: func( @@ -485,7 +485,7 @@ func TestGroupByNodes(t *testing.T) { tests := []struct { fname string - nodes []int + nodes []int expectedResults []result }{ {"avg", []int{2, 4}, []result{ // test normal group by nodes @@ -507,7 +507,7 @@ func TestGroupByNodes(t *testing.T) { {"pod2.500", 8 * 12}, }}, {"sum", []int{}, []result{ // test empty slice handing. - {"*", (2 + 4 + 6 + 8 + 10 + 20 + 30 + 40) * 12}, + {"*", (2 + 4 + 6 + 8 + 10 + 20 + 30 + 40) * 12}, }}, } diff --git a/src/query/graphite/native/compiler.go b/src/query/graphite/native/compiler.go index 616bb21dd0..bbca546914 100644 --- a/src/query/graphite/native/compiler.go +++ b/src/query/graphite/native/compiler.go @@ -30,8 +30,8 @@ import ( "github.com/m3db/m3/src/query/graphite/lexer" ) -// compile converts an input stream into the corresponding Expression -func compile(input string) (Expression, error) { +// Compile converts an input stream into the corresponding Expression. +func Compile(input string) (Expression, error) { booleanLiterals := map[string]lexer.TokenType{ "true": lexer.True, "false": lexer.False, @@ -322,7 +322,7 @@ func (c *compiler) errorf(msg string, args ...interface{}) error { // ExtractFetchExpressions extracts timeseries fetch expressions from the given query func ExtractFetchExpressions(s string) ([]string, error) { - expr, err := compile(s) + expr, err := Compile(s) if err != nil { return nil, err } diff --git a/src/query/graphite/native/compiler_test.go b/src/query/graphite/native/compiler_test.go index 61dc7b4cc8..40f917082f 100644 --- a/src/query/graphite/native/compiler_test.go +++ b/src/query/graphite/native/compiler_test.go @@ -276,7 +276,7 @@ func TestCompile1(t *testing.T) { } for _, test := range tests { - expr, err := compile(test.input) + expr, err := Compile(test.input) require.Nil(t, err, "error compiling: expression='%s', error='%v'", test.input, err) require.NotNil(t, expr) assertExprTree(t, test.result, expr, fmt.Sprintf("invalid result for %s: %v vs %v", @@ -381,7 +381,7 @@ func TestCompileErrors(t *testing.T) { } for _, test := range tests { - expr, err := compile(test.input) + expr, err := Compile(test.input) require.NotNil(t, err, "no error for %s", test.input) assert.Equal(t, test.err, err.Error(), "wrong error for %s", test.input) assert.Nil(t, expr, "non-nil expression for %s", test.input) diff --git a/src/query/graphite/native/engine.go b/src/query/graphite/native/engine.go index 39c662eefa..a1a9d234b8 100644 --- a/src/query/graphite/native/engine.go +++ b/src/query/graphite/native/engine.go @@ -50,5 +50,5 @@ func (e *Engine) FetchByQuery( // Compile compiles an expression from an expression string func (e *Engine) Compile(s string) (Expression, error) { - return compile(s) + return Compile(s) }