You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
gosqlx: ExtractMetadata and Extract* return tables/columns/functions in random map order #619
gosqlx.ExtractMetadata returns Tables, Columns, Functions and their qualified variants in Go map iteration order, so repeated calls on the same AST return differently ordered slices. ExtractTables, ExtractTablesQualified, ExtractColumns, ExtractColumnsQualified and ExtractFunctions have the same problem. This makes their output unsuitable for snapshot tests, caching keys or stable CLI/JSON output.
Reproduction
tree, _:=gosqlx.Parse("SELECT a, b, c, d, e, f, g, h FROM t1 JOIN t2 ON t1.x = t2.y JOIN t3 ON t3.z = t1.x")
fori:=0; i<20; i++ {
m:=gosqlx.ExtractMetadata(tree)
fmt.Println(strings.Join(m.Columns, ","), strings.Join(m.Tables, ","))
}
Actual (main 61ca6c8): Columns came back in 20 distinct orders across 20 calls, for example c,h,x,a,b,d,e,f,g,y,z and then x,y,z,a,d,e,g,h,b,c,f. Tables came back as t1,t2,t3 15 times, t2,t3,t1 4 times and t3,t1,t2 once.
Expected: the same order on every call, either first-appearance order or sorted.
Notes
pkg/gosqlx/extract.go:557 (stringSetToSlice) and pkg/gosqlx/extract.go:568 (qualifiedSetToSlice) range over the dedup maps and never sort the result. All the Extract* functions and ExtractMetadata (extract.go:700-704) go through these helpers.
Simplest fix: slices.Sort the result in both helpers, with a total order on QualifiedName (Schema, Table, Name). Keeping first-appearance order would need an ordered slice next to each dedup map in metadataCollector.
Activity
fix(gosqlx): return Extract* and ExtractMetadata results in determini…