Would it be possible to run a python function in BigQuery?
It seems like C can be compiled to WebAssembly and run in BQ, per this blog post from Felipe.
And of course Python can be compiled to C or C++ using cython or some other tools (or it could even be transpiled to javascript). So then my question is does anyone have any experience executing a python function in BigQuery. If so, what is the flow that you're using to do it?
Possible options here are:
- "Transform" the python into javascript to run.
- Compile the python into c or cpp and compile that into wasm
Here is an example input to work with:
(1) Source
id product
1 box
2 bottle
(2) Python functions to use
def double_id(row):
return row['id'] * 2
def product_code(row):
# B3
return row['product'].upper()[0] + str(len(row['product']))
(3) Expected output
id product double_id product_code
1 box 2 B3
2 bottle 4 B6
I'm not just looking to re-write the above using javascript (which would probably be the easiest way to do this), but I'm looking for a more generalized solution, if there is one that exists -- where I can take a python (standard library) function and use it in a BigQuery query.