oracle 外部表 时间戳,Hive建立外部表与时间戳转换(含建dual表,修改列名)

建外部表,之前hadoop职位统计就是这么做的

hive> drop table job;

OK

Time taken: 5.446 seconds

hive> show tables;

OK

Time taken: 0.018 seconds

hive> create external table job(area string, experience string, degree string,

> num string, salary string)

> row format delimited fields terminated by ','

> location '/job';#在hdfs先建好这个文件夹,并上传好数据

OK

Time taken: 0.103 seconds

hive> select * from job;

OK

北京3-5年本科3人 15001-20000元/月

北京1-3年本科3人 10001-15000元/月

杭州3-5年本科1人 15001-20000元/月

。。。

hive> select area, count(area) from job group by area;

建表

hive> create external table tctest(uid string,goodsid string,behtype string,space string,category string,time string)

hive> row format delimited fields terminated by ','

hive> location '/tianchitest';

将日期转化为时间戳

hive> select unix_timestamp(time,'yyyyMMddHH') from tctest;利用上面的函数+CTAS语句创建一个含时间戳的表

hive> create table tcc as select uid,goodsid,behtype,space,category,unix_timestamp(time,'yyyy-MM-dd HH') from tctest;

最好直接改列名

hive> create table tcc as select uid,goodsid,behtype,space,category,unix_timestamp(time,'yyyy-MM-dd HH') as time from tctest;

dual表

因为Hive里没有自带dual表,所以我们要自己建一个

hive> create table dual(dummy string);#之后建一个dual.txt里面写个值X

hive> load data local inpath '/home/guo/dual.txt' into table dual;

hive> select unix_timestamp("2014-12-18 23:59:59") from dual;

OK

1418918399

Time taken: 0.082 seconds, Fetched: 1 row(s)

hive> select unix_timestamp("2014-12-17 23:59:59") from dual;

OK

1418831999

Time taken: 0.112 seconds, Fetched: 1 row(s)

将时间戳转化为日期

hive> select from_unixtime(1418831999) from dual;

OK

2014-12-17 23:59:59

Time taken: 0.111 seconds, Fetched: 1 row(s)

查看表结构

hive> describe tcc;

OK

uid string

goodsid string

behtype string

space string

category string

_c5 bigint

Time taken: 0.025 seconds, Fetched: 6 row(s)修改列名,注意那是反引号

hive> alter table tcc change `_c5` time bigint;

OK

Time taken: 0.172 seconds

将hive表中内容导到本地

guo@guo:~$ hive -e "select * from tcpredict" >> predict.csv

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值