S DHANUSH
S DHANUSH

Reputation: 3

Regarding Template Language

STRING func(INTEGER a,INTEGER b) := EMBED(Python)
return str(a+b);
ENDEMBED;
string s:=func(1,2);
#EXPAND(s);

Here is a sample code.

Error : #EXPAND expects a constant string.

Is there a way to first get string s after computing function such that #EXPAND assumes it as a constant? Because I need to run some code in string which is computed in a function(Python). Importing the string from another file also failed to work.

Thank you

Upvotes: 0

Views: 45

Answers (1)

Richard Taylor
Richard Taylor

Reputation: 780

Short answer -- not that I know of.

You have hit upon my one serious frustration with ECL's Template Language -- the fact that it almost always requires constant strings. This is due to the history and the fundamental reason why it was created. ECL's Template Language was originally designed to be an XML text parser to generate ECL code that would have been too complex to simply write to handle all possible permutations.

The specific use case that caused its creation was to parse an XML string coming to the HPCC Systems platform from a website where the end-user could choose any/all of (possibly hundreds) of demographics to apply to filtering the end-result record set. The website would construct the XML string to contain only the chosen set of demographics and their appropriate ranges of values to filter for. It would then send that constant XML string to the HPCC Systems platform as the input argument to a MACRO that would use the Template Language to parse the XML and generate the ECL code to produce the result for just that specific set of demographics and value ranges.

In my many years of working with ECL's Template Language I have "run into" this issue many times, and have tried every possible way I could imagine to get around it. The only way I have found to make it work is to figure out a way to make that string a constant (sometimes requiring me to run the job as two separate workunits -- the first to generate a constant XML string, and the second to do the actual work with that string).

You may, of course, submit a JIRA ticket requesting changes to the Template Language. Or, since we are Open Source, you could take a look at the Template Language source code and see if you can remove the need for constants (this would help the entire community).

Good Luck!

Upvotes: 2

Related Questions