简体   繁体   中英

How to install npm packages in BigQuery?

I unfortunately can not any reliable documentation on how to use an npm package in BigQuery. I want to use the package isitblocked in BigQuery and parse the URLs in my tables through the library.

I only found this blog , but I can't re-procedure the steps there and get the following error while using webpack:

`assets by status 390 bytes [cached] 1 asset./index.ts 2.43 KiB [built] [code generated] [1 error] WARNING in configuration The 'mode' option has not been set, webpack will fallback to > 'production' for this value. Set 'mode' option to 'development' or 'production' to enable > defaults for each environment. You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/configuration/mode/ ERROR in./index.ts 1:16 Module parse failed: Unexpected token (1:16) You may need an appropriate loader to handle this file type, > currently no loaders are configured to process this file. See > > https://webpack.js.org/concepts#loaders import envPaths = require("env-paths"); | import Listr = require("listr"); | import fs = require("fs-extra"); \

The package I try to install is isitblocked .

I did it step by step in the google Shell and it prompted to install the webpack. Please include the mode none or production

npx webpack --config webpack.config.js --mode none

Then upload the file under dist and edit the BigQuery query to:

CREATE TEMP FUNCTION get_rand_card_number()
RETURNS STRING
LANGUAGE js   
OPTIONS (
library=["gs://***your*bucket*name***/creditcard-generator.js"]
)
AS r"""
return webpackNumbers.GenCC("Amex"); # Still wrong function name
""";

CREATE TEMP FUNCTION get_rand_id()
RETURNS STRING
LANGUAGE js
AS r"""
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 4 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(4);
});
""";


SELECT 
     x,
     get_rand_id() as unique_id, 
     get_rand_card_number() as credit_card_number 
FROM 
   unnest(generate_array(1,100,1)) x

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM