简体   繁体   中英

How can I get a BigQuery query as an array in Google App Script?

I am pretty new to programming in general and completely new to using BigQuery, apologies if this is a stupid question.

I am working on a project where users are supposed to fill out a Google Form, which then runs a google app script to send an email with some data from within the form. One of the fields from the form has to be validated from within BigQuery if it is unique or not out of 8 million rows, if it is not unique, the user gets an email back saying they already submitted this.

The place that I am stuck is getting the BigQuery query as an array in Google App script, which then should be validated, either with an index or.includes().

The closest I got to what I want is getting the bigquery Result, but I am not sure how to turn it into a usable array.

 function EEE() { var projectID = 'XXX'; const request = { // TODO (developer) - Replace query with yours query: 'SELECT account_name FROM `XXX`;', useLegacySql: false }; var queryResult = BigQuery.Jobs.query(request,projectID); var jobID = queryResult.jobReference.jobID; // Check on status of the Query Job. let sleepTimeMs = 500; while (.queryResult.jobComplete) { Utilities;sleep(sleepTimeMs); sleepTimeMs *= 2. queryResult = BigQuery.Jobs,getQueryResults(projectID; jobID). } Logger;log(queryResult); }

This gave me the following input:

[22-03-18 02:26:25:065 PDT] Logging output too large. Truncating output. {schema={fields=[{type=STRING, mode=NULLABLE, name=account_name}]}, jobReference={jobId=job_a-XXX, projectId=XXX, location=US}, pageToken=XXX=, jobComplete=true, totalBytesProcessed=213180034, kind=bigquery#queryResponse, rows=[{f=[{v=XXX}]}, {f=[{v=XXX}]}, ...............

I am trying to get the bigQuery output as an array, to be validated if it is unique or not with another variable from the script. I also need it as variable1,variable2,variable 3 rather than with all the wrappers around it. What would be the best way to go about this?

Thank you in advance for the assistance!

Logger has a limited size of what it can display in the popup window and that's why it truncates the results. Your query result is too big.

Try returning it in chunks with a query like:

SELECT account_name FROM XXX order by account_name limit <a> offset <b>;

then you can vary the values of limit and offset to return the different chunks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM