无法访问类型为ARRAY <struct <resource string,=“” Permission =“”的字符串,=“” grant =“” bool =“”

时间:2019-02-07 01:13:04

标签: google-bigquery

=的值的字段权限“”

尝试运行此查询(mytable不是真实的表名):

enter image description here

遇到此错误:Cannot access field permission on a value with type ARRAY<STRUCT<resource STRING, permission STRING, granted BOOL, ...>> at [2:41]

它在模式中说它只是一个字符串: enter image description here

当我预览表格时,它看起来像这样:

enter image description here

1 个答案:

答案 0 :(得分:3)

从下面的模式中可以看到-#standardSQL SELECT DISTINCT x.permission FROM `your_table`, UNNEST(protopayload_auditlog.authorizationInfo) x LIMIT 10 是一个数组

enter image description here

因此,要访问数组元素,请先将其UNNEST删除,如下面的示例所示

#standardSQL
SELECT DISTINCT x.permission
FROM `your_table` t,
t.protopayload_auditlog.authorizationInfo x
LIMIT 10

结果为

enter image description here

注意:上述查询中UNNEST'ing的快捷方式是

how do I concat it to a comma separated string?
  

更新#standardSQL SELECT ARRAY_TO_STRING(ARRAY(SELECT permission FROM t.protopayload_auditlog.authorizationInfo), ',') permissions FROM `your_table` t LIMIT 10

public class TaskManager {
    static ExecutorService e = Executors.newFixedThreadPool(4);
    private TaskManager(){

    }
    public static void addAsyncTask(AsyncTaskWrapper task){
        e.submit(task);
    }
}