Google bigquery 在BigQuery UDF中使用js包
我试图创建一个BigQueryUDF,它需要一个外部npm包Google bigquery 在BigQuery UDF中使用js包,google-bigquery,user-defined-functions,Google Bigquery,User Defined Functions,我试图创建一个BigQueryUDF,它需要一个外部npm包 CREATE TEMPORARY FUNCTION tempfn(message STRING) RETURNS STRING LANGUAGE js AS """ var tesfn = require('js-123'); return tesfn(message) """; SELECT tempfn("Hello") as test; 这给了我一个错误 ReferenceError:在tempfn(字符串
CREATE TEMPORARY FUNCTION tempfn(message STRING)
RETURNS STRING
LANGUAGE js AS """
var tesfn = require('js-123');
return tesfn(message)
""";
SELECT tempfn("Hello") as test;
这给了我一个错误
ReferenceError:在tempfn(字符串)第2行未定义require,
第15-16栏
有什么方法可以使用这些包吗?您不能使用JavaScript UDF中的
require
加载npm包。但是,您可以根据需要从GCS加载外部库。文档中给出的示例是
CREATE TEMP FUNCTION myFunc(a FLOAT64, b STRING)
RETURNS STRING
LANGUAGE js AS
"""
// Assumes 'doInterestingStuff' is defined in one of the library files.
return doInterestingStuff(a, b);
"""
OPTIONS (
library="gs://my-bucket/path/to/lib1.js",
library=["gs://my-bucket/path/to/lib2.js", "gs://my-bucket/path/to/lib3.js"]
);
SELECT myFunc(3.14, 'foo');
这里假设您在云存储中有具有这些名称的文件,其中一个文件定义了
doInterestingStuff
您不能使用JavaScript UDF中的require
加载npm包。但是,您可以根据需要从GCS加载外部库。文档中给出的示例是
CREATE TEMP FUNCTION myFunc(a FLOAT64, b STRING)
RETURNS STRING
LANGUAGE js AS
"""
// Assumes 'doInterestingStuff' is defined in one of the library files.
return doInterestingStuff(a, b);
"""
OPTIONS (
library="gs://my-bucket/path/to/lib1.js",
library=["gs://my-bucket/path/to/lib2.js", "gs://my-bucket/path/to/lib3.js"]
);
SELECT myFunc(3.14, 'foo');
这里假设您在云存储中有具有这些名称的文件,其中一个文件定义了doInterestingStuff