Derivative Processor

The Derivative processor is used to derive one or more new columns through computations on existing fields present in the data source.

The Derivative processor is selected from the menu bar of the Designer Window and then placed on the diagram.

Properties

The editable properties are shown in Figure 4.21, “Derivative Wizard”.

Figure 4.21. Derivative Wizard

Derivative Wizard

There are three tabs in the Derivative properties: Base, Derived and JavaScript.

Working with the Derivative processor

To derive two new columns from the Stores data source using the Derivative processor:

  1. Add a JDBC data source, Stores, to the repository.

  2. Add a Composite DataSource to the repository and open it.

  3. Select Stores.ds, drag it into the Composite diagram and drop it.

  4. Add a Derivative processor.

  5. Connect Stores.ds to the Derivative processor and connect the output to Result. The designer window appears as shown in Figure 4.23, “Sample Derivative Flow”.

    Figure 4.23. Sample Derivative Flow

    Sample Derivative Flow

Deriving a new column using a formula

To calculate the percentage of meat available in the stores:

  1. After connecting the stores data source with the Derivative processor using the Derivative procedure given above, invoke the Derivative Wizard by double clicking the Derivative processor.

  2. The fields available in the data source are listed in the Base tab.

  3. Select the Derived tab. In this window, click Add Column. The Add Column dialog box appears.

  4. Enter the name as meat_percentage in the text box provided.

  5. Select the Data type of the column as long.

  6. Enter the formula

    meat/store*100

    in the value text box. The dialog box is shown in Figure 4.24, “Completed Add Column Dialog”.

    Figure 4.24. Completed Add Column Dialog

    Completed Add Column Dialog
  7. Click OK and the column is added to the Derived tab window.

  8. Click Finish and view the Result.

The output is shown in Figure 4.25, “Derived Result”. A new column meat_percentage has been added to the datasource, displaying the percentage of meat space available in the stores.

Figure 4.25. Derived Result

Derived Result

Deriving new columns using the various Date functions

Date manipulations usually require values such as 5 days ahead, 3 years ahead, 20 days before and 5 months before to be calculated.

  1. Just like the previous illustration, connect Stores.ds to a Derivative processor.

  2. After connecting, open the Derivative processor by double-clicking the processor or right-click it and select Properties.

  3. The fields available in the data source are listed in the Base tab

  4. Select the Derived tab. In this window, click Add.

  5. Enter the name of the column as Ahead_5_days. Select Date as the Data Type. Enter

    offsetDays(first_opened_date,5);

    in the Value text box. This function will calculate 5 days ahead of the day in the given date. Click OK. The "Ahead_5_days" column is added to the Derivative Wizard.

  6. Click Add. The Add Column dialog box pops up. Enter name of the column as Ahead_3_years. Select Date as the Data Type. Enter

    offsetYears(first_opened_date,3);

    in the Value text box. This function will calculate 3 years ahead of the year specified in the given date. Click OK. The "Ahead_3_years" column is added to the Derivative Wizard.

  7. Click Add to add a new column. The Add Column dialog box pops up. Enter name of the column as offset_20days_before. Select Date as the Data Type. Enter

    offsetDays(first_opened_date,-20);

    in the Value text box. This function will calculate 20 days before the day specified in the given date. Click OK. The "offset_20days_before" column is added to the Derivative Wizard.

  8. Click Add to add a new column. Enter name of the column as offset_5months_before. Select Date as the Data Type. Enter

    offsetMonths(first_opened_date,-5);

    in the Value text box. This function will calculate 5 months before the month specified in the given date. Click OK. The "offset_5months_before" column is added to the Derivative Wizard.

  9. After entering the Column the Derivative Wizard appears as shown in Figure 4.26, “Completed Add Column Screen”. Click Finish in the Derivative Wizard.

    Figure 4.26. Completed Add Column Screen

    Completed Add Column Screen
  10. The output is shown in Figure 4.27, “Date Manipulations Result”. It can be seen that the offset dates are derived and displayed in new columns added to the data source.

    Figure 4.27. Date Manipulations Result

    Date Manipulations Result

Deriving a new column using the Java script function

As an example, to calculate the percentage of Frozen area in the stores:

  1. After connecting the Stores data source with the Derivative processor using the Derivative procedure given above, open the Derivative Wizard properties.

  2. The fields available in the data source are listed in the Base tab.

  3. Select the JavaScript tab window and enter the following code:

    function percent()
    { 
    	percentage=frozen/store*100; 
    	return percentage;
    }
  4. Select the Derived tab window. Click Add. The Add Column dialog box appears.

  5. Enter the name of the derived field as frozen_percentage. Select long as the data type. Enter the function name

    percent();

    in the value text box. Click OK.

  6. The column is added in the Derived window of the Derivative Wizard. Click Finish and view the Result.

A new column frozen_percentage has been added to the data source, displaying the percentage of Frozen area in the stores.