hive支持所有mysql语法_hive的使用 + hive的常用语法

本博文的主要内容有:

.hive的常用语法

.内部表

.外部表

.内部表,被drop掉,会发生什么?

.外部表,被drop掉,会发生什么?

.内部表和外部表的,保存的路径在哪?

.用于创建一些临时表存储中间结果

.用于向临时表中追加中间结果数据

.分区表(分为,分区内部表和分区外部表)

.hive的结构和原理

.hive的原理和架构设计

hive的使用

对于hive的使用,在hadoop集群里,先启动hadoop集群,再启动mysql服务,然后,再hive即可。

1、在hadoop安装目录下,sbin/start-all.sh。

2、在任何路径下,执行service mysql start (CentOS版本)、sudo /etc/init.d/mysql start (Ubuntu版本)

3、在hive安装目录下的bin下,./hive

对于hive的使用,在spark集群里,先启动hadoop集群,再启动spark集群,再启动mysql服务,然后,再hive即可。

1、在hadoop安装目录下,sbin/start-all.sh。

2、在spark安装目录下,sbin/start-all.sh

3、在任何路径下,执行service mysql start (CentOS版本)、sudo /etc/init.d/mysql start (Ubuntu版本)

3、在hive安装目录下的bin下,./hive

0a537654d138c2a7d1577a31a71809df.png

[hadoop@weekend110 bin]$ pwd

/home/hadoop/app/hive-0.12.0/bin

[hadoop@weekend110 bin]$ mysql -uhive -hweekend110 -phive

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 110

Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SHOW DATABASES;

+--------------------+

| Database |

+--------------------+

| information_schema |

| hive |

| mysql |

| test |

+--------------------+

4 rows in set (0.00 sec)

mysql> quit;

Bye

[hadoop@weekend110 bin]$

e959e714ff417da1409b146615d0f55a.png

[hadoop@weekend110 bin]$ pwd

/home/hadoop/app/hive-0.12.0/bin

[hadoop@weekend110 bin]$ ./hive

16/10/10 22:36:25 INFO Configuration.deprecation: mapred.input.dir.recursive is deprecated. Instead, use mapreduce.input.fileinputformat.input.dir.recursive

16/10/10 22:36:25 INFO Configuration.deprecation: mapred.max.split.size is deprecated. Instead, use mapreduce.input.fileinputformat.split.maxsize

16/10/10 22:36:25 INFO Configuration.deprecation: mapred.min.split.size is deprecated. Instead, use mapreduce.input.fileinputformat.split.minsize

16/10/10 22:36:25 INFO Configuration.deprecation: mapred.min.split.size.per.rack is deprecated. Instead, use mapreduce.input.fileinputformat.split.minsize.per.rack

16/10/10 22:36:25 INFO Configuration.deprecation: mapred.min.split.size.per.node is deprecated. Instead, use mapreduce.input.fileinputformat.split.minsize.per.node

16/10/10 22:36:25 INFO Configuration.deprecation: mapred.reduce.tasks is deprecated. Instead, use mapreduce.job.reduces

16/10/10 22:36:25 INFO Configuration.deprecation: mapred.reduce.tasks.speculative.execution is deprecated. Instead, use mapreduce.reduce.speculative

Logging initialized using configuration in jar:file:/home/hadoop/app/hive-0.12.0/lib/hive-common-0.12.0.jar!/hive-log4j.properties

SLF4J: Class path contains multiple SLF4J bindings.

SLF4J: Found binding in [jar:file:/home/hadoop/app/hadoop-2.4.1/share/hadoop/common/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: Found binding in [jar:file:/home/hadoop/app/hive-0.12.0/lib/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]

hive> SHOW DATABASES;

OK

default

hive

Time taken: 12.226 seconds, Fetched: 2 row(s)

hive> quit;

[hadoop@weekend110 bin]$

36693bc4850340caec5a307812db745c.png

总结,mysql比hive,多出了自己本身mysql而已。

CREATE TABLE page_view(

viewTime INT,

userid BIGINT,

page_url STRING,

referrer_url STRING,

ip STRING COMMENT 'IP Address of the User'

)

COMMENT 'This is the page view table'

PARTITIONED BY(dt STRING, country STRING)

ROW FORMAT DELIMITED

FIELDS TERMINATED BY '\001'

STORED AS SEQUENCEFILE; TEXTFILE

a0cf3ba625bdc2cf887b25cac55d092f.png

原因解释如下:

68de7269cb8e0c6b2cd090dc56d7483a.png

0668fba836cccfe8a9c4a7568fc7b702.png

0000101  iphone6pluse 64G 6888

0000102  xiaominote  64G 2388

CREATE TABLE t_order(id int,name string,rongliang string,price double)

ROW FORMAT DELIMITED

FIELDS TERMINATED BY '\t'

;

30781ec7ff8d699245f733f48c18d293.png

现在,我们来开始玩玩

6d318ce0104e2034b0919efb9545231d.png

[hadoop@weekend110 bin]$ pwd

/home/hadoop/app/hive-0.12.0/bin

[hadoop@weekend110 bin]$ ./hive

16/10/10 10:16:38 INFO Configuration.deprecation: mapred.input.dir.recursive is deprecated. Instead, use mapreduce.input.fileinputformat.input.dir.recursive

16/10/10 10:16:38 INFO Configuration.deprecation: mapred.max.split.size is deprecated. Instead, use mapreduce.input.fileinputformat.split.maxsize

16/10/10 10:16:38 INFO Configuration.deprecation: mapred.min.split.size is deprecated. Instead, use mapreduce.input.fileinputformat.split.minsize

16/10/10 10:16:38 INFO Configuration.deprecation: mapred.min.split.size.per.rack is deprecated. Instead, use mapreduce.input.fileinputformat.split.minsize.per.rack

16/10/10 10:16:38 INFO Configuration.deprecation: mapred.min.split.size.per.node is deprecated. Instead, use mapreduce.input.fileinputformat.split.minsize.per.node

16/10/10 10:16:38 INFO Configuration.deprecation: mapred.reduce.tasks is deprecated. Instead, use mapreduce.job.reduces

16/10/10 10:16:38 INFO Configuration.deprecation: mapred.reduce.tasks.speculative.execution is deprecated. Instead, use mapreduce.reduce.speculative

Logging initialized using configuration in jar:file:/home/hadoop/app/hive-0.12.0/lib/hive-common-0.12.0.jar!/hive-log4j.properties

SLF4J: Class path contains multiple SLF4J bindings.

SLF4J: Found binding in [jar:file:/home/hadoop/app/hadoop-2.4.1/share/hadoop/common/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: Found binding in [jar:file:/home/hadoop/app/hive-0.12.0/lib/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]

hive>

遇到,如下问题

aa20b5429427c7fd7b5b94bcb8f7e8d4.png

FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.metastore.HiveMetaStoreClient

先Esc,再Shift,再 . + /

dfbcf5824cc414b4c79c2c81805f8577.png

9d5691fdd77c6b19e88cd358f95cefd2.png

hive.metastore.schema.verification

true

Enforce metastore schema version consistency.

True: Verify that version information stored in metastore matches with one from Hive jars.  Also disable automatic

schema migration attempt. Users are required to manully migrate schema after Hive upgrade which ensures

proper metastore schema migration. (Default)

False: Warn if the version information stored in metastore doesn't match with one from in Hive jars.

改为

hive.metastore.schema.verification

false

Enforce metastore schema version consistency.

True: Verify that version information stored in metastore matches with one from Hive jars.  Also disable automatic

schema migration attempt. Users are required to manully migrate schema after Hive upgrade which ensures

proper metastore schema migration. (Default)

False: Warn if the version information stored in metastore doesn't match with one from in Hive jars.

1df12f4e09d6b58861d40c3dcf0406f2.png

19537ea0dba0d57487131b714e167df9.png

很多人这样写

CREATE TABLE t_order(

id int,

name string,

rongliang string,

price double

)

ROW FORMAT DELIMITED

FIELDS TERMINATED BY '\t';

hive> CREATE TABLE t_order(id int,name string,rongliang string,price double)

> ROW FORMAT DELIMITED

> FIELDS TERMINATED BY '\t'

> ;

OK

Time taken: 28.755 seconds

hive>

850cb7d4b8adf9a99c90caf94a4c43ed.png

测试连接下,

c89cee8e00e261818b77eaa308d94b83.png

668bef718e80e0bbd7ea7fe57b4412f6.png

正式连接

708cba3593a5e801b06411d1c85f23fb.png

4441068ec70cc2f780efdb0219696fdf.png

6c9726167ebf5ce19e4cdf2aa463f1f9.png

成功!

这里呢,我推荐一款新的软件,作为入门。

之类呢,再可以玩更高级的,见

1dbaf335dc105040779cec928c714c9c.png

a6b73c9ee9950465d84100a74a70cee0.png

6fd02d58afecedacf37d6596ba1efdca.png

前提得要开启hive

66cff1d49ec712c658b61ea4b627b788.png

de7ce63b18df75e6f344547ec95151c3.png

注意:第一步里,输入后,不要点击“确定”。直接切换到“常规。”

关于,第二步。看下你的hive安装目录下的hive-site.xml,你的user和password。若你配置的是root,则第二步里用root用户。

b424dc37a5cf2e6727c14e6c47327940.png

5204851fdf4147eaea5da96f8c40f64e.png

配置完第二步,之后,再最后点击“确定。”

1fdb55a0daff14290d0d4b3d1cc90bbd.png

通过show databases;可以查看数据库。默认database只有default。

87abae33a7c0775d384320abae05adab.png

hive> CREATE DATABASE hive;      //创建hive数据库,只是这个数据库的名称,命名为hive而已。

OK

Time taken: 1.856 seconds

hive> SHOW DATABASES;

OK

default

hive

Time taken: 0.16 seconds, Fetched: 2 row(s)

hive> use hive;    //使用hive数据库

OK

Time taken: 0.276 seconds

很多人这样写法

CREATE TABLE t_order(

id int,

name string,

rongliang string,

price double

)

ROW FORMAT DELIMITED

FIELDS TERMINATED BY '\t';

hive> CREATE TABLE t_order(id int,name string,rongliang string,price double)

> ROW FORMAT DELIMITED

> FIELDS TERMINATED BY '\t'

> ;

OK

Time taken: 0.713 seconds

hive> SHOW TABLES;

OK

t_order

Time taken: 0.099 seconds, Fetched: 1 row(s)

hive>

对应着,

18c9cd456285657aec23fcb3fa8c0d23.png

TBLS,其实就是TABLES,记录的是表名等。

09c84c425c36a6d1cc80d4c3e43599f6.png

5673b4d367cbaf5806f2bfdc6145b9c7.png

6a045ce152ab6ea64a0c0f0d31e36c72.png

63f3e5b1f8b879ec73e776d650155a0d.png

e0825f96f1439a5b97116b731f801005.png

d652ae9b43924095acc102a7ab94d2f9.png

061b0efcc1e31f00b0f13efa282e8b9b.png

3d037ebede3c3cf88467511c9ad81992.png

5f22999e0181447624aa3bd29fc028a3.png

a9ecfb215dc97777d1e2b27d7894579e.png

ebb3621472ff083e00ae5b3de301004b.png

好的,现在,来导入数据。

新建

48480c0bcf570070e7e6bcc16315ae01.png

[hadoop@weekend110 ~]$ ls

app             c.txt                                         flowArea.jar             jdk1.7.0_65                 wc.jar

a.txt           data                                          flow.jar                 jdk-7u65-linux-i586.tar.gz  words.log

blk_1073741856  download                                      flowSort.jar             Link to eclipse             workspace

blk_1073741857  eclipse                                       HTTP_20130313143750.dat  qingshu.txt

b.txt           eclipse-jee-luna-SR2-linux-gtk-x86_64.tar.gz  ii.jar                   report.evt

[hadoop@weekend110 ~]$ mkdir hiveTestData

[hadoop@weekend110 ~]$ cd hiveTestData/

[hadoop@weekend110 hiveTestData]$ ls

[hadoop@weekend110 hiveTestData]$ vim XXX.data

c111c29933955a04ea4ca03d9363982e.png

0000101 iphone6pluse  64G  6888

0000102 xiaominote  64G  2388

0000103 iphone5s  64G  6888

0000104 mi4  64G  2388

0000105 mi3  64G  6388

0000106 meizu  64G  2388

0000107 huawei  64G  6888

0000108 zhongxing  64G  6888

dc0c3a5e2f8dae58c79292832bc91595.png

本地文件的路径是在,

[hadoop@weekend110 hiveTestData]$ pwd

/home/hadoop/hiveTestData

[hadoop@weekend110 hiveTestData]$ ls

XXX.data

[hadoop@weekend110 hiveTestData]$

dd3ea0b077c03e462a8a4af19505f3d2.png

[hadoop@weekend110 bin]$ ./hive

16/10/10 17:23:09 INFO Configuration.deprecation: mapred.input.dir.recursive is deprecated. Instead, use mapreduce.input.fileinputformat.input.dir.recursive

16/10/10 17:23:09 INFO Configuration.deprecation: mapred.max.split.size is deprecated. Instead, use mapreduce.input.fileinputformat.split.maxsize

16/10/10 17:23:09 INFO Configuration.deprecation: mapred.min.split.size is deprecated. Instead, use mapreduce.input.fileinputformat.split.minsize

16/10/10 17:23:09 INFO Configuration.deprecation: mapred.min.split.size.per.rack is deprecated. Instead, use mapreduce.input.fileinputformat.split.minsize.per.rack

16/10/10 17:23:09 INFO Configuration.deprecation: mapred.min.split.size.per.node is deprecated. Instead, use mapreduce.input.fileinputformat.split.minsize.per.node

16/10/10 17:23:09 INFO Configuration.deprecation: mapred.reduce.tasks is deprecated. Instead, use mapreduce.job.reduces

16/10/10 17:23:09 INFO Configuration.deprecation: mapred.reduce.tasks.speculative.execution is deprecated. Instead, use mapreduce.reduce.speculative

Logging initialized using configuration in jar:file:/home/hadoop/app/hive-0.12.0/lib/hive-common-0.12.0.jar!/hive-log4j.properties

SLF4J: Class path contains multiple SLF4J bindings.

SLF4J: Found binding in [jar:file:/home/hadoop/app/hadoop-2.4.1/share/hadoop/common/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: Found binding in [jar:file:/home/hadoop/app/hive-0.12.0/lib/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]

hive> SHOW DATABASES;

OK

default

hive

Time taken: 15.031 seconds, Fetched: 2 row(s)

hive> use hive;

OK

Time taken: 0.109 seconds

hive> LOAD DATA LOCAL INPATH '/home/hadoop/hiveTestData/XXX.data' INTO TABLE t_order;

Copying data from file:/home/hadoop/hiveTestData/XXX.data

Copying file: file:/home/hadoop/hiveTestData/XXX.data

Failed with exception File /tmp/hive-hadoop/hive_2016-10-10_17-24-21_574_6921522331212372447-1/-ext-10000/XXX.data could only be replicated to 0 nodes instead of minReplication (=1).  There are 1 datanode(s) running and no node(s) are excluded in this operation.

at org.apache.hadoop.hdfs.server.blockmanagement.BlockManager.chooseTarget(BlockManager.java:1441)

at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getAdditionalBlock(FSNamesystem.java:2702)

at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.addBlock(NameNodeRpcServer.java:584)

at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.addBlock(ClientNamenodeProtocolServerSideTranslatorPB.java:440)

at org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos$ClientNamenodeProtocol$2.callBlockingMethod(ClientNamenodeProtocolProtos.java)

at org.apache.hadoop.ipc.ProtobufRpcEngine$Server$ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:585)

at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:928)

at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:2013)

