我是hadoop的初学者。刚开始在Ubuntu14.04上使用hive,cdh5的 Impala 。
我的数据格式如下
A¦aa¦bb¦cc
A¦bb¦cc¦ac¦dd¦ff¦fg
B¦aa¦ac
...
第一列可以是键,但其他部分没有固定长度或固定列数。完全不同。我不知道每行有多少列。所以我把这个改成
Col1¦col2
A¦aa
A¦bb
A¦cc
A¦bb
A¦cc
A¦ac
A¦dd
....
但我花了很长时间,因为我有数百个文件,每个都有超过10万行和30 GB的大小。在我将第一种格式转换为第二种格式之后,文件大小增加了两到三倍。所以我想跳过这个过程。
问题1。如果我将原始文件导入到hdfs中,我可以在hive或impala上使用一些类似“selectdistinct col1,col2 from…”的sql吗?会有结果的
Col1¦col2
A¦aa
A¦bb
A¦cc
A¦ac
A¦dd
....
问题2。如果q1是可能的,那么sql呢?还是一样吗?”选择不同的列1,列2从…“
2条答案
按热度按时间mqkwyuun1#
问题1是的,可以通过hive或impala读取已处理的(完成所有初始工作后)文件。我提供给你的解决方案是在Hive下面。
登录到配置单元并创建一个外部表。
根据问题中提供的输入,我假设您的分隔符为“|”,格式为文本。这将在您的数据上创建一个表。
同样的代码可以用于在impala中创建表。
问题2。
登录到配置单元并运行以下命令。
uurv41yg2#
简单明了的mapreduce程序最适合您的场景,以下代码供您参考:
以下程序一次将执行2个操作:
1) 收集行数据并转换为键值对
2) 消除重复项并只存储不同的值以输出,因为键是初始标记+值标记的组合,因此将消除重复项。示例(a | bb)将是您的键,null作为值。
代码:
提供原始数据文件夹作为第一个参数,第二个参数作为输出文件夹
输入文件:input.txt
输出文件:part-r-00000文件
最后,将mapreduce输出路径绑定为配置单元表的输入路径,以便进一步查询
希望这是有用的。