Skip to main content
Solved

Pivot stage on empty json list


 I have created the simple SDC pipeline with json as input data.
When i pivot the list item from json, it works fine when list has the elements but its eliminates the records when list is empty
Pivot on revision works but requirements does not produce record
Appreciate any help . Thanks in advance.
 {
            "id": 22,
            "active": true,
            "code": "210_34",
            "productcomponents": [],
            "category": {
                "id": 21,
                "code": "SOP",
                "name": "Standard Operating Procedures"
            },
            "revisions": [
                {
                    "id": 27,
                    "active": true,
                    "created": "2020-08-19 15:45:18"
                }
            ],
            "requirements": []
}

Best answer by mikelsr

If I understood correctly, perhaps we could add another stage to filter out the pivoted fields, and then merge the output records of that stage and the pivot stage like in the following image.

Pipeline overview

If both stages filter the `/revisions` field you get the following input records in the destination stage:

Combined output of Field Pivoter and Field Remover

 

Is this closer to what you expected? You can find the exported pipeline attached to this message.

 

Regards

View original
Did this topic help you find an answer to your question?

5 replies

mikelsr
StreamSets Employee
  • StreamSets Employee
  • 5 replies
  • April 26, 2022

Hi,

 

According to the documentation [1] the Pivot Field stage creates one record per item in the list or map you are pivoting.

When you pivot a field, the Field Pivoter creates a new record for each first-level item in the list or map.

The list being pivoted in the case of `/requirements` has no items, so no records are created.

 

Feel free to reply if I did not get the question right or if you are looking for some other functionality, in which case we can look for another pipeline design to achieve it.

 

[1] https://docs.streamsets.com/portal/platform-datacollector/latest/datacollector/UserGuide/Processors/ListPivoter.html#GeneratedRecords


  • Author
  • Fan
  • 4 replies
  • April 26, 2022

Thank you for the quick response

I was expecting record with only with non pivoted fields. What is the alternative solution for this situation when list is empty.


mikelsr
StreamSets Employee
  • StreamSets Employee
  • 5 replies
  • Answer
  • April 26, 2022

If I understood correctly, perhaps we could add another stage to filter out the pivoted fields, and then merge the output records of that stage and the pivot stage like in the following image.

Pipeline overview

If both stages filter the `/revisions` field you get the following input records in the destination stage:

Combined output of Field Pivoter and Field Remover

 

Is this closer to what you expected? You can find the exported pipeline attached to this message.

 

Regards


Drew Kreiger
Rock star
Forum|alt.badge.img
  • Senior Community Builder at StreamSets
  • 95 replies
  • April 29, 2022

@meghraj was @mikelsr suggestion helpful? If so, Please select  “Best answer” :) 


Drew Kreiger
Rock star
Forum|alt.badge.img
  • Senior Community Builder at StreamSets
  • 95 replies
  • May 2, 2022

@meghraj I have made Mikes suggestion the best answer. Thanks of for letting me know! 


Reply