[英]BigQuery Temporary function converts int to string
I am using bigquery with standart SQL.我正在使用带有标准 SQL 的 bigquery。 When I pass to a function int field, the function converts it to string.当我传递给 function int 字段时,function 将其转换为字符串。
Here is the code:这是代码:
CREATE TEMPORARY FUNCTION test_function(int_field INT64) RETURNS INT64
LANGUAGE js AS """
throw typeof(int_field)
//return int_field
""";
WITH
test_table as (SELECT 1 as int_field)
SELECT test_function(int_field) from test_table
Here is Error: string at test_function(INT64) line 2, column 1
这是错误: string at test_function(INT64) line 2, column 1
Here is Job ID: fabrika-okon:bquijob_2cb8c50e_15d9db59b4f
这是作业 ID: fabrika-okon:bquijob_2cb8c50e_15d9db59b4f
As JavaScript does not support a 64-bit integer type, INT64 is unsupported in input or output types for JavaScript UDFs . 由于JavaScript不支持64位整数类型, 因此JavaScript UDF的输入或输出类型不支持INT64 。 Instead, use FLOAT64 to represent integer values as a number, or STRING to represent integer values as a string. 而是使用FLOAT64将整数值表示为数字,或使用STRING将整数值表示为字符串。
See more at SQL type encodings in JavaScript
进一步了解SQL type encodings in JavaScript
You can try this:你可以试试这个:
CREATE TEMP FUNCTION calculateGender(gender NUMERIC) RETURNS STRING LANGUAGE js AS
"switch(gender){ case 0: return 'Male'; case 1: return 'Female';}";
SELECT calculateGender(0) as Masculino, calculateGender(1) as Femenino;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.