问题
Chrome V8 - the JavaScript engine - recently added support for BigInt - arbitrary precision large integers:
- https://developers.google.com/web/updates/2018/05/bigint
Can I use these BigInt in BigQuery?
回答1:
Yes! BigQuery runs one of the latest versions of V8, so it already supports BigInts.
To use them:
CREATE TEMP FUNCTION testBigInt()
RETURNS ARRAY<STRING>
LANGUAGE js AS """
return [
Number.MAX_SAFE_INTEGER
, Number.MAX_SAFE_INTEGER+2
, Number.MAX_SAFE_INTEGER+1
, Number.MAX_SAFE_INTEGER+100
, BigInt(Number.MAX_SAFE_INTEGER) + 2n];
""";
SELECT testBigInt()
9007199254740991
9007199254740992
9007199254740992
9007199254741092
9007199254740993
From the results, note that JavaScript silently produces the wrong answer when not using BigInt - hence the need for BigInts.
To keep the BigInts compatible with BigQuery, you'll need to treat them as String. Stay tuned, as we've requested improvements for this.
With the wrong types you might get these errors:
- Error: Failed to coerce output value 9007199254740993 to type NUMERIC
- Error: Failed to coerce output value 9007199254740992 to type INT64
来源:https://stackoverflow.com/questions/52825129/can-i-use-js-bigint-in-a-bigquery-udf