Reputation: 178
Using the bigquery, I need to extract the components of URL such as hostname, query_parameters,paths, and fragment.
Since bigquery UDF supports javascript, I found thi same URL library which is natively available in browsers and nodejs. I created the bigquery udf using this library.
CREATE OR REPLACE FUNCTION dataset.parseURL(url STRING)
RETURNS JSON
LANGUAGE js AS
r"""
const uri = URL(url);
return {
host: uri.host,
path: uri.pathname,
fragment: uri.hash,
...
};
"""
When I try to call it in a query in query editor, I get the error:
ReferenceError: URL is not defined at UDF$1(STRING)
I know that I need to load external js library in GCS bucket and mention it in OPTIONS (library=['gs://bucket/URL.js'])
.
The URL is not a native class or module in bigquery javascript. I searched online for its js file, also tired to build a bundle js using webpack but it did not work. Is there any way I can get this URL module js be recognized by bigquery?
Upvotes: 0
Views: 70
Reputation: 452
BigQuery UDFs don't support certain browser APIs
like URL due to their restricted JavaScript runtime environment.
BigQuery UDFs can't call external APIs, it won't be able to run and perform additional API calls. As mentioned by @Mikhhali can try with the BigQuery NET functions .
As of now BigQuery UDFs do not support browser-specific APIs like URL .If you want that feature you can open a new Feature request
as per your requirements on the public issue tracker describing your issue and vote [+1] and Eng team will look on the feature for future implementation
Upvotes: 0