Skip to content

Commit

Permalink
feat(spanner/spansql): fix unstable SelectFromTable SQL
Browse files Browse the repository at this point in the history
googleapis#4457 made unstable SQL string, and fail test sometimes like this.
```
--- FAIL: TestSQL (0.00s)
    sql_test.go:410: {{false [A] [{Table  map[FORCE_INDEX:Idx GROUPBY_SCAN_OPTIMIZATION:TRUE]}] {4 B b <nil>} [] [] []} [] <nil> <nil>}.SQL() wrong.
         got SELECT A FROM Table@{GROUPBY_SCAN_OPTIMIZATION=TRUE,FORCE_INDEX=Idx} WHERE B = @b
        want SELECT A FROM Table@{FORCE_INDEX=Idx,GROUPBY_SCAN_OPTIMIZATION=TRUE} WHERE B = @b
```
Because map range result is unstable.
This PR makes the SQL output stable by sorting the Hints keys.
  • Loading branch information
takeshi.nakata committed Jul 21, 2021
1 parent 3d305fa commit 02731d4
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions spanner/spansql/sql.go
Expand Up @@ -25,6 +25,7 @@ package spansql

import (
"fmt"
"sort"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -373,6 +374,7 @@ func (sft SelectFromTable) SQL() string {
kvs[i] = fmt.Sprintf("%s=%s", k, v)
i++
}
sort.Strings(kvs)
str += strings.Join(kvs, ",")
str += "}"
}
Expand Down

0 comments on commit 02731d4

Please sign in to comment.