I am trying to compile a simple UDF for checking if the string is completely alphabetic.
This is my code
#include "Vertica.h"When I try compiling it using this statement
#include <algorithm> using namespace Vertica; using namespace std; /* * ScalarFunction implementation for a UDSF that adds * two numbers together. */ class isalpha : public ScalarFunction { public: virtual void processBlock(ServerInterface &srvInterface, BlockReader &arg_reader, BlockWriter &res_writer) { do { std::string inStr = arg_reader.getStringRef(0).str(); size_t pos; while( (pos=inStr.find('.')) != string::npos || (pos=inStr.find(',')) != string::npos ) inStr.erase(pos, 1); int sizeOfString = inStr.length(); int iteration = 0; bool isAlpha = true; while(iteration < sizeOfString) { if(!isalpha(inStr[iteration])) { isAlpha = false; break; } iteration++; } res_writer.setBool(isAlpha); // Finish writing the row, and advance to the next output row res_writer.next(); // Continue looping until there are no more input rows } while (arg_reader.next()); } }; class isalphaFactory : public ScalarFunctionFactory { // return an instance of Add2Ints to perform the actual addition. virtual ScalarFunction *createScalarFunction(ServerInterface &interface) { // Calls the vt_createFuncObj to create the new Add2Ints class instance. return vt_createFuncObj(interface.allocator, isalpha); } virtual void getPrototype(ServerInterface &interface, ColumnTypes &argTypes, ColumnTypes &returnType) { // Takes two ints as inputs, so add ints to the argTypes object argTypes.addVarchar(); returnType.addBool(); } }; // Register the factory with HP Vertica RegisterFactory(isalphaFactory);
g++ -D HAVE_LONG_INT_64 -I /opt/vertica/sdk/include -Wall -shared -Wno-unused-value -fPIC -o home/dbadmin/navin/isalpha.so isalpha.cpp /opt/vertica/sdk/include/Vertica.cpp
isalpha.cpp: In member function ‘virtual Vertica::ScalarFunction* isalphaFactory::createScalarFunction(Vertica::ServerInterface&)’:
isalpha.cpp:72: error: ISO C++ forbids applying ‘sizeof’ to an expression of function type
isalpha.cpp:72: error: expected type-specifier before ‘isalpha’
isalpha.cpp:72: error: expected ')' before ‘isalpha’
isalpha.cpp:72: error: cannot convert ‘int*’ to ‘Vertica::ScalarFunction*’ in return
I tried googling these errors, but no effective solution to this.
Can anybody point out what mistakes I am doing and explain me the mistakes and solution.
Thanks in Advance