hive 创建表
来源:互联网 发布:主播助手软件 编辑:程序博客网 时间:2024/05/29 14:40
HQL对sql语句的扩展,可以定义表的数据文件存储在什么位置,以及定义表文件存储格式。
create table if not exists hives.employees(name string comment 'employee name',salary float comment 'employee salary',subordinates array<string> comment 'names of subordinates',deducations map<string,float> comment 'Keys-value',address struct <street:string,city:string,state:string,zip:int> comment 'home address')comment 'Description of the table'tblproperties('creator'='me','create_at'='20170424')location '/user/hive/warehouse/hives.db/employees'
hive自动添加两个属性:last_modified_by 保存着最后一个修改这个表的用户的用户名,last_modified_time 最后一次修改这个表的时间。
用户可以只拷贝一个表的结构,使用like关键字:
hive (default)> create table copy_table like hives.employees;OKTime taken: 0.326 seconds
查看表结构:
这种方式可以指定location 属性,其他的属性模式是不可重新定义的。
hive (default)> create table copy_table_struct like employees location '/user/hive/warehouse/copy/';OKTime taken: 0.102 secondshdfs目录结构:
使用 describe extended table_name 可以查看表的详细描述信息
也可以使用formatted关键字代替extended,实际中formatted使用的比较多:
hive (default)> describe formatted copy_table_struct;
我们创建的这些表称为hive的内部表,如果删除表,hive也会把对应的数据删除掉,这样管理表不方便和其他工作共享数据。为了弥补这一缺点,可以创建外部表。
外部表
create external table if not exists bus( CARDID string,LINEID string,BEGINTIME string,ENDTIME string,STATIONFROM string,STATIONTO string,BUSID string)row format delimited fields terminated by ','location '/user/hive/external/data/bus'put数据:
[hadoop@localhost ~]$hadoop fs -put 201404_bus.csv /user/hive/external/data/bus/查询外部表数据:
hive (default)> select * from bus limit 10;
0 0
- hive创建表
- Hive创建表
- hive创建表详解
- hive表的创建
- 01-Hive创建表
- hive 创建表详解
- Hive创建外部表
- hive 创建表
- Hive创建表
- Hive创建表
- hive创建表
- Hive创建dual表
- Hive创建表和分区
- Hive创建TABLE_PARAMS表失败
- Hive创建TABLE_PARAMS表失败
- hive 创建/删除/截断表
- hive查看表创建过程
- Excel文件创建HIVE表
- BZOJ4870: [Shoi2017]组合数问题
- C++第五次实验
- tiny6410 通过按键玩中断
- MindManager中如何将思维导图设置为默认模板?
- 【SHOI&SXOI2017】bzoj4868 期末考试
- hive 创建表
- Java多线程关于生产者和消费者
- vim编辑器的简单使用
- HDU
- 项目中ajax请求第二次的乱码问题
- DOM2
- 中国大学生计算机设计大赛报名及作品提交攻略
- Commit failed with error ***remains in conflict 解决android studio svn文件冲突的问题
- 求最大面积