如何从 pig 中的文本文件的一行中转储特定列?
How to dump a particular column from a row of a text file in pig ?
我是 pig.I 的新手,我的数据在 .txt 文件中,我想从此文本中检索特定的列 file.The 此文本文件中的列用 ;
分隔.
例如,如果行是
1;1;13;2010-09-13T19:16:26.763;239;383084;10;16575;2013-04-05T15:50:48.133;2015-11-21T04:55:50.150;I've rooted my phone. Now what? What do I gain from rooting?;2;0;162;2011-01-25T08:44:10.820;
,
然后我想从上面的行中检索第 4th 列。
那么,检索第 4th 列的 pig 脚本应该是什么,即 (239)
.
你有分号作为分隔符使用 PigStorage
A = LOAD '/path/to/file' USING PigStorage(';');
dump A
转储 A 的输出:
(1,1,13,2010-09-13T19:16:26.763,239,383084,10,16575,2013-04-05T15:50:48.133,2015-11-21T04:55:50.150,I've
rooted my phone. Now what? What do I gain from
rooting?,2,0,162,2011-01-25T08:44:10.820)
B =foreach A generate ;
dump B
转储 B 的输出
(239)
如果您想为您的列命名并使用该名称检索,您可以在加载命令中使用 AS
A = LOAD '/path/to/file' USING PigStorage(';') AS(col1,col2...);
Dumping given column with name.
B =foreach A generate col1;
dump B
我是 pig.I 的新手,我的数据在 .txt 文件中,我想从此文本中检索特定的列 file.The 此文本文件中的列用 ;
分隔.
例如,如果行是
1;1;13;2010-09-13T19:16:26.763;239;383084;10;16575;2013-04-05T15:50:48.133;2015-11-21T04:55:50.150;I've rooted my phone. Now what? What do I gain from rooting?;2;0;162;2011-01-25T08:44:10.820;
,
然后我想从上面的行中检索第 4th 列。
那么,检索第 4th 列的 pig 脚本应该是什么,即 (239)
.
你有分号作为分隔符使用 PigStorage
A = LOAD '/path/to/file' USING PigStorage(';');
dump A
转储 A 的输出:
(1,1,13,2010-09-13T19:16:26.763,239,383084,10,16575,2013-04-05T15:50:48.133,2015-11-21T04:55:50.150,I've rooted my phone. Now what? What do I gain from rooting?,2,0,162,2011-01-25T08:44:10.820)
B =foreach A generate ;
dump B
转储 B 的输出
(239)
如果您想为您的列命名并使用该名称检索,您可以在加载命令中使用 AS
A = LOAD '/path/to/file' USING PigStorage(';') AS(col1,col2...);
Dumping given column with name.
B =foreach A generate col1;
dump B