MCPcopy Index your code
hub / github.com/sqlc-dev/sqlc / convertSelectWithUnionQuery

Method convertSelectWithUnionQuery

internal/engine/clickhouse/convert.go:41–79  ·  view source on GitHub ↗
(n *chast.SelectWithUnionQuery)

Source from the content-addressed store, hash-verified

39}
40
41func (c *cc) convertSelectWithUnionQuery(n *chast.SelectWithUnionQuery) ast.Node {
42 if len(n.Selects) == 0 {
43 return &ast.TODO{}
44 }
45
46 // Single select without union
47 if len(n.Selects) == 1 {
48 return c.convert(n.Selects[0])
49 }
50
51 // Build a chain of SelectStmt with UNION operations
52 var result *ast.SelectStmt
53 for i, sel := range n.Selects {
54 stmt, ok := c.convert(sel).(*ast.SelectStmt)
55 if !ok {
56 continue
57 }
58 if i == 0 {
59 result = stmt
60 } else {
61 unionMode := ast.Union
62 if i-1 < len(n.UnionModes) {
63 switch strings.ToUpper(n.UnionModes[i-1]) {
64 case "ALL":
65 unionMode = ast.Union
66 case "DISTINCT":
67 unionMode = ast.Union
68 }
69 }
70 result = &ast.SelectStmt{
71 Op: unionMode,
72 All: n.UnionAll || (i-1 < len(n.UnionModes) && strings.ToUpper(n.UnionModes[i-1]) == "ALL"),
73 Larg: result,
74 Rarg: stmt,
75 }
76 }
77 }
78 return result
79}
80
81func (c *cc) convertSelectQuery(n *chast.SelectQuery) *ast.SelectStmt {
82 stmt := &ast.SelectStmt{}

Callers 1

convertMethod · 0.95

Calls 1

convertMethod · 0.95

Tested by

no test coverage detected