2017-07-11 127 views
1

一些處理,我得到以下陣列後的BigQuery查詢:值傳遞的數組與大熊貓

users = array([u'5451709866311680', u'4660301072957440', u'6370791394377728', 
    u'5121933955825664', u'4778500988862464', u'5841867648270336', 
    u'4751430816628736', u'4869137213947904', u'5152642703556608', 
    u'6531810976595968', u'4824167228637184', u'6058117842337792', 
    u'5969360933879808', u'4764494160986112', u'5443041280131072', 
    u'4846257587617792', u'5409371420884992', u'6197117949313024', 
    u'6643644022915072', u'5060273861820416'], dtype=object) 

然後我想在BigQuery中另一個表來查詢該用戶,但我有問題。

query = """ 
SELECT * 
FROM games 
WHERE user_id IN %users 
""" 
segment = pd.io.gbq.read_gbq(query, project_id='shared', dialect='standard) 

任何人都知道如何進行?

感謝您在您的查詢,而不是在熊貓

回答

0

可能是你有問題。爲了讓這個查詢工作,你必須做一些事情,如:

query = """ 
SELECT * 
FROM crozzles.games 
WHERE user_id IN UNNEST(['user1', 'user2', 'user3']) 
""" 

如果不這樣做UNNEST您的數組,那麼的BigQuery無法查找其inner values

有一兩件事你可以做的就是這樣的:

query = """ 
SELECT * 
FROM crozzles.games 
WHERE user_id IN UNNEST(%s) 
""" %(map(str, users)) 

應導致:

query = """SELECT * 
    FROM crozzles.games 
    WHERE user_id IN UNNEST(['5451709866311680', '4660301072957440', '6370791394377728', '5121933955825664', '4778500988862464', '5841867648270336', '4751430816628736', '4869137213947904', '5152642703556608', '6531810976595968', '4824167228637184', '6058117842337792', '5969360933879808', '4764494160986112', '5443041280131072', '4846257587617792', '5409371420884992', '6197117949313024', '6643644022915072', '5060273861820416'])