gpt4 book ai didi

hadoop - 使用Pig Latin进行列到行的转换

转载 作者:行者123 更新时间:2023-12-02 21:28:46 26 4
gpt4 key购买 nike

A = load 'input.txt'; 
dump A;
"0,1, 2,3,4
5, 6,7, 8,9
B = foreach A generate FLATTEN(TOBAG(*));
dump B
("0)
(1)
( 2)
(3)
(4)
(5)
( 6)
(7)
( 8)
(9)

我想对上面的每个字段执行一些替换和修剪操作。我如何将其转换回原始格式?

预期产量
0,1,2,3,4

5,6,7,8,9

最佳答案

是的,这确实是一个实验性问题。

行到列的转换和列到行的转换!

是的,通过从RANK运营商那里获得很少的帮助,我认为我们可以实现这一目标

我为下面的输入尝试了下面的代码

输入:

 0,1,2,3,4 
5,6,7,8,9

在 pig 以下脚本中,有两个转储语句
numbers = LOAD '/home/inputfiles/col_to_row.txt' USING PigStorage() As(line:chararray);

numbers_rank = RANK numbers;

numbers_each = FOREACH numbers_rank GENERATE $0 as rank_key,FLATTEN(TOKENIZE(line)) as each_number;

rows_to_columns = FOREACH numbers_each GENERATE each_number;

dump rows_to_columns;--Will give you each number in a separate row..


numbers_grp = GROUP numbers_each BY rank_key;

columns_to_rows = FOREACH numbers_grp GENERATE FLATTEN(BagToTuple(numbers_each.each_number));

dump columns_to_rows; -- Will give you as Per original input data set

输出:
   dump rows_to_columns;

(0)
(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
(9)


dump columns_to_rows;

(0,1,2,3,4)
(5,6,7,8,9)

关于hadoop - 使用Pig Latin进行列到行的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35010252/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com