Skip to content

Commit

Permalink
[query] Expose Graphite Compile method. (#2624)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnikola authored Sep 10, 2020
1 parent 8223666 commit 47eaa98
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/query/graphite/native/aggregation_functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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},
}},
}

Expand Down
6 changes: 3 additions & 3 deletions src/query/graphite/native/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions src/query/graphite/native/compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/query/graphite/native/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 47eaa98

Please sign in to comment.