skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. Well, you have nothing to split in a single element. If you want to avoid failure on single elements, you can use ConvertRecord instead of ConvertAvroToJson.

    The difference is, that ConvertRecord will provide you the attribute record.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) between ConvertRecord and SplitJSON.

    So you can config it as such:

    Routing Strategy=Route to ‘matched’ if all match

    match(dynamic property)=${record.count:equals(1)}

    Then, transfer connect matched relationship to the processor that is placed after your SplitJSON, and connect unmatched to your SplitJSON processor.
    That way, if there’s a single record(which shouldn’t need any splitting), it will avoid the processor SplitJSON.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search