In this other question https://stackoverflow.com/a/36145155/2259571 a code example was posted that defines a Javascript UDF function inline, not in the BigQuery UI UDF Editor, not in a bq command-line --udf_resource option, but loaded directly from the text of the SQL query.
Where in the BigQuery documentation can I find more info about how this is done?
JS(...) looks like a function but I cannot find it in the documentation at https://cloud.google.com/bigquery/query-reference I also cannot find anything about this construct in https://cloud.google.com/bigquery/user-defined-functions Am I just missing it? Or is it undocumented?
Here is a simplified version of the query (this runs in the BigQuery UI and in the bq command line tool):
SELECT outputA
FROM JS(
// input table
(
SELECT text2 as inputA
FROM
(SELECT 'mikhail' AS text2),
(SELECT 'mike' AS text2),
(SELECT 'michael' AS text2),
(SELECT 'javier' AS text2),
(SELECT 'thomas' AS text2)
)
// input columns
, inputA
// output schema
, "[{name: 'outputA', type:'string'}]"
// function
, "function(r, emit) {
emit({
outputA: 'XX ' + r.inputA + ' XX'
});
}"
)
Output:
outputA
XX mikhail XX
XX mike XX
XX michael XX
XX javier XX
XX thomas XX