(qc *QueryCatalog, rvs []*ast.RangeVar, args []paramRef, params *named.ParamSet, embeds rewrite.EmbedSet)
| 22 | } |
| 23 | |
| 24 | func (comp *Compiler) resolveCatalogRefs(qc *QueryCatalog, rvs []*ast.RangeVar, args []paramRef, params *named.ParamSet, embeds rewrite.EmbedSet) ([]Parameter, error) { |
| 25 | c := comp.catalog |
| 26 | |
| 27 | aliasMap := map[string]*ast.TableName{} |
| 28 | // TODO: Deprecate defaultTable |
| 29 | var defaultTable *ast.TableName |
| 30 | var tables []*ast.TableName |
| 31 | |
| 32 | typeMap := map[string]map[string]map[string]*catalog.Column{} |
| 33 | indexTable := func(table catalog.Table) error { |
| 34 | tables = append(tables, table.Rel) |
| 35 | if defaultTable == nil { |
| 36 | defaultTable = table.Rel |
| 37 | } |
| 38 | schema := table.Rel.Schema |
| 39 | if schema == "" { |
| 40 | schema = c.DefaultSchema |
| 41 | } |
| 42 | if _, exists := typeMap[schema]; !exists { |
| 43 | typeMap[schema] = map[string]map[string]*catalog.Column{} |
| 44 | } |
| 45 | typeMap[schema][table.Rel.Name] = map[string]*catalog.Column{} |
| 46 | for _, c := range table.Columns { |
| 47 | cc := c |
| 48 | typeMap[schema][table.Rel.Name][c.Name] = cc |
| 49 | } |
| 50 | return nil |
| 51 | } |
| 52 | |
| 53 | for _, rv := range rvs { |
| 54 | if rv.Relname == nil { |
| 55 | continue |
| 56 | } |
| 57 | fqn, err := ParseTableName(rv) |
| 58 | if err != nil { |
| 59 | return nil, err |
| 60 | } |
| 61 | if _, found := aliasMap[fqn.Name]; found { |
| 62 | continue |
| 63 | } |
| 64 | table, err := c.GetTable(fqn) |
| 65 | if err != nil { |
| 66 | if qc == nil { |
| 67 | continue |
| 68 | } |
| 69 | // If the table name doesn't exist, first check if it's a CTE |
| 70 | if _, qcerr := qc.GetTable(fqn); qcerr != nil { |
| 71 | return nil, err |
| 72 | } |
| 73 | continue |
| 74 | } |
| 75 | err = indexTable(table) |
| 76 | if err != nil { |
| 77 | return nil, err |
| 78 | } |
| 79 | if rv.Alias != nil { |
| 80 | aliasMap[*rv.Alias.Aliasname] = fqn |
| 81 | } |
no test coverage detected