如何放置映射类型的记录< string,array< string>>使用Firehose Python SDK胶水

发布于 2025-01-29 17:18:15 字数 1146 浏览 4 评论 0原文

首先,我创建了一个简单的胶水模式和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 技术交流群。

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

发布评论

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