用于反斜杠的BigQuery非法转义序列/

时间:2017-01-12 18:16:17

标签: google-bigquery

我正在使用UDF为“test / test”这样的短语做一点正则表达式,我遇到了一个我无法纠正的错误。

CREATE TEMPORARY FUNCTION parseMethod(queryString STRING)
RETURNS STRING
LANGUAGE js AS
\"\"\"
var match_regex = /test\/(\w+)/i;
var found_method;
if(found_method = queryString.match(match_regex)){
  method_list = found_method[1];
}
return method_list;
\"\"\";

SELECT
parseMethod('test/test') AS result

当我运行此代码时,出现错误

Error in query string: Error processing job
'click-1315:XXXXXXXX': Syntax error:
Illegal escape sequence: \/

javascript函数在node.js中运行正常,所以我猜测解析BigQuery不喜欢这种格式。我也试过了\\/但同样的错误。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

您只需要删除CREATE TEMPORARY FUNCTION语句中的反斜杠,并在正则表达式中添加一对。这似乎有效:

CREATE TEMPORARY FUNCTION parseMethod(queryString STRING)
RETURNS STRING
LANGUAGE js AS
"""
var match_regex = /test\\/(\\w+)/i;
var found_method;
if(found_method = queryString.match(match_regex)){
  method_list = found_method[1];
}
return method_list;
""";

SELECT
parseMethod('test/test') AS result;