For some code, and related comments, you may check the "Command and control now easier in BigQuery with scripting and stored procedures"
page. It may be worthwhile posting this question in forums such as
stackoverflow, where programmers with this specific experience might be ready to provide you with the code samples.