2

When using Google Cloud DataLab, I am struggling to create a UDF that returns a STRUCT.

As a minimal example, if I do this in a datalab notebook:

%bq udf -n demo -l js
// Some fn description
// @param x FLOAT64
// @returns STRUCT<Name STRING>

var obj = {name:"John"};
return obj;

then I run into the following error:

UDF return type must be defined using // @returns <type>

whereas, when using the BigQuery web UI I can do:

CREATE TEMPORARY FUNCTION demo(x FLOAT64)
RETURNS STRUCT<Name STRING>
LANGUAGE js AS """
return {
Name: "John"
};
""";

SELECT demo(data) as demoOutput
FROM UNNEST([1,2]) AS data;

and get the expected output.

How can I declare a UDF that returns a STRUCT using Datalab?

Stewart_R
  • 13,764
  • 11
  • 60
  • 106

1 Answers1

3

Sorry you're hitting this bug, caused by a type parsing regex that does not accept whitespace. Please see this github issue, there's an outstanding fix that is likely to go in the next release.

yelsayed
  • 5,236
  • 3
  • 27
  • 38