2015-02-24 40 views
6

我試圖在BigQuery中運行一個查詢,它有兩個子選擇和一個連接,但我無法讓它工作。我正在做的一個解決方法是自行運行子查詢,然後將它們保存爲表,然後使用連接執行另一個查詢,但我認爲我應該可以使用一個查詢來完成此操作。谷歌BigQuery要求加入每個,但我已經在使用它

,我發現了錯誤:

Table too large for JOIN. Consider using JOIN EACH. For more details, please see https://developers.google.com/bigquery/docs/query-reference#joins

,但我已經在使用一個連接各。我嘗試過使用交叉連接和每個組使用組,但這些給我不同的錯誤。關於這個主題的堆棧溢出的其他問題沒有幫助,一個說這是一個在BigQuery中的錯誤,另一個是有人使用'交叉連接每個'...

以下是我的SQL,原諒我,如果它已滿錯誤的,但我認爲它應該工作:

select 
t1.device_uuid, 
t1.session_uuid, 
t1.nth, 
t1.Diamonds_Launch, 
t2.Diamonds_Close 
from (
    select 
    device_uuid, 
    session_uuid, 
    nth, 
    sum(cast([project_id].[table_id].attributes.Value as integer)) as Diamonds_Launch 
    from [project_id].[table_id] 
    where name = 'App Launch' 
    and attributes.Name = 'Inventory - Diamonds' 
    group by device_uuid, session_uuid, nth 
    ) as t1 
join each (
    select 
    device_uuid, 
    session_uuid, 
    nth, 
    sum(cast([project_id].[table_id].attributes.Value as integer)) as Diamonds_Close 
    from [project_id].[table_id] 
    where name = 'App Close' 
    and attributes.Name = 'Inventory - Diamonds' 
    group by device_uuid, session_uuid, nth 
    ) as t2 
on t1.device_uuid = t2.device_uuid 
and t1.session_uuid = t2.session_uuid 

回答

6

您在JOIN EACH內有GROUP BYGROUP BY以基數(不同值的數量)命中限制,最終的分組不可並行化。這限制了BigQuery執行連接的能力。

如果將GROUP BY更改爲​​,這很可能會起作用。

(是的,我知道這是不愉快和不規範。根據BigQuery團隊目前在做這樣的事情「只是工作」努力工作。)

3

這可以被組合成一個單一的查詢:

SELECT device_uuid, 
     session_uuid, 
     nth, 
     SUM(IF (name = 'App Launch', INTEGER([project_id].[table_id].attributes.Value), 0)) AS Diamonds_Launch, 
     SUM(IF (name = 'App Close', INTEGER([project_id].[table_id].attributes.Value), 0)) AS Diamonds_Close, 
FROM [project_id].[table_id] 
WHERE attributes.Name = 'Inventory - Diamonds' 
GROUP BY device_uuid, 
     session_uuid, 
     nth 

您還可以使用組的每個大表。

+1

謝謝Pentium10,我想應該有辦法用一條SELECT語句做這件事,但我無法弄清楚。 – Davidjb 2015-02-24 22:22:56

相關問題