【问题标题】:Use js packages in BigQuery UDF在 BigQuery UDF 中使用 js 包
【发布时间】:2018-11-15 07:22:50
【问题描述】:

我试图创建一个需要外部 npm 包的 BigQuery UDF。

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(STRING) 第 2 行定义, 第 15-16 列

有什么方法可以让我使用这些包吗?

【问题讨论】:

    标签: google-bigquery user-defined-functions


    【解决方案1】:

    您不能使用 require 从 JavaScript UDF 加载 npm 包。但是,您可以从 GCS 加载外部库,如 outlined in the documentation。文档给出的示例是,

    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');
    

    这里假设您在 Cloud Storage 中有具有这些名称的文件,并且其中一个定义了 doInterestingStuff

    【讨论】:

      猜你喜欢
      • 2020-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-27
      • 1970-01-01
      • 2019-07-19
      • 1970-01-01
      • 2022-01-22
      相关资源
      最近更新 更多