Skip to content

Instantly share code, notes, and snippets.

@eduard93
Last active May 8, 2020 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eduard93/32d6525cc2ff4ea3ad9ab4a1d052fd85 to your computer and use it in GitHub Desktop.
Save eduard93/32d6525cc2ff4ea3ad9ab4a1d052fd85 to your computer and use it in GitHub Desktop.
Dataframe in ObjectScript manipulation
<?xml version="1.0" encoding="UTF-8"?>
<Export generator="IRIS" version="26" zv="IRIS for Windows (x86-64) 2019.4.0ML (Build 147U)" ts="2020-05-08 17:43:53">
<Class name="test.person">
<Super>%Persistent</Super>
<TimeChanged>65507,60451.875534</TimeChanged>
<TimeCreated>65507,59112.748662</TimeCreated>
<Property name="Name">
<Type>%String</Type>
</Property>
<Property name="City">
<Type>%String</Type>
</Property>
<Property name="Phone">
<Type>%String</Type>
</Property>
<Storage name="Default">
<Type>%Storage.Persistent</Type>
<DataLocation>^test.personD</DataLocation>
<DefaultData>personDefaultData</DefaultData>
<IdLocation>^test.personD</IdLocation>
<IndexLocation>^test.personI</IndexLocation>
<StreamLocation>^test.personS</StreamLocation>
<Data name="personDefaultData">
<Structure>listnode</Structure>
<Subscript/>
<Value name="1">
<Value>%%CLASSNAME</Value>
</Value>
<Value name="2">
<Value>Name</Value>
</Value>
<Value name="3">
<Value>City</Value>
</Value>
<Value name="4">
<Value>Phone</Value>
</Value>
</Data>
</Storage>
</Class>
<Class name="test.process">
<Super>Ens.BusinessProcessBPL,isc.py.ens.ProcessUtils</Super>
<TimeChanged>65507,62708.805203</TimeChanged>
<TimeCreated>65507,60546.376329</TimeCreated>
<DependsOn>isc.py.ens.ProcessUtils</DependsOn>
<Property name="PythonOperation">
<Type>%String</Type>
<InitialExpression>"isc.py.ens.Operation"</InitialExpression>
<Parameter name="MAXLEN" value="128"/>
</Property>
<Parameter name="SETTINGS">
<Default><![CDATA[PythonOperation:Basic:selector?context={Ens.ContextSearch/ProductionItems?targets=1&productionName=@productionId}]]></Default>
</Parameter>
<XData name="BPL">
<Description>
BPL Definition</Description>
<XMLNamespace>http://www.intersystems.com/bpl</XMLNamespace>
<Data><![CDATA[
<process language='objectscript' request='Ens.Request' response='Ens.Response' >
<sequence >
<assign name="Kill Extent" property="status" value="##class(test.person).%KillExtent()"/>
<call name='Import' target='@..%Process.PythonOperation' async='1' >
<annotation><![CDATA[
import pandas as pd
import numpy as np
import random
]]]]><![CDATA[></annotation>
<request type='isc.py.msg.ExecutionRequest' >
<assign property="callrequest.Code" value='process.GetAnnotation("Import")' action="set" />
</request>
<response type='isc.py.msg.ExecutionResponse' />
</call>
<sync name='Wait for Import' calls='Import' type='all'/>
<call name='Generate Data' target='@..%Process.PythonOperation' async='1' >
<annotation><![CDATA[
data = [ ["Joe", "Boston", "7-234-4567"], ["Ron", "Dallas", "7-234-5678"]]
columns = ["Name", "City", "Phone"]
df = pd.DataFrame(np.array(data), columns=columns)
]]]]><![CDATA[></annotation>
<request type='isc.py.msg.ExecutionRequest' >
<assign property="callrequest.Code" value='process.GetAnnotation("Generate Data")' action="set" />
</request>
<response type='isc.py.msg.ExecutionResponse' />
</call>
<sync name='Wait for Generate Data' calls='Generate Data' type='all' />
<call name='Create Custom Query' target='@..%Process.PythonOperation' async='1' >
<annotation>Need to run only once</annotation>
<request type='isc.py.msg.CreateCQRequest' >
<assign property="callrequest.Variable" value='"df"' action="set" />
<assign property="callrequest.Classname" value='"test.df"' action="set" />
</request>
<response type='Ens.Response'/>
</call>
<sync name='Wait for Create Custom Query' calls='Create Custom Query' type='all' />
<call name='Insert' target='@..%Process.PythonOperation' async='1' disabled="true" >
<annotation><![CDATA[
INSERT INTO test.person (Name, City, Phone)
SELECT Name, City, Phone
FROM test.df('df')
]]]]><![CDATA[></annotation>
<request type='isc.py.msg.SQLRequest' >
<assign property="callrequest.Query" value='process.GetAnnotation("Insert")' action="set" />
</request>
<response type='Ens.Response'/>
</call>
<sync name='Wait for Insert' calls='Insert' type='all' />
<call name='Insert List' target='@..%Process.PythonOperation' async='1' >
<annotation><![CDATA[
INSERT INTO test.person (Name, City, Phone)
SELECT $list(Columns, 1), $list(Columns, 2), $list(Columns, 3)
FROM isc_py_query.List('df')
]]]]><![CDATA[></annotation>
<request type='isc.py.msg.SQLRequest' >
<assign property="callrequest.Query" value='process.GetAnnotation("Insert List")' action="set" />
</request>
<response type='Ens.Response'/>
</call>
<sync name='Wait for Insert List' calls='Insert List' type='all' />
<call name='Insert Args' target='@..%Process.PythonOperation' async='1' >
<annotation><![CDATA[
INSERT INTO test.person (Name, City, Phone)
VALUES (?, ?, ?)
]]]]><![CDATA[></annotation>
<request type='isc.py.msg.SQLRequest' >
<assign property="callrequest.Query" value='process.GetAnnotation("Insert Args")' action="set" />
<assign property="callrequest.Args" value='"Ed"' action="append" />
<assign property="callrequest.Args" value='"Moscow"' action="append" />
<assign property="callrequest.Args" value='"123456"' action="append" />
</request>
<response type='Ens.Response'/>
</call>
<sync name='Wait for Insert Args' calls='Insert Args' type='all' />
<call name='Random Phone' target='@..%Process.PythonOperation' async='1' >
<annotation><![CDATA[
df['Phone'] = df['Phone'].apply(lambda v: random.randint(1, 1000))
]]]]><![CDATA[></annotation>
<request type='isc.py.msg.ExecutionRequest' >
<assign property="callrequest.Code" value='process.GetAnnotation("Random Phone")' action="set" />
</request>
<response type='isc.py.msg.ExecutionResponse' />
</call>
<sync name='Wait for Random Phone' calls='Random Phone' type='all' />
<call name='Update' target='@..%Process.PythonOperation' async='1' disabled="true" >
<annotation><![CDATA[
UPDATE test.person p
SET p.City=obj.City, p.Phone=obj.Phone
FROM (SELECT Name, City, Phone FROM test.df('df')) obj
WHERE p.Name=obj.Name
]]]]><![CDATA[></annotation>
<request type='isc.py.msg.SQLRequest' >
<assign property="callrequest.Query" value='process.GetAnnotation("Update")' action="set" />
</request>
<response type='Ens.Response'/>
</call>
<sync name='Wait for Update' calls='Update' type='all' />
</sequence>
</process>
]]></Data>
</XData>
<XData name="Empty">
<Data><![CDATA[
<xml>
<call name='' target='@..%Process.PythonOperation' async='1' >
<annotation><![CDATA[
]]]]><![CDATA[></annotation>
<request type='isc.py.msg.ExecutionRequest' >
<assign property="callrequest.Code" value='process.GetAnnotation("")' action="set" />
</request>
<response type='isc.py.msg.ExecutionResponse' />
</call>
<sync name='Wait for ' calls='' type='all' />
</xml>
]]></Data>
</XData>
<Storage name="Default">
<Type>%Storage.Persistent</Type>
<DefaultData>processDefaultData</DefaultData>
<Data name="processDefaultData">
<Subscript>"process"</Subscript>
<Value name="1">
<Value>ConnectionType</Value>
</Value>
<Value name="2">
<Value>WorkDirectory</Value>
</Value>
<Value name="3">
<Value>PythonOperation</Value>
</Value>
</Data>
</Storage>
</Class>
</Export>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment