Bulat
Bulat

Reputation: 6979

BigQuery cost for complex logic in custom functions

I am using relatively expensive computation in the custom function defined like this:

CREATE TEMP FUNCTION HMAC256(message STRING, secret STRING)
  RETURNS STRING
  LANGUAGE js
  OPTIONS (
    -- copy this Forge library file to Storage:
    -- https://cdn.jsdelivr.net/npm/[email protected]/dist/forge.min.js
    -- @see https://github.com/digitalbazaar/forge
    library=["gs://.../forge.min.js"]
  )
  AS
"""
  var hmac = forge.hmac.create();
  hmac.start('sha256', secret);
  hmac.update(message);
  return hmac.digest().toHex();
""";


SELECT HMAC256("test", "111");

-- Row  f0_
-- 1    f8320c4eded4b06e99c1a884a25c80b2c88860e13b64df1eb6f0d3191023482b

Will this be more expensive compared to applying LOWER function for example?

I cannot see anything different in the bytes billed details while HMAC256 took 4 min on my dataset compared to 14 seconds for LOWER.

It would be awesome if price is the same. I have a feeling I miss something.

Upvotes: 0

Views: 132

Answers (1)

Yun Zhang
Yun Zhang

Reputation: 5518

Yes. The cost will be the same. Your query can get more complicated and more expensive to BigQuery, but you're only charged of same rate until your query hit the limit. Your off-limits query will fail if you don't have reservation (aka flat-rate slots).

All high compute queries under tier 100 are billed as tier 1.

All queries above tier 100 will fail with a RESOURCES_EXCEEDED_PER_BYTE error unless the query is running in a reserved instance.

Upvotes: 1

Related Questions