我正在尝试从某些表中获取数据,并将它们传递给 bigquery 中的 JavaScript UDF。
我编写了以下代码,但我似乎无法理解将我的选择结果存储在所需结构中的正确语法,然后如何将其传递给我的 udf 函数。
DECLARE arg1 ARRAY<STRING>;
DECLARE arg2 ARRAY<STRUCT <col1 STRING, col2 STRING> >;
DECLARE res1 ARRAY<STRING>;
SET arg1 = ARRAY<STRING>["Adams", "Joseph", "Davis", "Mary", "Jesus"] ;
CREATE TEMP FUNCTION myfunction(arg1 ARRAY<STRING> , arg2 ARRAY<STRUCT<col1 STRING, col2 STRING> > )
RETURNS ARRAY<STRING>
LANGUAGE js AS '''
return ["a", "b", "c"]
''';
SET ARG2 = (SELECT AS STRUCT(
WITH TBL1 AS
(SELECT 'Adams' as LastName, 50 as SchoolID UNION ALL
SELECT 'Buchanan', 52 UNION ALL
SELECT 'Coolidge', 52 UNION ALL
SELECT 'Davis', 51 UNION ALL
SELECT 'Eisenhower', 77)
SELECT LastName as col1, SchoolID as col2 FROM TBL1));
SET res1 = select res FROM UNNEST(myfunction( arg1, arg2 )) res;