问题
We have a partitioned table in google bigquery that we query using the _PARTITIONTIME field (otherwise the queries will cost too much).
How can I make Tableau use _PARTITIONTIME pseudo column?
回答1:
When configuring your datasource in Tableau, select "Google BigQuery" from the list of available sources, go through the OAuth dance, and then select your project and dataset.
At this point, you will be presented with a list of tables in the dataset, as well as an option to use "New Custom SQL" at the bottom. Select this option, and enter your query exactly as you have been using it. Assuming that the query contains a segment similar to the below:
...WHERE _PARTITIONTIME BETWEEN TIMESTAMP(“2016-05-01”) AND TIMESTAMP(“2016-05-06”)
Now, highlight the dates within that where clause and click on the "Insert Parameter" dropdown menu in the query editor. This will allow you to parameterize your query and dynamically choose the dates you want to query from within your Tableau workbook!
Hopefully this helps!
回答2:
A more flexible solution would be to just drag and drop the table as you would normally. After that click 'datasource - convert to custom SQL' This way tableau has written most of the SQL for you. Last part.... DONT add a where clause and stop user exploration Add this instead:
_PARTITIONTIME
AS mypartitiondate
Now you can use this as you would any other date column but you are using partition time instead. Caveats to that are if you use this column you cant drill in below the level of the partitions (eg trying to see hourly trades on a daily partitioned dataset). That would require user knowledge to know to start using another date column for that part instead.
来源:https://stackoverflow.com/questions/39569572/how-to-query-a-partitioned-table-in-bigquery-from-tableau