Perl language shapers and sizers

This example uses the following file name: ShaperSizerAe.pm

Code

The code in this example demonstrates both a shaper and sizer, each of which use the same code and perform essentially the same task. The code returns as output the given input. It does not demonstrate retrieving the literal fields, just the shaper/sizer functionality.
package ShaperSizerAe;
use nzae::Ae;
use strict 'vars';
use autodie;
our @ISA = qw(nzae::Ae);
my $self = ShaperSizerAe->new();
$self->run();
sub runSizer()
{
my $self = shift;
$self->runShaper(@_);
}
sub runShaper()
{
my $self = shift;
my $inputType = $self->getInputType(0);
my $columnName = $self->getDataTypeName($inputType);
my $stringHash = $self->getDataStringHash();
my $numericHash = $self->getDataNumericHash();
if ( exists $stringHash->{$inputType} )
{
my $size = $self->getInputSize(0);
return $self->addOutputColumnString($columnName, $inputType, $size);
}
elsif ( exists $numericHash->{$inputType} )
{
my $precision = $self->getInputPrecision(0);
my $scale = $self->getInputScale(0);
$self->addOutputColumnNumeric($columnName, $inputType, $precision,
$scale);
}
else
{
$self->addOutputColumn($columnName, $inputType);
}
}
sub _getFunctionResult()
{
my $self = shift;
return @_;
}
1;

Deployment

Deploy the script:
$NZ_EXPORT_DIR/ae/utilities/bin/compile_ae --language perl --version 3 \
--template deploy ShaperSizerAe.pm

Registration

Register the example as a UDF and a UDTF:
$NZ_EXPORT_DIR/ae/utilities/bin/register_ae --language perl --version 3 \
--template udf --exe ShaperSizerAe.pm --sig "sizerPl(varchar(ANY))" \
--return "varchar(ANY)"
$NZ_EXPORT_DIR/ae/utilities/bin/register_ae --language perl --version 3 \
--template udtf --exe ShaperSizerAe.pm --sig "shaperPl(VARARGS)" \
--return "table(ANY)"