BigQuery文档在哪里描述了如何在SQL中内联定义Javascript UDF函数(不在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)?

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

问题描述

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

在BigQuery文档中,我可以找到关于如何完成的更多信息?

JS(...)看起来像一个函数,但我在 https://cloud.google.com/bigquery/query-reference 我也无法在 https://cloud.google.com/bigquery/user-defined-functions 我是否错过了它?或者它是没有记录的?



以下是查询的简化版本(可在BigQuery UI和bq命令行工具中运行):

  SELECT outputA 
FROM JS(
//输入表

)SELECT text2 as inputA

(SELECT'mikhail'AS text2),
(SELECT'mike'AS text2),
(SELECT'michael'AS text2),
(SELECT'javier 'AS text2),
(SELECT'thomas'AS text2)


//输入栏
,inputA

//输出模式
,[{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语法,故意留下未记录的内容。我们目前没有计划移除或改变这个功能,但它也不是官方支持的功能。



我们有计划在一些内联JS UDF提供官方支持点,但语法略有不同。



如果您想要使用此功能,请参阅Mikhail的答案。 b $ b

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.

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

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?

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

  }"
)

Output:

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

解决方案

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.

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

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

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

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