// findColumn looks up the column described by a QualifiedName. The qname will be normalized. func (qt qvalResolver) findColumn(qname *parser.QualifiedName) (columnRef, error) { ref := columnRef{colIdx: invalidColIdx} if err := qname.NormalizeColumnName(); err != nil { return ref, err } // We can't resolve stars to a single column. if qname.IsStar() { err := fmt.Errorf("qualified name \"%s\" not found", qname) return ref, err } // TODO(radu): when we support multiple FROMs, we will find the node with the correct alias; if // no alias is given, we will search for the column in all FROMs and make sure there is only // one. For now we just check that the name matches (if given). if qname.Base == "" { qname.Base = parser.Name(qt.table.alias) } if equalName(qt.table.alias, string(qname.Base)) { colName := qname.Column() for idx, col := range qt.table.columns { if equalName(col.Name, colName) { ref.table = qt.table ref.colIdx = idx return ref, nil } } } err := fmt.Errorf("qualified name \"%s\" not found", qname) return ref, err }
func (v *qnameVisitor) getDesc(qname *parser.QualifiedName) *TableDescriptor { if v.desc == nil { return nil } if qname.Base == "" { qname.Base = parser.Name(v.desc.Alias) return v.desc } if equalName(v.desc.Alias, string(qname.Base)) { return v.desc } return nil }
func (p *planner) normalizeTableName(qname *parser.QualifiedName) error { if qname == nil || qname.Base == "" { return fmt.Errorf("empty table name: %s", qname) } if len(qname.Indirect) == 0 { if p.session.Database == "" { return fmt.Errorf("no database specified") } qname.Indirect = append(qname.Indirect, parser.NameIndirection(qname.Base)) qname.Base = parser.Name(p.session.Database) } return nil }