大讲台谈Hive(后篇一).docVIP

  • 6
  • 0
  • 约7.88千字
  • 约 12页
  • 2017-05-05 发布于上海
  • 举报
大讲台谈Hive(后篇一)

大讲台谈Hive(后篇一) 大讲台谈hive(后篇一) Hive 操作 表操作 Hive 和 Mysql 的表操作语句类似,如果熟悉 Mysql,学习Hive 的表操作就非常容易了,下面对 Hive 的表操作进行深入讲解。 1、创建表 Hive 的数据表分为两种,内部表和外部表。 内部表:Hive 创建并通过 LOAD DATA INPATH 进数据库的表,这种表可以理解为数据和表结构都保存在一起的数据表。当通过 DROP TABLE table_name 删除元数据中表结构的同时,表中的数据也同样会从 HDFS 中被删除。 外部表:在表结构创建以前,数据已经保存在 HDFS 中,通过创建表结构,将数据格式化到表的结果里。当进行 DROP TABLE table_name 操作的时候,Hive 仅仅删除元数据的表结构,而不删除 HDFS 上的文件,所以,相比内部表,外部表可以更放心大胆地使用。 2、表查询 Hive 的查询语句与标准 SQL 语句类似 3、 数据加载 首先创建一个表 table2,table4,必须声明文件格式STORED AS TEXTFILE,否则数据无法加载。 1. hivegt; create table table2(uid STRING,gender STRING,ip STRING) row format delimited fields terminated by #39;\t#39; STORED AS TEXTFILE; 2. hivegt; create table table4(uid STRING,gender STRING,ip STRING) row format delimited fields terminated by #39;\t#39; STORED AS TEXTFILE; (1) 加载本地数据 加载本地数据使用 LOCAL 关键字, 4、 插入表 (1) 单表插入 创建一个表 insert_table,表结构和 table2 的结构相同,把 table2 表中的数据插入到新建的表 insert_table 中 (2) 多表插入 在table2中,查询字段 uid 并插入 test_insert1 表,查询字段 uid 并插入 test_insert2 表 视图操作 1) 创建一个测试表。 1. 2. 3. 4. 5. 6. 7. 8. hivegt; create table test(id int,name string); OK Time taken: 0.385 seconds hivegt; desc test; OK id int name string Time taken: 0.261 seconds, Fetched: 2 row(s) 2) 基于表 test 创建一个 test_view 视图。 1. hivegt; create view test_view(id,name_length) as select id,length(name) from test; 3) 查看 test_view 视图属性。 1. hivegt; desc test_view; 4) 查看视图结果。 1. hivegt; select * from test_view; 索引操作 1) Hive 创建索引。 1. hivegt; create index user_index on table user(id) as #39;pact.CompactIndexHandler#39; with deferred rebuild IN TABLE user_index_table; 2) 更新数据。 1. 3) 删除索引 1. 4) 查看索引 1. hivegt; show index on user; hivegt; drop index user_index on user; hivegt; alter index user_index on user

文档评论(0)

1亿VIP精品文档

相关文档