at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:2009)

at java.security.AccessController.doPrivileged(Native Method)

at javax.security.auth.Subject.doAs(Subject.java:415)

at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1556)

at org.apache.hadoop.ipc.Server$Handler.run(Server.java:2007)

FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.CopyTask

hive>

cea39889d9a9fdfbbd93a162d5c1a097.png

错误是:

Failed with exception File /tmp/hive-hadoop/hive_2016-10-10_17-54-30_887_2531771020597467111-1/-ext-10000/XXX.data could only be replicated to 0 nodes instead of minReplication (=1).  There are 1 datanode(s) running and no node(s) are excluded in this operation.

解决方法:

出现此类报错主要原因是datanode存在问题,要么硬盘容量不够,要么datanode服务器down了。检查datanode,重启Hadoop即可解决。

我的这里,有错误,还没解决!

这里,t_order_wk,对应,我的t_order而已。只是表名不一样

6cf9e08197cc1a96a3335105ae3d017c.png

1f38e6ba74e43767f34229c03de76ab4.png

哇,多么的明了啊!

3298c752baa29056dbc5324622a4c7a1.png

d49e0750b34caa0287780574492b4445.png

这一句命令,比起MapReduce语句来,多么的牛!  其实,hive本来就是用mapreduce写的,只是作为数据仓库,为了方便。

hive的常用语法

已经看到了hive的使用,很方便,把SQL语句,翻译成mapreduce语句。

f761fc81e86ee9bb50b134fc954e8397.png

986a93dd7d66227bb22ba16aaf1840d9.png

25fd5f33c518ce8295813c793077bdf9.png

50159af262699e320023d779cd666c8c.png

d5498544d99d5df777a72c54152064a2.png

f947ed78aa6052a8aa664ed737a51b94.png

由此可见,xxx.data是向hive中表,加载进文件,也即,这文件是用LOAD进入。(从linux本地  -> hive中数据库)

yyy.data是向hive中表,加载进文件,也即,这文件是用hadoop fs –put进入。(从hdfs里   -> hive中数据库)

无论,是哪种途径,只要文件放进了/user/hive/warehouse/t_order_wk里,则,都可以读取到。

2bed6cee0293a98da475398b66023a6c.png

32f2f2f32b2055e7e7e7e3b99adc8146.png

a7008308ab1a4bb1d6ccee81c2cd0e03.png

de0187db531297d0dd6d3dfbe1620527.png

c1c923589ea84aa0e53a6e904c17580a.png

b3e50c52e5fa637cfc930fe1a037f0d5.png

557e6d56b401e89093d75675d1681497.png

8f283b168ad5224e83d43047e798cd51.png

22bbca7f96962182bab135dd97d9ea11.png

44d56b23e1867ca72fdd656608ef6551.png

fd23ede755b1777e7bd333ae903a3926.png

67db15cc831ab012c4e0c8b63e607bbd.png

则,LOAD DATA LOCAL INPATH ,这文件是在,本地,即Linux里。从本地里导入

LOAD DATA INPATH,这文件是在,hdfs里。从hdfs里导入

那么,由此可见,若这DATA,即这文件,是在hdfs里,如uuu.data,则如“剪切”。

会有一个问题。如是业务系统产生的,我们业务或经常要读,路径是写好的,把文件移动了,

会干扰业务系统的进行。为此,解决这个问题,则,表为EXTERNAL。这是它的好处。

//external

CREATE EXTERNAL TABLE tab_ip_ext(id int, name string,

ip STRING,

country STRING)

ROW FORMAT DELIMITED FIELDS TERMINATED BY ','

STORED AS TEXTFILE

LOCATION '/external/hive';

fdb5fa32e8c63cffe41f7d604c384c17.png

405cb81327522e8c06db579d95a6374c.png

47129830bd1f0e2c187a701adfb11b33.png

为此,我们现在,去建立一个ETTERNAL表,与它jjj.data,关联起来。Soga,终于懂了。

1b06313c95ecee3eedd1cf255a48500a.png

088d27759b2f21ed17c84d246df2647e.png

cd931c6222d616f21bbebec590d711e3.png

内部表,被drop掉,会发生什么?

dec99c78b6c9dbcc8342b5911953135e.png

61040daa921ddeaa1e07254ecb5a5420.png

以及,内部表t_order_wk里的那些文件(xxx.data、yyy.data、zzz.data、jjj.data)都被drop掉了。

dba5ea0c122eb2e1a8604152718ffbb5.png

