1.学习
1.创建数据库
2.创建表
创建代码:
hive> create table xie070501.h_sys_org(id int,org_name string,parent_org_id int,create_time date)
> comment 'org info'
> row format delimited
> fields terminated by '\t'
> lines terminated by '\n'
> stored as textfile;
3.导入数据
本地文件内容:
linux操作:
4.表操作
//查看所有数据库
show databases;
//查看当前数据库下的所有表
show tables;
//重命名表名
ALTER TABLE org RENAME TO sys_org;
//重命名类型
ALTER TABLE sys_org CHANGE name org_name String;
//添加列
ALTER TABLE sys_org ADD COLUMNS ( test STRING COMMENT 'test column');
//删除列
alter table xie070501.h_sys_org replace columns (id int,org_name string,parent_org_id int,create_time date);
2.问题
1.return code 2
错误:ql.Driver: FAILED: Execution Error, return code 2 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask
原因和解决办法:namenode内存空间不够,JVM剩余内存空间不够新job运行所致。执行:set hive.exec.mode.local.auto=true;
2.Name node is in safe mode
具体错误:执行hive命令出现Caused by: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.hdfs.server.namenode.SafeModeException): Cannot create directory /tmp/hive/root/54b4e862-0f21-4300-af4a-dba417a17da8. Name node is in safe mode.
解决办法:hadoop dfsadmin -safemode leave
或者有可能是namenode没启动完,稍等下再执行hive