Skip to content

Instantly share code, notes, and snippets.

@pcejrowski
Last active March 30, 2022 20:46
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcejrowski/6abcb9813f3125b63da1f8ddda986bde to your computer and use it in GitHub Desktop.
Save pcejrowski/6abcb9813f3125b63da1f8ddda986bde to your computer and use it in GitHub Desktop.
Farm Fingerprint function

Farm Fingerprint in different languages

BigQuery SQL

The FARM_FINGERPRINT(value) functioncomputes the fingerprint of the STRING or BYTES input using the Fingerprint64 function from the open-source FarmHash library. The output of this function for a particular input will never change.

select FARM_FINGERPRINT("alphabet")
-2427165924636348523

Scala/Java

Use Guava

Welcome to the Ammonite Repl 2.1.4 (Scala 2.13.2 Java 1.8.0_131)
@ import $ivy.`com.google.guava:guava:28.0-jre`
import $ivy.$

@ import com.google.common.hash.Hashing
import com.google.common.hash.Hashing

@ import java.nio.charset.StandardCharsets
import java.nio.charset.StandardCharsets

@ Hashing.farmHashFingerprint64().hashString("alphabet", StandardCharsets.UTF_8).asLong;
res4: Long = -2427165924636348523L

Python

Use pyfarmhash:

pip install pyfarmhash
Python 3.7.5 (default, Nov  1 2019, 02:16:38)
[Clang 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import farmhash
>>> import ctypes
>>> ctypes.c_long(farmhash.fingerprint64('alphabet'))
c_long(-2427165924636348523)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment