CARMA C++
carma::dbms::MonitorDataQueryManager Class Reference

Class to compose and execute a query of the monitor database. More...

#include <carma/dbms/MonitorDataQueryManager.h>

Public Member Functions

std::map< int, carma::dbms::TableexecNarrowQueries ()
 execute "narrow" queries. More...
 
carma::dbms::Table execWideQuery ()
 execute "wide" query. More...
 
std::set
< carma::dbms::MonitorAggregateType
getAggregateDataTypes () const
 get the aggregate data types used by this query More...
 
std::map< int, std::string > getNarrowRSQueries () const
 get the SELECT queries which will produce (generally) multiple narrow (as in narrow table, no joins) result sets More...
 
std::vector< std::string > getSetUpQueries () const
 get the queries which should be run to set up the tables that will be those on which the narrow SELECT queries are run, as well as the first set of queries that will produce the final wide result set More...
 
std::map
< carma::dbms::MonitorAggregateType,
std::vector< std::string > > 
getTablesToQuery () const
 get the tables which this class will need to query to produce the result set More...
 
std::string getWideRSQuery () const
 get the final wide result set query More...
 
std::vector< std::string > getWideSetUpQueries () const
 get the queries which should be run to set up the tables that will be those on which the final wide result set query is run. More...
 
std::string mdqmGetColumnName (DBColumn column) const
 Return the column name string for the given column type. More...
 
 MonitorDataQueryManager (const MPSelectorSet &selectors, const carma::dbms::TimeRangeFilter *const trFilter, const carma::dbms::DBConnection *const dbc)
 constructor More...
 
 MonitorDataQueryManager (const MPSelectorSet &selectors, const carma::dbms::TimeRangeFilter *const trFilter, const std::set< const carma::dbms::MonitorPointFilter * > &mpfilters, const carma::dbms::DBConnection *const dbc)
 Create a monitor data query with a time range filter which is ANDed to a set of MonitorPointFilters (the monitor point filters in the set are all ORed together) and a set of MonitorPointSelectors. More...
 
 ~MonitorDataQueryManager ()
 destructor deletes any "temporary" tables created for wide query More...
 

Static Public Member Functions

static carma::util::frameType getBeginningOfProduction ()
 get the frameCount that marks the beginning of production More...
 

Protected Member Functions

void cacheTagIDToDataType_ ()
 cache the tag id to data type mapping More...
 
void constructFilterClauses_ ()
 
void createJoinSetUpQueries_ (const std::vector< std::vector< const carma::dbms::MonitorPointSelector * > > &mpssVec)
 
void createNarrowRSQueries_ ()
 create the narrow result set queries, ie these are queries which will produce info on a single tagID per result set More...
 
void createQueries_ ()
 create the queries to submit to the database More...
 
void createSetUpQueries_ ()
 create the set up queries, these are the queries which create the temporary tables which are ultimately the targets of the select queries which create the result sets which are accessible via the public API More...
 
void createWideRSQuery_ ()
 create the wide result set query, ie this is the query which will create a single, wide table containing n columns where n is the sum of all the columns specified in the monitor point selectors which were passed to the constructor More...
 
void determineAggregateTableTypes_ ()
 determine which aggregate table types will need to be used in the query More...
 
void determineTablesToQuery_ ()
 handle one component filters when determining which aggregate table types need to be queried More...
 
void doSanityChecks_ ()
 do some sanity checking on values passed to the constructor More...
 
void execSetUpQueries_ () const
 execute the set up queries More...
 
void execWideSetUpQueries_ () const
 execute the CREATE TABLE queries necessary to produce the tables which will be joined in the wide query More...
 
void init_ ()
 

Protected Attributes

std::map
< carma::dbms::MonitorAggregateType,
std::string > 
aggType2FilterClause_
 holds the filter clauses More...
 
std::map
< carma::dbms::MonitorAggregateType,
std::vector< const
carma::dbms::MonitorPointFilter * > > 
aggType2MPFilters_
 
std::map
< carma::dbms::MonitorAggregateType,
std::vector< const
carma::dbms::MonitorPointSelector * > > 
aggType2MPSelectors_
 
std::set< MonitorAggregateTypeaggTypes_
 the aggregate data types relevant to this query More...
 
carma::dbms::MonitorAverageType avgType_
 
const carma::dbms::DBConnectiondbc_
 
bool haveRunSetUpQueries_
 
bool haveRunWideSetUpQueries_
 
const std::set< const
carma::dbms::MonitorPointFilter * > 
mpFilters_
 
std::map< int, std::string > narrowRSQueries_
 queries to execute to produce (generally) several "narrow" (as in tables, no joins are done) result sets More...
 
MPSelectorSet selectors_
 
std::vector< std::string > setUpQueries_
 the queries in the order they should be submitted to the database which create and populate the tables which will actually be queried to produce the requested results set(s) More...
 
std::vector< std::string > tablesToDropUponDestruction_
 
std::map
< carma::dbms::MonitorAggregateType,
carma::dbms::Table
tablesToQuery_
 holds the monitor data tables relevant to this query More...
 
std::map< unsigned, const
carma::dbms::MonitorPointFilter * > 
tagID2MPFilter_
 
carma::dbms::Table tagIDToDataTypeID_
 this variable is only used if the ResultsCache singleton doesn't exist and cannot be created More...
 
std::map
< carma::dbms::MonitorAggregateType,
std::string > 
tmpTableName_
 
const
carma::dbms::TimeRangeFilter
trFilter_
 
std::string wideErrMsg_
 
std::string wideRSQuery_
 query to execute to produce a singe "wide" (generally using several joins) table More...
 
std::vector< std::string > wideSetUpQueries_
 the queries in the order they should be submitted to the database which create and populate temporary tables necessary for the single "wide" query More...
 

Static Protected Attributes

static const std::string TAGID_TO_DATATYPE
 
static int tCount_
 temporary table counter to better assure that created temp tables will have unique names More...
 

Detailed Description

Class to compose and execute a query of the monitor database.

A query is specified using a set of carma::dbms::MonitorPointSelectors, a carma::dbms::TimeRangeFilter, and an optional set of carma::dbms::MonitorPointFilters. If a monitor point is represented (via its tagID) in the set of specified MonitorPointSelectors but is not represented in the set of MonitorPointFilters, the filter that is applied is based on its tagID alone.

Query Types

Narrow Result Set Queries

This class permits two types of queries. The first type, referred to as narrow result set queries, are queries which isolate each monitor point in the set of MonitorPointSelectors. For each monitor point, the following query is performed:
SELECT [selection specification] FROM T where [time range filter specification] AND [monitor point filter specification]
where [selection specification] is determined from the MonitorPointSelector, T is the table or union of the set of tables which contain times falling within the TimeRangeFilter, [time range filter specification] represents the filtering imposed by the TimeRangeFilter, and [monitor point filter specification] is the filtering imposed by the MonitorPointFilter with the same tagID as the MonitorSelector in question, if any. If there is no MonitorPointFilter with the same tagID as the MonitorPointSelector in question, a filter of the form
tagID=[the tagID of the MonitorPointSelector in question] is used.

Thus, a result set is produced for each MonitorPointSelector, using the specified TimeRangeFilter and a filter specific to the monitor point in question. These queries are executed, and the result sets returned to the client using the execNarrowQueries() method.

Wide Result Set Query

The second form of query this class allows is the so-called wide result set query. In this case, all the MonitorPointSelectors and MonitorPointFilters (if any) are combined in a single query which generally requires several table joins. The produced result set has the same number of columns as the sum of all the columns specified by all the MonitorPointSelectors, (hence the name wide result set). Individual MonitorPointFilters are all ANDed together and ANDed with the TimeRangeFilter to produce a single filter. Again, in cases where a MonitorPointSelector does not have a corresponding MonitorPointFilter, a simple filter on tagID is used. This query is executed and the wide result set returned to the client via the execWideQuery() method. Because some truly monstrous result sets can be produced in this way (and because doing so can bring the database server to its knees) there are limitations placed on how many MonitorPointSelectors and MonitorPointFilters can be specified, which ultimately determines the maximum number of allowed columns in the result set and the maximum number of table joins which are permitted to produce it. FIXME: Guidelines still to come.

Other Notes


This class attempts to use the carma::dbms::ResultsCache singleton, and thus the parent application should instantiate the singleton via a call to ResultsCache::getCache() (and should also dispose of the singleton when all objects have finished with it via a call to
ResultsCache::closeCache()
). If run at the telescope site where only recent data are kept, the shouldCheckArchive() method can be run to determine if the time range may include data which is no longer in the site database and therefore should be submitted to the long term archive.

See Also
carma::dbms::MonitorPointSelector
carma::dbms::MonitorPointFilter
carma::dbms::TimeRangeFilter
carma::dbms::ResultsCache

Definition at line 108 of file MonitorDataQueryManager.h.

Constructor & Destructor Documentation

carma::dbms::MonitorDataQueryManager::MonitorDataQueryManager ( const MPSelectorSet selectors,
const carma::dbms::TimeRangeFilter *const  trFilter,
const carma::dbms::DBConnection *const  dbc 
)

constructor

Parameters
timerange filter which also contains information on what average type to search for
otherFiltersother filter to apply, will be AND'ed to trFilter
validdb connection to use
Exceptions
DBConnectionException
IllegalArgumentExceptionif the lesser time in the time range filter is less than the value returned by getBeginningOfProduction() Create a monitor data query with only a time range filter and a set of MonitorPointSelectors.
Parameters
selectorsthe set of monitor point selectors to use
trFiltertime range filter which also contains information on what average type to search for
dbcvalid db connection to use
Exceptions
DBConnectionException
IllegalArgumentExceptionif the lesser time in the time range filter is less than the value returned by getBeginningOfProduction()
carma::dbms::MonitorDataQueryManager::MonitorDataQueryManager ( const MPSelectorSet selectors,
const carma::dbms::TimeRangeFilter *const  trFilter,
const std::set< const carma::dbms::MonitorPointFilter * > &  mpfilters,
const carma::dbms::DBConnection *const  dbc 
)

Create a monitor data query with a time range filter which is ANDed to a set of MonitorPointFilters (the monitor point filters in the set are all ORed together) and a set of MonitorPointSelectors.

The monitor point filters in mpfilters must all have unique tagIDs

Parameters
selectorsthe set of monitor point selectors to use
mpFiltersthe set of monitor point filters to be used
trFiltertime range filter which also contains information on what average type to search for
dbcvalid db connection to use
Exceptions
DBConnectionException
IllegalArgumentExceptionif the lesser time in the time range filter is less than the value returned by getBeginningOfProduction()
carma::dbms::MonitorDataQueryManager::~MonitorDataQueryManager ( )

destructor deletes any "temporary" tables created for wide query

Member Function Documentation

void carma::dbms::MonitorDataQueryManager::cacheTagIDToDataType_ ( )
protected

cache the tag id to data type mapping

void carma::dbms::MonitorDataQueryManager::createNarrowRSQueries_ ( )
protected

create the narrow result set queries, ie these are queries which will produce info on a single tagID per result set

void carma::dbms::MonitorDataQueryManager::createQueries_ ( )
protected

create the queries to submit to the database

void carma::dbms::MonitorDataQueryManager::createSetUpQueries_ ( )
protected

create the set up queries, these are the queries which create the temporary tables which are ultimately the targets of the select queries which create the result sets which are accessible via the public API

void carma::dbms::MonitorDataQueryManager::createWideRSQuery_ ( )
protected

create the wide result set query, ie this is the query which will create a single, wide table containing n columns where n is the sum of all the columns specified in the monitor point selectors which were passed to the constructor

void carma::dbms::MonitorDataQueryManager::determineAggregateTableTypes_ ( )
protected

determine which aggregate table types will need to be used in the query

void carma::dbms::MonitorDataQueryManager::determineTablesToQuery_ ( )
protected

handle one component filters when determining which aggregate table types need to be queried

handle a TagIDFilter when determining which aggregate table types need to be queried handle a TagIDSetFilter when determining which aggregate table types need to be queried determine which monitor data tables contain info relevant for this query this is essentially the set of tables which have data in the specified time range for the specified average type and also contain data of (one of) the aggregate types

void carma::dbms::MonitorDataQueryManager::doSanityChecks_ ( )
protected

do some sanity checking on values passed to the constructor

std::map<int,carma::dbms::Table> carma::dbms::MonitorDataQueryManager::execNarrowQueries ( )

execute "narrow" queries.

These queries in general produce several tables (1 table per tagID); no joins are done between tables representing different tagIDs This method is not const because it modifies the bool switch to indicate that the set up queries for this object have been run

Returns
the result sets, the returned map has tagIDs as keys and Tables (result sets) as values
void carma::dbms::MonitorDataQueryManager::execSetUpQueries_ ( ) const
protected

execute the set up queries

carma::dbms::Table carma::dbms::MonitorDataQueryManager::execWideQuery ( )

execute "wide" query.

This query produces a single table which is the result of joining all the necessary tables which are reflected in the monitor point selectors and filters. This method is not const because it modifies the bool switch to indicate that the wide set up queries for this object have been run

Returns
the single result set which may contain very many columns
void carma::dbms::MonitorDataQueryManager::execWideSetUpQueries_ ( ) const
protected

execute the CREATE TABLE queries necessary to produce the tables which will be joined in the wide query

std::set<carma::dbms::MonitorAggregateType> carma::dbms::MonitorDataQueryManager::getAggregateDataTypes ( ) const

get the aggregate data types used by this query

Returns
the aggregate data types used by the query
static carma::util::frameType carma::dbms::MonitorDataQueryManager::getBeginningOfProduction ( )
static

get the frameCount that marks the beginning of production

Returns
get the frameCount that marks the beginning of production
std::map<int,std::string> carma::dbms::MonitorDataQueryManager::getNarrowRSQueries ( ) const

get the SELECT queries which will produce (generally) multiple narrow (as in narrow table, no joins) result sets

Definition at line 220 of file MonitorDataQueryManager.h.

std::vector<std::string> carma::dbms::MonitorDataQueryManager::getSetUpQueries ( ) const

get the queries which should be run to set up the tables that will be those on which the narrow SELECT queries are run, as well as the first set of queries that will produce the final wide result set

Returns
the set up queries which should be run (in the order they appear in the vector)

Definition at line 202 of file MonitorDataQueryManager.h.

std::map<carma::dbms::MonitorAggregateType, std::vector<std::string> > carma::dbms::MonitorDataQueryManager::getTablesToQuery ( ) const

get the tables which this class will need to query to produce the result set

Returns
the tables which will be queried
std::string carma::dbms::MonitorDataQueryManager::getWideRSQuery ( ) const

get the final wide result set query

Returns
the wide result set query

Definition at line 228 of file MonitorDataQueryManager.h.

std::vector<std::string> carma::dbms::MonitorDataQueryManager::getWideSetUpQueries ( ) const

get the queries which should be run to set up the tables that will be those on which the final wide result set query is run.

In order to produce the wide result set from the original monitor data tables, first the queries from getSetUpQueries() are run, then the queries (if any) from getWideSetUpQueries() are run, and finally, the query from getWideRSQuery() is run.

Definition at line 212 of file MonitorDataQueryManager.h.

std::string carma::dbms::MonitorDataQueryManager::mdqmGetColumnName ( DBColumn  column) const

Return the column name string for the given column type.

If column is COLUMN_VALUE, and avgType_ isn't FRAME_AVG, return COLUMN_INTEGRATEDVALUE instead.

Member Data Documentation

std::map<carma::dbms::MonitorAggregateType, std::string> carma::dbms::MonitorDataQueryManager::aggType2FilterClause_
protected

holds the filter clauses

Definition at line 287 of file MonitorDataQueryManager.h.

std::set<MonitorAggregateType> carma::dbms::MonitorDataQueryManager::aggTypes_
protected

the aggregate data types relevant to this query

Definition at line 293 of file MonitorDataQueryManager.h.

std::map<int,std::string> carma::dbms::MonitorDataQueryManager::narrowRSQueries_
protected

queries to execute to produce (generally) several "narrow" (as in tables, no joins are done) result sets

Definition at line 313 of file MonitorDataQueryManager.h.

std::vector<std::string> carma::dbms::MonitorDataQueryManager::setUpQueries_
protected

the queries in the order they should be submitted to the database which create and populate the tables which will actually be queried to produce the requested results set(s)

Definition at line 306 of file MonitorDataQueryManager.h.

std::map<carma::dbms::MonitorAggregateType, carma::dbms::Table> carma::dbms::MonitorDataQueryManager::tablesToQuery_
protected

holds the monitor data tables relevant to this query

Definition at line 271 of file MonitorDataQueryManager.h.

carma::dbms::Table carma::dbms::MonitorDataQueryManager::tagIDToDataTypeID_
protected

this variable is only used if the ResultsCache singleton doesn't exist and cannot be created

Definition at line 299 of file MonitorDataQueryManager.h.

int carma::dbms::MonitorDataQueryManager::tCount_
staticprotected

temporary table counter to better assure that created temp tables will have unique names

Definition at line 336 of file MonitorDataQueryManager.h.

std::string carma::dbms::MonitorDataQueryManager::wideRSQuery_
protected

query to execute to produce a singe "wide" (generally using several joins) table

Definition at line 330 of file MonitorDataQueryManager.h.

std::vector<std::string> carma::dbms::MonitorDataQueryManager::wideSetUpQueries_
protected

the queries in the order they should be submitted to the database which create and populate temporary tables necessary for the single "wide" query

Definition at line 320 of file MonitorDataQueryManager.h.


The documentation for this class was generated from the following file: