Write the Test Code - Aster Execution Engine

Teradata Aster® Developer Guide

Product
Aster Execution Engine
Release Number
7.00.02
Published
July 2017
Language
English (United States)
Last Update
2018-04-13
dita:mapPath
xnl1494366523182.ditamap
dita:ditavalPath
Generic_no_ie_no_tempfilter.ditaval
dita:id
ffu1489104705746
lifecycle
previous
Product Category
Software

For example code that shows how to write a test program, read the samples such as testrun-tax_input.c that are provided in the sqlmr-sdk/example/c/udf directory of the SDK. In a nutshell, when writing your test program for the TestRunner framework, you can do the following:

  • Use the SqlmrSimpleTestParams fields functionFile and functionName to store the path and name of the executable (.so file) to be tested.
  • Use the column utilities of SqlmrSimpleTestParams to build a data input table, which is an array of SqlmrTestColumnDefinition objects. This simulates a table.
  • Specify the name of the input file that will fill the simulated table with data, as well as sources for any arguments the function takes. The test data in the input file is assumed to be tab-delimited. For an example input file, see sqlmr-sdk/example/c/udf/tax_input/testrun.in.
  • If your user defined function uses installed files (for example to feed additional data to the function) use the SqlmrSimpleTestParams field installedFileDirectoryOrNull to specify the location of the simulated installed file. This allows TestRunner to simulate the installed files feature of an Aster instance. (See Manage Functions and Files in an Aster Instance.)
  • Specify where the test results will be saved (using the completedContractFileName field for the completed user defined function runtime contract results and the outputFileName field for the function's output).
  • Specify those user defined function-specific test parameters in the structure SqlmrSimpleScalarAggFunctionTestParams, which is described in Test Parameters Structures.
  • Run the test using one of the following test functions:
    SQLMR_API_EXPORT
     SqlmrErrorH sqlmr_runSimpleAggregatorFunctionTest(
        SqlmrCoreEnvironmentH coreOrNull,
        SqlmrSimpleTestParams const* testParams,
        SqlmrSimpleScalarAggrFunctionTestParams const* udafTestParams
        ) SQLMR_ERROR_RESULT;
    
    SQLMR_API_EXPORT
     SqlmrErrorH sqlmr_runDecomposableAggregatorFunctionTest(
        SqlmrCoreEnvironmentH coreOrNull,
        SqlmrSimpleTestParams const* testParams,
        SqlmrSimpleScalarAggrFunctionTestParams const* udafTestParams,
        int decompCount,
        const char* tmpdir
        ) SQLMR_ERROR_RESULT;
    
    SQLMR_API_EXPORT
     SqlmrErrorH sqlmr_runSimpleScalarFunctionTest(
        SqlmrCoreEnvironmentH coreOrNull,
        SqlmrSimpleTestParams const* testParams,
        SqlmrSimpleScalarAggrFunctionTestParams const* udsfTestParams
        ) SQLMR_ERROR_RESULT;

    The following table describes API methods:

    API Methods
    API Method Function to Test Description
    sqlmr_runSimpleAggregatorFunctionTest non-decomposable Run the non-decomposable aggregate function.
    sqlmr_runDecomposableAggregatorFunctionTest composable Run the decomposable aggregate and test the function. The method first computes the final result using the non-decomposable codebase for the test function (for example, invoke the function with rowToFinal execution path). The method then uses the decomposable features of the test function and invokes the function with execution paths rowToPartitial and partitialToFinal—the output from the partialToFinal phase gives the final result. Now, we check if the final results the decomposable and non-decomposable codebase are equivalent.
    sqlmr_runSimpleScalarFunctionTest scalar Run the scalar function in test mode.

It can be convenient to mimic the naming conventions of the examples. To do this, name your test program testrun-function_name.c, as in testrun-tax_input.c.