This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from ocadotechnology/views_change
Views now deduplicate data from 2 days instead of 3
- Loading branch information
Showing
5 changed files
with
15 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
#standardSQL | ||
-- This view aggregates all partition metadata from last 3 days and deduplicates it based on partition reference. | ||
-- Deleted table/partition can be returned by this query up to 3 days. | ||
-- This view aggregates all partition metadata from last 2 days and deduplicates it based on partition reference. | ||
-- Deleted table/partition can be returned by this query up to 2 days. | ||
SELECT projectId, datasetId, tableId, partitionId, creationTime, lastModifiedTime, location, numBytes, numLongTermBytes, numRows, type FROM ( | ||
SELECT projectId, datasetId, tableId, partitionId, creationTime, lastModifiedTime, location, numBytes, numLongTermBytes, numRows, type, | ||
row_number() OVER (PARTITION BY projectId, datasetId, tableId, partitionId ORDER BY snapshotTime DESC) AS rownum | ||
FROM `$PROJECT_ID.bigquery.partition_metadata_v1_0` | ||
WHERE | ||
_PARTITIONTIME BETWEEN TIMESTAMP(DATE_ADD(CURRENT_DATE(), INTERVAL -2 DAY)) | ||
_PARTITIONTIME BETWEEN TIMESTAMP(DATE_ADD(CURRENT_DATE(), INTERVAL -1 DAY)) | ||
AND CURRENT_TIMESTAMP()) | ||
WHERE rownum = 1 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
#standardSQL | ||
-- This view aggregates all table metadata from last 3 days and deduplicates it based on table reference. | ||
-- Deleted table can be returned by this query up to 3 days. | ||
-- This view aggregates all table metadata from last 2 days and deduplicates it based on table reference. | ||
-- Deleted table can be returned by this query up to 2 days. | ||
SELECT projectId, datasetId, tableId, creationTime, lastModifiedTime, location, numBytes, numLongTermBytes, numRows, type FROM ( | ||
SELECT projectId, datasetId, tableId, creationTime, lastModifiedTime, location, numBytes, numLongTermBytes, numRows, type, | ||
row_number() OVER (PARTITION BY projectId, datasetId, tableId ORDER BY snapshotTime DESC) AS rownum | ||
FROM `$PROJECT_ID.bigquery.table_metadata_v1_0` | ||
WHERE | ||
_PARTITIONTIME BETWEEN TIMESTAMP(DATE_ADD(CURRENT_DATE(), INTERVAL -2 DAY)) | ||
_PARTITIONTIME BETWEEN TIMESTAMP(DATE_ADD(CURRENT_DATE(), INTERVAL -1 DAY)) | ||
AND CURRENT_TIMESTAMP()) | ||
WHERE rownum = 1 |
6 changes: 3 additions & 3 deletions
6
bq_schemas/bigquery_views_legacy_sql/partition_metadata_v1_0.sql
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
-- This view aggregates all partition metadata from last 3 days and deduplicates it based on partition reference. | ||
-- Deleted table/partition can be returned by this query up to 3 days. | ||
-- This view aggregates all partition metadata from last 2 days and deduplicates it based on partition reference. | ||
-- Deleted table/partition can be returned by this query up to 2 days. | ||
SELECT projectId, datasetId, tableId, partitionId, creationTime, lastModifiedTime, location, numBytes, numLongTermBytes, numRows, type FROM ( | ||
SELECT projectId, datasetId, tableId, partitionId, creationTime, lastModifiedTime, location, numBytes, numLongTermBytes, numRows, type, | ||
row_number() OVER (PARTITION BY projectId, datasetId, tableId, partitionId ORDER BY snapshotTime DESC) AS rownum, | ||
FROM [bigquery.partition_metadata_v1_0] | ||
WHERE | ||
_PARTITIONTIME BETWEEN TIMESTAMP(UTC_USEC_TO_DAY(NOW() - 48 * 60 * 60 * 1000000)) | ||
_PARTITIONTIME BETWEEN TIMESTAMP(UTC_USEC_TO_DAY(NOW() - 24 * 60 * 60 * 1000000)) | ||
AND TIMESTAMP(UTC_USEC_TO_DAY(CURRENT_TIMESTAMP()))) | ||
WHERE rownum = 1 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
-- This view aggregates all data from last 3 days and deduplicates it based on table reference. | ||
-- Deleted table can be returned by this query up to 3 days. | ||
-- This view aggregates all data from last 2 days and deduplicates it based on table reference. | ||
-- Deleted table can be returned by this query up to 2 days. | ||
SELECT * FROM ( | ||
SELECT projectId, datasetId, tableId, creationTime, lastModifiedTime, location, numBytes, numLongTermBytes, numRows, type, timePartitioning.type AS partitioningType, | ||
row_number() OVER (PARTITION BY projectId, datasetId, tableId ORDER BY snapshotTime DESC) AS rownum, | ||
COUNT(partition.partitionId) WITHIN RECORD AS partitionCount | ||
FROM [bigquery.table_metadata_v0_1] | ||
WHERE | ||
_PARTITIONTIME BETWEEN TIMESTAMP(UTC_USEC_TO_DAY(NOW() - 48 * 60 * 60 * 1000000)) | ||
_PARTITIONTIME BETWEEN TIMESTAMP(UTC_USEC_TO_DAY(NOW() - 24 * 60 * 60 * 1000000)) | ||
AND TIMESTAMP(UTC_USEC_TO_DAY(CURRENT_TIMESTAMP()))) | ||
WHERE rownum = 1 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
-- This view aggregates all table metadata from last 3 days and deduplicates it based on table reference. | ||
-- Deleted table can be returned by this query up to 3 days. | ||
-- This view aggregates all table metadata from last 2 days and deduplicates it based on table reference. | ||
-- Deleted table can be returned by this query up to 2 days. | ||
SELECT projectId, datasetId, tableId, creationTime, lastModifiedTime, location, numBytes, numLongTermBytes, numRows, type FROM ( | ||
SELECT projectId, datasetId, tableId, creationTime, lastModifiedTime, location, numBytes, numLongTermBytes, numRows, type, | ||
row_number() OVER (PARTITION BY projectId, datasetId, tableId ORDER BY snapshotTime DESC) AS rownum, | ||
FROM [bigquery.table_metadata_v1_0] | ||
WHERE | ||
_PARTITIONTIME BETWEEN TIMESTAMP(UTC_USEC_TO_DAY(NOW() - 48 * 60 * 60 * 1000000)) | ||
_PARTITIONTIME BETWEEN TIMESTAMP(UTC_USEC_TO_DAY(NOW() - 24 * 60 * 60 * 1000000)) | ||
AND TIMESTAMP(UTC_USEC_TO_DAY(CURRENT_TIMESTAMP()))) | ||
WHERE rownum = 1 |