kettle连接Hive操作
从Hive中下载数据到excel中
-
拉出表输入步骤,然后创建一个新的数据库连接,连接上Hive。
这里第一次连接时报错,怀疑是Hive没启动,后面在node-1上运行hive发现还是不行,然后使用node-3远程连接Hive,再在这进行测试,发现ok。
-
选取要导出的表,后续的步骤一致了。
向Hive中写入数据
将刚刚下载下来的数据写入到test1表中。
首先拉出excel输出和表输入,然后老步骤,不过这里的数据库连接是连接Hive。
通过Hadoopcopyfiles作业组件把数据加载到hive数据库中
将下面链接下载好的数据上传至Hive中。
<http://wiki.pentaho.com/download/attachments/23530622/weblogs_parse.txt.zip?version=1&modificationDate=1327068013000>
- 先在Hive上创建对应的表。
建表语句:
create table pttest.weblogs(
t_ip string,
full_request string,
day string,
month string,
month_num int,
year string,
hour string,
minute string,
second string,
timezone string,
http_verb string,
uri string,
http_status_code string,
bytes_returned string,
referrer string,
user_agent string
)
row format delimited fields terminated by '\t';
- 然后创建一个作业(这里不是创建转换),使用Hadoop copy file 作业组件。
-
查看结果。
执行Hive的SQL语句
创建一个作业,使用核心对象下的脚本里的SQL,连接上Hive,然后执行下面SQL。
SQL语句:
create table pttest.weblogs_agg
as
select t_ip,year,month,month_num,count(*)
from pttest.weblogs
group by t_ip,year,month,month_num;