MCPcopy Create free account
hub / github.com/rilldata/rill / SQL

Method SQL

runtime/metricsview/astsql.go:10–43  ·  view source on GitHub ↗

SQL builds a SQL query from the AST. It returns the query and query arguments to be passed to the database driver.

()

Source from the content-addressed store, hash-verified

8// SQL builds a SQL query from the AST.
9// It returns the query and query arguments to be passed to the database driver.
10func (a *AST) SQL() (string, []any, error) {
11 b := &sqlBuilder{
12 ast: a,
13 out: &strings.Builder{},
14 }
15
16 if len(a.CTEs) > 0 {
17 b.out.WriteString("WITH ")
18 for i, cte := range a.CTEs {
19 if i > 0 {
20 b.out.WriteString(", ")
21 }
22 b.out.WriteString(cte.Alias)
23 b.out.WriteString(" AS (")
24 err := b.writeSelect(cte)
25 if err != nil {
26 return "", nil, err
27 }
28 b.out.WriteString(") ")
29 }
30 }
31
32 var err error
33 if a.Query.UseDisplayNames {
34 err = b.writeSelectWithDisplayNames(a.Root)
35 } else {
36 err = b.writeSelect(a.Root)
37 }
38 if err != nil {
39 return "", nil, err
40 }
41
42 return b.out.String(), b.args, nil
43}
44
45type sqlBuilder struct {
46 ast *AST

Callers 8

writeSubqueryMethod · 0.95
TestCompileFunction · 0.95
SchemaMethod · 0.95
QueryMethod · 0.95
ExportMethod · 0.95
SearchMethod · 0.95

Calls 3

writeSelectMethod · 0.95
StringMethod · 0.65

Tested by 1

TestCompileFunction · 0.76