【发布时间】:2016-06-13 05:11:04
【问题描述】:
我在查询中定义并注册了一个UDF函数,但看起来大查询不喜欢函数定义字符串中的转义引号\",有人知道如何在大查询中使用转义引号吗?
这是我的例子:
SELECT
Social_Connection,
Device_Type
FROM
js(
-- input table
(
SELECT
user_attribute.Name,
user_attribute.Value
FROM
UDF_TESTING.testing_src ),
-- input vars
user_attribute.Name,
user_attribute.Value,
-- output schema
"[{name: 'Social_Connection', type: 'string'},
{name: 'Device_Type', type: 'string'}]",
-- the function
"function(row, emit) {
var social_connection_index = 0;
var device_type_index = 0;
for (var i = 0; i < row.user_attribute.length; i++) {
if (row.user_attribute[i].Name == \"Social_Connection\") { // <------big query complains about the escape quote
social_connection_index = i;
}
if (row.user_attribute[i].Name == \"Device_Type\") { // <----- same as here
device_type_index = i;
}
}
emit( {Social_Connection: row.user_attribute[social_connection_index].Value,
Device_Type: row.user_attribute[device_type_index].Value} )
}")
【问题讨论】:
-
可以只用单引号吗? row.user_attribute[i].Name == 'Social_Connection'
-
在这个例子中我可以,但是我有一些使用单引号和双引号的嵌套字符串,我必须使用转义字符..
-
在您的示例中,引号不是字符串的一部分,因此您可以安全地为它们使用单引号。 \" 和 \' 当你在字符串中使用它们时应该工作。如果不是这种情况,很高兴看到例子。我只是做了快速的虚拟测试,它工作得很好
-
但我想知道是否可以在大查询查询文本中使用转义字符
-
正如我所说,它对我有用 - 如果你能提供困扰你的例子 - 我希望我能告诉你
标签: google-bigquery user-defined-functions