Generate Schema from CSV string and Write Generated Schema to String #87
-
Hi there, I'm trying to generate a schema from a CSV string object within a google cloud function and then write this generated schema to a new string so that I can use this in the bigquery table load job. I was assuming I'd be able to do something like;
However I can't seem to get this working. My interpretation of the README makes me think that this is not possible and I need to write the schema to an output file before I can use it in a load job. Is there a way to generate a schema based off a CSV string (or file like object) and write the schema back to a string? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
The generator = SchemaGenerator(input_format='csv',sanitize_names=True,quoted_values_are_strings=True)
with file_blob.open("r") as csv_file:
schema_map = generator.deduce_schema(csv_fie)
generated_schema = generator.flatten_schema(schema_map) I recommend getting this working using a small local file before pulling in the complexity of Google Cloud Storage and BigQuery. Looking at the explanation in the README.md (https://github.com/bxparks/bigquery-schema-generator#SchemaGeneratorDeduceSchema), I definitely need to make that example more clear. |
Beta Was this translation helpful? Give feedback.
-
I uploaded a bunch of examples here: The |
Beta Was this translation helpful? Give feedback.
I uploaded a bunch of examples here:
https://github.com/bxparks/bigquery-schema-generator/tree/develop/examples
The
examples/csvreader.py
file is probably the most relevant to you.