Data mapping - cfxdm - dm:eval

Eval

Given an expression evaluates the expression string. If performed on the data frame row, it evaluates bypassing the row as a dictionary. If performed on a single value, it expects an additional argument 'key' to be used in the expression.

@param expr: The expression to evaluate. @param key: An optional 'key' if evaluated on a single value instead of a dictionary.

This function allows users to dynamically evaluate expressions from a string-based input. If a user passes in a string to eval, it evaluates the input string as an expression. RDA eval internally maps to Python language eval.

  • Eval is a built-in- function used in python, eval function parses the expression argument and evaluates it as a python expression. In simple words, the eval function evaluates the “String” like a python expression and returns the result as an integer.

  • Eval function is used in situations or applications that need to evaluate mathematical expressions. Also if the user wants to evaluate the string into code then can use the eval function, because the eval function evaluates the string expression and returns the integer as a result.

Example 1:

Step 1: Create an empty eval_example_1 using AIOps studio as shown in the below screenshot.

This pipeline provides example usage of eval to remove starting and ending characters from a

start using the index mechanism

Step 2: Add the following pipeline code/commands into the above-created pipeline as shown in the below screenshot:

You can copy the below code into your pipeline and execute that in your environment. ##### This pipeline creates a simple as array of elements called vmlist. ##### RDA function eval is used to demo this example. ##### This function array index pattern to strip or remove starting and ##### ending characters and returns the elements using eval @dm:empty --> @dm:addrow vmlist = "['vm-1','vm-2','vm-3']" --> @dm:eval vmlist = "vmlist[1:-1]"

Step 3: Click verify button to make sure syntax and pipeline code is correct (as shown below)

Step 4: Click execute button and execute the pipeline. RDA will execute the pipeline without any errors (as shown below)

Step 5: RDA uses the function eval to use search pattern as mentioned in the pipeline code and strips the characters at index '1' and '-1' (last index from right), return the string. Eval in the current pipeline uses the underlying Python eval function to perform the logic. In this example, vmlist is an array of vm elements and the pipeline uses the 'eval' function to remove '[1:-1]' and returns the output string as shown below.

Example 2:

Step 1: Create an empty eval_example_2 using AIOps studio as shown in the below screenshot.

This pipeline provides example usage of eval to remove starting and ending characters from a string using inbuilt library functions lstrip, rstrip that are available.

Step 2: Add the following pipeline code/commands into the above=created pipeline as shown in the below screenshot:

You can copy the below code into your pipeline and execute that in your environment. ##### This pipeline creates a simple as array of elements called vmlist. ##### RDA function eval is used to demo this example. ##### This pipeline uses lstrip and rstrip library functions ##### and rturns the string. @dm:empty --> @dm:addrow vmlist = "['vm-1','vm-2','vm-3']" --> @dm:eval vmlist = "vmlist.lstrip('[').rstrip(']')"

Step 3: Click verify button to make sure syntax and pipeline code is correct (as shown below)

Step 4: Click execute button and execute the pipeline. RDA will execute the pipeline without any errors (as shown below)

Step 5: RDA uses the function eval to use library functions lstrip and rstrip to remove starting char '[' and ending char ']'. Eval in the current pipeline uses the underlying Python eval function to perform the logic. In this example, vmlist is an array of vm elements and the pipeline uses 'eval' and underlying library functions to strip the characters and returns the output a string as shown below.

Example 3:

Step 1: Create an empty eval_example_3 using AIOps studio as shown in the below screenshot.

This pipeline provides example usage of eval using expression to substitute string based on the logic.

Step 2: Add the following pipeline code/commands into the above-created pipeline as shown in the below screenshot:

You can copy the below code into your pipeline and execute that in your environment. ##### This pipeline adds bunch of rows with ipaddress, hostname and ids ##### Some of the elements (ipaddress or hostname), are added empty ##### to demo the eval use case ##### RDA function eval is used to demo this example. ##### In this pipeline, eval uses expression to evaluate and substitute ##### its value based on whether string is empty or non-empty ##### If it is non-empty, value is used or if empty, default string is ##### substituted as shown in the output @dm:empty --> @dm:addrow ipaddress = '10.10.1.1' & hostname = 'host-1-1' & id = 'a1' --> @dm:addrow ipaddress = '10.10.1.2' & id = 'a2' --> @dm:addrow ipaddress = '10.10.1.1' & id = 'a3' --> @dm:addrow hostname = 'host-1-1' & id = 'a4' --> @dm:addrow d = 'a4' --> @dm:eval hostname = "'' + str(hostname) if hostname else 'Empty Hostname' " --> @dm:eval ipaddress = "'' + str(ipaddress) if ipaddress else 'Empty IPAddress' " --> @dm:map from = 'hostname,ipaddress' & to = 'IP_or_Hostname' & func = 'any_non_null'

