重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
Hive存储是基于hadoop hdfs文件系统的,通过默认内嵌的Derby 数据库或外部数据库系统(如MySQL)组织元数据访问,下面就通过实际案例描述其存储过程。
创新互联公司专注于企业营销型网站、网站重做改版、宜州网站定制设计、自适应品牌网站建设、H5技术、商城网站建设、集团公司官网建设、成都外贸网站制作、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为宜州等各大城市提供网站开发制作服务。
1, 在hive 中创建表,然后把外部csv文件导入其中(外部文件为Batting.csv, 内部表为temp_batting):
hive>create table temp_batting(col_value STRING);
hive> show tables;
OK
temp_batting
...
hive>LOAD DATAINPATH'hive/data/Batting.csv' OVERWRITE INTO TABLE temp_batting;
2, 查看外部mysql数据库,可以看到新创建的temp_batting表:
mysql> use hive;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
mysql> select * from TBLS;
+--------+-------------+-------+------------------+-------+-----------+-------+--------------+----------------+--------------------+--------------------+
| TBL_ID | CREATE_TIME | DB_ID | LAST_ACCESS_TIME | OWNER | RETENTION | SD_ID |TBL_NAME | TBL_TYPE | VIEW_EXPANDED_TEXT |VIEW_ORIGINAL_TEXT |
+--------+-------------+-------+------------------+-------+-----------+-------+--------------+----------------+--------------------+----------
| 66 | 1432707070 | 1 | 0 | root | 0 | 66 | temp_batting | MANAGED_TABLE |NULL | NULL |
| |
+--------+-------------+-------+------------------+-------+-----------+-------+--------------+----------------+--------------------+----------
...
查看其在hdfs上存储路径:
mysql> select * from SDS;
+-------+-------+--------------------------------------------------+---------------+---------------------------+--------------------------------------------------------+-------------+------------------------------------------------------------+----------+
| SD_ID | CD_ID | INPUT_FORMAT |IS_COMPRESSED | IS_STOREDASSUBDIRECTORIES | LOCATION | NUM_BUCKETS |OUTPUT_FORMAT | SERDE_ID |
+-------+-------+--------------------------------------------------+---------------+---------------------------+--------------------------------
| 66 | 71 | org.apache.hadoop.mapred.TextInputFormat | | |hdfs://localhost:9000/user/hive/warehouse/temp_batting | -1 |org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat | 66 |
可以看到是:
hdfs://localhost:9000/user/hive/warehouse/temp_batting
3,到hadoop 的hdfs文件系统中查看这个表路径:
[root@lr rli]# hadoop dfs -ls /user/hive/warehouse
DEPRECATED: Use of this script to execute hdfs command is deprecated.
Instead use the hdfs command for it.
...
drwxr-xr-x - root supergroup 02015-05-27 14:16 /user/hive/warehouse/temp_batting
...
[root@lr rli]# hadoop dfs -ls/user/hive/warehouse/temp_batting
DEPRECATED: Use of this script to execute hdfs command isdeprecated.
Instead use the hdfs command for it.
Found 1 items
-rwxr-xr-x 1 root supergroup 6398990 2015-05-2714:02 /user/hive/warehouse/temp_batting/Batting.csv
可以看到其文件大小及内容。
结论:
Hive通过关联数据库系统记录文件的存储路径,属性等,实际数据存在hdfs系统中,当通过select等操作生成相应的map/reduce进程进一步数据分析处理。