BookmarkSubscribeRSS Feed

Converting an Event Stream Processing DS2 table server mode function to run as a MAS module

Started ‎09-10-2018 by
Modified ‎09-12-2018 by
Views 1,844

In Event Stream Processing(ESP) 5.2, support for the Procedural window input handler that used DS2 code run in table server mode is deprecated.  This means that to migrate from previous releases of Event Stream Processing to release 5.2, the DS2 table server mode code must be changed to run as a MAS module.   The MAS module then needs to be moved to the calculate window. The following code snippet changes the opcode of incoming events. Here’s how to convert it from using DS2 to MAS.

Here is the existing procedural window in ESP 5.1:

 

<window-procedural pubsub="true" output-insert-only="true" index="pi_EMPTY" produces-only-inserts="true" pubsub-index="pi_EMPTY" name="Procedural1">
          <schema>
            <fields>
              <field name="id" type="int64" key="true"/>
<field name="sum" type="double"/>
<field name="average" type="double"/>
            </fields>
          </schema>
          <ds2-tableserver source="input_window">
            <code><![CDATA[ds2_options cdump;
data esp.out;
method run();
     set esp.in;
     if _opcode = 3 then return;
     else do;
       _opcode = 1;
      end;
   end;
enddata;]]></code>
</ds2-tableserver>
</window-procedural>

 

This code looks at the _opcode value.  For _opcode of 3, which is a delete, the event is dropped.  For all other _opcodes, the _opcode is set to 1, which is an insert.  This module does not modify or use any of the fields in the input schema or output schema of the model.  This means there are no field values to pass to the MAS module.  The MAS module will need the input opcode and the output opcode.  The opcode values used by MAS are strings instead of integers.  There is a conversion table for the opcodes in the Event Stream Processing 5.2 User's Guide, which also documents additional information on migrating to a MAS module.

 

Here is the MAS module DS2 code to convert the opcodes:

 

<mas-modules>
<mas-module language="ds2" module="module_1" func-names="Make_Insert">
  <code>                    
      ds2_options sas;
      package module_1/overwrite=yes;
      /* Declare the function.  Must declare the input opcode and the output opcode */
      method Make_Insert(varchar(16) _inOpcode, in_out varchar _outOpcode);                                                                                    
           if _inOpcode = 'delete' then do;
            _outOpcode = 'noop'; /* Suppress event */                                                                         
           end;      
           else do;
               _outOpcode = 'insert';    /* Set the output event to be an Insert */                                                               
           end; /* End Make_Insert method */
      endpackage;
   </code>
</mas-module>
</mas-modules>

 

The function defines a method(Make_Insert).  The method has two parameters, the input opcode(_inOpcode) and the output opcode(_outOpcode).  The in_out definition tells MAS that _outOpcode is an output variable.  The rest of the code is very similar to the previous function with the integer opcode values replaced with strings and the correct opcode variable used.   The special value "noop" is used to tell ESP not to output an event.  With this new MAS module, the procedural window can be changed to:

 

<window-procedural pubsub="true" output-insert-only="true" index="pi_EMPTY" produces-only-inserts="true" pubsub-index="pi_EMPTY" name="Procedural1">
          <schema>
            <fields>
              <field name="id" type="int64" key="true"/>
<field name="sum" type="double"/>
<field name="average" type="double"/>
            </fields>
          </schema>
<mas-map>
<window-map module="module_1" function="Make_Insert" revision="0" source="input_window"/>
</mas-map>
</window-procedural>

 

The window-map tag refers back to the mas-module previously defined.  None of the schema fields are changed.  Now that the procedural window is updated to use the MAS module, the final piece of the conversion to 5.2 is done with the dfesp_xml_migrate tool.  The dfesp_xml_migrate tool will convert the procedural window to a calculate window in the XML model.  The XML model can now be run on ESP 5.2.  

Version history
Last update:
‎09-12-2018 04:55 PM
Updated by:

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Labels
Article Tags