如何放置映射类型的记录< string,array< string>>使用Firehose Python SDK胶水
首先,我创建了一个简单的胶水模式和AWS交付流。使用简单类型(例如字符串或浮点),我可以通过使用以下python代码将记录放在交货流中,并看到它转换为S3上的镶木quet文件:
import json
import boto3
STREAM_NAME = 'TEST-STREAM'
def generate(stream_name, kinesis_client, output=True):
count = 0
total = 2000
while count < total:
count += 1
response = kinesis_client.put_record(
DeliveryStreamName=stream_name,
Record={
'Data': json.dumps({'id': '1234', 'value': 0.4})
}
)
if __name__ == '__main__':
generate(STREAM_NAME, boto3.client('firehose', region_name='eu-west-1'))
但是,当我添加带有类型的字段时MAP&lt; string,array&lt; string&gt;&gt;
访问我的架构,并与其他数据调用put_record api,发生以下错误:
response = kinesis_client.put_record(
DeliveryStreamName=stream_name,
Record={
'Data': json.dumps({'id': '1234', 'value': 0.4, 'data':['a','b']})
}
)
错误:
Data does not match the schema. org.openx.data.jsonserde.json.JSONArray cannot be cast to org.openx.data.jsonserde.json.JSONObject
我缺少什么?
As a start, I have created a simple Glue schema and an AWS delivery stream. With simple types such as string or float, I am able to put a record to the delivery stream and see it transformed into a parquet file on S3 by using the following Python code:
import json
import boto3
STREAM_NAME = 'TEST-STREAM'
def generate(stream_name, kinesis_client, output=True):
count = 0
total = 2000
while count < total:
count += 1
response = kinesis_client.put_record(
DeliveryStreamName=stream_name,
Record={
'Data': json.dumps({'id': '1234', 'value': 0.4})
}
)
if __name__ == '__main__':
generate(STREAM_NAME, boto3.client('firehose', region_name='eu-west-1'))
However, when I add a field with the type MAP <STRING, ARRAY <STRING>>
to my schema and call the put_record API with the additional data, the following error occurs:
response = kinesis_client.put_record(
DeliveryStreamName=stream_name,
Record={
'Data': json.dumps({'id': '1234', 'value': 0.4, 'data':['a','b']})
}
)
Error:
Data does not match the schema. org.openx.data.jsonserde.json.JSONArray cannot be cast to org.openx.data.jsonserde.json.JSONObject
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论