An Example demonstrates how to use ZetaSketch with BigQuery.
$ git clone https://github.com/phstudy/zetasketch-bigquery-example.git
$ cd zetasketch-bigquery-example
$ GOOGLE_APPLICATION_CREDENTIALS=/path/to/my/key.json ./gradlew run
HyperLogLogPlusPlus<String> hll = new HyperLogLogPlusPlus.Builder().buildForStrings();
hll.add("apple");
hll.add("orange");
hll.add("banana");
String sql = //
"SELECT"
+ " HLL_COUNT.INIT(fruit) AS fruit_hll"
+ " FROM UNNEST(['apple', 'orange', 'banana']) AS fruit";
TableResult result = queryBigQuery(sql);
FieldValueList row = result.getValues().iterator().next();
byte[] hllBytes = row.get("fruit_hll").getBytesValue();
HyperLogLogPlusPlus<String> rst = (HyperLogLogPlusPlus<String>) HyperLogLogPlusPlus.forProto(hllBytes);
String base64Str = Base64.getEncoder().encodeToString(hll.serializeToByteArray());
String sql = "SELECT HLL_COUNT.EXTRACT(FROM_BASE64('" + base64Str + "')) AS fruit_cnt";
TableResult result = queryBigQuery(sql);
FieldValueList row = result.getValues().iterator().next();
long cnt = row.get("fruit_cnt").getLongValue();