【问题标题】:Map a hive partition to a location将 hive 分区映射到某个位置
【发布时间】:2014-10-19 13:14:39
【问题描述】:

我有一个按年、月、日和小时进行分区的配置单元外部表。

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

我该如何支持这一点? (而不是将目录更改为在单个数字值上不具有零前缀)。

谢谢,

男人

【问题讨论】:

  • 提供双引号有什么问题?

标签: hadoop hive hql hiveql


【解决方案1】:

在我回答之前,这确实涉及更改目录名称,但它确实会让您的查询变得简单。

我们的分区有类似的结构,但不是使用这种格式 2014/05/10/07/22 的名称,而是使用 2014/201405/ 20140510/07/20140510.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

还可以直接运行其他有关日期和月份的查询,而无需明确指定月份和年份。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-19
    • 1970-01-01
    • 2020-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多