Resources exceeded during query execution: Table metadata used for the
query is too large が出た

BigQueryを使っていたら、広範囲のデータを扱おうとしたら、こんなエラーが出ました。

Resources exceeded during query execution: Table metadata used for the
query is too large

調べてみると、対象データがデカすぎて諦めたとのこと(意訳)。

どうも集計とかorder byとかすると内部的に容量使いまくって動かないことがあるらしい。

いや、BigなQueryとしてどうなんだい? と思ってSQLを見てみたら、

FROM
(TABLE_DATE_RANGE(eop.pageview,
TIMESTAMP('${FROM_DATE}'),
TIMESTAMP('${TO_DATE}')))

こんな感じになっていました。
あまりBQに詳しくないのですが、調べてみたらTABLE_DATE_RANGEはレガシーSQLだそうで。

スタンダードSQL方式にしてみたら動くか試してみます。

記載例)

#standardSQL
select
*
from
`mydat.data_table_*`
where
_TABLE_SUFFIX between '20180101' and '20181231'


参考:
https://cloud.google.com/bigquery/docs/reference/standard-sql/wildcard-table-reference?hl=ja#migrating_legacy_sql_table_wildcard_functions
https://cloud.google.com/bigquery/docs/reference/standard-sql/migrating-from-legacy-sql?hl=ja
https://note.mu/fjustin/n/n16907ccde019
http://gugurekasu.blogspot.com/2016/03/bigquery.html