Skip to content

Instantly share code, notes, and snippets.

@apeckham
Last active July 1, 2021 15:21
Show Gist options
  • Save apeckham/df8e10695013f854aea286dcab4823a2 to your computer and use it in GitHub Desktop.
Save apeckham/df8e10695013f854aea286dcab4823a2 to your computer and use it in GitHub Desktop.
bigquery javascript UDF to extract URL components and query parameters with URI.js
-- gsutil mb -p project-id gs://my-udf-bukkit/
-- wget https://cdn.jsdelivr.net/uri.js/1.18.10/URI.min.js
-- gsutil cp URI.min.js gs://my-udf-bukkit/
-- open https://medialize.github.io/URI.js/docs.html
CREATE TEMP FUNCTION myFunc(b STRING)
RETURNS STRING
LANGUAGE js AS
"""
return URI(b).query(true)['my-param'];
"""
OPTIONS (
library="gs://my-bigquery-udfs/URI.min.js"
);
SELECT myFunc('http://www.example.com/my-path.txt?my-param=a%20b%21c');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment