简体   繁体   English

NiFi JoltTransformJson仅输出第一条记录

[英]NiFi JoltTransformJson outputs only first record

I am sending to NiFi JoltTransformJSON a number of records like: 我正在向NiFi JoltTransformJSON发送一些记录,例如:

{"uid":"x1","timestamp_ms":1419717816375}
{"uid":"x2","timestamp_ms":1419717816376}
...

They are coming via ComsumeKafkaRecord, and its RecordWriter is JsonRecordSetWriter configured with "One line per object". 它们通过ComsumeKafkaRecord传入,其RecordWriter是配置为“每个对象一行”的JsonRecordSetWriter。 I veried via Data provenance, that there are,say,5 records coming out of it when I send 5 to Kafka. 我通过数据出处证实,当我向Kafka发送5条记录时,有5条记录。

Jolt spec for Shift transform is Shift变换的震动规格为

{
  "*": "&0",
 "timestamp_ms": "timestamp"
}

So I just want to rename one field. 所以我只想重命名一个字段。 I verified in Advanced section that this spec changes my json as requested. 我在“高级”部分中验证了此规范可按要求更改json。

But when I start all components and send 5 messages, I only get the first from JoltTransformJson - verified with Data Provenance. 但是,当我启动所有组件并发送5条消息时,我仅从JoltTransformJson获得了第一条消息-已通过Data Provenance验证。

{"uid":"x1","timestamp":1419717816375}

What's wrong here? 怎么了

Update: it turned out that I had to use JoltTransformRecord, then it went as I expected, ie 5 message in, 5 out. 更新:原来我必须使用JoltTransformRecord,然后它按我的预期进行,即5条消息输入,5条消息输出。

But I am still puzzled what made JoltTransformJson behave like that? 但是我仍然感到困惑的是,是什么让JoltTransformJson表现得如此?

What made it behave like that is the fact that you referred your data(one record per line) as JSON while your data is not JSON. 造成这种情况的原因是,您将数据(每行一条记录)引用为JSON,而数据不是JSON。 If it was JSON, then it would at least start and end with [] and each line (except for the final one) end with a comma. 如果是JSON,则它至少应以[]开头和结尾,并且每行(最后一行除外)都以逗号结尾。

Since JoltTransformJSON accepts only JSON, it behaved like that. 由于JoltTransformJSON仅接受JSON,因此具有类似的行为。

Regarding your edit, JoltTransformRecord knows how to process the records individually, as different JSON objects, and that's why it worked using it. 关于您的编辑,JoltTransformRecord知道如何将记录作为不同的JSON对象分别处理,这就是使用它的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM