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.
Fix for #9, BigQuery views are now automatically created
- Loading branch information
1 parent
973907d
commit 39f0de2
Showing
9 changed files
with
200 additions
and
35 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
-- 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)) | ||
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
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
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Table(object): | ||
def __init__(self, group, name, json_dict): | ||
self.group = group | ||
self.name = name | ||
self.json_dict = json_dict | ||
|
||
def __str__(self): | ||
return "Table(group={}, name={})".format(self.group, self.name) |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class View(object): | ||
def __init__(self, group, name, file_content): | ||
self.group = group | ||
self.name = name | ||
self.file_content = file_content | ||
|
||
def __str__(self): | ||
return "View(group={}, name={})".format(self.group, self.name) | ||
|
||
@property | ||
def query(self): | ||
return "".join(self.file_content) | ||
|
||
@property | ||
def description(self): | ||
desc_lines = [line[2:] for line in self.file_content | ||
if line.startswith('--')] | ||
return "".join(desc_lines) |
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
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
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import unittest | ||
|
||
from gcp_census.model.view import View | ||
|
||
|
||
class TestModelCreator(unittest.TestCase): | ||
def test_should_parse_view(self): | ||
# given | ||
view = View('group', 'name', | ||
['--desc1\n', '--desc2\n', 'SELECT * FROM\n', 'table']) | ||
|
||
# when & then | ||
self.assertEqual(view.description, 'desc1\ndesc2\n') | ||
self.assertEqual(view.query, '--desc1\n--desc2\nSELECT * FROM\ntable') |
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,8 +1,14 @@ | ||
import os | ||
import json | ||
|
||
|
||
def content(filename): | ||
if not os.path.exists(filename): | ||
raise Exception("File not found: {0}".format(filename)) | ||
with open(filename, 'r') as f: | ||
return f.read() | ||
|
||
|
||
def get_body_from_http_request(call): | ||
payload = call[1][2] | ||
return json.loads(payload) if payload else None |