MCPcopy Index your code
hub / github.com/rilldata/rill / inferSQLRefs

Method inferSQLRefs

runtime/parser/parse_model.go:320–364  ·  view source on GitHub ↗

inferSQLRefs attempts to infer table references from the node's SQL. The provided node must have a non-empty SQL field.

(node *Node)

Source from the content-addressed store, hash-verified

318// inferSQLRefs attempts to infer table references from the node's SQL.
319// The provided node must have a non-empty SQL field.
320func (p *Parser) inferSQLRefs(node *Node) ([]ResourceName, error) {
321 // Currently only supports DuckDB.
322 driver, _, _ := p.driverForConnector(node.Connector)
323 if driver != "duckdb" {
324 return nil, nil
325 }
326
327 // Skip if the SQL is templated (because the DuckDB parser may choke on the template handlebars)
328 if node.SQLUsesTemplating {
329 return nil, nil
330 }
331
332 // Parse the SQL
333 ast, err := duckdbsql.Parse(node.SQL)
334 if err != nil {
335 path := node.SQLPath
336 if path == "" {
337 path = node.YAMLPath
338 }
339
340 var posError duckdbsql.PositionError
341 if errors.As(err, &posError) {
342 return nil, pathError{
343 path: path,
344 err: locationError{
345 err: posError.Err(),
346 location: &runtimev1.CharLocation{
347 Line: uint32(findLineNumber(node.SQL, posError.Position)),
348 },
349 },
350 }
351 }
352 return nil, pathError{path: path, err: newDuckDBError(err)}
353 }
354
355 // Scan SQL for table references, tracking references in refs
356 var refs []ResourceName
357 for _, t := range ast.GetTableRefs() {
358 if !t.LocalAlias && t.Name != "" && t.Function == "" && len(t.Paths) == 0 {
359 refs = append(refs, ResourceName{Name: t.Name})
360 }
361 }
362
363 return refs, nil
364}
365
366func (p *Parser) trackResourceNamesForDataPaths(ctx context.Context, name ResourceName, inputProps map[string]any) error {
367 c, ok := inputProps["invalidate_on_change"].(bool)

Callers 1

parseModelMethod · 0.95

Calls 6

driverForConnectorMethod · 0.95
ErrMethod · 0.95
ParseFunction · 0.92
findLineNumberFunction · 0.85
newDuckDBErrorFunction · 0.85
GetTableRefsMethod · 0.80

Tested by

no test coverage detected