Reputation: 222582
I am using big query client with python to retrieve the table names from big query.
result = client._get_all_tables(datasetID,cache=False)
print result
for x in result:
The result is as follows,
{u'totalItems': 7, u'tables': [{u'kind': u'bigquery#table', u'type': u'TABLE', u'id': u'publicdata:samples.github_nested', u'tableReference': {u'projectId': u'publicdata', u'tableId': u'github_nested', u'datasetId': u'samples'}}, {u'kind': u'bigquery#table', u'type': u'TABLE', u'id': u'publicdata:samples.github_timeline', u'tableReference': {u'projectId': u'publicdata', u'tableId': u'github_timeline', u'datasetId': u'samples'}}, {u'kind': u'bigquery#table', u'type': u'TABLE', u'id': u'publicdata:samples.gsod', u'tableReference': {u'projectId': u'publicdata', u'tableId': u'gsod', u'datasetId': u'samples'}}, {u'kind': u'bigquery#table', u'type': u'TABLE', u'id': u'publicdata:samples.natality', u'tableReference': {u'projectId': u'publicdata', u'tableId': u'natality', u'datasetId': u'samples'}}, {u'kind': u'bigquery#table', u'type': u'TABLE', u'id': u'publicdata:samples.shakespeare', u'tableReference': {u'projectId': u'publicdata', u'tableId': u'shakespeare', u'datasetId': u'samples'}}, {u'kind': u'bigquery#table', u'type': u'TABLE', u'id': u'publicdata:samples.trigrams', u'tableReference': {u'projectId': u'publicdata', u'tableId': u'trigrams', u'datasetId': u'samples'}}, {u'kind': u'bigquery#table', u'type': u'TABLE', u'id': u'publicdata:samples.wikipedia', u'tableReference': {u'projectId': u'publicdata', u'tableId': u'wikipedia', u'datasetId': u'samples'}}], u'kind': u'bigquery#tableList', u'etag': u'"hnk59tKBkX8cdlePZ8VtzgVzuO4/2P51RdhDvk7tUvXpY_uairNEWDE"'}
How to get the tablenames from the above dictionary list?
Expected Output:
github_nested
github_timeline
gsod
natality
shakespeare
trigrams
wikipedia
Upvotes: 1
Views: 49
Reputation: 222582
I have done in the following way,
tablesWithDetails = result["tables"]
print tablesWithDetails
for inditable in tablesWithDetails:
tables.append(inditable["id"])
return tables
Upvotes: 1