@@ -41,9 +41,12 @@ func pushdownSort(ctx *sql.Context, a *Analyzer, n sql.Node, scope *Scope) (sql.
41
41
}
42
42
43
43
childAliases := aliasesDefinedInNode (sort .Child )
44
- var schemaCols []string
44
+ var schemaCols []tableCol
45
45
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
+ })
47
50
}
48
51
49
52
var colsFromChild []string
@@ -55,7 +58,7 @@ func pushdownSort(ctx *sql.Context, a *Analyzer, n sql.Node, scope *Scope) (sql.
55
58
name := strings .ToLower (n .Name ())
56
59
if stringContains (childAliases , name ) {
57
60
colsFromChild = append (colsFromChild , n .Name ())
58
- } else if ! stringContains (schemaCols , name ) {
61
+ } else if ! tableColsContaints (schemaCols , tableColFromNameable ( n ) ) {
59
62
missingCols = append (missingCols , n .Name ())
60
63
}
61
64
}
@@ -296,3 +299,13 @@ func findExprNameables(e sql.Expression) []sql.Nameable {
296
299
})
297
300
return result
298
301
}
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
+ }
0 commit comments