Step 3: Click verify button to make sure syntax and pipeline code is correct (as shown below)

Step 4: Click execute button and execute the pipeline. RDA will execute the pipeline without any errors (as shown below)

Step 5: RDA uses the function eval along with the expression(s) that are part of the pipeline to evaluate expression based on an empty or non-empty string within the expression and substitute default value in case of an empty string (or else, provide value). In this example, ipaddress and hostname are evaluated within the expression. Once evaluated, empty and non-empty strings are substituted as per pipeline logic and return the output as a string as shown below.

Example 4:

Step 1: Create an empty eval_math_example_1 using AIOps studio as shown in the below screenshot.

Step 2: Add the following pipeline code/commands into the above-created pipeline as shown in the below screenshot:

You can copy the below code into your pipeline and execute that in your environment. ##### This pipeline adds bunch of rows with integer columns column1, column2 and ids ##### to demo the eval use case with math functions ##### In this pipeline, eval uses integer conversion followed by math function ##### as expression to calculate values and substitute its value based on underlying ##### library function (pow) @dm:empty --> @dm:addrow column1 = '0' & column2 = '1' & id = 'a1' --> @dm:addrow column1 = '1' & column2 = '2' & id = 'a2' --> @dm:addrow column1 = '2' & column2 = '4' & id = 'a3' --> @dm:addrow column1 = '3' & column2 = '8' & id = 'a4' --> @dm:addrow column1 = '4' & column2 = '16' & id = 'a5' --> @dm:eval column3 = " pow(2,(int(column2))) "

Step 3: Click verify button to make sure syntax and pipeline code is correct (as shown below)

Step 4: Click execute button and execute the pipeline. RDA will execute the pipeline without any errors (as shown below)

Step 5: RDA uses the function eval along with 'integer' conversion and math function 'pow' to perform the mathematical operation, substitute the resulting values, and returns column3 with new values as shown in the below screenshot.

In the above example, RDA uses 'dm:eval' in conjunction with the underlying mathematical expression (along with integer conversion and math function 'pow')

Example 5:

Step 1: Create an empty eval_math_example_2 using AIOps studio as shown in the below screenshot.

Step 2: Add the following pipeline code/commands into the above-created pipeline as shown in the below screenshot:

You can copy the below code into your pipeline and execute that in your environment. ##### This pipeline adds bunch of rows with ##### id, cluster info, date, budget, actual amount allocated to a dummy org. ##### to demo the eval use case with math function ##### In this pipeline, RDA uses eval function along with integer conversion ##### followed by math addition as expression to calculate values. In addition, ##### pipeline adds a new column 'variance' to extract values. ##### RDA dm:filter is used to selectively pick only required columns and print the #### output. @dm:empty --> @dm:addrow id = '0' & cluster = 'clust-a' & date ='2014-01-01' & budget = '11000' & actual = '10000' --> @dm:addrow id = '1' & cluster = 'clust-a' & date ='2014-02-01' & budget = '1200' & actual = '1000' --> @dm:addrow id = '2' & cluster = 'clust-b' & date ='2014-03-01' & budget = '200' & actual = '100' --> @dm:addrow id = '3' & cluster = 'clust-b' & date ='2014-04-01' & budget = '200' & actual = '300' --> @dm:addrow id = '4' & cluster = 'clust-c' & date ='2014-05-01' & budget = '400' & actual = '450' --> @dm:addrow id = '5' & cluster = 'clust-c' & date ='2014-06-01' & budget = '700' & actual = '1000' --> @dm:addrow id = '6' & cluster = 'clust-c' & date ='2014-07-01' & budget = '1200' & actual = '1000' --> @dm:addrow id = '7' & cluster = 'clust-c' & date ='2014-08-01' & budget = '200' & actual = '100' --> @dm:eval variance = " str( int(budget) + int(actual) )" --> *dm:filter * get id, date, cluster, budget, actual, variance

Step 3: Click verify button to make sure syntax and pipeline code is correct (as shown below)

