Root Functions - Code Examples

Example of a Root Function that Includes a Fabric Command

Use a Root function to set an environment prior to fetching the data, for example to ensure that source data is not extracted from Production to avoid overloading the source system. The Root function sets the environment on a session level and selects the data from the source environment:

  1. Create a Root function using the generated code, add the WHERE clause and the parameters binding.
String sql = "SELECT * From ACTIVITY WHERE CUSTOMER_ID = ? ";
ludb().fetch(sql, i_customer_id).each(row->{
   yield(row.cells());
});
  1. Add a Fabric command, for example set environment using a predefined Global variable:
fabric().execute("set environment='" + SOURCE_ENV_NAME + "'");

Full example of the entire fnPop_NEW_ACTIVITY Root Function can be found in the Demo project.

Example of a Root Function that Retrieves Data from Several Data Sources

Use a Root function to retrieve source data from several data sources, for example the current LU and an additional DB interface. Add an SQL query per each data source.

  1. Create a Root function using the generated code for the first query that retrieves the data from the LU:
String sql1 = "Select * From ACTIVITY where CUSTOMER_ID = ?";
Db.Rows rows = ludb().fetch(sql1,i_customer_id);
  1. Then, to bring information from other data sources, create an additional SQL query to retrieve the data and populate it into the output Object[] structure:
ludb().fetch(sql1, i_customer_id ).each(row-> {
   ...
   caseRows = db("CRM_DB").fetch(sql2,activityID);    
   for (Db.Row caseRow:caseRows) {
      //retrieve the required data
      ...
      //create an Array to add the output into Object[]
      List<String> caseList = new ArrayList<String>();
      caseList.add(customerID);
      ...
      yield(result);  
   });
}

Full example of the entire fnPop_ACT_CASE_NOTE Root Function can be found in the Demo project.

Example of a Dummy Root Function

Create a dummy Root function when the LU table is populated by an Enrichment function or a population of another LU table:

if (1 == 2) yield(new Object[]{null});

Previous

Root Functions - Code Examples

Example of a Root Function that Includes a Fabric Command

Use a Root function to set an environment prior to fetching the data, for example to ensure that source data is not extracted from Production to avoid overloading the source system. The Root function sets the environment on a session level and selects the data from the source environment:

  1. Create a Root function using the generated code, add the WHERE clause and the parameters binding.
String sql = "SELECT * From ACTIVITY WHERE CUSTOMER_ID = ? ";
ludb().fetch(sql, i_customer_id).each(row->{
   yield(row.cells());
});
  1. Add a Fabric command, for example set environment using a predefined Global variable:
fabric().execute("set environment='" + SOURCE_ENV_NAME + "'");

Full example of the entire fnPop_NEW_ACTIVITY Root Function can be found in the Demo project.

Example of a Root Function that Retrieves Data from Several Data Sources

Use a Root function to retrieve source data from several data sources, for example the current LU and an additional DB interface. Add an SQL query per each data source.

  1. Create a Root function using the generated code for the first query that retrieves the data from the LU:
String sql1 = "Select * From ACTIVITY where CUSTOMER_ID = ?";
Db.Rows rows = ludb().fetch(sql1,i_customer_id);
  1. Then, to bring information from other data sources, create an additional SQL query to retrieve the data and populate it into the output Object[] structure:
ludb().fetch(sql1, i_customer_id ).each(row-> {
   ...
   caseRows = db("CRM_DB").fetch(sql2,activityID);    
   for (Db.Row caseRow:caseRows) {
      //retrieve the required data
      ...
      //create an Array to add the output into Object[]
      List<String> caseList = new ArrayList<String>();
      caseList.add(customerID);
      ...
      yield(result);  
   });
}

Full example of the entire fnPop_ACT_CASE_NOTE Root Function can be found in the Demo project.

Example of a Dummy Root Function

Create a dummy Root function when the LU table is populated by an Enrichment function or a population of another LU table:

if (1 == 2) yield(new Object[]{null});

Previous