Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion bigquery/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,8 @@ def _parse_table_name(self, table_id):
"""Parse a table name in the form of appid_YYYY_MM or
YYYY_MM_appid and return a tuple consisting of YYYY-MM and the app id.

Returns (None, None) in the event of a name like <desc>_YYYYMMDD_<int>

Parameters
----------
table_id : str
Expand Down Expand Up @@ -1463,9 +1465,10 @@ def _parse_table_name(self, table_id):
year_month = "-".join(attributes[-2:])
app_id = "-".join(attributes[:-2])


# Check if date parsed correctly
if year_month.count("-") == 1 and all(
[num.isdigit() for num in year_month.split('-')]):
[num.isdigit() for num in year_month.split('-')]) and len(year_month) == 7:
return year_month, app_id

return None, None
Expand Down
11 changes: 10 additions & 1 deletion bigquery/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,15 @@ def test_not_inside_range(self):
"kind": "bigquery#tableList",
"etag": "\"GSclnjk0zID1ucM3F-xYinOm1oE/cn58Rpu8v8pB4eoJQaiTe11lPQc\"",
"tables": [
{
"kind": "bigquery#table",
"id": "project:dataset.notanappspottable_20130515_0261",
"tableReference": {
"projectId": "project",
"datasetId": "dataset",
"tableId": "notanappspottable_20130515_0261"
}
},
{
"kind": "bigquery#table",
"id": "project:dataset.2013_05_appspot_1",
Expand Down Expand Up @@ -2389,7 +2398,7 @@ def test_get_all_tables(self):
bq = client.BigQueryClient(mock_bq_service, 'project')

expected_result = [
'2013_05_appspot', '2013_06_appspot_1', '2013_06_appspot_2',
'notanappspottable_20130515_0261', '2013_05_appspot', '2013_06_appspot_1', '2013_06_appspot_2',
'2013_06_appspot_3', '2013_06_appspot_4', '2013_06_appspot_5',
'appspot_6_2013_06', 'table_not_matching_naming'
]
Expand Down