Parser Classes

This section describes information that is specific to the C++ API. See User-Defined Parser for general information about implementing the UDParser and ParserFactory classes.

UDParser API

The API provides the following methods for extension by subclasses:

virtual void setup(ServerInterface &srvInterface, SizedColumnTypes &returnType);
				
virtual StreamState process(ServerInterface &srvInterface, DataBuffer &input, InputState input_state)=0;
				
virtual void cancel(ServerInterface &srvInterface);

virtual void destroy(ServerInterface &srvInterface, SizedColumnTypes &returnType);

virtual RejectedRecord getRejectedRecord();
		

Rejecting Records

The process() method might need to reject input. To reject data, you must do two things:

  • Create a getRejectedRecord() method on your UDParser subclass that returns an object of type Vertica::RejectedRecord. This record contains the data that you want to reject, a string describing the reason for rejection, the size of the data, and the terminator string. See RejectedRecord in VerticaUDl.h or the SDK documentation for details.
  • Reject a row by returning REJECT from process(). Vertica then calls getRejectedRecord() to process the rejected record before the next call to process().

You can fulfill these requirements by including code in your parser class such as:

     Vertica::RejectedRecord myRejRec;
     Vertica::RejectedRecord getRejectedRecord() {
        return myRejRec;
     }

In your process() method, add code such as:

if (some rejection condition) {
	RejectedRecord rr("Bad Record!", "foo data", 8, "\n");
	myRejRec = rr;
	return Vertica::REJECT;
	}

ContinuousUDParser API

The ContinuousUDParser class extends UDParser and adds the following methods for extension by subclasses:

virtual void initialize(ServerInterface &srvInterface);
 
virtual void run();
 
virtual void deinitialize(ServerInterface &srvInterface);

UDChunker API

The UDChunker API provides the following methods for extension by subclasses:

virtual void setup(ServerInterface &srvInterface, 
			SizedColumnTypes &returnType);

virtual StreamState alignPortion(ServerInterface &srvInterface, 
			DataBuffer &input, InputState state);
				 
virtual StreamState process(ServerInterface &srvInterface, 
			DataBuffer &input, InputState input_state)=0;			

virtual void cancel(ServerInterface &srvInterface);
 
virtual void destroy(ServerInterface &srvInterface, 
			SizedColumnTypes &returnType);

ParserFactory API

The API provides the following methods for extension by subclasses:

virtual void plan(ServerInterface &srvInterface, PerColumnParamReader &perColumnParamReader, PlanContext &planCtxt);

virtual UDParser * prepare(ServerInterface &srvInterface, PerColumnParamReader &perColumnParamReader, 
			PlanContext &planCtxt, const SizedColumnTypes &returnType)=0;

virtual void getParameterType(ServerInterface &srvInterface, SizedColumnTypes &parameterTypes);

virtual void getParserReturnType(ServerInterface &srvInterface, PerColumnParamReader &perColumnParamReader, 
			PlanContext &planCtxt, const SizedColumnTypes &argTypes, 
			SizedColumnTypes &returnType);

virtual bool isParserApportionable();
				
// C++ API only:
virtual bool isChunkerApportionable(ServerInterface &srvInterface);
				
virtual UDChunker * prepareChunker(ServerInterface &srvInterface, PerColumnParamReader &perColumnParamReader, 
			PlanContext &planCtxt, const SizedColumnTypes &returnType);

If you are using Apportioned Load to divide a single input into multiple load streams, implement isParserApportionable() and/or isChunkerApportionable() and return true. Returning true from these methods does not guarantee that Vertica will apportion the load. However, returning false from both indicates that it will not try to do so.

If you are using Cooperative Parse, implement prepareChunker() and return an instance of your UDChunker subclass. Cooperative parse is supported only for the C++ API.

Vertica calls the prepareChunker() method only for unfenced functions. This method is not available when you use the function in fenced mode.

If you want your chunker to be available for apportioned load, implement isChunkerApportionable() and return true.

After creating your ParserFactory, you must register it with the RegisterFactory macro.