Closed sanimesa closed 1 month ago
Hey @sanimesa !
Sorry for the delayed response.
When you have a proto with fields word
and num_word_count
, the STRUCT
should have fields with names word
and numWordCount
to match it. If the names don't match, the pbwrapper.parse
call won't work.
To get the appropriate field names, you can use this trick:
CREATE OR REPLACE FUNCTION
test.toMyProtoMessage(input STRUCT<dummyField STRING>)
RETURNS STRING
LANGUAGE js OPTIONS ( library=["gs://###/pbwrapper.js"] ) AS r"""
let message = pbwrapper.setup("dummypackage.DummyMessage")
return JSON.stringify(message)
""";
SELECT
test.toMyProtoMessage(STRUCT(word)) AS protoResult,
FROM
`bigquery-public-data.samples.shakespeare`
LIMIT
1;
Going to close this issue as @ron-gal provided a solution, please follow up if needed!
I tried the example from the documentation which has a STRUCT<STRING, BIGNUMERIC> and it does not produce anything For a single string field, the UDF does return values.
This is the proto file I used:
The UDF:
Thanks.