def create_table_schema()

in datasets/noaa_passive_bioacoustic/pipelines/_images/run_csv_transform_kub/csv_transform.py [0:0]


def create_table_schema(schema_filepath: str, table_id: str) -> list:
    logging.info("Defining table schema")
    schema = []
    with open(schema_filepath) as f:
        sc = f.read()
    schema_struct = json.loads(sc)
    for table_field in schema_struct:
        if table_field == table_id:
            for schema_field in schema_struct[table_field]:
                fld_name = schema_field["name"]
                fld_type = schema_field["type"]
                try:
                    fld_descr = schema_field["description"]
                except KeyError:
                    fld_descr = ""
                fld_mode = schema_field["mode"]
                schema.append(
                    bigquery.SchemaField(
                        name=fld_name,
                        field_type=fld_type,
                        mode=fld_mode,
                        description=fld_descr,
                    )
                )
    return schema