2015-04-14 97 views
0

这是我的猪脚本无法使用Azure中的PowerShell

$QueryString = "A = load 'wasb://[email protected]$StorageAccount.blob.core.windows.net/table1' using PigStorage(',') as (col1 chararray,col2 chararray,col3 chararray,col4 chararray,col5 chararray,col6 chararray,col7 int,col8 int);" + 
"user_list = foreach A GENERATE $0;" + 
"unique_user = DISTINCT user_list;" + 
"unique_users_group = GROUP unique_user ALL;" + 
"uu_count = FOREACH unique_users_group GENERATE COUNT(unique_user);" + 
"DUMP uu_count;" 

当我执行上述猪脚本

'2015-04-14 23:17:55,177 [main] ERROR org.apache.pig.PigServer - exception during parsing: Error during parsing. <line 1, column 166> mismatched input 'chararray' expecting RIGHT_PAREN 
Failed to parse: <line 1, column 166> mismatched input 'chararray' expecting RIGHT_PAREN 
at org.apache.pig.parser.QueryParserDriver.parse(QueryParserDriver.java:241) 
at org.apache.pig.parser.QueryParserDriver.parse(QueryParserDriver.java:179) 
at org.apache.pig.PigServer$Graph.parseQuery(PigServer.java:1678) 
at org.apache.pig.PigServer$Graph.access$000(PigServer.java:1411) 
at org.apache.pig.PigServer.parseAndBuild(PigServer.java:344) 
at org.apache.pig.PigServer.executeBatch(PigServer.java:369) 
at org.apache.pig.PigServer.executeBatch(PigServer.java:355) 
at org.apache.pig.tools.grunt.GruntParser.executeBatch(GruntParser.java:140) 
at org.apache.pig.tools.grunt.GruntParser.processDump(GruntParser.java:769) 
at org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:372) 
at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:198) 
at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:173) 
at org.apache.pig.tools.grunt.Grunt.exec(Grunt.java:84) 
at org.apache.pig.Main.run(Main.java:509) 
at org.apache.pig.Main.main(Main.java:156) 
2015-04-14 23:17:55,177 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1200: <line 1, column 166> mismatched input 'chararray' expecting RIGHT_PAREN 

我编辑这样剩下的LOAD语句我得到这个错误执行生猪脚本的脚本是同一

$QueryString = "A = load 'wasb://[email protected]$StorageAccount.blob.core.windows.net/table1';" + 

现在我得到的错误是

2015-04-14 23:23:00,117 [main] ERROR org.apache.pig.PigServer - exception during parsing: Error during parsing. <line 1, column 162> Syntax error, unexpected symbol at or near ';' 
Failed to parse: <line 1, column 162> Syntax error, unexpected symbol at or near ';' 
at org.apache.pig.parser.QueryParserDriver.parse(QueryParserDriver.java:241) 
at org.apache.pig.parser.QueryParserDriver.parse(QueryParserDriver.java:179) 
at org.apache.pig.PigServer$Graph.parseQuery(PigServer.java:1678) 
at org.apache.pig.PigServer$Graph.access$000(PigServer.java:1411) 
at org.apache.pig.PigServer.parseAndBuild(PigServer.java:344) 
at org.apache.pig.PigServer.executeBatch(PigServer.java:369) 
at org.apache.pig.PigServer.executeBatch(PigServer.java:355) 
at org.apache.pig.tools.grunt.GruntParser.executeBatch(GruntParser.java:140) 
at org.apache.pig.tools.grunt.GruntParser.processDump(GruntParser.java:769) 
at org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:372) 
at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:198) 
at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:173) 
at org.apache.pig.tools.grunt.Grunt.exec(Grunt.java:84) 
at org.apache.pig.Main.run(Main.java:509) 
at org.apache.pig.Main.main(Main.java:156) 
2015-04-14 23:23:00,132 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1200: <line 1, column 162> Syntax error, unexpected symbol at or near ';' 
Details at logfile: C:\apps\dist\hadoop-2.4.0.2.1.9.0-2196\logs\pig_1429053777602.log 

我不明白错误是什么。你能有人帮我上的Windows PowerShell执行这个查询(我使用Windows PowerShell ISE,这样我就可以编辑查询)

terminal execution

+0

你能告诉你如何执行脚本?命令行? –

+0

@JanChrbolka我添加了一个终端的图片 – dheee

回答

1

的问题是,在这个声明user_list = foreach A GENERATE $0;。 PowerShell将$ 0解释为参数,并且由于未定义PowerShell正在替换空字符串。您可以定义脚本参数一样$0 = '$0';或只是逃避$,如:

user_list = foreach A GENERATE `$0; 

PowerShell使用`(反引号,旁边的“1”键)作为双引号的转义字符字符串。

因此脚本可以看起来像:

$0 = '$0'; 
$QueryString = "A = load 'wasb://[email protected]$storageAccountName.blob.core.windows.net/table1' using PigStorage(',') as (col1,col2,col3,col4,col5,col6,col7,col8) ;"+ 
"user_list = foreach A GENERATE $0;" + 
"unique_user = DISTINCT user_list;" + 
"unique_users_group = GROUP unique_user ALL;" + 
"uu_count = FOREACH unique_users_group GENERATE COUNT(unique_user);" + 
"DUMP uu_count;" 

$QueryString = "A = load 'wasb://[email protected]$storageAccountName.blob.core.windows.net/table1' using PigStorage(',') as (col1,col2,col3,col4,col5,col6,col7,col8) ;"+ 
"user_list = foreach A GENERATE `$0;" + 
"unique_user = DISTINCT user_list;" + 
"unique_users_group = GROUP unique_user ALL;" + 
"uu_count = FOREACH unique_users_group GENERATE COUNT(unique_user);" + 
"DUMP uu_count;"