1

As illustrated here, dumping the wasm byte code and copy past into the javascript seems difficult.

Fuyang Liu
  • 1,496
  • 13
  • 26

1 Answers1

5

I guess you mean a better way than copying into JS - I haven't investigated that (yet), but this will make UDFs easier for others to use:

  • Move the .js out of the query into a file.
  • Create a persistent function.

Then people will be able to call it like this:

SELECT fhoffa.x.sample_wasm_udf([2,3,4])

To create this function I did:

CREATE OR REPLACE FUNCTION fhoffa.x.sample_wasm_udf(x ARRAY<INT64>) 
RETURNS ARRAY<INT64>
LANGUAGE js AS '''
   return main(x)
'''
OPTIONS (library="gs://fh-bigquery/js/wasm.udf.js");

For more on persistent functions, see:

Felipe Hoffa
  • 54,922
  • 16
  • 151
  • 325
  • Aha, I see, thanks, this could help I think. Just a follow up question, only gs:// is supported? If the js file is on some github page or on some web server, would it be also supported? – Fuyang Liu Feb 06 '20 at 21:23
  • @Felipe is there a place where I can see all global persistent UDFs available? Like "fhoffa.x...."? – stkvtflw Apr 18 '22 at 11:51