'How to convert Hive schema to Bigquery schema using Python?

What i get from api:

"name":"reports"
"col_type":"array<struct<imageUrl:string,reportedBy:string>>"

So in hive schema I got:

reports array<struct<imageUrl:string,reportedBy:string>>

Note: I got hive array schema as string from api

My target:

bigquery.SchemaField("reports", "RECORD", mode="NULLABLE",
        fields=(
             bigquery.SchemaField('imageUrl', 'STRING'),
             bigquery.SchemaField('reportedBy', 'STRING')
               )
     )

Note: I would like to create universal code that can handle when i receive any number of struct inside of the array.

Any tips are welcome.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source