Page tree
Skip to end of metadata
Go to start of metadata

Embedded python from ECL code.

  • Tested on Python 2.6.6
  • For External Web service call, the IP should be opened from the calling server / node cluster.
  • With builds prior to 4.2.2 on CentOS 5 or 6, have to add the following (or equivalent) to hpcc_setenv file (in /opt/HPCCSystems/bin)
    export LD_PRELOAD=/usr/lib64/’

Prior to release 4.2.0, on some distros the embedded python code will not work correctly on code that contains embedded carriage-returns, which includes code saved using the ECL IDE,. But can be invoked via couple of other options.

Option 1: Using Playground from the Tech Preview / ECL Watch for testing.

Option 2: From Command Line.

Option 1: Use Tech Preview / ECL Watch from ECLWatch Web page.



Sample Code: (Highlighted in Green is the ECL Code, and the rest is all python code):

import python;
set of string splitwords(string s) := embed(Python)
    return s.split()
Str := 'a word a day keeps the grammarian away';


Select the target to <thor> and click on Submit.

Results: [Result 1]

Option 2 from command line:

Save the ECL code in C:\temp\simple_python_embed.ecl

Compile using eclcc:
eclcc -E -o C:\temp\simple_python_embed.eclxml C:\temp\simple_python_embed.ecl

Submit workunit using eclplus:
eclplus query owner=<Owner> server=<Server> cluster=<Cluster> password=<Password> @C:\temp\simple_python_embed.eclxml timeout=36000


Workunit <WU> submitted

[Result 1]



Calling a Webservice SOAP Call from embedded ecl 

Code: (Highlighted in Green is the ECL Code, and the rest is all python code)

import python;
set of string getSOAPResponse():= embed(python)
import sys, httplib
SoapMessage = """<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:act="" xmlns:data="" xmlns:soapenv="">
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="" xmlns:wsu="">
<wsse:UsernameToken wsu:Id=" ">
<wsse:Password Type=""></wsse:Password>
<wsse:Nonce EncodingType=""></wsse:Nonce>
print SoapMessage
#construct and send the header
webservice = httplib.HTTPS("")
webservice.putrequest("POST", "")
webservice.putheader("Host", "")
webservice.putheader("User-Agent", "Python post")
webservice.putheader("Content-type", "text/xml; charset=\"UTF-8\"")
webservice.putheader("Content-length", "%d" % len(SoapMessage))
webservice.putheader("SOAPAction", "")
# get the response
statuscode, statusmessage, header = webservice.getreply()
print "Response: ", statuscode, statusmessage
print "headers: ", header
res = webservice.getfile().read()
L = []
return L

The result in this SOAP Webservice call is an XML and code snippet below uses standard ECL Library to parse the XML.

The XML is parsed using standard ECL Library code.

lineRec := {STRING line};
in1 := DATASET([{'<XML>'}], linerec);
outRec := RECORD
   String variable1fromresult;
   String variable2fromresult;
multipleResponseRec := RECORD
   dataset(outRec) oRec;
activityRec t(lineRec L) := TRANSFORM
   SELF.orec := xmlproject('<children>', 
                                     self.variable1 := xmltext('variable1'),
                                     self.variable2 := xmltext('variable2')));
newOutRec := RECORD
   String variable1  := XMLTEXT('variable1');
   String variable2  := XMLTEXT('variable2');
outds := parse(in1, line, t(LEFT), XML('ROOT/PARENT/CHILD'));
newOutRec tform (RECORDOF(activityRec) l, INTEGER c) := TRANSFORM
   self.variable1 := l.orec[c].variable1;
   self.variable2 := l.orec[c].variable2;
   self := l; 
ds := NORMALIZE(outds,LEFT.orec,tform(LEFT,COUNTER)); 
  • No labels