外部表,被drop掉,会发生什么?

7c073a8a54407fcb92808d7708c28cea.png

是自定义的,hive_ext,在/下

9ed6b925733b13e5d41e5b3bbc586df3.png

df86028b6061127e0bf693cc490c0c6b.png

654b30ccd70e0d1c937cc62daa29afda.png

内部表和外部表的,保存的路径在哪?

4410bc4dcdfb6ff782069f3de52129ae.png

用于创建一些临时表存储中间结果

CTAS,即CREATE AS的意思

// CTAS  用于创建一些临时表存储中间结果

CREATE TABLE tab_ip_ctas

AS

SELECT id new_id, name new_name, ip new_ip,country new_country

FROM tab_ip_ext

SORT BY new_id;

fa14b51a404e7181645b29a901c646cd.png

f41c819ac995ab4f0fada18471d92304.png

5198ebb543edb773a76e6d5ed3b82e04.png

b5a0f1a1f289706e3a93ec06956aed39.png

670f28fd674a7daffa158d7ddb345e9b.png

用于向临时表中追加中间结果数据

//insert from select   用于向临时表中追加中间结果数据

create table tab_ip_like like tab_ip;

insert overwrite table tab_ip_like

select * from tab_ip;

这里,没演示

分区表

//PARTITION

create table tab_ip_part(

id int,

name string,

ip string,

country string

)

partitioned by (part_flag string)

row format delimited fields terminated by ',';

LOAD DATA LOCAL INPATH '/home/hadoop/ip.txt' OVERWRITE INTO TABLE tab_ip_part PARTITION(part_flag='part1');

LOAD DATA LOCAL INPATH '/home/hadoop/ip_part2.txt' OVERWRITE INTO TABLE tab_ip_part PARTITION(part_flag='part2');

select * from tab_ip_part;

select * from tab_ip_part  where part_flag='part2';

select count(*) from tab_ip_part  where part_flag='part2';

alter table tab_ip change id id_alter string;

ALTER TABLE tab_cts ADD PARTITION (partCol = 'dt') location '/external/hive/dt';

show partitions tab_ip_part;

每个月生成的订单记录,对订单进行统计,哪些商品的最热门,哪些商品的销售最大,哪些商品点击率最大,哪些商品的关联最高。

如果,对订单整个分析很大,为提高效率,在建立表时,就分区。

则,多了一个选择,你也可以对全部来,也可以对某个分区来。则按分区来。

afa897ec383348b4dffc80b348c4b521.png

795acbf2f4e79087a3eb013da1108c70.png

f5165b1392752b3de8ac8c51c2da1fd8.png

fc6eff4af300b185c6a49d10491723c2.png

0988d2958f7aef7f5a3d789595d613d3.png

f2c33dc2972269ef9341de40aefa05ff.png

0117dad7890e8d4f7fb5201923c7b6eb.png

81fcf6684fde9a674b746151006779af.png

c02148edef2d96b5e4d07f31e31fe761.png

d2c695aee28d5815dc0c2c92a57fd706.png

49fbbc6d0d8f4d562745d4cf0470f976.png

9948bb44fe49badba3bf65caa3d42229.png

c6015bbdfedaa2d0b309d90e05059ccc.png

//PARTITION

create table tab_ip_part(id int,name string,ip string,country string)

partitioned by (part_flag string)

row format delimited fields terminated by ',';

load data local inpath '/home/hadoop/ip.txt' overwrite into table tab_ip_part

partition(part_flag='part1');

load data local inpath '/home/hadoop/ip_part2.txt' overwrite into table tab_ip_part

partition(part_flag='part2');

select * from tab_ip_part;

select * from tab_ip_part where part_flag='part2';

select count(*) from tab_ip_part where part_flag='part2';

alter table tab_ip change id id_alter string;

ALTER TABLE tab_cts ADD PARTITION (partCol = 'dt') location '/external/hive/dt';

show partitions tab_ip_part;

这里,不多演示赘述了。

hive的结构和原理

510013c25764eaa2c1a6ca6327a9a292.png

hive的原理和架构设计

f5c59e9ba4598b4857b395507ee3c560.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值