Python language scalar function (remote mode)

Code

The code to run in remote mode is the same as the code for local mode. See Python Language Scalar Function.

Deployment

Use the standard deployment, as in local mode:

$NZ_EXPORT_DIR/ae/utilities/bin/compile_ae --language python64 \
     --template deploy ./applyop.py --version 3

Registration

To register the Python file for remote mode, run:

$NZ_EXPORT_DIR/ae/utilities/bin/register_ae --language python64 --version 3 \
     --template udf --exe applyop.py \
     --sig "remote_applyop(varchar(1), int4, int4)" --return int4 --remote \
     --rname applyOpRemote

In addition, a launcher is registered:

$NZ_EXPORT_DIR/ae/utilities/bin/register_ae --language python64 --version 3 \
     --template udtf --exe applyop.py --sig "launch_remote_applyop(int8)" \
     --return "TABLE(aeresult varchar(255))" --remote --launch \
     --rname applyOpRemote

With the exception of --rname, --exe and the name portion of --sig, all launchers look like this example. The launcher itself is a UDTF and not a UDF since that is the interface for all launchers. The --rname must match up to the name in the code.

Running

To run the AE in remote mode, the executable is run as a “server.” In this instance it handles only queries run on the host. Usually, AEs are started on the SPUs as well. Internally, after the server AE gets a request from the NPS system, it "forks" before it calls nzaeRun(). Start the executable running on the host using the launch command from nzsql:

SELECT * FROM TABLE WITH FINAL(launch_remote_applyop(0));
AERESULT
-------------------------------------------------------------------------
tran: 7192 DATA slc: 0 hardware: 0 machine: spubox1 process: 8306 thread: 8306
(1 row)</pre>

Running ps -aef | grep applyop shows that the executable is running on the host. Now run the AE:

SELECT remote_applyop('*', 2, 13);
 REMOTE_APPLYOP
----------------
             26