casa
5.7.0-16
|
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 MArray< Bool > | getArrayBool (const TableExprId &id) |
virtual MArray< Int64 > | getArrayInt (const TableExprId &id) |
virtual MArray< Double > | getArrayDouble (const TableExprId &id) |
virtual MArray< DComplex > | getArrayDComplex (const TableExprId &id) |
virtual MArray< String > | getArrayString (const TableExprId &id) |
virtual MArray< MVTime > | getArrayDate (const TableExprId &id) |
const String & | getUnit () const |
Get the unit. More... | |
const Record & | getAttributes () const |
Get the attributes. 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 std::vector< TENShPtr > &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 | |
std::vector< TENShPtr > & | 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 | setAttributes (const Record &attributes) |
Set the attributes 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... | |
Private Attributes | |
std::vector< TENShPtr > | itsOperands |
TableExprNodeRep::NodeDataType | itsDataType |
Int | itsNDim |
IPosition | itsShape |
String | itsUnit |
Record | itsAttributes |
Bool | itsIsConstant |
Bool | itsIsAggregate |
Bool | itsApplySelection |
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.
|
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).
|
inline |
|
inline |
Do not apply the selection.
Definition at line 360 of file UDFBase.h.
References casacore::False, and itsApplySelection.
void casacore::UDFBase::getAggrNodes | ( | vector< TableExprNodeRep * > & | aggr | ) |
Get the nodes in the function operands representing an aggregate function.
|
virtual |
Reimplemented in casacore::UDFMSCal.
|
virtual |
Reimplemented in casacore::DirectionUDF.
|
virtual |
Reimplemented in casacore::UDFMSCal.
|
virtual |
|
virtual |
Reimplemented in casacore::UDFMSCal.
|
virtual |
Reimplemented in casacore::UDFMSCal.
|
inline |
|
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.
|
virtual |
|
virtual |
Reimplemented in casacore::UDFMSCal.
|
virtual |
|
virtual |
Reimplemented in casacore::UDFMSCal.
|
virtual |
|
virtual |
Reimplemented in casacore::UDFMSCal, casacore::HelpMsCalUDF, and casacore::HelpMeasUDF.
|
inline |
void casacore::UDFBase::init | ( | const std::vector< TENShPtr > & | arg, |
const Table & | table, | ||
const TaQLStyle & | |||
) |
Initialize the function object.
|
inline |
Tell if the UDF is an aggregate function.
Definition at line 356 of file UDFBase.h.
References itsIsAggregate.
Referenced by casacore::TableExprUDFNode::isAggregate().
|
inline |
Tell if the UDF gives a constant result.
Definition at line 352 of file UDFBase.h.
References itsIsConstant.
|
inline |
|
inlineprotected |
|
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.
|
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.
|
protected |
Define if the UDF is an aggregate function (usually used in GROUPBY).
|
protected |
Set the attributes of the result.
If this function is not called by the setup function of the derived class, the result has no attributes.
|
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.
|
protected |
Set the data type.
This function must be called by the setup function of the derived class.
|
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.
|
protected |
Set the shape of the results if it is fixed and known.
|
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.
|
privatepure virtual |
Set up the function object.
Implemented in casacore::UDFMSCal, casacore::DirectionUDF, casacore::FrequencyUDF, casacore::EarthMagneticUDF, casacore::PositionUDF, casacore::RadialVelocityUDF, casacore::DopplerUDF, casacore::EpochUDF, casacore::HelpMsCalUDF, and casacore::HelpMeasUDF.
|
inline |
|
private |
Definition at line 382 of file UDFBase.h.
Referenced by disableApplySelection().
|
private |
Definition at line 379 of file UDFBase.h.
Referenced by getAttributes().
|
private |
Definition at line 375 of file UDFBase.h.
Referenced by dataType().
|
private |
Definition at line 381 of file UDFBase.h.
Referenced by isAggregate().
|
private |
Definition at line 380 of file UDFBase.h.
Referenced by isConstant().
|
private |
|
private |
Definition at line 374 of file UDFBase.h.
Referenced by operands().
|
private |
|
private |
|
staticprivate |