Skip to content

Commit dc1964a

Browse files
fix for name resolution collision bug (dolt#1661)
1 parent 597d3e2 commit dc1964a

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

sql/analyzer/resolve_orderby.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ func pushdownSort(ctx *sql.Context, a *Analyzer, n sql.Node, scope *Scope) (sql.
4141
}
4242

4343
childAliases := aliasesDefinedInNode(sort.Child)
44-
var schemaCols []string
44+
var schemaCols []tableCol
4545
for _, col := range sort.Child.Schema() {
46-
schemaCols = append(schemaCols, strings.ToLower(col.Name))
46+
schemaCols = append(schemaCols, tableCol{
47+
table: strings.ToLower(col.Source),
48+
col: strings.ToLower(col.Name),
49+
})
4750
}
4851

4952
var colsFromChild []string
@@ -55,7 +58,7 @@ func pushdownSort(ctx *sql.Context, a *Analyzer, n sql.Node, scope *Scope) (sql.
5558
name := strings.ToLower(n.Name())
5659
if stringContains(childAliases, name) {
5760
colsFromChild = append(colsFromChild, n.Name())
58-
} else if !stringContains(schemaCols, name) {
61+
} else if !tableColsContaints(schemaCols, tableColFromNameable(n)) {
5962
missingCols = append(missingCols, n.Name())
6063
}
6164
}
@@ -296,3 +299,13 @@ func findExprNameables(e sql.Expression) []sql.Nameable {
296299
})
297300
return result
298301
}
302+
303+
func tableColFromNameable(n sql.Nameable) (tc tableCol) {
304+
tc = tableCol{
305+
col: n.Name(),
306+
}
307+
if t, ok := n.(sql.Tableable); ok {
308+
tc.table = t.Table()
309+
}
310+
return
311+
}

sql/analyzer/validation_rules.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,3 +475,13 @@ func stringContains(strs []string, target string) bool {
475475
}
476476
return false
477477
}
478+
479+
func tableColsContains(strs []tableCol, target tableCol) bool {
480+
for _, s := range strs {
481+
if s == target {
482+
return true
483+
}
484+
}
485+
return false
486+
}
487+

0 commit comments

Comments
 (0)