Debugging and Editing a Parser (Processor)
Open the Processor Editor
From the configuration page, you can open the process editor by clicking on the processor that you want to edit in the left panel.
The histograms will change from to show the histogram for that processor. More importantly, an "Editor" button will appear on the bottom of the panel allowing you to edit the process. Clicking the Editor button will display the process code workspace page.
Process Code Workspace
The workspace is divided into four panel. Going clockwise from the top left these panels are:
- Code Panel. This is the code the processor will run. A processors start with a code entry point of main().
- Entry Panel. The entry panel is a tab panel. Its default state is the "input" state and allows a custom JSON object to be placed here. The "event trail" option shows the last ten (10) JSON objects related to the results of the processor.
- Output Panel. This shows the outgoing object that the is exiting the processor.
- Standard Output. This panel shows the console standard output that a process may write to. This is done by using a printf command. The "logs" tab will show the standard error out.
Input Panel: Run Test
Above the input panel, there is a button called "Run Test".
Run Test will take the JSON object in the input panel and present it as the input to main() in the code panel.
For the above example, the JSON has four root properties: obj, props, size, and source. Consider this code snippet in the Code panel:
function main({obj, size, source}) {
// Replacement for Java (Groovy) parser
Every incoming JSON record is unique. Looking at the event trail will show the data, but a programmer normally uses printf statement to see the shape and status of the object in the code.
The main routine is using an enumerated parameter to match the incoming root properties. Another variation would be:
function main(rawObj) {
printf("Incoming object is %s", rawObj)
return { status: "abort" }
}
In this version, the code will send the object to standard out (console panel) and send the object (in this case rawObj) to the abort queue.
Returning Status
There are three common status that the main function
- pass. Sends the record to the defined sink(s).
- abort. The JSON record drops to the next processor.
- drop. Stop processing the JSON record and discard it.
The returning status directs where the JSON record will go.
Leaving the Editor
Use Cancel button to return the Platform Configuration page. The reason is that the editor is a modal of the configuration page. Using the browser navigation will send you to the page you were previous on before working on the Platform.
Updated 8 months ago