casacore
|
Abstract base class for a user-defined TaQL function. More...
#include <UDFBase.h>
Public Types | |
typedef UDFBase * | MakeUDFObject(const String &functionName) |
The signature of a global or static member function creating an object of the UDF. More... | |
Public Member Functions | |
UDFBase () | |
Only default constructor is needed. More... | |
virtual | ~UDFBase () |
Destructor. More... | |
virtual Bool | getBool (const TableExprId &id) |
Evaluate the function and return the result. More... | |
virtual Int64 | getInt (const TableExprId &id) |
virtual Double | getDouble (const TableExprId &id) |
virtual DComplex | getDComplex (const TableExprId &id) |
virtual String | getString (const TableExprId &id) |
virtual TaqlRegex | getRegex (const TableExprId &id) |
virtual MVTime | getDate (const TableExprId &id) |
virtual Array< Bool > | getArrayBool (const TableExprId &id) |
virtual Array< Int64 > | getArrayInt (const TableExprId &id) |
virtual Array< Double > | getArrayDouble (const TableExprId &id) |
virtual Array< DComplex > | getArrayDComplex (const TableExprId &id) |
virtual Array< String > | getArrayString (const TableExprId &id) |
virtual Array< MVTime > | getArrayDate (const TableExprId &id) |
const String & | getUnit () const |
Get the unit. More... | |
void | getAggrNodes (vector< TableExprNodeRep * > &aggr) |
Get the nodes in the function operands representing an aggregate function. More... | |
void | getColumnNodes (vector< TableExprNodeRep * > &cols) |
Get the nodes in the function operands representing a table column. More... | |
void | init (const PtrBlock< TableExprNodeRep * > &arg, const Table &table, const TaQLStyle &) |
Initialize the function object. More... | |
TableExprNodeRep::NodeDataType | dataType () const |
Get the data type. More... | |
Int | ndim () const |
Get the dimensionality of the results. More... | |
const IPosition & | shape () const |
Get the result shape if the same for all results. More... | |
Bool | isConstant () const |
Tell if the UDF gives a constant result. More... | |
Bool | isAggregate () const |
Tell if the UDF is an aggregate function. More... | |
void | disableApplySelection () |
Do not apply the selection. More... | |
void | applySelection (const Vector< uInt > &rownrs) |
If needed, let the UDF re-create column objects for a selection of rows. More... | |
Static Public Member Functions | |
static void | registerUDF (const String &name, MakeUDFObject *func) |
Register the name and construction function of a UDF (thread-safe). More... | |
static UDFBase * | createUDF (const String &name, const TaQLStyle &style) |
Create a UDF object (thread-safe). More... | |
Protected Member Functions | |
PtrBlock< TableExprNodeRep * > & | operands () |
Get the operands. More... | |
void | setDataType (TableExprNodeRep::NodeDataType) |
Set the data type. More... | |
void | setNDim (Int ndim) |
Set the dimensionality of the results. More... | |
void | setShape (const IPosition &shape) |
Set the shape of the results if it is fixed and known. More... | |
void | setUnit (const String &unit) |
Set the unit of the result. More... | |
void | setConstant (Bool isConstant) |
Define if the result is constant (e.g. More... | |
void | setAggregate (Bool isAggregate) |
Define if the UDF is an aggregate function (usually used in GROUPBY). More... | |
virtual void | recreateColumnObjects (const Vector< uInt > &rownrs) |
Let a derived class recreate its column objects in case a selection has to be applied. More... | |
Private Member Functions | |
virtual void | setup (const Table &table, const TaQLStyle &)=0 |
Set up the function object. More... | |
Static Private Attributes | |
static map< String, MakeUDFObject * > | theirRegistry |
static Mutex | theirMutex |
Abstract base class for a user-defined TaQL function.
This class makes it possible to add user-defined functions (UDF) to TaQL. A UDF has to be implemented in a class derived from this class and can contain one or more user-defined functions.
A few functions have to be implemented in the class as described below. In this way TaQL can be extended with arbitrary functions, which can be normal functions as well as aggregate functions (often used with GROUPBY).
A UDF is a class derived from this base class. It must contain the following member functions. See also the example below.
makeObject | a static function to create an object of the UDF class. This function needs to be registered. |
setup | this virtual function is called after the object has been created. It should initialize the object using the function arguments that can be obtained using the function operands() . The setup function should perform the following:
|
getXXX | these are virtual get functions for each possible data type. The get functions matching the data types set by the setup function need to be implemented. The get functions have an argument TableExprId defining the table row (or record) for which the function has to be evaluated. If the UDF is an aggregate functions the TableExprId has to be upcasted to an TableExprIdAggr object from which all TableExprId objects in an aggregation group can be retrieved. const vector<TableExprId>& ids = aid.result().ids(id.rownr()); |
A UDF has to be made known to TaQL by adding it to the UDF registry with its name and 'makeObject' function. UDFs will usually reside in a shared library that is loaded dynamically. TaQL will load a UDF in the following way:
The following examples show a normal UDF function.
It returns True if the function argument matches 1. It can be seen that it checks if the argument is an integer scalar.
The following example shows an aggregate UDF function. It calculates the sum of the cubes of the values in a group.
More examples of UDF functions can be found in classes UDFMSCal and DirectionUDF.
casacore::UDFBase::UDFBase | ( | ) |
Only default constructor is needed.
|
virtual |
Destructor.
If needed, let the UDF re-create column objects for a selection of rows.
It calls the function recreateColumnObjects.
Referenced by disableApplySelection().
|
static |
Create a UDF object (thread-safe).
It looks in the map with fixed function names. If unknown, it looks if a wildcarded function name is supported (for PyTaQL).
Referenced by disableApplySelection().
|
inline |
|
inline |
Do not apply the selection.
Definition at line 348 of file UDFBase.h.
References applySelection(), createUDF(), casacore::False, and itsApplySelection.
void casacore::UDFBase::getAggrNodes | ( | vector< TableExprNodeRep * > & | aggr | ) |
Get the nodes in the function operands representing an aggregate function.
Referenced by getUnit().
|
virtual |
Reimplemented in casacore::UDFMSCal.
|
virtual |
Reimplemented in casacore::DirectionUDF.
|
virtual |
Reimplemented in casacore::UDFMSCal.
|
virtual |
Reimplemented in casacore::UDFMSCal, casacore::DirectionUDF, casacore::PositionUDF, and casacore::EpochUDF.
|
virtual |
Reimplemented in casacore::UDFMSCal.
|
virtual |
Reimplemented in casacore::UDFMSCal.
|
virtual |
Evaluate the function and return the result.
Their default implementations throw a "not implemented" exception.
Reimplemented in casacore::UDFMSCal.
void casacore::UDFBase::getColumnNodes | ( | vector< TableExprNodeRep * > & | cols | ) |
Get the nodes in the function operands representing a table column.
Referenced by getUnit().
|
virtual |
|
virtual |
Reimplemented in casacore::UDFMSCal.
|
virtual |
Reimplemented in casacore::UDFMSCal, casacore::DirectionUDF, casacore::PositionUDF, and casacore::EpochUDF.
|
virtual |
Reimplemented in casacore::UDFMSCal.
|
virtual |
|
virtual |
Reimplemented in casacore::UDFMSCal.
|
inline |
Get the unit.
Definition at line 265 of file UDFBase.h.
References getAggrNodes(), getColumnNodes(), itsUnit, and setup().
void casacore::UDFBase::init | ( | const PtrBlock< TableExprNodeRep * > & | arg, |
const Table & | table, | ||
const TaQLStyle & | |||
) |
Initialize the function object.
Referenced by operands().
|
inline |
Tell if the UDF is an aggregate function.
Definition at line 344 of file UDFBase.h.
References itsIsAggregate.
Referenced by casacore::TableExprUDFNode::isAggregate(), and operands().
|
inline |
Tell if the UDF gives a constant result.
Definition at line 340 of file UDFBase.h.
References itsIsConstant.
Referenced by operands().
|
inline |
Get the dimensionality of the results.
(0=scalar, -1=array with variable ndim, >0=array with fixed ndim
Definition at line 332 of file UDFBase.h.
References itsNDim.
Referenced by operands().
|
inlineprotected |
Get the operands.
Definition at line 281 of file UDFBase.h.
References casacore::arg(), init(), isAggregate(), isConstant(), itsOperands, ndim(), recreateColumnObjects(), registerUDF(), setAggregate(), setConstant(), setDataType(), setNDim(), setShape(), setUnit(), and shape().
|
protectedvirtual |
Let a derived class recreate its column objects in case a selection has to be applied.
The default implementation does nothing.
Reimplemented in casacore::UDFMSCal.
Referenced by operands().
|
static |
Register the name and construction function of a UDF (thread-safe).
An exception is thrown if this name already exists with a different construction function.
Referenced by operands().
|
protected |
Define if the UDF is an aggregate function (usually used in GROUPBY).
Referenced by operands().
|
protected |
Define if the result is constant (e.g.
if all arguments are constant). If this function is not called by the setup function of the derived class, the result is not constant.
Referenced by operands().
|
protected |
Set the data type.
This function must be called by the setup function of the derived class.
Referenced by operands().
|
protected |
Set the dimensionality of the results.
0 means that the results are scalars.
-1 means that the results are arrays with unknown dimensionality.
>0 means that the results are arrays with that dimensionality. This function must be called by the setup function of the derived class.
Referenced by operands().
|
protected |
Set the shape of the results if it is fixed and known.
Referenced by operands().
|
protected |
Set the unit of the result.
If this function is not called by the setup function of the derived class, the result has no unit.
Referenced by operands().
|
privatepure virtual |
Set up the function object.
Implemented in casacore::UDFMSCal, casacore::DirectionUDF, casacore::PositionUDF, and casacore::EpochUDF.
Referenced by getUnit().
|
inline |
Get the result shape if the same for all results.
Definition at line 336 of file UDFBase.h.
References itsShape.
Referenced by operands().
|
private |
Definition at line 369 of file UDFBase.h.
Referenced by disableApplySelection().
|
private |
Definition at line 363 of file UDFBase.h.
Referenced by dataType().
|
private |
Definition at line 368 of file UDFBase.h.
Referenced by isAggregate().
|
private |
Definition at line 367 of file UDFBase.h.
Referenced by isConstant().
|
private |
|
private |
Definition at line 362 of file UDFBase.h.
Referenced by operands().
|
private |
|
private |
|
staticprivate |