2017-04-02 4 views
0

Google BigQueryで従来のSQLを使用していますが、COUNT(DISTINCT field, n)を使用しようとしています。BigQueryエラー - UNIQUE_HEAPにはint32引数が必要です

SELECT 
    hits.page.pagePath AS Page, 
    COUNT(DISTINCT CONCAT(fullVisitorId, INTEGER(visitId)), 1e6) AS UniquePageviews, 
    COUNT(DISTINCT fullVisitorId, 1e6) as Users 
FROM 
    [xxxxxxxx.ga_sessions_20170101] 
GROUP BY 
    Page 
ORDER BY 
    UniquePageviews DESC 
LIMIT 
    20 

BigQueryのもそのため私は、このエラーの原因となっている行を確認していないエラーの行番号が表示されない:ここでは

UNIQUE_HEAP requires an int32 argument which is greater than 0 (error code: invalidQuery)

は、私が使用している私のクエリです:しかし、私は次のエラーを取得しています。

What could be possible cause of above error?

答えて

1

あなたCOUNT(DISTINCT)1e6を使用しないでください。代わりに、2番目のパラメータ'N'(デフォルトは1000)に実際のINTEGER値を使用するか、代わりにEXACT_COUNT_DISTINCT()を使用してください。

COUNT(DISTINCT) documentation

EXACT_COUNT_DISTINCT() documentation

If you require greater accuracy from COUNT(DISTINCT), you can specify a second parameter, n, which gives the threshold below which exact results are guaranteed. By default, n is 1000, but if you give a larger n, you will get exact results for COUNT(DISTINCT) up to that value of n. However, giving larger values of n will reduce scalability of this operator and may substantially increase query execution time or cause the query to fail.

To compute the exact number of distinct values, use EXACT_COUNT_DISTINCT. Or, for a more scalable approach, consider using GROUP EACH BY on the relevant field(s) and then applying COUNT(*). The GROUP EACH BY approach is more scalable but might incur a slight up-front performance penalty.

関連する問題