【SDC】StreamSets实战之路-16-实战篇-数据序列化与反序列化

主要通过一个数据序列化与反序列化的案例来介绍Streamsets(3.20.0 汉化版)的使用,因为大数据加工与处理的时候,避免不了数据的序列化与反序列化,这里主要讲一下使用数据序列化插件和反序列化插件实现avro格式数据序列化与反序列化,。当然还是可以序列化其他格式,这里挑一个难的讲一下。

学习目的:学习使用Data Generator 和 Data Parser。

需要配置一个数据流。

序列化效果:

反序列化效果:

1.一些JSON格式的数据:

{"cont":{"disk_total":1024,"disk_used":100,"disk_free":924,"file_sum":94,"file_type_sum":20,"file_grow_num":20,"disk_grow_num":20,"file_type_sum_document_docx":200,"file_type_sum_document_txt":200,"disk_used_document_docx":200,"disk_used_document_txt":600},"status_tag":{"tag_version":"1.0","data_type":4,"data_subtype":16387,"producer_id":24705,"timestamp":"2020-03-24 12:00:00.00"}}

Avro schema:

{"type": "record","name": "cont1","fields": [{"name": "cont","type": {"type": "record","name": "cont2","fields": [{"name": "disk_total","type": "int"},{"name": "disk_used","type": "int"},{"name": "disk_free","type": "int"},{"name": "file_sum","type": "int"},{"name": "file_type_sum","type": "int"},{"name": "file_grow_num","type": "int"},{"name": "disk_grow_num","type": "int"},{"name": "file_type_sum_document_docx","type": "int"},{"name": "file_type_sum_document_txt","type": "int"},{"name": "disk_used_document_docx","type": "int"},{"name": "disk_used_document_txt","type": "int"}]}}]}

1.使用开发测试origin类组件准备一些json格式的数据

2.数据序列成avro格式

使用数据序列化插件将json格式的数据序列化成avro格式并通过byte数组输出,下面配置一下数据输出的字段cont2和类型Byte array。

配置一下数据格式为avro,并需要配置一下avro的schema(不知道avro格式的可以学习一下)

3.将序列的数据反序列

使用数据反序列化插件将avro格式的数据反序列化成json格式,下面配置一下要反序列化的数据字段cont2和数据输出的字段cont2(将反序列化的结果还存到cont2中)。

同样将序列化中用到的avro schema填入。

Streamsets实战之路正在更新中,尽情期待!!!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

九层之台起于累土

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值