0
votes

In BigQuery you can add JavaScript UDFs, which will be executed on an instance of V8. This page on googleblog.com (just about the only page I could find on the subject) states that

JavaScript UDFs are executed on instances of Google V8 running on Google servers. Your code runs close to your data in order to minimize added latency.

So when I have data in, for example, Europe, I expect that the UDF will be executed in the same region. However, when I run the following query it appears that the instance is not as close to my data as I expected:

CREATE TEMP FUNCTION getDate()
RETURNS String
LANGUAGE js AS """
return new Date();
""";
SELECT CURRENT_DATETIME() dateTimeBigQuery
     , getDate() as dateTimeJavaScript

Output of this statement:

dateTimeBigQuery                    dateTimeJavaScript
2018-10-10T07:42:32.556699          Wed Oct 10 2018 00:42:32 GMT-0700 (PDT)

This page on Time functions in BigQuery tells me that the CURRENT_DATETIME() function returns the UTC datetime when there's no timezone specified.

This page on Date functions in JavaScript states

If no arguments are provided, the constructor creates a JavaScript Date object for the current date and time according to system settings for timezone offset.

When I'm using data from a BigQuery table (datetime without timezone) and passing that to the JavaScript function, it will also be return the datetime at GMT-0700

So am I safe to assume that the instance of V8 is not running close to my data? And if that's the case, is there a way to make specify a region for that instance?

1

1 Answers

1
votes

BigQuery overrides the constructor for Date to use UTC, rather than picking up the time zone from wherever the UDF is executing, in order to be consistent with the CURRENT_DATE, CURRENT_DATETIME, etc. functions. The actual V8 environments always run alongside the jobs that execute other logic in the query.