Skip to content

Instantly share code, notes, and snippets.

@hamakn
Last active March 21, 2024 00:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamakn/65243b7120df5daeb374d7c500fd099b to your computer and use it in GitHub Desktop.
Save hamakn/65243b7120df5daeb374d7c500fd099b to your computer and use it in GitHub Desktop.
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