Python language example
This example uses the following file name: libenv.py.
Code
The environment and shared library classes provide information about the environment and
libraries associated with an AE. This example takes one argument, an integer. If the integer equals
0, the AE outputs the environment it sees. If the integer equals 1, the AE looks the environment up
as a library.
import nzae
class LibEnvAe(nzae.Ae):
def _run(self):
for row in self:
if row[0] == 0:
for name, value in self.getEnvironment().iteritems():
self.output([name, value])
else:
for name, value in self.yieldSharedLibraries().iteritems():
self.output([name, value])
LibEnvAe.run()
Deployment
Deploy the script:
$NZ_EXPORT_DIR/ae/utilities/bin/compile_ae --language python64 \
--template deploy ./libenv.py --version 3
Registration
Register the
example:
$NZ_EXPORT_DIR/ae/utilities/bin/register_ae --language python64 --version 3 \
--template udtf --exe libenv.py --sig "lib_env(int4)" \
--return "table(name varchar(1000), value varchar(1000))"
Running
Note that the output from this example is specific to the environment. Therefore, your actual
output will resemble, but not match, the following text.
SELECT * FROM TABLE WITH FINAL(lib_env(1));
NAME | VALUE
-------------------------------------------------------------------------
LIBNZAEADAPTERS | /nz/DATA/base/1/library/200245/host/libnzaeadapters.so
LIBNZAEPARENT | /nz/DATA/base/1/library/200244/host/libnzaeparent.so
LIBNZAECHILD | /nz/DATA/base/1/library/200247/host/libnzaechild.so
(3 rows)
SELECT * FROM TABLE WITH FINAL (lib_env(0)) LIMIT 5;
NAME | VALUE
-------------------------------------------------------------------------
AE_PYTHON_ROOT | /nz/export/ae/languages/python/2.7/host64
NPS_MODEL | TT4
NZAE_SHLIB_AUTO_LIBNZAEADAPTERS | 1
NZAE_RUNTIME_TRANSACTION_ID | 8558
NZAE_OPERATION_TIMEOUT | 1800
(5 rows)
Note: This output might vary as the name might be preceded by a database name
with periods separating it from the library name. For example,
xxx..LIBNZAECHILD
.
Also, the numbers displayed in the value path name might be different and of the form:
/nz/DATA/base/<dbOID>/library/<objectOID>/host/<libraryname>.so.