简体   繁体   中英

Can I use `TextEncoder` in Bigquery JS UDF?

I am trying to use some Rust wasm code in Bigquery as UDF, and in order to pass on Java String to Rust code the TextEncoder and TextDecoder would be needed to conveniently doing that. As it mentioned here Passing a JavaScript string to a Rust function compiled to WebAssembly

But when I try out some of my code on BigQuery, I encountered an error saying TextEncoder is not defined.

在此处输入图片说明

You can try it out as well with a query like this: https://github.com/liufuyang/rb62-wasm/blob/master/try-3-old.sql

While a working version without using TextEncoder is at https://github.com/liufuyang/rb62-wasm/blob/master/try-3.sql

That means the object is not defined.

As an option, bring your own TextEncoder.

For example, take your try-3-old.sql , and then add this line at the end of the JS UDF definition:

return main();
'''
OPTIONS (library="gs://fh-bigquery/js/inexorabletash.encoding.js");

And now it works:

在此处输入图片说明


(wondering, what's the goal with rb62?)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM