hive外部表的建立與數據匹配


1.建立hive的外部表匹配hdfs上的數據

出現如下報錯:

hive (solar)> select   * from solar.ori_mysql_sqoop_open_third_party_user_da limit 10;
OK
Failed with exception java.io.IOException:java.io.IOException: Not a file: hdfs://f04/sqoop/open/third_party_user/dt=2016-12-12
Time taken: 0.043 seconds

再來看一下這個表的結構:

hive (solar)> show create table solar.ori_mysql_sqoop_open_third_party_user_da;
OK
CREATE EXTERNAL TABLE `solar.ori_mysql_sqoop_open_third_party_user_da`(
  `id` string COMMENT 'from deserializer',
  `md5` string COMMENT 'from deserializer',
  `appid` string COMMENT 'from deserializer',
  `createdtime` string COMMENT 'from deserializer')
ROW FORMAT SERDE
  'org.apache.hadoop.hive.serde2.OpenCSVSerde'
WITH SERDEPROPERTIES (
  'escapeChar'='\\',
  'quoteChar'='\'',
  'separatorChar'=',')
STORED AS INPUTFORMAT
  'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT
  'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
  'hdfs://f04/sqoop/open/third_party_user'
TBLPROPERTIES (
  'COLUMN_STATS_ACCURATE'='false',
  'last_modified_by'='maintain',
  'last_modified_time'='1481608526',
  'numFiles'='0',
  'numRows'='-1',
  'rawDataSize'='-1',
  'totalSize'='0',
  'transient_lastDdlTime'='1481608526')
Time taken: 0.024 seconds, Fetched: 26 row(s)

可以發現這個表沒有建立分區,但是在hdfs上是有分區的:

hive (solar)> dfs -ls hdfs://f04/sqoop/open/third_party_user
            > ;
Found 4 items
-rw-r--r--   3 maintain supergroup          0 2016-12-13 05:00 hdfs://f04/sqoop/open/third_party_user/_SUCCESS
drwxr-xr-x   - maintain supergroup          0 2016-12-13 11:39 hdfs://f04/sqoop/open/third_party_user/dt=2016-12-12
-rw-r--r--   3 maintain supergroup        194 2016-12-13 05:00 hdfs://f04/sqoop/open/third_party_user/part-m-00000
-rw-r--r--   3 maintain supergroup        350 2016-12-13 05:00 hdfs://f04/sqoop/open/third_party_user/part-m-00001

解決方法是刪除這個分區目錄,就可以匹配數據了:

hive (solar)> dfs -ls -rmr hdfs://f04/sqoop/open/third_party_user/dt=2016-12-12
hive (solar)> select   * from solar.ori_mysql_sqoop_open_third_party_user_da limit 10;
OK
2	5086043868858874977	1	1481011995823
4	-724068265655153681	1	1481011997002

2.hive建立有分區的外部表時,發現沒有數據

有可能是因為沒有加partition,加partiiton后,再查一下數


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM