Google bigquery 如何在bigquery的自定义项中使用平方根函数
为什么JS sqrt()函数不起作用Google bigquery 如何在bigquery的自定义项中使用平方根函数,google-bigquery,Google Bigquery,为什么JS sqrt()函数不起作用 CREATE TEMPORARY FUNCTION sqt(x int64) RETURNS int64 LANGUAGE js AS """ return sqrt(x); """; with table1 as( select 25 as x union all select 100 as x union all select 625 as x ) select x,sqt(x)square_root from table1 错误:Ref
CREATE TEMPORARY FUNCTION sqt(x int64)
RETURNS int64
LANGUAGE js AS """
return sqrt(x);
""";
with table1 as(
select 25 as x union all
select 100 as x union all
select 625 as x
)
select x,sqt(x)square_root from table1
错误:ReferenceError:sqt(INT64)第2行第2-3列没有定义sqrt,JavaScript函数是
Math.sqrt
。请尝试以下方法:
CREATE TEMPORARY FUNCTION sqt(x int64)
RETURNS int64
LANGUAGE js AS """
return Math.sqrt(x);
""";
with table1 as(
select 25 as x union all
select 100 as x union all
select 625 as x
)
select x,sqt(x)square_root from table1
请注意,
INT64
不是JavaScript UDF的官方支持类型(因为没有等效的JavaScript类型)。最好使用FLOAT64
。JavaScript函数是Math.sqrt
。请尝试以下方法:
CREATE TEMPORARY FUNCTION sqt(x int64)
RETURNS int64
LANGUAGE js AS """
return Math.sqrt(x);
""";
with table1 as(
select 25 as x union all
select 100 as x union all
select 625 as x
)
select x,sqt(x)square_root from table1
请注意,INT64
不是JavaScript UDF的官方支持类型(因为没有等效的JavaScript类型)。最好改用FLOAT64