API Integraiton - transfer
In addition to applications external to ADP, various APIs can be called in Python from functions executed by Avgidea Function.
To execute APIs from a function, Avgidea Function must be configured and quotas must be set.
Working with Storage
Objects can be retrieved and stored between the function execution environment (runtime) and Storage. Objects on the runtime are temporarily stored and deleted when the function execution ends.
# Obtaining a file from Storage
adpy.get(datasource='as1', object='file1.csv')
Function
get
Parameters
datasource : Datasource name of Avgidea Storage
object : Name of the object on the datasource to be stored in the runtime
# Saving a file to Storage
adpy.put(datasource='as1', object='file1.csv')
Funciton
put
Parameters
datasource : Datasource name of Avgidea Storage
object : Name of the object in the runtime to be stored in the datasource
override : If the object already exists, overwrite (default); if False, add a timestamp to the object name
Copying Object between Storage
You can perform object copying between Avgidea Storage Datasources.
# Copy object from as1 to as2 (single object)
adpy.log("start transfer from as1 to as2")
resp = adpy.transfer(frm='as1', to='as2', object='sample.csv')
adpy.log("end transfer : " + resp['status'])
Function
transfer
Parameters
frm : Origin datasource name
to : Destination datasource name
object : Object name in the origin datasource
Return value
resp : Status of transfer process and message
# Copy object from as1 to as2 (multiple objects)
adpy.log("start transfer from as1 to as2")
resp = adpy.transfer(frm='as1', to='as2', filter='sample')
adpy.log("end transfer : " + resp['status'])
Function
transfer
Parameters
frm : Origin datasource name
to : Destination datasource name
filter : Copy objects whose object name contains the specified string. If not specified, all objects in the data source are targeted.
Return value
resp : Status of transfer process and message
Loading CSV files from storage to database
From within a function, you can send a request to load a CSV file on Storage into the database.
# Uploading CSV file from as1 to orcl
adpy.log("start transfer from as1 to orcl")
resp = adpy.transfer(frm='as1', to='orcl', object='employees.csv', table='employees', worker=4)
adpy.log("end transfer : " + resp['status'])
Function
transfer
Parameters
frm : Datasource name of storage
to : Datasource name of database
object : CSV file in storage to be loaded into database
table : Name of table to load
worker : Number of parallels in data loading
Return value
resp : Status of transfer process and message
Extracting CSV files from a database
From within a function, you can send a request to extract a table in the database to Storage.
# Extract a CSV file from orcl to as1
adpy.log("start transfer from as1 to orcl")
resp = adpy.transfer(frm='orcl', to='as1', table='sample')
adpy.log("end transfer : " + resp['status'])
Function
transfer
Parameters
frm : Datasource name of storage
to : Datasource name of database
table : Name of table to be extracted
Return value
resp : Status of transfer process and message