我可以在BigQuery UDF中使用JS BigInt吗? [英] Can I use JS BigInt in a BigQuery UDF?

查看:84
本文介绍了我可以在BigQuery UDF中使用JS BigInt吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Chrome V8-JavaScript引擎-最近添加了对BigInt的支持-任意精度的大整数:

Chrome V8 - the JavaScript engine - recently added support for BigInt - arbitrary precision large integers:

我可以在BigQuery中使用这些BigInt吗?

Can I use these BigInt in BigQuery?

推荐答案

是的! BigQuery运行的是最新版本的V8之一,因此它已经支持BigInts.

Yes! BigQuery runs one of the latest versions of V8, so it already supports BigInts.

要使用它们:

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

从结果中,请注意,当不使用BigInt时,JavaScript会默默地产生错误的答案-因此需要BigInts.

From the results, note that JavaScript silently produces the wrong answer when not using BigInt - hence the need for BigInts.

要使BigInts与BigQuery兼容,您需要将它们视为String.请保持关注,因为我们要求对此进行改进.

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:

  • 错误:无法强制输出值9007199254740993键入NUMERIC
  • 错误:无法强制输出值9007199254740992键入INT64

这篇关于我可以在BigQuery UDF中使用JS BigInt吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