BigQuery问题与时间查询

时间:2017-03-03 15:47:52

标签: google-bigquery

请您帮我解决一下这个问题:我不明白TIMESTAMP_MILLIS无效的原因

    SELECT DATE, 
           MAX(CASE WHEN customDimensions.index = 1 THEN customDimensions.value END) AS CUSTOMDIMENSIONS_VALUE, 
           visitNumber, 
           fullvisitorid, 
           device.deviceCategory, 
           hits.page.pagePath, 
           IFNULL(hits.page.pagePathLevel2, '') AS HITS_PAGE_PAGEPATHLEVEL2,            
           IFNULL(hits.page.pagePathLevel3, '') AS HITS_PAGE_PAGEPATHLEVEL3,
           hits.page.pageTitle, 
           TIMESTAMP_SECONDS(visitStartTime) AS visitStart,
           TIMESTAMP_MILLIS(1000 * visitStartTime + hits.time) AS hitStart, 
           hits.hitNumber, 
           hits.hour, 
           hits.minute, 
           hits.isEntrance, 
           hits.isExit, 
           CONCAT(fullvisitorid, STRING(visitid)) AS sessionid 
    FROM (FLATTEN([Table], customDimensions.value )) 
    WHERE hits.page.hostname CONTAINS 'X'' AND customDimensions.value != "null" AND hits.type = 'PAGE' AND (customDimensions.index = 1 OR hits.customDimensions.index = 11) 
    GROUP EACH BY DATE, visitStartTime, fullVisitorId, visitNumber, device.deviceCategory, hits.page.pagePath, hits.page.pageTitle, hits.hitNumber, hits.time, hits.hour, hits.minute, hits.isEntrance, hits.isExit 
    LIMIT 100000

1 个答案:

答案 0 :(得分:1)

  

我不明白为什么TIMESTAMP_MILLIS无效。你能帮我吗

您的查询存在的问题是您在同一查询中混合使用BigQuery Legacy SQLStandard SQL

例如:
在查询的下方 - 是旧版SQL功能

FROM (FLATTEN([Table], customDimensions.value ))   

TIMESTAMP_MILLISTIMESTAMP_SECONDS是标准SQL仅支持的函数 - 您可以在旧版SQL中找到类似的函数(例如MSEC_TO_TIMESTAMPSEC_TO_TIMESTAMP()

你需要坚持一个或另一个。 BigQuery Team建议使用Standard SQL,我绝对是第二个!