Step 4: Click execute button and execute the pipeline. RDA will execute the pipeline without any errors (as shown below)

Step 5: RDA uses the function 'dm:eval' along with 'integer' conversion and addition in calculating variance values. This pipeline also uses dm:filter to print selective columns after variance calculation. Output is as shown below screenshot.

Example 6

Step 1: Create an empty eval_date_example_1 using AIOps studio as shown in the below screenshot.

This pipeline provides example usage of eval using an expression for the 'date' string.

Step 2: Add the following pipeline code/commands into the above-created pipeline as shown in the below screenshot:

You can copy the below code into your pipeline and execute that in your environment. ##### This pipeline adds bunch of rows with integer values to a column name 'Daily' ##### Pipeline uses RDA 'to_type' function to convert string values to integer, ##### uses dm:eval function and math functions to calculate integer to value ##### in milliseconds, finally use 'change-time-format' to convert milliseconsds ##### to date string. ##### In this pipeline, RDA uses eval, to_type, change-time-format functions ##### along with integer and milliseconds conversion @dm:empty --> @dm:addrow Daily = '1' --> @dm:addrow Daily = '2' --> @dm:addrow Daily = '3' --> @dm:addrow Daily = '4' --> @dm:addrow Daily = '5' --> @dm:addrow Daily = '6' --> @dm:to_type columns = "Daily" & type = int --> @dm:eval Daily = 'int(time_now_as_ms()) - (24*60*60*1000 * Daily )' --> @dm:change-time-format columns = 'Daily' & from_format = 'ms' & to_format = '%Y-%m-%d'

Add the above pipeline code and save the pipeline as shown below.

Step 3: Click verify button to make sure syntax and pipeline code is correct (as shown below)

Step 4: Click execute button and execute the pipeline. RDA will execute the pipeline without any errors (as shown below)

Step 5: RDA uses the function eval along with other RDA functions 'time_now_as_ms', 'change-time-format' to display 'date' in proper user readable format as shown below.

Similar to the above example, users can try other expressions using other columns.

Example 7

Step 1: Create an empty eval_wwpn_example_1 using AIOps studio as shown in the below screenshot.

This pipeline provides example usage of eval to properly format WWPN that is stored as a string. This example is especially useful for network/storage element manipulation that uses WWPN.

Step 2: Add the following pipeline code/commands into the above-created pipeline as shown in the below screenshot:

You can copy the below code into your pipeline and execute that in your environment. ##### This pipeline creates a WWWPN string WWPN "c050760aa8ac0070" ##### RDA function eval is used to demo this example ##### Below code snippet converts above WWPN to standard format : c0:50:76:0a:a8:ac:00:70 @dm:empty --> @dm:addrow WWPN = "c050760aa8ac0070" --> @dm:eval WWPN = "WWPN[0:2] + ':' + WWPN[2:4] + ':' + WWPN[4:6] + ':' + WWPN[6:8] + ':' + WWPN[8:10] + ':' + WWPN[10:12] + ':' + WWPN[12:14] + ':' + WWPN[14:16]"

Add the above pipeline code and save the pipeline as shown below.

Step 3: Click verify button to make sure syntax and pipeline code is correct (as shown below)

Step 4: Click execute button and execute the pipeline. RDA will execute the pipeline without any errors (as shown below)

Step 5: RDA uses the function eval along with other RDA functions to convert WWPN that is fed as a string (WWPN stored as a standard string format) to consumable WWPN format as shown in the below screen capture.

Example 8

Step 1: Create an empty eval_wwn_to_wwpn_wwnn_example_1 using AIOps studio as shown in the below screenshot.

This pipeline provides example usage of eval for WWN that is stored as a string and converted into WWPN / WWNN. This example is especially useful for network/storage element manipulation that uses WWPN/WWNN.

Step 2: Add the following pipeline code/commands into the above-created pipeline as shown in the below screenshot:

You can copy the below code into your pipeline and execute that in your environment.

##### This pipeline creates a WWN Example: (When WWNN and ##### WWPN reported as single ##### value/String) - WWN: 50:06:01:60:C8:E0:06:A8:50:06:01:64:48:E0:06:A8 ##### RDA function eval is used to demo this example ##### Below code snippet converts above ##### WWN: 50:06:01:60:C8:E0:06:A8:50:06:01:64:48:E0:06:A8 ##### Below bots splits the WWN to WWNN and WWPN as ##### WWNN: 50:06:01:60:C8:E0:06:A8 ##### WWPN: 50:06:01:64:48:E0:06:A8

@dm:empty --> @dm:addrow WWN = "50:06:01:60:C8:E0:06:A8:50:06:01:64:48:E0:06:A8" --> @dm:map attr = 'WWN' & func = 'replace' & oldvalue = ':' & newvalue = '' --> @dm:map from = 'WWN' & to = 'WWNN' --> @dm:map from = 'WWN' & to = 'WWPN' --> @dm:eval WWNN = "WWNN[0:2] + ':' + WWNN[2:4] + ':' + WWNN[4:6] + ':' + WWNN[6:8] + ':' + WWNN[8:10] + ':' + WWNN[10:12] + ':' + WWNN[12:14] + ':' + WWNN[14:16]" --> @dm:eval WWPN = "WWPN[16:18] +':'+ WWPN[18:20] + ':' + WWPN[20:22] + ':' + WWPN[22:24] + ':' + WWPN[24:26] + ':' + WWPN[26:28] + ':' + WWPN[28:30] + ':' + WWPN[30:32]"

Step 3: Click verify button to make sure syntax and pipeline code is correct (as shown below)

Step 4: Click execute button and execute the pipeline. RDA will execute the pipeline without any errors (as shown below)

Step 5: RDA uses the function eval along with other RDA functions to convert WWN that is fed as a string (WWN stored as a standard string format) to consumable WWNN and WWPN format as shown in the below screen capture.

Example 9

Step 1: Create an empty eval_mac_example_1 using AIOps studio as shown in the below screenshot.

This pipeline provides example usage of eval function to convert a MAC address which is in non-standard format to standard format by filling in appropriate 0 char buffer at respective places. MAC is treated as string input in the current example and with a dot (.) as a delimiter

Step 2: Add the following pipeline code/commands into the above-created pipeline as shown in the below screenshot:

You can copy the below code into your pipeline and execute that in your environment. ##### This pipeline creates a MAC Example in a non-standard format ##### MAC: 7eb60ae8c202 ##### RDA uses eval and other function to convert non-standard format ##### to standard MAC representation @dm:empty --> @dm:addrow MAC = "7eb60ae8c202" --> @dm:eval MAC = "MAC[0:2]+':'+MAC[2:4] + ':'+MAC[4:6] + ':'+MAC[6:8] + ':'+MAC[8:10] + ':'+MAC[10:12]"

Step 3: Click verify button to make sure syntax and pipeline code is correct (as shown below)

Step 4: Click execute button and execute the pipeline. RDA will execute the pipeline without any errors (as shown below)

Step 5: RDA converts raw MAC address to appropriate MAC using eval function using RDA pipeline as shown in the below screen capture.

Example 10

Step 1: Create an empty eval_mac_example_2 using AIOps studio as shown in the below screenshot.

This pipeline provides example usage of eval function to convert a MAC address which is in a non-standard format and also missing some of the digits that are needed for MAC address representation. An example MAC is as shown below (in standard string format):

MAC: 7e.b6.a.e8.c2.2

The below example pipeline captures a mechanism to convert incorrect MAC address correct MAC address format. This example pipeline is useful for any network/storage pipelines where accurate MAC address representation is required

Step 2: Add the following pipeline code/commands into the above-created pipeline as shown in the below screenshot:

You can copy the below code into your pipeline and execute that in your environment. ##### This pipeline creates a MAC Example in a non-standard format ##### and missing chars in MAC: 7e.b6.a.e8.c2.2 ##### RDA uses eval and other function to convert non-standard format ##### to standard MAC representation (First, it converts single digit ##### to 2 digits by adding 0 (zero) as prefix and 2nd bot ##### replaces '.' (dot) with ':' (colon) ) @dm:empty --> @dm:addrow MAC = "7e.b6.a.e8.c2.2" --> @dm:eval MAC = '".".join([s.zfill(2) for s in MAC.split(".")])' --> @dm:map attr = 'MAC' & func = 'replace' & oldvalue = '.' & newvalue = ':'

Step 3: Click verify button to make sure syntax and pipeline code is correct (as shown below)

Step 4: Click execute button and execute the pipeline. RDA will execute the pipeline without any errors (as shown below)

Step 5: RDA converts raw MAC address to appropriate MAC using eval function using RDA pipeline as shown in the below output screen capture.

Last updated