Firehose 输出到 s3 - 从年月日小时文件夹格式重新分区为 dt=YY-MM-DD 格式
Firehose out to s3 - re paritition from year month day hour folders format into dt=YY-MM-DD format
我在 AWS EMR 生态系统中工作。
我正在寻找重新分区 aws firehose 输出的智能方法:
s3://bucket/YYYY/MM/DD/HH
进入hive分区格式
s3://bucket/dt=YY-MM-DD-HH
有什么建议吗?
谢谢,
奥米德
我们已经使用 S3DistCp 解决了这个问题。我们每小时对数据进行一次聚合,按模式分组,并输出到带有适当前缀的目录。
这绝对是 Firehose 所缺少的功能,目前还没有办法只使用 Firehose 来做到这一点。
http://docs.aws.amazon.com/emr/latest/ReleaseGuide/UsingEMR_s3distcp.html
我使用 python 和 boto 移动文件并重新分区。
我应用了一个正则表达式来重命名密钥
YYYY/MM/DD/HH
到
dt=YY-MM-DD-HH
代码片段(注意 src 键被删除):
from boto.s3.connection import S3Connection
import re
conn = S3Connection('xxx','yyy')
##get buckets:
source_bucket='srcBucketName'
destination_bucket='dstBucketName'
src = conn.get_bucket(source_bucket)
dst = conn.get_bucket(destination_bucket)
##Iterate
for key in src.list():
#print key.name.encode('utf-8')
file = key.name.encode('utf-8')
replaced_file = re.sub(r'(\d{4})\/(\d{2})\/(\d{2})\/(\d{2})', r'dt=---' , file)
#print replaced_file
#actual copy
dst.copy_key(replaced_file,src.name,file,encrypt_key=True )
key.delete()
在 Boto3 中添加了相同的答案(以匹配当前的 lambda 默认包装)
import re
import boto3
##set buckets:
source_bucket='walla-anagog-us-east-1'
destination_bucket='walla-anagog-eu-west-1'
## regex from from YYYY/MM/DD/HH to dt=YYYY-MM-DD
##replaced_file = re.sub(r'(\d{4})\/(\d{2})\/(\d{2})\/(\d{2})', r'dt=--' , file)
client = boto3.client('s3')
s3 = boto3.resource('s3')
mybucket = s3.Bucket(source_bucket)
for object in mybucket.objects.all():
replaced_key = re.sub(r'(\d{4})\/(\d{2})\/(\d{2})\/(\d{2})', r'dt=--' , object.key)
print(object.key)
client.copy_object(Bucket=destination_bucket, CopySource=source_bucket+"/"+object.key, Key=replaced_key, ServerSideEncryption='AES256')
client.delete_object(Bucket=source_bucket, Key=object.key)
我在 AWS EMR 生态系统中工作。
我正在寻找重新分区 aws firehose 输出的智能方法:
s3://bucket/YYYY/MM/DD/HH
进入hive分区格式
s3://bucket/dt=YY-MM-DD-HH
有什么建议吗?
谢谢, 奥米德
我们已经使用 S3DistCp 解决了这个问题。我们每小时对数据进行一次聚合,按模式分组,并输出到带有适当前缀的目录。
这绝对是 Firehose 所缺少的功能,目前还没有办法只使用 Firehose 来做到这一点。
http://docs.aws.amazon.com/emr/latest/ReleaseGuide/UsingEMR_s3distcp.html
我使用 python 和 boto 移动文件并重新分区。 我应用了一个正则表达式来重命名密钥 YYYY/MM/DD/HH 到 dt=YY-MM-DD-HH
代码片段(注意 src 键被删除):
from boto.s3.connection import S3Connection
import re
conn = S3Connection('xxx','yyy')
##get buckets:
source_bucket='srcBucketName'
destination_bucket='dstBucketName'
src = conn.get_bucket(source_bucket)
dst = conn.get_bucket(destination_bucket)
##Iterate
for key in src.list():
#print key.name.encode('utf-8')
file = key.name.encode('utf-8')
replaced_file = re.sub(r'(\d{4})\/(\d{2})\/(\d{2})\/(\d{2})', r'dt=---' , file)
#print replaced_file
#actual copy
dst.copy_key(replaced_file,src.name,file,encrypt_key=True )
key.delete()
在 Boto3 中添加了相同的答案(以匹配当前的 lambda 默认包装)
import re
import boto3
##set buckets:
source_bucket='walla-anagog-us-east-1'
destination_bucket='walla-anagog-eu-west-1'
## regex from from YYYY/MM/DD/HH to dt=YYYY-MM-DD
##replaced_file = re.sub(r'(\d{4})\/(\d{2})\/(\d{2})\/(\d{2})', r'dt=--' , file)
client = boto3.client('s3')
s3 = boto3.resource('s3')
mybucket = s3.Bucket(source_bucket)
for object in mybucket.objects.all():
replaced_key = re.sub(r'(\d{4})\/(\d{2})\/(\d{2})\/(\d{2})', r'dt=--' , object.key)
print(object.key)
client.copy_object(Bucket=destination_bucket, CopySource=source_bucket+"/"+object.key, Key=replaced_key, ServerSideEncryption='AES256')
client.delete_object(Bucket=source_bucket, Key=object.key)