I have a requirement wherein I need to fetch metadata (table structure) from one of the BigQuery tables and, on that basis, create new tables. For example, table 'Metadata' contains some table structures.
In my Python script FileSubtype is passed dynamically from other script and on basis of it, column names and their corresponding datatypes would be fetched. And new tables will be created with these columns and datatypes.
Stuck part is, all these stuff has to be dynamic.
sample code (for testing purpose i have hardcoded the table name):
query1 = client.run_sync_query('%s limit 10' % QUERY)
query1.run()
rows = list(query1.fetch_data())
table = dataset.table('Sample_BQ_Table1')
for row in rows:
print(row[0])
# Set the table schema
table.schema = (
bigquery.SchemaField(row[0], 'STRING'),
)
table.create()
I am facing the error
TypeError: 'SchemaField' object is not iterable`
while setting table schema.