BigQuery异步查询作业使查询字符串变得混乱

时间:2014-01-30 19:27:44

标签: google-bigquery google-api-client

我正在使用Ruby Google API客户端来调用BigQuery。如果我通过bq.jobs.query同步调用它,那么Query工作正常。

这是工作:job_sQUillv1JOSPg7XdJa7k8JTexPc

这是实际查询:

    select uid,group_concat(event) as path from
    (select uid, event,t from 
    (select properties.distinct_id  as uid, event , properties.time  as t, t1.ev as ev, t1.time as originalTime from 
    [ziptrips.ziptrips_events ] 
    join 
    ( select properties.distinct_id  as user, properties.time  as time, event  as ev from 
    [ziptrips.ziptrips_events ] where properties.time  > 1385856000  and properties.time  < 1388534399  and event  = 'Home Page Loaded'  
    group by user,time,ev) as t1 
    on t1.user = properties.distinct_id  
    where properties.time  < t1.time) 
    group by uid,event ,t 
    order by t desc) 
    group by uid

然而,当我通过bq.jobs.insert异步执行相同的调用时,查询字符串会出现乱码(它有一大堆\ n和\ u003e等)。这项工作失败了。

    select uid,group_concat(event) as path from\n        (select uid, event,t from \n        (select properties.distinct_id  as uid, event , properties.time  as t, t1.ev as ev, t1.time as originalTime from \n        [ziptrips.ziptrips_events ] \n        join \n        ( select properties.distinct_id  as user, properties.time  as time, event  as ev from \n        [ziptrips.ziptrips_events ] where properties.time  \u003e 1385856000  and properties.time  \u003c 1388534399  and event  = 'Home Page Loaded'  \n        group by user,time,ev) as t1 \n        on t1.user = properties.distinct_id  \n        where properties.time  \u003c t1.time) \n        group by uid,event ,t \n        order by t desc) \n        group by uid

以下是代码:

        client,bq = initialize()
         config = {
        'query' => {
            'query' => query
            }
        }

result = client.execute(:api_method =>  bq.jobs.insert,  
        :parameters => {'projectId' => 'onefold-1'},
        :body_object => {
                    "configuration" => config,
                    "kid" => "bigquery#queryRequest",
                    "query" => query,
                    "maxResults" => 1000,
                    "defaultDataset" => {
                        "datasetId" => "#{dataset_id}",
                        "projectId" => 'onefold-1'
                    },
                    "timeoMs" => 3000,
                    "dryRun" => false,
                    "preserveNulls" => false,
                    "useQueryCache" => true,
                    "miCompletionRatio" => 1.0
                }
        )

我认为它与编码等有关。无法指出是否以及在何处指定编码。感谢任何指针或建议。

谢谢, NAVNEET

1 个答案:

答案 0 :(得分:0)

我发现这不是问题。同时发生了不同的错误,我将此错误与此相关联。 它有效!