MCPcopy Create free account
hub / github.com/brimdata/super / subqueryExpr

Method subqueryExpr

compiler/semantic/expr.go:1289–1313  ·  view source on GitHub ↗
(astExpr ast.Expr, array bool, body ast.Seq, inType super.Type)

Source from the content-addressed store, hash-verified

1287}
1288
1289func (t *translator) subqueryExpr(astExpr ast.Expr, array bool, body ast.Seq, inType super.Type) (*sem.SubqueryExpr, super.Type) {
1290 // We pass inType in whether or not it's correlated since an uncorrelated
1291 // subquery will just ignore it.
1292 seq, outType := t.seq(body, inType)
1293 correlated := isCorrelated(seq)
1294 e := &sem.SubqueryExpr{
1295 Node: astExpr,
1296 Array: array,
1297 Correlated: correlated,
1298 Body: seq,
1299 }
1300 // Add a nullscan only for uncorrelated queries that don't have a source.
1301 if !correlated && !HasSource(e.Body) {
1302 e.Body.Prepend(&sem.NullScan{})
1303 }
1304 if !array && t.scope.sql != nil {
1305 // SQL expects a record with a single column result so unravel this
1306 // condition with this complex cleanup...
1307 e.Body, outType = t.scalarSubqueryCheck(astExpr, e.Body, outType)
1308 }
1309 if array {
1310 outType = t.sctx.LookupTypeArray(outType)
1311 }
1312 return e, outType
1313}
1314
1315func (t *translator) scalarSubqueryCheck(n ast.Node, seq sem.Seq, thisType super.Type) (sem.Seq, super.Type) {
1316 // In a SQL expression (except for RHS of EXISTS or IN, which both use array result),

Callers 2

exprMethod · 0.95
existsExprMethod · 0.95

Calls 6

seqMethod · 0.95
scalarSubqueryCheckMethod · 0.95
isCorrelatedFunction · 0.85
HasSourceFunction · 0.85
LookupTypeArrayMethod · 0.80
PrependMethod · 0.45

Tested by

no test coverage detected