发布网友 发布时间:2022-04-08 02:35
共2个回答
懂视网 时间:2022-04-08 06:57
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-08 04:05
1、hive 命令行模式,直接输入/hive/bin/hive的执行程序,或者输入 hive --service cli