Perl language scalar function (remote mode)
Code
The code to run in remote mode is the same as the code for local mode. See Perl Language Scalar Function.
Deployment
Use the standard deployment, as in local mode:
$NZ_EXPORT_DIR/ae/utilities/bin/compile_ae --language perl --version 3 \
--template deploy ApplyOp.pm
Registration
To register the Perl file for remote mode, run:
$NZ_EXPORT_DIR/ae/utilities/bin/register_ae --language perl --version 3 \
--template udf --exe ApplyOp.pm \
--sig "remote_applyoppm(varchar(1), int4, int4)" --return int4 \
--remote --rname applyOpRemotePm
$NZ_EXPORT_DIR/ae/utilities/bin/register_ae --language perl --version 3 \
--template udtf --exe ApplyOp.pm --sig "launch_remote_applyoppm(int8)" \
--return "TABLE(aeresult varchar(255))" --remote --launch \
--rname applyOpRemotePm
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 on the system database:
SELECT * FROM TABLE WITH FINAL(launch_remote_applyoppm(0));
AERESULT
------------------------------------------------------------------------
tran: 296722 session: 16262 data slc: 0 hardware: 0 machine: vnairsim process:
19842 thread: 19842
(1 row)
Running ps -aef | grep ApplyOp shows that the executable is running on the host. Now run the AE:
SELECT remote_applyoppm('*', 3, 32);
REMOTE_APPLYOPPM
------------------
96
(1 row)
The running AE can be stopped as follows:
SELECT aeresult FROM TABLE WITH FINAL(inza..nzaejobcontrol('stop', 0,
'applyOpRemotePm',false, NULL, NULL));
AERESULT
-------------------------------------------------------------------------
vnairsim 24631 (applyOpRemotePm dataslc:-1 sess:-1 trans:-1) AE stopped
(1 row)