[英]`instanceof Date` not behaving as expected within a BigQuery UDF
Anyone have any insight into why the following results in false
instead of true
?任何人都知道为什么以下结果是false
而不是true
?
CREATE TEMPORARY FUNCTION test()
RETURNS BOOL
LANGUAGE js
AS
"""
const d = new Date();
return d instanceof Date;
""";
SELECT test();
Returns
false
(unexpected)返回false
(意外)
WORKAROUND:解决方法:
CREATE TEMPORARY FUNCTION test()
RETURNS BOOL
LANGUAGE js
AS
"""
const d = new Date();
return Object.prototype.toString.call(d) === '[object Date]';
""";
SELECT test();
Returns
true
(as expected)返回true
(如预期)
The instanceof Date
seams not to work. instanceof Date
接缝不起作用。
For other objects, like String
it works fine.对于其他对象,如String
,它工作正常。
There is a JavaScript workaround possible : 有一个 JavaScript 解决方法:
CREATE TEMPORARY FUNCTION test()
RETURNS BOOL
LANGUAGE js
AS
"""
var d = new Date();
var s= new String('String created with constructor');
//return s instanceof String;
return typeof d.getMonth === 'function';
""";
SELECT test();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.