# 查看需要导入Hive的track.log文件内容 $ cat /data/track.log
{"logs":[{"timestamp":"1475912701768","rpid":"63146996042563584","name":"birdben.ad.click_ad","bid":0,"uid":0,"did":0,"duid":0,"hb_uid":0,"ua":"","device_id":"","server_timestamp":1475912715001}],"level":"info","message":"logs","timestamp":"2016-10-08T07:45:15.001Z"} # 创建表test_local_table hive> CREATE TABLE IF NOT EXISTS test_local_table(logs array<struct<name:string, rpid:string, bid:string, uid:string, did:string, duid:string, hbuid:string, ua:string, device_id:string, ip:string, server_timestamp:BIGINT>>, level STRING, message STRING, client_timestamp BIGINT) partitioned by (dt string) ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe' STORED AS TEXTFILE; # 从本地文件系统中导入数据到Hive表 hive> load data local inpath '/data/track.log' into table test_local_table partition (dt='2016-10-18'); # 导入完成之后,查询test_local_table表中的数据 hive> select * from test_local_table;
OK
[{"name":"birdben.ad.click_ad","rpid":"63146996042563584","bid":"0","uid":"0","did":"0","duid":"0","hbuid":null,"ua":"","device_id":"","ip":null,"server_timestamp":1475912715001}] info logs NULL 2016-10-18
Time taken: 0.106 seconds, Fetched: 1 row(s) # 在HDFS的/hive/warehouse目录中查看track.log文件,这就是我们将本地系统文件导入到Hive之后,存储在HDFS的路径 # test_hdfs.db是我们的数据库 # test_local_table是我们创建的表 # dt=2016-10-18是我们创建的Partition $ hdfs dfs -ls /hive/warehouse/test_hdfs.db/test_local_table/dt=2016-10-18
Found 1 items
-rwxr-xr-x 2 yunyu supergroup 268 2016-10-17 21:19 /hive/warehouse/test_hdfs.db/test_local_table/dt=2016-10-18/track.log # 查看文件内容 $ hdfs dfs -cat /hive/warehouse/test_hdfs.db/test_local_table/dt=2016-10-18/track.log
{"logs":[{"timestamp":"1475912701768","rpid":"63146996042563584","name":"birdben.ad.click_ad","bid":0,"uid":0,"did":0,"duid":0,"hb_uid":0,"ua":"","device_id":"","server_timestamp":1475912715001}],"level":"info","message":"logs","timestamp":"2016-10-08T07:45:15.001Z"}
|