The gists for "Time Travel with BigQuery" blogpost in puccetti.io
Created
March 8, 2021 11:22
-
-
Save alepuccetti/277fe07f200ccac33f98ae4217740fa5 to your computer and use it in GitHub Desktop.
Time Travel with BigQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- returning the total number of devices and events seen by the system at the beginning of the precious hours. | |
| SELECT | |
| count(distinct device_id) as devices, | |
| count(*) as events, | |
| FROM table_a | |
| FOR SYSTEM_TIME AS OF TIMESTAMP_TRUNC(TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 1 HOUR, HOUR)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- returning the total number of devices and events seen by the system at a specific timestamp | |
| SELECT | |
| count(distinct device_id) as devices, | |
| count(*) as events, | |
| FROM table_a | |
| FOR SYSTEM_TIME AS OF “point_in_time_timestmap”; | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE OR REPLACE TABLE `project.dataset.table_a_recovered` as ( | |
| SELECT | |
| * | |
| FROM `project_id.datasaet_id.table_a` FOR SYSTEM_TIME AS OF “point_in_time_timestmap”; | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT | |
| * | |
| FROM `project_id.datasaet_id.table_a` FOR SYSTEM_TIME AS OF TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 3 HOUR) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT | |
| * | |
| FROM `project_id.datasaet_id.table_a` FOR SYSTEM_TIME AS OF "point_in_time_timestmap" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment