Last active
July 1, 2021 15:21
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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