如何使用pig脚本在内容中插入换行符

i2loujxw  于 2021-06-24  发布在  Pig
关注(0)|答案(1)|浏览(372)

这是数据
123456789,q,w,e,r,20120513年
123,77,88,8,jj,oo,“ooo,\r\n”“d,\r\ndf,123”,20120514年
123,77,88,8,jj,oo,ooo,20120514年
我想用pig脚本将这些字符\r\n替换为换行符。

Pig Script:

    REGISTER file:///usr/share/pig/contrib/piggybank/java/piggybank.jar;

    DEFINE CSVLoader org.apache.pig.piggybank.storage.CSVLoader;

    RAW = LOAD '/home/bannie/test/test.log' 
            USING CSVLoader()  AS (
                a: chararray, 
                b: chararray, 
                c: chararray, 
                d: chararray, 
                e: chararray, 
                f: chararray, 
                g: chararray, 
                h: chararray
            );

    C = FOREACH RAW GENERATE REPLACE(g, '\\\\r\\\\n', '\uxxxx') as max;

grunt> C = FOREACH RAW GENERATE REPLACE(g, '\\\\r\\\\n', '\u000f') as max;
    grunt> C = FOREACH RAW GENERATE REPLACE(g, '\\\\r\\\\n', '\u000e') as max;
    grunt> C = FOREACH RAW GENERATE REPLACE(g, '\\\\r\\\\n', '\u000d') as max;
    2013-06-03 17:53:42,629 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1200: <line 55, column 32>  mismatched input '(' expecting SEMI_COLON
    Details at logfile: /home/bannie/pig_1370249955149.log
    grunt> C = FOREACH RAW GENERATE REPLACE(g, '\\\\r\\\\n', '\u000a') as max;
    2013-06-03 17:53:47,601 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1200: <line 55, column 32>  mismatched input '(' expecting SEMI_COLON
    Details at logfile: /home/bannie/pig_1370249955149.log
    grunt> C = FOREACH RAW GENERATE REPLACE(g, '\\\\r\\\\n', '\u000b') as max;
    grunt> C = FOREACH RAW GENERATE REPLACE(g, '\\\\r\\\\n', '\u000c') as max;

Anyone knows how to insert it?
e0bqpujr

e0bqpujr1#

不能在文件中插入任何内容。pig与hadoop map reduce有相同的局限性。默认情况下,输出是一个包含部分文件的目录。

相关问题