Skip to content

Instantly share code, notes, and snippets.

@hamakn
Last active Jun 5, 2021
Embed
What would you like to do?
how to deal with FARM_FINGERPRINT between BQ and golang
select
FARM_FINGERPRINT("UserCustomerID + salt"), -- => -3587376224092439943
mod(abs(FARM_FINGERPRINT("UserCustomerID + salt")), 100) -- => 43
package main
import (
"fmt"
"github.com/dgryski/go-farm"
)
// http://cavaliercoder.com/blog/optimized-abs-for-int64-in-go.html
func abs(n int64) int64 {
y := n >> 63
return (n ^ y) - y
}
func main() {
y := farm.Fingerprint64([]byte("UserCustomerID + salt"))
fmt.Println(y) // => 14859367849617111673
fmt.Println(int64(y)) // => -3587376224092439943
fmt.Println(abs(int64(y)) % 100) // 43
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment