selectFrom analyzes the FROM clause which is a cross-joined set of table expressions. inType is from the immediate pipe parent in a top-level select, nil otherwise
(loc ast.Loc, from ast.SQLTableExpr, seq sem.Seq, inType super.Type)
| 295 | // selectFrom analyzes the FROM clause which is a cross-joined set of table expressions. |
| 296 | // inType is from the immediate pipe parent in a top-level select, nil otherwise |
| 297 | func (t *translator) selectFrom(loc ast.Loc, from ast.SQLTableExpr, seq sem.Seq, inType super.Type) (sem.Seq, relScope) { |
| 298 | if from == nil { |
| 299 | // No FROM clause means the pipe parent is providing input in which |
| 300 | // case inType is the type of that input, or there is no input at all, |
| 301 | // in which case we should model an empty table. |
| 302 | if inType == nil || inType == super.TypeNull { |
| 303 | // Model no or null input as an input table so that column checks fail. |
| 304 | return seq, newTableFromType(t.sctx.MustLookupTypeRecord([]super.Field{}), t.checker.unknown) |
| 305 | } |
| 306 | return seq, newTableFromType(inType, t.checker.unknown) |
| 307 | } |
| 308 | off := len(seq) |
| 309 | hasParent := off > 0 |
| 310 | seq, scope := t.sqlTableExpr(from, seq) |
| 311 | if off >= len(seq) { |
| 312 | // The chain didn't get lengthed so semFrom must have encountered |
| 313 | // an error... |
| 314 | return seq, badTable |
| 315 | } |
| 316 | // If we have parents with both a from and select, report an error but |
| 317 | // only if it's not a RobotScan where the parent feeds the from operateor. |
| 318 | if _, ok := seq[off].(*sem.RobotScan); !ok { |
| 319 | if hasParent { |
| 320 | t.error(loc, errors.New("SELECT cannot have both an embedded FROM clause and input from parents")) |
| 321 | return append(seq, badOp), badTable |
| 322 | } |
| 323 | } |
| 324 | return seq, scope |
| 325 | } |
| 326 | |
| 327 | // sqlValues analyzes the values expression which currently cannot depend |
| 328 | // on the input data (until we add support for lateral joins; then a values |
no test coverage detected