You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 3, 2022. It is now read-only.
%%bq udf --name unstackCustomDimensions -l js
// A function that pluses one
// @param x ARRAY<STRUCT<index INT64, value STRING>>
// @returns ARRAY<STRING>
var customDimensions = new Array(30)
for (i = 0; i < customDimensions.length; i++) {
customDimensions[i] = 'n/a'
}
for (i = 0; i < x.length; i++) {
customDimensions[x[i].index-1] = x[i].value
}
return customDimensions;
And get the output
invalidQuery: No matching signature for function JS:UNSTACKCUSTOMDIMENSIONS for argument types: ARRAY<STRUCT<index INT64, value STRING>>. Supported signature: UNSTACKCUSTOMDIMENSIONS() at [11:7]
I was looking at the code, in the file _bigquery.py on line 517 the following pattern is mentioned
Which is used to parse the incoming parameters when a UDF is defined. The regular expression doesn't seem to recognize any spaces or commas which makes it impossible to define structs.
Some output from my playing around in ipython is shown below. When I use the same UDF in the "old-school" big-query console everything works fine.
In [1]: param_pattern = r'^\s*\/\/\s*@param\s+([<>\w]+)\s+([<>\w]+)\s*$'
re.findall(param_pattern, '//@param test STRUCT<>')
Out[7]: [('test', 'STRUCT<>')]
In [8]: re.findall(param_pattern, '//@param test STRUCT<t INT64>')
Out[8]: []
In [9]: re.findall(param_pattern, '//@param test STRUCT<INT64>')
Out[9]: [('test', 'STRUCT<INT64>')]
In [10]: re.findall(param_pattern, '//@param test STRUCT<INT64,STRING>')
Out[10]: []
In [11]: re.findall(param_pattern, '//@param test ARRAY<STRUCT<INT64,STRING>>')
Out[11]: []
In [12]: re.findall(param_pattern, '//@param test ARRAY<STRUCT<INT64>>')
Out[12]: [('test', 'ARRAY<STRUCT<INT64>>')]
In [13]: param_pattern = r'^\s*\/\/\s*@param\s+([<>\w]+)\s+([<>\w,\s]+)\s*$'
In [14]: re.findall(param_pattern, '//@param test ARRAY<STRUCT<INT64>>')
Out[14]: [('test', 'ARRAY<STRUCT<INT64>>')]
In [15]: re.findall(param_pattern, '//@param test ARRAY<STRUCT<INT64,STRING>>')
Out[15]: [('test', 'ARRAY<STRUCT<INT64,STRING>>')]
In [16]: re.findall(param_pattern, '//@param test ARRAY<STRUCT<index INT64,value STRING>>')
Out[16]: [('test', 'ARRAY<STRUCT<index INT64,value STRING>>')]
The return type regular expression seem to suffer from the same fault.
Thanks for creating an otherwise great product, it really make it easy to explore data :)
The text was updated successfully, but these errors were encountered:
Thanks for catching that @hhagblom. The regex is very loose anyway, and doesn't rule out all incorrect syntax, so I think it's fine if we allow an arbitrary number of words with the addition of spaces.
I have created a UDF query
And get the output
I was looking at the code, in the file _bigquery.py on line 517 the following pattern is mentioned
Which is used to parse the incoming parameters when a UDF is defined. The regular expression doesn't seem to recognize any spaces or commas which makes it impossible to define structs.
Some output from my playing around in ipython is shown below. When I use the same UDF in the "old-school" big-query console everything works fine.
The return type regular expression seem to suffer from the same fault.
Thanks for creating an otherwise great product, it really make it easy to explore data :)
The text was updated successfully, but these errors were encountered: