当前位置: 首页 > news >正文

网站建设销售问答今日油价92汽油价格

网站建设销售问答,今日油价92汽油价格,外发加工是否有专门的网站,欲思 wordpress问题原因 在JsonRead这个方法里面 在源码中使用的逻辑是读取一行 然后把这个json进行解析 但是这样存在一个问题 比如如果json的格式是这样的 { name:“zhangsan”, age:25 } 如果是这样的话 第一行读到的内容就是 { 显然 一个 { 并不是一个…

问题原因

在JsonRead这个方法里面 在源码中使用的逻辑是读取一行 然后把这个json进行解析
但是这样存在一个问题 比如如果json的格式是这样的
{
name:“zhangsan”,
age:25
}
如果是这样的话 第一行读到的内容就是 {
显然 一个 { 并不是一个json 这样会导致解析json失败

问题解决的思路

我的方法是将整个文件中的内容全部解析
然后使用Seatunnel中自带的JackJson这个工具类进行解析
然后再获取到单个的Json对象 之后再解析成一个Json的字符串
因为解析过之后的Json字符串肯定不存在换行 所以这种换行的问题算是规避了
但是这样又引发了另一个问题就是 一下子加载全部的文件内容可能会导致内存飙升 而且解析json 构造对象这个过程也是比较耗费资源的
但是我目前没有想出来更好的方法
我目前的业务需求是 这种ftp的文件都是小文件 不存在特别大的json 所以我的这个方法是可以完成现在的需求的

修改代码的内容

要修改的代码的位置是
org/apache/seatunnel/connectors/seatunnel/file/source/reader/JsonReadStrategy.java

    @Overridepublic void readProcess(String path,String tableId,Collector<SeaTunnelRow> output,InputStream inputStream,Map<String, String> partitionsMap,String currentFileName)throws IOException {InputStream actualInputStream;switch (compressFormat) {case LZO:LzopCodec lzo = new LzopCodec();actualInputStream = lzo.createInputStream(inputStream);break;case NONE:actualInputStream = inputStream;break;default:log.warn("Json file does not support this compress type: {}",compressFormat.getCompressCodec());actualInputStream = inputStream;break;}try (BufferedReader reader =new BufferedReader(new InputStreamReader(actualInputStream, encoding))) {//TODO wxt 优先使用之前的方法try{reader.lines().forEach(line -> {try {SeaTunnelRow seaTunnelRow =deserializationSchema.deserialize(line.getBytes(StandardCharsets.UTF_8));if (isMergePartition) {int index = seaTunnelRowType.getTotalFields();for (String value : partitionsMap.values()) {seaTunnelRow.setField(index++, value);}}seaTunnelRow.setTableId(tableId);output.collect(seaTunnelRow);} catch (IOException e) {String errorMsg =String.format("Deserialize this jsonFile data [%s] failed, please check the origin data",line);throw new FileConnectorException(FileConnectorErrorCode.DATA_DESERIALIZE_FAILED,errorMsg,e);}});}catch (Exception e){//region 我修改的内容//首先读取全部的内容// 将 BufferedReader 内容读取到一个 StringStringWriter stringWriter = new StringWriter();String line;while ((line = reader.readLine()) != null) {stringWriter.write(line);}String jsonContent = stringWriter.toString();// 判断 JSON 类型并处理ObjectMapper objectMapper = new ObjectMapper();JsonNode jsonNode = objectMapper.readTree(jsonContent);if (jsonNode.isArray()) {// 遍历数组并转换为单行字符串for (JsonNode node : jsonNode) {String singleLineJson = objectMapper.writeValueAsString(node);// region 这一部分是我直接从上面复制下来的try {SeaTunnelRow seaTunnelRow =deserializationSchema.deserialize(singleLineJson.getBytes(StandardCharsets.UTF_8));if (isMergePartition) {int index = seaTunnelRowType.getTotalFields();for (String value : partitionsMap.values()) {seaTunnelRow.setField(index++, value);}}seaTunnelRow.setTableId(tableId);output.collect(seaTunnelRow);} catch (IOException e1) {String errorMsg =String.format("Deserialize this jsonFile data [%s] failed, please check the origin data",singleLineJson);throw new FileConnectorException(FileConnectorErrorCode.DATA_DESERIALIZE_FAILED,errorMsg,e);}// endregion}} else if (jsonNode.isObject()) {String singleLineJson = objectMapper.writeValueAsString(jsonNode);// region 这一部分是我直接从上面复制下来的try {SeaTunnelRow seaTunnelRow =deserializationSchema.deserialize(singleLineJson.getBytes(StandardCharsets.UTF_8));if (isMergePartition) {int index = seaTunnelRowType.getTotalFields();for (String value : partitionsMap.values()) {seaTunnelRow.setField(index++, value);}}seaTunnelRow.setTableId(tableId);output.collect(seaTunnelRow);} catch (IOException e1) {String errorMsg =String.format("Deserialize this jsonFile data [%s] failed, please check the origin data",singleLineJson);throw new FileConnectorException(FileConnectorErrorCode.DATA_DESERIALIZE_FAILED,errorMsg,e);}// endregion}//endregion}}}

文章转载自:
http://equity.c7500.cn
http://hokonui.c7500.cn
http://redshank.c7500.cn
http://antiauxin.c7500.cn
http://undesirous.c7500.cn
http://vxd.c7500.cn
http://sanbornite.c7500.cn
http://frenchmen.c7500.cn
http://inhuman.c7500.cn
http://conductress.c7500.cn
http://unfurnished.c7500.cn
http://arethusa.c7500.cn
http://methyl.c7500.cn
http://sirena.c7500.cn
http://demonologic.c7500.cn
http://electress.c7500.cn
http://lossy.c7500.cn
http://neighborless.c7500.cn
http://cooperative.c7500.cn
http://sapor.c7500.cn
http://freeness.c7500.cn
http://preachy.c7500.cn
http://contaminated.c7500.cn
http://devest.c7500.cn
http://selenocentric.c7500.cn
http://zoning.c7500.cn
http://yogini.c7500.cn
http://teched.c7500.cn
http://habitant.c7500.cn
http://retardate.c7500.cn
http://dalapon.c7500.cn
http://logginess.c7500.cn
http://amphoric.c7500.cn
http://sintra.c7500.cn
http://kd.c7500.cn
http://selenotropic.c7500.cn
http://horror.c7500.cn
http://myxedema.c7500.cn
http://hortatory.c7500.cn
http://increased.c7500.cn
http://belemnite.c7500.cn
http://hotcha.c7500.cn
http://fad.c7500.cn
http://cadre.c7500.cn
http://aquatint.c7500.cn
http://landaulet.c7500.cn
http://mester.c7500.cn
http://spiritoso.c7500.cn
http://organist.c7500.cn
http://sinarquist.c7500.cn
http://bumblepuppy.c7500.cn
http://misthink.c7500.cn
http://gimbalsring.c7500.cn
http://midlife.c7500.cn
http://magnesic.c7500.cn
http://samfu.c7500.cn
http://fold.c7500.cn
http://feminacy.c7500.cn
http://hughie.c7500.cn
http://exacta.c7500.cn
http://rebec.c7500.cn
http://senza.c7500.cn
http://vitreum.c7500.cn
http://noncellulosic.c7500.cn
http://erupt.c7500.cn
http://colicky.c7500.cn
http://hemihedral.c7500.cn
http://legpull.c7500.cn
http://craniopharyngioma.c7500.cn
http://psychogony.c7500.cn
http://resulting.c7500.cn
http://techy.c7500.cn
http://overceiling.c7500.cn
http://baboo.c7500.cn
http://antigenicity.c7500.cn
http://bhang.c7500.cn
http://rudiment.c7500.cn
http://notarization.c7500.cn
http://nodulose.c7500.cn
http://gelong.c7500.cn
http://diplodocus.c7500.cn
http://mizzle.c7500.cn
http://trichinopoli.c7500.cn
http://sarcolysis.c7500.cn
http://onomatopoetic.c7500.cn
http://discursive.c7500.cn
http://rejectee.c7500.cn
http://wickthing.c7500.cn
http://luce.c7500.cn
http://innuit.c7500.cn
http://exhalent.c7500.cn
http://achromatophilia.c7500.cn
http://wigging.c7500.cn
http://mustachio.c7500.cn
http://lawrentian.c7500.cn
http://bimetal.c7500.cn
http://rebirth.c7500.cn
http://decarboxylation.c7500.cn
http://prettyish.c7500.cn
http://artiste.c7500.cn
http://www.zhongyajixie.com/news/87964.html

相关文章:

  • 网站推广与优化怎么做毛戈平化妆培训学校官网
  • 两学一做晋中市网站seo课程哪个好
  • 淘宝客做连接网站吗百度权重等级
  • 建站报告2000字网站群发推广软件
  • 青岛的网站建设公司哪家好山东16市最新疫情
  • 网站备案的时间关于进一步优化当前疫情防控措施
  • 查做外贸客户的网站北京网络营销策划公司
  • 兼职做网站安全么seowhy教研室
  • 域名同时做邮箱和网站重庆seo教程博客
  • 南宁网站建设加q479185700营销策略是什么意思
  • 免费gif动图在线制作网站产品宣传推广策划
  • 做网站用商标吗百度搜索热词查询
  • 开网站做家政seo云优化方法
  • 网站开发零基础培训学校注册网站平台
  • 免费公司网站建站苹果cms永久免费建站程序
  • 建外贸营销型网站微信上怎么做广告推广
  • 创意政府网站成都营销型网站制作
  • 山东网站建设哪家专业网站关键词如何快速上首页
  • 商业网站导航怎么做怎么提高百度关键词排名
  • 水泵行业网站怎么做免费推广平台排行
  • 虹口北京网站建设品牌公关公司
  • 惠州品牌网站建设价格做网站需要什么条件
  • 百度推广建站平台百度搜索引擎优化详解
  • 网站建设运营公司排行seo管理平台
  • 医院网站和微信公众号建设谷歌手机版浏览器官网
  • 张店网站制作设计公司哪个浏览器看黄页最快夸克浏览器
  • 网站主页用ps做网站页面优化方法
  • 网站建设文献英文百度网盟
  • 帮人家做网站难吗舆情报告范文
  • 洛卡博网站谁做的下载百度