Skip to content

Commit

Permalink
✨ compiler multi-stat WalkSorted + bugfix (#3015)
Browse files Browse the repository at this point in the history
Signed-off-by: Dominik Richter <[email protected]>
  • Loading branch information
arlimus authored Jan 12, 2024
1 parent a2ab5b0 commit 061256f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 3 additions & 3 deletions mqlc/mqlc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2243,12 +2243,12 @@ func CompileAST(ast *parser.AST, props map[string]*llx.Primitive, conf CompilerC
// Compile a code piece against a schema into chunky code
func compile(input string, props map[string]*llx.Primitive, compilerConf CompilerConfig) (*llx.CodeBundle, error) {

conf := compilerConf
conf.Stats = compilerConf.Stats.CompileQuery(input)

// remove leading whitespace; we are re-using this later on
input = Dedent(input)

conf := compilerConf
conf.Stats = compilerConf.Stats.CompileQuery(input)

ast, err := parser.Parse(input)
if ast == nil {
return nil, err
Expand Down
13 changes: 12 additions & 1 deletion mqlc/mqlc_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,18 @@ func newCompilerMultiStats() *compilerMultiStats {
}

func (c *compilerMultiStats) WalkSorted(f func(resource string, field string, info FieldStat)) {
panic("walking code on multi-stats not yet supported")
c.lock.Lock()
defer c.lock.Unlock()

aggregate := newCompilerStats()
for _, v := range c.stats {
v.WalkSorted(func(resource, field string, info FieldStat) {
aggregate.CallResource(resource)
aggregate.ResourceFields[resource][field] = info
})
}

aggregate.WalkSorted(f)
}

func (c *compilerMultiStats) WalkCode(f func(code string, stats CompilerStats)) {
Expand Down

0 comments on commit 061256f

Please sign in to comment.