为S3年/月/日/小时文件夹创建自动分区

发布于 2025-01-15 08:12:44 字数 967 浏览 2 评论 0原文

我的 S3 存储桶具有以下结构。

's3://st.pix/year/month/day/hour' for example
's3://st.pix/2022/09/01/06'

因此,我尝试使用以下代码在此存储桶上创建分区表:

CREATE EXTERNAL TABLE IF NOT EXISTS `acco`.`Accesn` (

  `ad_id` string,

) 
PARTITIONED BY (year string, month string, day string , hour string)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe' 
WITH SERDEPROPERTIES (
  'serialization.format' = ',',
  'field.delim' = ','
) LOCATION 's3://st.pix/${year}/${month}/${day}/${hour}/'
TBLPROPERTIES ('has_encrypted_data'='false','compressionType'='gzip');

并在运行后立即创建

MSCK REPAIR TABLE Accesn

,但不幸的是,此查询没有结果。

SELECT count(*) FROM `acco`.`Accesn` where year ='2022' and month= '03' and day ='01' and hour ='01'

我可以在 LOCATION 中使用 ${year}/${month}/${day}/${hour}/ 吗? 如果不是,有哪些选项可以动态执行此操作,而不是对特定分区使用 ALTER TABLE .. ADD PARTITION 。

My S3 bucket has the following structure.

's3://st.pix/year/month/day/hour' for example
's3://st.pix/2022/09/01/06'

So I tried to create a partition table on this bucket using this code:

CREATE EXTERNAL TABLE IF NOT EXISTS `acco`.`Accesn` (

  `ad_id` string,

) 
PARTITIONED BY (year string, month string, day string , hour string)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe' 
WITH SERDEPROPERTIES (
  'serialization.format' = ',',
  'field.delim' = ','
) LOCATION 's3://st.pix/${year}/${month}/${day}/${hour}/'
TBLPROPERTIES ('has_encrypted_data'='false','compressionType'='gzip');

and right after run

MSCK REPAIR TABLE Accesn

But unfortunately, this query gets no result.

SELECT count(*) FROM `acco`.`Accesn` where year ='2022' and month= '03' and day ='01' and hour ='01'

Can I use ${year}/${month}/${day}/${hour}/ in my LOCATION ?
If no, what are the options to do it dynamically and not using ALTER TABLE .. ADD PARTITION for a specific partition.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文