发布网友 发布时间:2022-04-21 08:27
共6个回答
懂视网 时间:2022-04-30 07:54
hive (default)> show create table test;
OK
createtab_stmt
CREATE TABLE test
(
id
int)
ROW FORMAT SERDE
‘org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe’
STORED AS INPUTFORMAT
‘org.apache.hadoop.mapred.TextInputFormat’
OUTPUTFORMAT
‘org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat’
LOCATION
‘hdfs://nameservice1/user/hive/warehouse/test’
TBLPROPERTIES (
‘transient_lastDdlTime’=’1436799093’)
Time taken: 0.135 seconds, Fetched: 12 row(s)
其他获得表的信息
hive (default)> create external table testexttable(
> name string comment ‘name value‘,
> addr string comment ‘addr value‘
> );
OK
Time taken: 10.172 seconds
create table if not exists testtable(
name string comment ‘name value‘,
addr string comment ‘addr value‘
)
row format delimited fields terminated by ‘ ‘ lines terminated by ‘
‘ stored as textfile
;
hive (default)> load data local inpath ‘/liguodong/hivedata/datatest’ overwrite into table testtable;
hive (default)> load data local inpath ‘/liguodong/hivedata/datatest’ into table testtable;
如果没有使用overwrite,则会再拷贝一份数据,不会覆盖原来的数据。
hive (default)> create external table if not exists employees(
> name string,
> salary string,
> subordinates array<string>,
> deductions map<string,float>,
> address struct<street:string,city:string,state:string,zip:int>
> )
> row format delimited fields terminated by ‘ ‘
> collection items terminated by ‘,‘
> map keys terminated by ‘:‘
> lines terminated by ‘
‘
> stored as textfile
> location ‘/liguodong/data/‘
> ;
hive> select * from employees;
OK
tony 1338 ["a1","a2","a3"] {"k1":1.0,"k2":2.0,"k3":3.0} {"street":"s1","city":"s2","state":"s3","zip":4}
mark 5453 ["a4","a5","a6"] {"k4":4.0,"k5":5.0,"k6":6.0} {"street":"s4","city":"s5","state":"s6","zip":6}
ivy 323 ["a7","a8","a9"] {"k7":7.0,"k8":8.0,"k9":9.0} {"street":"s7","city":"s8","state":"s9","zip":9}
Time taken: 10.204 seconds, Fetched: 3 row(s)
查树组
hive> select subordinates[1] from employees;
Total MapReduce CPU Time Spent: 2 seconds 740 msec
OK
a2
a5
a8
查map
hive> select deductions["k2"] from employees;
OK
2.0
NULL
NULL
Time taken: 75.812 seconds, Fetched: 3 row(s)
查结构体
hive> select address.city from employees;
Total MapReduce CPU Time Spent: 2 seconds 200 msec
OK
s2
s5
s8
Time taken: 75.311 seconds, Fetched: 3 row(s)
注意:select *
不执行mapreduce,只进行一个本地的查询。
而select 某个字段
生成一个job,执行mapreduce。
select * from employees;
select * from employees limit 10;
内部表删除,会连同hdfs存储的数据一同删除,而外部表删除,只会删除外部表的元数据信息。
hive (default)> drop table testtable;
OK
Time taken: 10.283 seconds
hive (default)> drop table testexttable;
OK
Time taken: 0.258 seconds
版权声明:本文为博主原创文章,未经博主允许不得转载。
Hive命令行常用操作(数据库操作,表操作)
标签:hive 数据库操作 命令行 表操作
热心网友 时间:2022-04-30 05:02
工具:(1)HIVE;
(2)电脑;
(3)Xshell;
采用hdfs命令进行删除表中的部分数据:
1、先使用hdfs查看该表实际分区以及数据目录位置
hdfs dfs -ls /user/hive/warehouse/tbdata.db/表名小写/;
2、例如:使用hdfs命令删除该分区20161124目录
hdfs dfs -rm -r -f /user/hive/warehouse/tbdata.db/表名小写/etl_dt=20161124;
3、最后查看是否有分区目录;
4、最查看进hive命令行查看此表是否还有数据。
热心网友 时间:2022-04-30 06:20
Hive是不支持更新操作的,你可以这样子做,从Hive表中查询出你想保留的数据,并且输入到原来的表中。热心网友 时间:2022-04-30 07:55
在我实际的开发经验中,可以这样做。热心网友 时间:2022-04-30 09:46
insert overwrite table t_table1 select * from t_table1 where XXXX;热心网友 时间:2022-04-30 11:54
insert overwrite table t_table1 select * from t_table1 where XXXX; 其中xxx是你需要保留的数据的查询条件。 如果清空表,如下: insert overwrite table t_table1 select * from t_table1 where 1=0;