2015-04-14 25 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;"