Lua functions for column map procedures

Column map procedures support most standard Lua functions. Column map procedures also support functions that are specific to Optim™.

A column map procedure can contain either a complex expression or a set of standard functions.

Complex expression

A complex expression is an unstructured block of statements. When a column map procedure contains a complex expression, the complex expression is called for every row processed. A complex expression is functionally the same as a cm_transform() function, but a complex expression cannot contain a formal function statement.

The following example complex expression replaces nil values in a column with 1 and leaves all other values unchanged.
srcvalue = optim.source.getcolumnvalue()
if srcvalue = nil then 
  optim.target.setcolumnvalue('1') 
else 
  optim.target.setcolumnvalue(srcvalue) 
end 

Standard function names for user-defined functions

Use the following function names in your Lua column map procedures. Each of these functions is called automatically at the point indicated. You can also create functions with other function names and call these functions from the standard functions.
Name Description Required
cm_load() This function is called before any tables are processed. No
cm_unload() This function is called after all tables are processed. No
cm_starttable() This function is called at the start of processing for each table. No
cm_endtable() This function is called at the end of processing for each table. No
cm_transform() This function is called for every row processed. Yes

Global functions

The following functions are available in all column map procedure execution contexts.
Name Description
optim.parms.num() Get the number of parameters that are passed to the column map procedure.
optim.parms.get(n) Get the value of the parameter at index n.
optim.print() Print messages to process report.

Data store functions

Use the following functions to get information about the source and target data stores.
Name Description
optim.source.getdbalias() Get the DB alias of the source data store.
optim.source.getcreatorid() Get the creator ID of the source data store.
optim.target.getdbalias() Get the DB alias of the target data store.
optim.target.getcreatorid() Get the creator ID of the target data store.

Table functions

Use the following functions to get information about the source and target tables. Table functions can be used only within a complex expression or within the cm_starttable(), cm_endtable(), and cm_transform() functions.
Name Description
optim.source.gettablename() Get the name of the source table.
optim.target.gettablename() Get the name of the target table.

Column functions

Use the following functions to get information about the source and target columns, transform column data, and write the result to the target column.
Name Description
optim.source.getcolumnvalue()
Get a value from the column whose name is entered as a parameter. If no column is named, the function gets a value from the source column. Use this function for nonnumeric columns and for numeric columns that have data types other than the following data types:
  • DECIMAL
  • DOUBLE
  • FLOAT
  • DECIMAL FLOAT (Informix®)
  • NUMBER (Oracle)

A runtime error is generated if you use the optim.source.getcolumnvalue() function to get values from columns with binary data types.

optim.source.getcolumnasdouble()
Get a value in double-precision format from the column whose name is entered as a parameter. If no column is named, the function gets a value in double-precision format from the source column. Use this function to get data from columns that have the following data types:
  • DECIMAL
  • DOUBLE
  • FLOAT
  • DECIMAL FLOAT (Informix)
  • NUMBER (Oracle)
optim.source.getcolumnlength() Get the length of the column whose name is entered as a parameter. If no column is named, the function gets the length of the source column.
optim.source.getcolumnname() Get the name of the source column.
optim.source.getcolumntype() Get the data type of the column whose name is entered as a parameter. If no column is named, the function gets the column type of the source column.
optim.target.setcolumnvalue()

Set the value of a target column.

A runtime error is generated if you use the optim.target.setcolumnvalue() function to set values in columns with binary data types.

The optim.target.setcolumnvalue() function can be used only within a complex expression or within the cm_transform function.

optim.target.getcolumnlength() Get the length of the column whose name is entered as a parameter. If no column is named, the function gets the length of the target column.
optim.target.getcolumnname() Get the name of the target column.
optim.target.getcolumntype() Get the data type of the column whose name is entered as a parameter. If no column is named, the function gets the data type from the target column.
optim.target.iscolumnnullable() Determine whether the column whose name is entered as a parameter is nullable. If no column is named, the function determines whether the target value is nullable. The function returns true if the column is nullable and returns false if the column is not nullable.
optim.mask()

Call an Optim Data Privacy Providers (ODPP) provider.

Each call contains the value to be masked, the provider to use to mask the value, and the parameters that determine how the provider masks the value. Use the information in the Optim data privacy provider library to determine which parameters are to be used in the call.

The following example shows a valid call to mask the email address username@example.com by using the email provider.
optim.mask('username@example.com', pro=eml, mtd=rep, 
wheninv=pre, flddef1=(name=emlvarchar, dt=varchar_sz))

The optim.mask() function can be used only within a complex expression or within the cm_transform function.

optim.rejectrow()

Skip row and go to the next row.

The optim.rejectrow() function can be used only within a complex expression or within the cm_transform function.

Unsupported functions

The following categories of functions are not supported in column map procedures.
  • Input and output functions in the Lua io library
  • Functions for loading and building modules in the Lua package library:
    • module
    • require
    • package.cpath
    • package.loaded
    • package.loaders
    • package.loadlib
    • package.path
    • package.preload
    • package.seeall
  • string.dump()


Feedback