I am using convert AvroToJson processor to convert avro to json and then split json with expression $.* to break json array to individual record.
It is failing in case there is single element in json and not an array.
Can someone help with regular expression to support both array and single element.
2
Answers
You may want to try using ConvertRecord processor with an AvroReader and JsonWriter, then use SplitRecord with a record count of 1.
It may also be possible to avoid splitting to individual records. Typically that is done in order to manipulate each record, but with the record processors you can typically manipulate them in place, thus improving performance significantly by not splitting.
Well, you have nothing to split in a single element. If you want to avoid failure on single elements, you can use
ConvertRecord
instead ofConvertAvroToJson
.The difference is, that
ConvertRecord
will provide you the attributerecord.count
which tells you how many records are included in this FlowFile(and also a more generic flow).This will allow you to put a middle processor(
RouteOnAttribute
) betweenConvertRecord
andSplitJSON
.So you can config it as such:
Then, transfer connect
matched
relationship to the processor that is placed after yourSplitJSON
, and connectunmatched
to yourSplitJSON
processor.That way, if there’s a single record(which shouldn’t need any splitting), it will avoid the processor
SplitJSON
.