I am facing a challenge with ESQL code. I have an XML message that contains a recurring segment, and I need to extract unique values from a specific element within that segment. Following is the input XML message,
<MSG>
<RecurringSegment>
<Element>val1</Element>
</RecurringSegment>
<RecurringSegment>
<Element>val2</Element>
</RecurringSegment>
<RecurringSegment>
<Element>val1</Element>
</RecurringSegment>
<RecurringSegment>
<Element>val3</Element>
</RecurringSegment>
<!-- ... (more recurring segments) ... -->
</MSG>
I have written the following ESQL code that iterates through the recurring segment, identifies unique values within the specific element (e.g., <Element>), and stores them in an output variable.
DECLARE uniqueVals ROW;
DECLARE i INTEGER 1;
FOR obj AS InputRoot.XMLNSC.MSG.RecurringSegment[] DO
IF (NOT(CONTAINS(uniqueVals, obj.Element))) THEN
SET uniqueVals.val[i] = obj.Element;
SET i = i + 1;
END IF;
END FOR;
But this is not working; need assistance with the ESQL code to achieve this.
The CONTAINS function works only on string data types (BIT,BLOB,CHAR), not on ROW.
Following works good in case you have not too many unique values:
With your input this produces following result:
This style of programming is not efficient for many unique values because
occurences.{val}is not implemented by ESQL like a hash map.