ApplyDriver Version 3

Code in this section is saved in a file called ApplyDriverV3.java.

Code

The main code for determining the AE logic has been moved from ApplyDriverV2 to DataConnection. Therefore, ApplyDriverV3 is used to retrieve a local AE data connection API and call DataConnection.useApi.

// ApplyDriverV3.java
// driver for Module 4
package org.netezza.education;

import org.netezza.ae.*;

public class ApplyDriverV3 {
    public static final void main(String [] args) {
        NzaeFactory factory = NzaeFactory.Source.getFactory();

        if (factory.isLocal()) {
            DataConnection.useApi(factory.getLocalApi());
        } else {
            throw new RuntimeException(
                "Expecting Local AE only");
        }
    }
}

Compilation

$NZ_EXPORT_DIR/ae/utilities/bin/compile_ae --language java --template compile
--version 3 --db dev \
     "ApplyDriverV3.java DataConnection.java ApplyOperation.java \
     ApplyResult.java ApplyUtil.java CloneRows.java"

Registration

$NZ_EXPORT_DIR/ae/utilities/bin/register_ae --language java --template udf
--version 3 --db dev \
     --sig "applyOperationV3Sf(varargs)" --return double \
     --define java_class=org.netezza.education.ApplyDriverV3 --level 1 \
     --environment "'APPLY_FUNCTION'='OPERATION'" \
     --environment "'APPLY_INFO'='true'" \
     --environment "'NZAE_LOG_DIR'='/nz/export/ae/log'"

$NZ_EXPORT_DIR/ae/utilities/bin/register_ae --language java --template udtf
--version 3 --db dev \
     --sig "applyOperationV3Tf(varargs)" --return "table(result double)" \
     --define java_class=org.netezza.education.ApplyDriverV3 --level 1 \
     --environment "'APPLY_FUNCTION'='OPERATION'" \
     --environment "'APPLY_INFO'='true'" \
    --environment "'NZAE_LOG_DIR'='/nz/export/ae/log'"

$NZ_EXPORT_DIR/ae/utilities/bin/register_ae --language java --template udtf
--version 3 --db dev \
     --sig "applyResultV3(varchar(16), double)" \
     --return "table(result double)" \
     --define java_class=org.netezza.education.ApplyDriverV3 --level 1 \
     --noparallel --environment "'APPLY_FUNCTION'='RESULT'" \
     --environment "'APPLY_INFO'='true'" \
     --environment "'NZAE_LOG_DIR'='/nz/export/ae/log'"

$NZ_EXPORT_DIR/ae/utilities/bin/register_ae --language java --template udtf
--version 3 --db dev \
     --sig "cloneRowsV3(varargs)" --return "table(any)" \
     --define java_class=org.netezza.education.ApplyDriverV3 --dynamic 2 \
     --level 1 --environment "'APPLY_FUNCTION'='CLONE'" \
     --environment "'APPLY_INFO'='true'" \
     --environment "'NZAE_LOG_DIR'='/nz/export/ae/log'"

Running Table Function cloneRowsV3

This is a direct test of the clone functionality.

SELECT * FROM TABLE WITH FINAL(cloneRowsV3(1, 2, 3, 4, 'CLONE_COUNT=3,
 CLONE_COLUMN_NAMES="col1,col2,col3,col4"'));
 COL1 | COL2 | COL3 | COL4
------+------+------+------
    1 |    2 |    3 |    4
    1 |    2 |    3 |    4
    1 |    2 |    3 |    4
(3 rows)

Running All Functions

The output of the cloneRowsV3 SQL function is streamed into the applyOperationV3Tf SQL function, which in turn is streamed into the applyResultV3 SQL function.

SELECT re.result FROM edutestdata, TABLE WITH FINAL(cloneRowsV3(f1, f2, f3,
 f4, 'CLONE_COUNT=3, CLONE_COLUMN_NAMES="col1,col2,col3,col4"')),
 TABLE WITH FINAL(applyOperationV3Tf(> '+', col1, col2, col3, col4)) op,
 TABLE WITH FINAL(applyResultV3('sum', op.result)) re WHERE color = 'red';
 RESULT
--------
   1239