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

Method writeSubquery

runtime/metricsview/astexpr.go:83–128  ·  view source on GitHub ↗
(sub *Subquery)

Source from the content-addressed store, hash-verified

81}
82
83func (b *sqlExprBuilder) writeSubquery(sub *Subquery) error {
84 // We construct a Query that combines the parent Query's contextual info with that of the Subquery.
85 outer := b.ast.Query
86 inner := &Query{
87 MetricsView: outer.MetricsView,
88 Dimensions: []Dimension{sub.Dimension},
89 Measures: sub.Measures,
90 PivotOn: nil,
91 Spine: nil,
92 Sort: nil,
93 TimeRange: outer.TimeRange,
94 ComparisonTimeRange: outer.ComparisonTimeRange,
95 Where: sub.Where,
96 Having: sub.Having,
97 Limit: nil,
98 Offset: nil,
99 TimeZone: outer.TimeZone,
100 UseDisplayNames: false,
101 Rows: false,
102 QueryLimits: outer.QueryLimits,
103 UnusedFields: nil,
104 } //exhaustruct:enforce
105
106 // Generate SQL for the subquery
107 innerSecurity := b.ast.Security
108 if !b.visible {
109 innerSecurity = skipMetricsViewSecurity{}
110 }
111 innerAST, err := NewAST(b.ast.MetricsView, innerSecurity, inner, b.ast.Dialect)
112 if err != nil {
113 return fmt.Errorf("failed to create AST for subquery: %w", err)
114 }
115 sql, args, err := innerAST.SQL()
116 if err != nil {
117 return fmt.Errorf("failed to generate SQL for subquery: %w", err)
118 }
119
120 // Output: (SELECT <dimension> FROM (<subquery>))
121 b.writeString("(SELECT ")
122 b.writeString(b.ast.Dialect.EscapeIdentifier(sub.Dimension.Name))
123 b.writeString(" FROM (")
124 b.writeString(sql)
125 b.writeString("))")
126 b.args = append(b.args, args...)
127 return nil
128}
129
130func (b *sqlExprBuilder) writeCondition(cond *Condition) error {
131 switch cond.Operator {

Callers 1

writeExpressionMethod · 0.95

Calls 5

SQLMethod · 0.95
writeStringMethod · 0.95
NewASTFunction · 0.85
ErrorfMethod · 0.65
EscapeIdentifierMethod · 0.65

Tested by

no test coverage detected