Creating Netezza User Defined Functions in C++

STEPS TO CREATE NETEZZA UDF

For creating UDF in netezza we should have knowledge of C++ programming. The post explains how to create netezza UDF which finds greater value out of two values passed.
STEP 1 :
Write C++ code for the function. The code refers the the below header files.
#include "udxinc.h"
#include "udxhelpers.h"
 And namespace list is mentioned below
using namespace nz::udx::dthelpers;
using namespace nz::udx;
The sample code for the greater of two numbers is mentioned below.
#include "udxinc.h"
#include "udxhelpers.h"
#include <ctype.h>
using namespace nz::udx;

class greaterOfTwo : public Udf
{

  public:
    static Udf* instantiate();

    virtual ReturnValue evaluate()
    {
      int64 first = int64Arg(0);
      int64 second = int64Arg(1);

      int64 returnValue = 0;

      if (first > second) returnValue = first; else returnValue = second;

      NZ_UDX_RETURN_INT64(returnValue);
    }
};

Udf* greaterOfTwo::instantiate()
{
  return new greaterOfTwo();
}


STEP 2:
We use the netezza command line utility (nzudxcompile) to compile the C++ code. The sample code to compile the C++ code is mentioned below.


NZ_DATABASE=MYDB;
nzudxcompile -g --sig "greaterOfTwo(bigint,bigint)" --return "bigint" --class greaterOfTwo /export/home/user/mydata/greatest.cpp
 

No comments:

श्री हनुमान चालीसा (Sri Hanuman Chalisa)

श्री हनुमान चालीसा दोहा श्रीगुरु चरन सरोज रज, निजमन मुकुरु सुधारि। बरनउं रघुबर बिमल जसु, जो दायक फल चारि।। बुद्धिहीन तनु जानिके, सुमिरौं पवन...