在Bigquery Standard SQL UDF中包含某些字段会产生错误

时间:2017-07-10 22:25:17

标签: javascript google-bigquery

我在BigQuery中编写标准SQL和JavaScript UDF的组合,结构如

CREATE TEMPORARY FUNCTION process_hits(
  ga_hits ARRAY<
    STRUCT<
      ...
      hit_number INT64,
      time INT64,
      type STRING,
      ...
      events STRUCT<
        category STRING,
        action STRING,
        label STRING,
        value INT64      
      >
    >
  >
) RETURNS ARRAY<
    STRUCT<
      hit_number INT64,
      raw_hit_number INT64,
      type STRING,
      ...
      events STRUCT<
        category STRING,
        action STRING,
        label STRING,
        value INT64
      >,
      ...
  > LANGUAGE js AS """
    var hit_numbers = [];
    var return_hit = [];
    for(var i=0;i<ga_hits.length;i++) {
      if(ga_hits[i]["type"] == "PAGE") {
        hit_numbers.push(ga_hits[i]["hit_number"]);
      }
    }
    hit_numbers.sort();

    for(var i=0;i<ga_hits.length;i++) {
      if(ga_hits[i]["page"]["hostname"] != null) {
        if(ga_hits[i]["page"]["hostname"].indexOf("realself.com") > -1) {
          return_dict = {"metrics": ga_hits[i].metrics,
                         "topic": ga_hits[i].topic,
                         "debug_topic": ga_hits[i].debug_topic,
                         "content": ga_hits[i].content,
                         "debug_content": ga_hits[i].debug_content,
                         "page": ga_hits[i].page,
                         ...

当我从输入ARRAY&gt;复制大部分键时到JS UDF中的输出对象(或直接返回输入对象),它工作正常。当我包含hits.type或hits.events.category时,我得到错误&#34;错误:无法强制输出值对象:&#39; [object Object]&#39;输入ARRAY&gt;&#34;。有没有人有任何想法?

0 个答案:

没有答案