Hive外部表使用分区partition

2019-03-28 13:36|来源: 网络

1)创建外部表

create external table test(username String,work string) PARTITIONED BY(year String, month String, day String) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' LOCATION '/tmp/test/';  

2)修改表创建分区

alter table test add partition (year='2010', month='04', day='18') location '2010/04/18';  

3)查看外部表目录变化
  1. [Hadoop@hadoopmaster hadoop-1.0.3]$ bin/hadoop fs -mkdir /tmp/test/  
  2. [hadoop@hadoopmaster hadoop-1.0.3]$ bin/hadoop fs -ls /tmp/test/  
  3. Found 1 items  
  4. drwxr-xr-x   - hadoop supergroup          0 2012-07-03 19:17 /tmp/test/2010  
  5. [hadoop@hadoopmaster hadoop-1.0.3]$ bin/hadoop fs -ls /tmp/test/2010  
  6. Found 1 items  
  7. drwxr-xr-x   - hadoop supergroup          0 2012-07-03 19:17 /tmp/test/2010/04  
  8. [hadoop@hadoopmaster hadoop-1.0.3]$ bin/hadoop fs -ls /tmp/test/2010/04  
  9. Found 1 items  
  10. drwxr-xr-x   - hadoop supergroup          0 2012-07-03 19:17 /tmp/test/2010/04/18  

4)给外部表加载数据

bin/hadoop fs -put /tmp/test.txt /tmp/test/2010/04/18/  

5)执行测试查询

  1. hive> select * from test limit 10;  
  2. OK  
  3. zzz     it      2010    04      18  
  4. xxx     edu     2010    04      18  
  5. Time taken: 0.42 seconds  
  6. hive> select * from test where year='2010' and month='04' and day='18' limit 10;  
  7. OK  
  8. zzz     it      2010    04      18  
  9. xxx     edu     2010    04      18  
  10. Time taken: 0.287 seconds  
  11. hive> select * from test where year='2010' and month='04' and day='19' limit 10;  
  12. OK  
  13. Time taken: 0.113 seconds  
  14. hive>   

相关问答

更多
  • 感谢@Samson Scharfrichter,我能够调试此问题。 解决方案位于此页面上升级HDFS上的共享库 检查hadoop fs -ls / user / oozie / share / lib / lib *目录。 Thanks to @Samson Scharfrichter I was able to debug this issue. The resolution lies on this page Upgrading the Shared Libraries on HDFS Check th ...
  • 是的,有一种方法: INSERT OVERWRITE TABLE PARTITION() SELECT 在执行此类操作之前,需要将hive.exec.dynamic.partition设置为true 。 请在此处查看详细信息: Hive语言手册DML - 动态分区 Yes, there is a way: INSERT OVERWRITE TABLE PARTITION(
  • 您似乎忘记了上一次INSERT OVERWRITE中的WHERE子句: INSERT INTO TABLE Unm_Parti_Trail PARTITION (Department = 'A') SELECT employeeid,firstname,designation, CASE WHEN employeeid=19 THEN 50000 ELSE salary END AS salary FROM Unm_Parti_Trail WHERE department = 'A'; It see ...
  • 没有。 如果HIVE Metastore没有看到分区,PrestoDB将无法看到它。 也许一个cron可以帮助你。 No. If the HIVE metastore doesn't see the partitions, PrestoDB will not see it. Maybe a cron can help you.
  • 它将帮助您通过在WHERE子句中指定周,您将搜索到的数据限制为特定周。 您可以在日期(或星期几)创建第二个分区,以便为您提供限制为一周或一周/日期的选项。 在加载期间启用动态分区可以使这些分区的创建更加容易。 It will help you in that by specifying the week in your WHERE clause you will limit the data searched to a specific week. You could create a second par ...
  • 恢复分区(MSCK REPAIR TABLE) https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-RecoverPartitions(MSCKREPAIRTABLE) MSCK REPAIR TABLE table_name; 分区将自动添加 Recover Partitions (MSCK REPAIR TABLE) https://cwiki.apache.org/confluen ...
  • 为了提高向ORC表插入数据的速度,可以尝试使用以下参数进行游戏 : hive.exec.orc.memory.pool hive.exec.orc.default.stripe.size hive.exec.orc.default.block.size hive.exec.orc.default.buffer.size dfs.blocksize 此外,你可能会看到,压缩是否也可以帮助你。 例如: SET mapreduce.output.fileoutputformat.compress.codec ...
  • 据我所知,当您将数据从其他非配置数据/表加载到配置单元时,配置单元采用源数据中的字段顺序。 因此,如果对hive表进行分区,则只能将源数据中的最后一列用作分区。 在你的情况下,我不知道为什么你没有得到任何输出,虽然输出是错误的,因为field1将是field4而field2将是你的分区表中的field5 。 我知道的唯一间接方式(不好)是在创建时首先创建非分区表,然后将数据从非分区表复制到分区表。 如果它占用了大量空间(虽然您稍后要删除非分区表),那么您需要更改源数据,我想,获取分区字段。 As I kno ...
  • 两个表的表现相对相同 您忘记了该分区的WHERE子句。 分区仅在您选择数据时提高性能。 SELECT * FROM T WHERE year_month = '2017_07' -- AND st_time < '2017_08_01 00:00:00.0' ; 没有这个,你仍然在扫描整个表格中的st_time值。 您可以将EXPLAIN添加到查询中以查看差异 通过将数据转换为Parquet或ORC,您将获得额外的性能改进 the performance of both tables is relati ...
  • 它不是一个新列,而是一个伪列,你应该重新创建你的表,添加如下的分区规范: create table table_name ( id int, name string, timestamp string ) partitioned by (date string) 然后像这样动态加载创建分区的数据 set hive.exec.dynamic.partition=true; set hive.exec.dynamic.part ...