Perl language example
This example uses the following file name: Libenv.pm.
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.
package Libenv;
use nzae::Ae;
use strict;
use autodie;
our @ISA = qw(nzae::Ae);
my $ae = Libenv->new();
$ae->run();
sub _run()
{
my $self = shift;
$self->iter();
}
sub iter()
{
#use while loop over library function getNext()
my $self = shift;
while ($self->getNext())
{
my @row = $self->getInputRow();
my $size = scalar(@row);
my $env;
if ($size > 0)
{
if ( $row[0] == 0 )
{
$env = $self->getEnvironment();
}
else
{
$env = $self->yieldSharedLibraries();
}
unless(defined $env)
{
$self->userError("Error fetching information");
}
my $limit = defined $row[1]? $row[1] : undef;
try
{
for my $key ( keys %$env )
{
$self->output($key, $env->{$key});
if ( defined $limit && $limit)
{
$limit--;
if ($limit == 0)
{
last;
}
}
}
}
catch
{
croak(nzae::Exceptions::AeInternalError->new(longmess("Error writing
output")));
};
}
else
{
$self->userError("Error fetching row");
}
}
}
1;Deployment
Deploy the
script:
$NZ_EXPORT_DIR/ae/utilities/bin/compile_ae --language perl --version 3 \
--template deploy Libenv.pmRegistration
Register the
example:
$NZ_EXPORT_DIR/ae/utilities/bin/register_ae --language perl --version 3 \
--template udtf --exe Libenv.pm --sig "lib_env(int4, int4)" \
--return "table(name varchar(1000), value varchar(1000))"Given a positive integer value,
the second argument acts as a limit to the number of results returned. This is used in place of
keyword LIMIT to exit the AE cleanly when the number of results returned must be limited.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, 3));
NAME | VALUE
-----------------+---------------------------------------------------
LIBNZAEPARENT | /nz/data.1.0/base/317943/library/319587/host/libnzaeparent.so
LIBNZAEADAPTERS |
/nz/data.1.0/base/317943/library/319331/host/libnzaeadapters.so
LIBNZAECHILD | /nz/data.1.0/base/317943/library/319332/host/libnzaechild.so
(3 rows)
SELECT * FROM TABLE WITH FINAL (lib_env(0, 5));
NAME VALUE
------------------------------------+---------------
NZAE_RUNTIME_USER_QUERY | 1
NPS_PLATFORM | xs
NZAE_OUTPUT_COLUMNS | 1,1
NZAE_DEBUG_LEVEL | 0
NZAE_REMOTE_NAME_DATA_SLICE | 0
(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.Additional shared libraries can be added during the registration step, by using the --deps option along with the library name.