Scalar Components
A Scalar component is one that takes primitive input values and return a single primitive value. However, the previous article 'Sequences', shows that the value returned from a connection point is always a sequence of values, i.e. a set of zero or more (0-n) values.Clearly if scalar components only operate on single values but connection points always convey sequences, then we need to be able to convert between them. The problem is resolved by extracting the values from the incoming sequence and feeding them to the underlying scalar function one at a time.
Notation - For these examples, curly brackets are used to describe the contents of a sequence:
{‘A’} is a sequence containing a single value ‘A’
{} is an empty sequence
{‘A’, ’B’} is sequence containing 2 values ‘A’ & ’B’
Liquid Data Mapper - Scalar Components |
FOREACH value1 IN inputSequenceString
RETURN_VALUE ConvertToUpper (value1)
The sequence returned from the ‘Upper 1’ component is:
{ ConvertToUpper (‘a’), ConvertToUpper (‘b’), ConvertToUpper (‘c’) }
Which evaluates to the sequence:
{ ‘A’, ‘B’, ‘C’ }
<!--Created by Liquid Data Mapper Libraries (www.liquid-technologies.com)-->
<Contacts>
<ContactDetails>
<Name>A</Name>
<Name>B</Name>
<Name>C</Name>
</ContactDetails>
</Contacts>
Scalar components with one input behave as you would expect, but scalar components with two or more inputs have a more noticeable effect of this transform.
Liquid Data Mapper - Scalar Components |
FOREACH stringValue in InputSequenceString
FOREACH lengthValue in InputSequenceLength
RETURN_VALUE GetStringLeft (stringValue, lengthValue)
So in this case the ‘String’ contains the sequence {‘ABCDEFGHIJ’, ‘qrstuvwxyz’}, and the ‘Length’ input contains the sequence {1, 4}, the resulting sequence is:
{ GetStringLeft (‘ABCDEFGHIJ’, 1), GetStringLeft(‘ABCDEFGHIJ’, 4), GetStringLeft(‘qrstuvwxyz’, 1), GetStringLeft(‘qrstuvwxyz’, 4)}
Which evaluates to
{‘A’, ‘ABCD’, ‘q’, ‘qrst’}
The result is the Cartesian product of the inputs:
<!--Created by Liquid Data Mapper Libraries (www.liquid-technologies.com)-->
<Contacts>
<ContactDetails>
<Name>A</Name>
<Name>ABCD</Name>
<Name>q</Name>
<Name>qrst</Name>
</ContactDetails>
</Contacts>
Tip: Execute the transform by pressing Shift-F5.Debug the transform by pressing F5 to start the debugger
F11 - Step Into
F9 - Set break point
F5 - Run (stops on break points)
A free trial of the Liquid Data Mapper is available from:
https://www.liquid-technologies.com/trial-download