如何创建使用用户定义函数的BigQuery视图? [英] How do I create a BigQuery view that uses a user-defined function?

查看:125
本文介绍了如何创建使用用户定义函数的BigQuery视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个BigQuery视图,该视图使用一个查询来调用一个用户 - 定义功能。如何告诉BigQuery在哪里可以找到UDF的代码文件?

解决方案

视图可以引用存储在 Google云端存储,内联代码blob或本地文件(内容将被加载到内联代码blob中)。

要使用BigQuery UI创建带有UDF的视图,只需按照正常运行查询时那样填写UDF资源,然后另存为视图。 (换句话说,不需要特殊的操作)。



要在命令行客户端创建视图时指定它们,请使用--view_udf_resource标志:

  bq mk --view =SELECT foo FROM myUdf(table)\ 
--view_udf_resource =gs:/在以上例子中, gs://my-bucket/my-code.js 将包含 myUdf()的定义。如果您需要在视图查询中引用多个代码文件,则可以提供多个 - view_udf_resources 标志。

您可以指定gs:// URI或本地文件。如果你指定一个本地文件,那么代码将被读取一次,并打包到内联代码资源中。



通过API,这是一个重复的字段,名为 userDefinedFunctionResources 。它是包含视图SQL的查询字段的兄弟。


I'd like to create a BigQuery view that uses a query which invokes a user-defined function. How do I tell BigQuery where to find the code files for the UDF?

解决方案

Views can reference UDF resources stored in Google Cloud Storage, inline code blobs, or local files (contents will be loaded into inline code blobs).

To create a view with a UDF using the BigQuery UI, just fill out the UDF resources as you would when running the query normally, and save as a view. (In other words, no special actions are required).

To specify these during view creation from the command-line client, use the --view_udf_resource flag:

bq mk --view="SELECT foo FROM myUdf(table)" \
  --view_udf_resource="gs://my-bucket/my-code.js"

In the above example, gs://my-bucket/my-code.js would contain the definition for myUdf(). You can provide multiple --view_udf_resources flags if you need to reference multiple code files in your view query.

You may specify gs:// URIs or local files. If you specify a local file, then the code will be read once and packed into an inline code resource.

Via the API, this is a repeated field named userDefinedFunctionResources. It is a sibling of the query field that contains the view SQL.

这篇关于如何创建使用用户定义函数的BigQuery视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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