是“ - view_udf_resource”破碎? [英] Is "--view_udf_resource" broken?

查看:76
本文介绍了是“ - view_udf_resource”破碎?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在View中引用UDF。根据BigQuery文档(' bq help mk ')和这篇文章如何创建一个使用用户定义函数的BigQuery视图?,可以使用 view_udf_resource 语法。



然而,当我尝试它时,我得到以下错误:

 #gsutil cat gs://mybucket/bar.js 
CREATE TEMP FUNCTION GetWord()AS('fire');

#bq mk --nouse_legacy_sql --view_udf_resource =gs://mybucket/bar2.js--view =SELECT 1 as one,GetWord()as myvaluemydataset.myfoo
查询字符串错误:找不到功能:[1:18] GetWord

我也有尝试使用Java API,并得到相同的错误:

  public void foo(){
final String viewQuery =#standardSQL\\\
SELECT 1 as one,GetWord()as myvalue;

UserDefinedFunction userDefinedFunction = UserDefinedFunction.inline(CREATE TEMP FUNCTION GetWord()AS('fire'););

ViewDefinition tableDefinition = ViewDefinition.newBuilder(viewQuery)
.setUserDefinedFunctions(userDefinedFunction)
.build();
TableId viewTableId = TableId.of(projectName,dataSetName,foobar);
final TableInfo tableInfo = TableInfo.newBuilder(viewTableId,tableDefinition).build();

bigQuery.create(tableInfo);
}

com.google.cloud.bigquery.BigQueryException:找不到函数:[2:19] GetWord

我做错了什么?或者是谷歌的文档有误导性,并且从视图中引用任何自定义UDF是不可能的?

您不能(当前)使用使用UDF的标准SQL创建视图。您需要将所有逻辑内联为查询本身的一部分,并且您正在查看的帖子是关于使用旧版SQL的JavaScript UDF。有一个开放功能请求来支持UDF的永久注册,但是,这将使您参考视图中的UDF。


I would like to reference a UDF inside a View. According to BigQuery documentation ('bq help mk') and to this post How do I create a BigQuery view that uses a user-defined function?, it is possible to do it with the "--view_udf_resource" syntax.

However, when I try it I get the following error:

# gsutil cat gs://mybucket/bar.js
CREATE TEMP FUNCTION GetWord() AS ('fire');

# bq mk --nouse_legacy_sql --view_udf_resource="gs://mybucket/bar2.js" --view="SELECT 1 as one, GetWord() as myvalue" mydataset.myfoo
Error in query string: Function not found: GetWord at [1:18]

I have also tried it with the Java API and I get the same error:

   public void foo(){
        final String viewQuery = "#standardSQL\n SELECT 1 as one, GetWord() as myvalue";

        UserDefinedFunction userDefinedFunction = UserDefinedFunction.inline("CREATE TEMP FUNCTION GetWord() AS ('fire');");

        ViewDefinition tableDefinition = ViewDefinition.newBuilder(viewQuery)
                .setUserDefinedFunctions(userDefinedFunction)
                .build();
        TableId viewTableId = TableId.of(projectName, dataSetName, "foobar");
        final TableInfo tableInfo = TableInfo.newBuilder(viewTableId, tableDefinition).build();

        bigQuery.create(tableInfo);
    }

com.google.cloud.bigquery.BigQueryException: Function not found: GetWord at [2:19]

Am I doing something wrong? Or is the Google's documentation misleading and it is not possible to reference any custom UDF from a View?

解决方案

You cannot (currently) create a view using standard SQL that uses UDFs. You need to have all of the logic be inline as part of the query itself, and the post that you are looking at is about JavaScript UDFs using legacy SQL. There is an open feature request to support permanent registration of UDFs, however, which would enable you to reference UDFs from views.

这篇关于是“ - view_udf_resource”破碎?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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