Created
November 19, 2022 02:36
-
-
Save rubenvarela/a998dfeab9a1c65a9239bcc6a8318bc7 to your computer and use it in GitHub Desktop.
BigQuery - JSON schema to basic Python Schema
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
#!/usr/bin/env python3 | |
import sys | |
import json | |
# used as | |
# bq show --schema --format=prettyjson PROJECT:DATASET.TABLE | ./main.py | |
data = "" | |
for x in sys.stdin: | |
data = data + x | |
loaded_data = json.loads(data) | |
for item in loaded_data: | |
print(f'bigquery.SchemaField("{item["name"]}", "{item["type"]}"),') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment