在猪中逃脱美元符号? [英] Escaping a Dollar Sign in Pig?
问题描述
这在 0.9.2 中不是问题,但在 0.10 中,当我尝试访问带有美元符号的映射中的键时,我被我未定义变量的错误所困扰.具体:
This wasn't a problem in 0.9.2, but in 0.10, when I try to access a key in a map that has a dollar sign in it, I get hammered with errors that I haven't defined the variable. Specifically:
blah = FOREACH meh GENERATE source, json_post_id#'$id' AS post_id;
返回
Undefined parameter : id
这很好,也有道理,但是当我修改为:
That's fine and makes sense, but when I amend it to:
blah = FOREACH meh GENERATE source, json_post_id#'\$id' AS post_id;
我明白了:
Unexpected character '$'
想法?
忘了提及:也尝试过使用 2 个反斜杠和 3 个反斜杠.没有骰子.[/编辑]
Forgot to mention: have tried with 2 backslashes and 3 backslashes as well. No dice. [/Edit]
推荐答案
基于对您的邮件存档的回复发布,看起来行为在使用 Grunt shell 并将其作为脚本运行时会有所不同."
Based on a response to your Mail Archive Posting, it looks like the behavior will be "different when using Grunt shell and running it as a script."
输入文件
cheolsoo@localhost:~/workspace/pig-svn $cat 1.txt $id,a
咕噜声
没有反斜杠的 $
有效:
The $
with no backslash works:
grunt> A = LOAD '1.txt' USING PigStorage(',') AS (k:chararray,
v:chararray); grunt> B = FOREACH A GENERATE TOMAP(k, v) AS M; grunt> C
= FOREACH B GENERATE M#'$id'; grunt> DUMP C; (a)
脚本
带有单个反斜杠的 $
有效:
The $
with a single backslash works:
cheolsoo@localhost:~/workspace/pig-svn $cat test.pig A = LOAD '1.txt'
USING PigStorage(',') AS (k:chararray, v:chararray); B = FOREACH A
GENERATE TOMAP(k, v) AS M; C = FOREACH B GENERATE M#'\$id'; DUMP C;
cheolsoo@localhost:~/workspace/pig-svn $./bin/pig -x local test.pig
(a)
此外,来自分割字符串的猪问题(STRSPLIT),您是否尝试过以下任一方法.
Also, from Pig problem with split string(STRSPLIT), have you tried either of the following.
正确转义字符
u0024
.使用单引号或双引号测试 single 以查看是否有所不同.这个答案表明单引号有所不同,但值得一提.
Correctly escaping the character
u0024
. Test single using single or double quotes to see if that makes a difference. This answer shows that the single quote makes a difference which you have but it's worth mentioning.
或者,尽管相关,将循环分解为一个块.
blah = FOREACH meh {
GENERATE source, json_post_id#'$id' AS post_id;
}
看起来您正在连接一个 id
.确保您不会使用 CONCAT()
.http://pig.apache.org/docs/r0.10.0/func.html#concat
It looks like you are concatenating an id
. Make sure you are not suppose to be using CONCAT()
. http://pig.apache.org/docs/r0.10.0/func.html#concat
根据Class PigStorage
文档(Pig 0.10.0 API):
According to the Class PigStorage
documentation (Pig 0.10.0 API):
使用字符分隔符将输入行解析为字段的加载函数.默认分隔符是制表符.您可以将任何字符指定为文字(a")、已知转义字符(\t")或十进制或十六进制值(\u001"、\x0A").
A load function that parses a line of input into fields using a character delimiter. The default delimiter is a tab. You can specify any character as a literal ("a"), a known escape character ("\t"), or a dec or hex value ("\u001", "\x0A").
这篇关于在猪中逃脱美元符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!