使用连字符管道 |-| 将数据加载到 Pig定界符

Loading Data to Pig with a pipe hyphen pipe |-| delimiter

当我尝试将 file.txt 加载到 Pig 时,出现以下错误:

pig script failed to validate: java.lang.RuntimeException: could not instantiate 'PigStorage' with arguments '[\|-\|]'

文件中的示例行是:

正文|-|正文|-|正文

我正在使用以下命令:

bag = LOAD 'file.txt' USING PigStorage('\|-\|') AS (v1:chararray, v2:chararray, v3:chararray);

是分隔符吗?我的正则表达式?

如果您不想编写自定义加载函数,您可以使用“-”作为分隔符加载您的记录,然后添加另一个步骤来替换所有“|”在你的领域。

bag = LOAD 'file.txt' USING PigStorage('-') AS (v1:chararray, v2:chararray, v3:chararray);
bag_new =  FOREACH bag GENERATE 
                    REPLACE(v1,'|','') as v1_new,
                    REPLACE(v2,'|','') as v2_new,
                    REPLACE(v3,'|','') as v3_new;