开发者学堂课程【大数据 Hive教程精讲:Apache Hive--初体验-理解什么是映射】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/90/detail/1366
Apache Hive--初体验-理解什么是映射
内容介绍:
DDL操作
DDL操作
创建表
建表语法
CREATE[EXTERNAL] TABLE [IF NOT EXISTS] table_name
[(col_name data_type [COMMENT col_comment], ...)]
[COMMENT table_comment]
[PARTITIONED BY (col_name data_type [COMMENT col_comment], ..)]
[CLUSTERED BY (col_name, col_name,...)
[SORTED BY (col_name [ASC|DESC], .
….)]INTO num_buckets BUCKETS]
[ROW FORMAT row_format]
[STORED AS file_format][LOCATION hdfs_path]
[root@node-1]#mkdir hivedata
[root@node-1 ~]# cd hivedata/
[root@node-1 hivedata]#
[root@node-1 hivedata]# vi 1.
i,a11en
,18
2,
tom, 233,jerry,28
"1.txt"[New]3L,31c written
[root@node-1"hivedata]# hadoop fs -mkdir /hivedata
[root@node-1 hivedata]# hadoop fs -put 1.txt /hivedata
Node-3:
Node-1:
hive-hcata1og-streaming-1.2.1.jar
hive-hcatalog-server-extensions-1.2.1.jarhcat-config.sh
[root@node-1 ~]#
[root@node-1 ~]# mkdir hivedata[root@node-1 ~]# cd hivedata/
[root@node-1 hivedata]#
[root@nod
é1 hivedata]# vi 1.txt
1,allen ,18
2,tom , 23
3,jerry,28
[root@node-1 hivedata]# hadoop fs -cp /hivedata/1.txt /user/hive/wa
rehouse/itcast.d
b/t_t1
[root@node-1 hivedata]# hadoop fs -cp /hivedata/1.txt /user/hive/wa
rehouse/itcast.db/t_t2
Node-3;
3rows selected (o.09 seconds)
1: jdbc:hive2: //node-1:10000> select count(*) from t_t2;
INFo : Number of reduce tasks determined at compile time: 1
INFO : In order to change the average load for a reducer (in bytesINFO : set hive.exec.reducers.bytes.per.reducer=<number>
INFO : In order to limit the maximum number of reducers :INFO: set hive.exec.reducers.max=<number>
INFO: In order to set a constant number of reducers:INFO: set mapreduce.job.reduces=<number>
INFO: number of'toiit-'
INFO: submitting tokens for job: job_1515988398381_0001
INFO: The ur1 to track the job: http: //node-1:8088/proxy/app1ication_1515988398381_OO01/
INFO : Starting Job = job_15i5988398381_0001
,Tracking URL = http://node-1:8088 /proxy/app1ication_1515988398381_0001/
INFO : Ki17 command =/export/server/hadoop-2.7.4/bin/hadoop job -ki11 job_1515988398381_0oo1
1、hive 建立一张表跟已经存在的结构化的数据文件产生映射关系
映射成功之后,就可以通过写sql来分析这结构化的数据避免了写mr程序的麻烦
2、数据库/user/hive/warehouse下的一个文件夹对应
表 数据库文件夹下面的子文件夹/user/hive/warehouse]itcast.db/t_t1
表的数据位置目前不能随便存放一定要在指定的数据库表的文件夹下面
建立表的时候可能还需要指定分隔符 否则有可能映射不成功