aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/query/query.go
blob: 3552c3f2ab1c3c58f2e4421c5affcf375b3298e8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package query

import (
	"fmt"
	"strings"
)

func writeIndent(b *strings.Builder, level int) {
	for range level {
		b.WriteByte('\t')
	}
}

func Compile(userQuery string, optimizationLevel int, numWorkers uint) (CompilationArtifact, error) {
	if numWorkers == 0 {
		return CompilationArtifact{}, fmt.Errorf("Cannot compile with 0 workers")
	}

	clause, err := Parse(Lex(userQuery))
	if err != nil {
		return CompilationArtifact{}, err
	}

	NewOptimizer(clause, numWorkers).Optimize(optimizationLevel)

	return clause.Compile()
}