描述如何在 SQL 中内联定义 Javascript UDF 函数的 BigQuery 文档在哪里(而不是在 UDF 编辑器或单独的文件中)? [英] Where is the BigQuery documentation describing how to define a Javascript UDF function inline in SQL (not in the UDF editor or a separate file)?

查看:11
本文介绍了描述如何在 SQL 中内联定义 Javascript UDF 函数的 BigQuery 文档在哪里(而不是在 UDF 编辑器或单独的文件中)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在另一个问题 https://stackoverflow.com/a/36145155/2259571 中,发布了一个代码示例内联定义 Javascript UDF 函数,不在 BigQuery UI UDF 编辑器中,不在 bq 命令行 --udf_resource 选项中,而是直接从 SQL 查询的文本中加载.

In this other question https://stackoverflow.com/a/36145155/2259571 a code example was posted that defines a Javascript UDF function inline, not in the BigQuery UI UDF Editor, not in a bq command-line --udf_resource option, but loaded directly from the text of the SQL query.

我可以在 BigQuery 文档的何处找到有关如何完成此操作的更多信息?

Where in the BigQuery documentation can I find more info about how this is done?

JS(...) 看起来像一个函数,但我在 的文档中找不到它https://cloud.google.com/bigquery/query-reference 我在 https://cloud.google.com/bigquery/user-defined-functions 我只是想念它吗?还是无证?

JS(...) looks like a function but I cannot find it in the documentation at https://cloud.google.com/bigquery/query-reference I also cannot find anything about this construct in https://cloud.google.com/bigquery/user-defined-functions Am I just missing it? Or is it undocumented?

这是查询的简化版本(在 BigQuery 界面和 bq 命令行工具中运行):

Here is a simplified version of the query (this runs in the BigQuery UI and in the bq command line tool):

SELECT outputA
FROM JS(
// input table
(
  SELECT text2 as inputA 
  FROM 
    (SELECT 'mikhail' AS text2),
    (SELECT 'mike' AS text2),
    (SELECT 'michael' AS text2),
    (SELECT 'javier' AS text2),
    (SELECT 'thomas' AS text2)
)

// input columns
, inputA

// output schema
, "[{name: 'outputA', type:'string'}]"

// function
, "function(r, emit) {

    emit({
      outputA: 'XX ' + r.inputA + ' XX'
    });

  }"
)

输出:

outputA
XX mikhail XX
XX mike XX
XX michael XX
XX javier XX
XX thomas XX

推荐答案

内联 JS 语法是alpha"语法,故意没有记录.我们目前没有删除或更改此功能的计划,但它也不是官方支持的功能.

The inline JS syntax is the "alpha" syntax and is deliberately left undocumented. We currently have no plans to remove or change this functionality, but it's also not an officially supported feature.

我们确实计划在未来的某个时候为内联 JS UDF 提供官方支持,但语法略有不同.

We do have plans to provide official support for inline JS UDFs at some point in the future, but with a slightly different syntax.

如果您不顾上述警告仍想使用此功能,请参阅 Mikhail 的回答.

If you'd like to use this feature despite the caveat above, see Mikhail's answer.

这篇关于描述如何在 SQL 中内联定义 Javascript UDF 函数的 BigQuery 文档在哪里(而不是在 UDF 编辑器或单独的文件中)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