【发布时间】:2015-04-17 22:28:41
【问题描述】:
试图让我的外部 CityHash 返回与 BigQuery Hash() 相同的值。 以下是我要匹配的值:
唯一匹配的散列字符串是一个空白字符串。
在BigQuery Query Reference 中,它提到它使用了 CityHash 库。我试过为 CityHash 使用多个外部库,它们彼此一致,但与 BigQuery Hash() 不一致
以下是 Go (Golang) 中的 CityHash 示例:
package main
import (
"fmt"
"bitbucket.org/creachadair/cityhash"
)
func main() {
var bytesToHash = []byte("mystringtohash")
myHash := int64(cityhash.Hash64(bytesToHash))
fmt.Printf("Hashed version of '%s': %d\n", bytesToHash, myHash)
bytesToHash = []byte("")
myHash = int64(cityhash.Hash64(bytesToHash))
fmt.Printf("Hashed version of '%s': %d\n", bytesToHash, myHash)
}
这是我的程序的输出:
Hashed version of 'mystringtohash': -6615946700494525143
Hashed version of '1234': 882600748797058222
Hashed version of '': -7286425919675154353
BigQuery 是否在对字符串进行哈希处理之前对其进行了特殊处理?
【问题讨论】:
-
您能否更新您的帖子以显示您的程序输出。
-
对我来说,BigQuery 结果与 C++ cityhash 库一致,我无法在 Go 操场上运行您的 Go 程序,它找不到 import cityhash(我对 Go 程序一无所知)
-
好的,我添加了 Go 代码的结果。感谢您的关注...
标签: hash google-bigquery