簡體   English   中英

將配置單元分區映射到某個位置

[英]Map a hive partition to a location

我有一個配置單元外部表,按年,月,日和小時進行分區。

PARTITIONED BY ( 
  `year` int, 
  `month` int, 
  `day` int, 
  `hour` int)
ROW FORMAT SERDE 
  'org.openx.data.jsonserde.JsonSerDe' 
STORED AS INPUTFORMAT 
  'org.apache.hadoop.mapred.SequenceFileInputFormat' 
OUTPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat'
LOCATION
    'hdfs://path/to/data'

數據存在於以下目錄中

2014/05/10/07/00

2014/05/10/07/01

...

2014/05/10/07/22

2014/05/10/07/23

當我使用以下方法選擇數據時,我得到結果:

Select * from my_table where year=2014 and month="05" and day="07" and hour="03"

但我希望能夠以引號查詢從零開始的值。 當前,以下兩個示例不起作用:

Select * from my_table where year=2014 and month=05 and day=07 and hour=03
Select * from my_table where year=2014 and month=5 and day=7 and hour=3

我該如何支持? (而不是更改目錄,使其在單個數字值上沒有零前綴)。

謝謝,

蓋伊

在我回答問題之前,這確實涉及更改目錄名稱,但這確實會使查詢變得簡單。

我們的分區具有類似的結構,但是我們使用2014/201405/20140510/07 / 20140510.22這樣的格式來代替使用名稱2014/05/10/07/22 基本上,分區是:

 PARTITIONED BY 
  (
  years bigint,
  months bigint,
  days bigint,
  hours float
  )  

現在有了使用它的好處:

問題中提到的查詢:

Select * from my_table where year=2014 and month=05 and day=07 and hour=03

新分區之后

Select * from my_table where hour = 20140507.03

同樣,無需直接指定月份和年份,就可以直接運行幾天和幾個月的其他查詢。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM