hive> create database test_hive;
OK
Time taken: 0.12 seconds
hive> show databases;
OK
default
test_hive
Time taken: 0.017 seconds, Fetched: 2 row(s)
hive> use test_hive;
OK
Time taken: 0.027 seconds
create table student(id int,name string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';
1.2 查看表信息
hive> desc student;
OK
id int
name string
Time taken: 0.126 seconds, Fetched: 2 row(s)
desc formatted student;(重点)
hive> desc formatted student;
OK
# col_name data_type comment
id int
name string
# Detailed Table Information
Database: test_hive
Owner: hadoop
CreateTime: Wed Jan 16 15:22:44 CST 2019
LastAccessTime: UNKNOWN
Protect Mode: None
Retention: 0
Location: hdfs://node1:8020/user/hive/warehouse/test_hive.db/student
Table Type: MANAGED_TABLE
Table Parameters:
transient_lastDdlTime 1547623364
# Storage Information
SerDe Library: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
InputFormat: org.apache.hadoop.mapred.TextInputFormat
OutputFormat: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
Compressed: No
Num Buckets: -1
Bucket Columns: []
Sort Columns: []
Storage Desc Params:
field.delim \t
serialization.format \t
Time taken: 0.078 seconds, Fetched: 28 row(s)
hive> desc extended student;
OK
id int
name string
Detailed Table Information Table(tableName:student, dbName:test_hive, owner:hadoop, createTime:1547623364, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:[FieldSchema(name:id, type:int, comment:null), FieldSchema(name:name, type:string, comment:null)], location:hdfs://node1:8020/user/hive/warehouse/test_hive.db/student, inputFormat:org.apache.hadoop.mapred.TextInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, parameters:{field.delim= , serialization.format=
Time taken: 0.077 seconds, Fetched: 4 row(s)
1.3 加载数据到表
表名前尽量加数据库的名字
load data local inpath '/home/hadoop/student.txt' into table test_hive.student;
1.4 查看 Hive 自带的函数
hive> show functions;
看某个函数如何使用
hive> desc function upper;
OK
upper(str) - Returns str with all characters changed to uppercase
Time taken: 0.022 seconds, Fetched: 1 row(s)
hive> desc function upper;
OK
upper(str) - Returns str with all characters changed to uppercase
Time taken: 0.022 seconds, Fetched: 1 row(s)
hive> desc function extended upper;
OK
upper(str) - Returns str with all characters changed to uppercase
Synonyms: ucase
Example:
> SELECT upper('Facebook') FROM src LIMIT 1;
'FACEBOOK'
Time taken: 0.015 seconds, Fetched: 5 row(s)
hive> select id,upper(name) uname from test_hive.student;
OK
1001 MIKE
1002 JOHN
1003 MARY
Time taken: 0.234 seconds, Fetched: 3 row(s)