简体   繁体   English

BigQuery 临时 function 将 int 转换为字符串

[英]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.

相关问题 BigQuery 自动将字符串转换为 int - BigQuery converts automatically a string into int Spark 写 Parquet 数组<string>加载到 BigQuery 时转换为不同的数据类型</string> - Spark writing Parquet array<string> converts to a different datatype when loading into BigQuery 从临时 Function 和动态 SQL 在 BigQuery 中创建视图 - Creating a View in BigQuery from Temporary Function and Dynamic SQL Bigquery 在使用 Python 加载 json 文件时将我的字符串字段转换为 integer - Bigquery converts my string field into integer while loading json file with Python BigQuery - operator = 参数类型没有匹配的签名:INT64,STRING - BigQuery - No matching signature for operator = for argument types: INT64, STRING bigquery sql 表 function 带字符串插值 - bigquery sql table function with string interpolation 在 BigQuery 中将 TIME 转换为 INT - Convert TIME to INT in BigQuery BigQuery function 通过查找表删除字符串中的单词 - BigQuery function to remove words in string by lookup table 如何减少 BigQuery 中的临时表过期时间 - How to reduce the temporary table expiration time in BigQuery Bigquery parquet 文件处理列表<string>作为清单<int32>当传递空数组时</int32></string> - Bigquery parquet file treats list<string> as list<int32> when empty array is passed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM