Implement CheckNamedValue for statsColumnConverter #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
實作
NamedValueChecker
這個 interface。Motivation and Context
起因
試著再 migrate 一次到 go modules 時,發現 unit test fail:
追查後發現是升級 mongo-go-driver 時導致其他 dependencies 也跟著升級:
升級 mongo-go-driver (v1.3.1 -> v1.4.0)
-> mongo-go-driver@v1.4.0 多了
github.com/aws/aws-sdk-go@v1.29.15
-> aws-sdk-go 依賴 go-sql-driver/mysql@v1.5.0
-> 我們原本的 go-sql-driver/mysql 是
7ebe0a500653eeb1859664bed5e48dec1e164e73
(v1.2 ~ v1.3 中間的 commit),根據 minimal version selection,go module 會選擇 v1.5.0。根源
在原本的 go-sql-driver/mysql 版本裡,呼叫
ConvertValue()
時,遇到 type 是 uint 的都會轉成 int64。[1]而 golang 內建的 sql package 會再檢查 converted 後的值,若是 uint 會回傳 false。[2]
但到了 go-sql-driver/mysql@v1.5.0 時,
ConvertValue()
不再把 uint 轉型成 int64 了 [3],driver.IsValue()
會是 false [4]。[1]
ConvertValue()@7ebe0a500653eeb1859664bed5e48dec1e164e73
[2]
IsValue()
[3]
ConvertValue()@v1.5.0
[4]
CheckNamedValue()
解法
CheckNamedValue()
而躲開使用ccChecker
[5]。[5] https://github.com/golang/go/blob/7c58ef732efd9bf0d0882bb95371ce1909924a75/src/database/sql/convert.go#L127
[6] https://github.com/aws/aws-sdk-go/blob/v1.35.5/go.mod
[7] https://github.com/mongodb/mongo-go-driver/blob/master/go.mod
詳情
ColumnConverter
裡的idx
參數實際上並沒有用到,所以給什麼都無所謂,他會回傳一個空的 converter object [8]。[8] https://github.com/go-sql-driver/mysql/blob/v1.5.0/statement.go#L42
Related Issue and PR