I have table in bigquery with struct
And problem with iserting data to test record
I try to insert in this way:
query = (
"""
INSERT INTO test.qwe (name, nick, test)
VALUES(@name, @nick, @test)
"""
)
hitTimeStamp = int(time.time())
query_params = [
bigquery.ScalarQueryParameter("name", "STRING", hitTimeStamp),
bigquery.ArrayQueryParameter("nick", "STRING", ["k","TEST"]),
bigquery.StructQueryParameter(
"test",
bigquery.ArrayQueryParameter("a", "STRING", ["adsfwerf","d"]),
bigquery.ArrayQueryParameter("b", "STRING", ["asda","sdfds"]),
),
]
job_config = bigquery.QueryJobConfig()
job_config.query_parameters = query_params
query_job = client.query(
query,
location="US",
job_config=job_config,
)
I expected the data will be inserted! Pls...

Right now I see a couple problems:
nickas an array, but it's defined as aSTRING.testas a struct containing arrays, butNESTED REPEATEDis actually an array containing structs.Unfortunately, it looks like the helpers you're using from the
google-cloud-pythonlibrary don't correctly support creating the output needed forNESTED REPEATED(array of struct) fields. There's an issue noting this that's currently in their "To Do" status (despite being marked as closed, there was no resolution).This is possible through other libraries as well as natively in the BigQuery DML syntax, which would look something like this:
(Note that there are several different syntaxes for working with
ARRAYandSTRUCTtypes, but this is the most concise which is why I chose it here.)So as a workaround, you could always build the query outside of the helpers provided by
google-cloud-pythonand then run it. You may also want to bump that issue thread and see if the project maintainers can provide any other workarounds or help get that functionality added—or you may need to look for another library that fully supports the features aroundNESTED REPEATEDfields.