How do I get the whole row object within an element of a calculation logic?

Question

Is there a way to get the whole row object within an element of a calculation logic? I have a calculation logic which is supposed to enrich each row of a Datamart based on existing data. Currently, I use the "UserEntry" option to fetch the existing data from the row. I need to read 48 values from the row and I don't want to create additional 48 "UserEntry" elements in my calculation logic.

Basically, I need to get every single row, read 48 fields (4 fields for each month), do some calculations and update 60 other fields (5 fields for each month).

Answer

Use:

def source api.getDatamartRowSet("source") def rowInFieldValueMapForm = source.getCurrentRow()

But don't mix this usage with the traditional user entry one: as soon as you use one user entry (that maps to a source field), only those mapped fields are included in the source rowset. While if you don't have any matching user entries, all fields are in the source rowset (which is what you want here).

To clarify:

  • A calculation normally always has a populated source rowset (the whole DS or DM, or optionally filtered if there is a filter configured in the DL).

  • The target rowset normally starts out empty.

  • If you don't access the rowsets directly, the tasks iterates over all rows in the source set, and adds a row to the target rowset after each successful formula evaluation (user entry mapping for source fields, formula element name mapping for target fields).

  • If you use the DatamartRowsSet API, you can get the current row as explained above, and add/update a row to the target as you know already. It's important to know those are separate objects.

You can obviously pass in a source row, augmented with you calculation results, to the target row set, but that does not effect the row in the source set. So for your use case you could either:

  1. Get source.currentRow, add the calculated field values, and do target.addRow(..).

  2. Get source.currentRow, and construct a new field value map containing the keys and calculated field values only, then add that to target.

The second approach is a bit cleaner.

 

In the Calculation task, a source rowset is always separate from a target rowset. If you don't specify a source in the DL, the source rowset gets populated from the target DS/DM, and the target rowset is empty. If you specify a source in the DL, the source rowset is populated from that source, and the target will also be empty. The target rowset gets populated by the task as it moves on. Another way to look at it is that if you don't set a source in the DL, the implicit source is the same as the target.

A final note: row level formula elements and direct DMRowSet manipulation don't always go together well. In this use case it is recommended:

  1. Using source.getCurrentRow (to avoid having to write all those user entries).

  2. But still use row level elements that map to target field names to add the data to the target rowset.

If you use target.addRow instead, you should not use row level elements (those could override your 'manually' added values).

(Answers by Serge Cooreman)





Found an issue in documentation? Write to us.