casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
casa::TableParseSelect Class Reference

Select-class for flex/bison scanner/parser for TableParse. More...

#include <TableParse.h>

List of all members.

Public Types

enum  CommandType {
  PSELECT,
  PUPDATE,
  PINSERT,
  PDELETE,
  PCOUNT,
  PCALC,
  PCRETAB
}

Public Member Functions

 TableParseSelect (CommandType type)
 Construct.
 ~TableParseSelect ()
 Destructor.
CommandType commandType () const
 Return the command type.
TableExprNode getNode () const
 Return the expression node.
void execute (Bool showTimings, Bool setInGiving, Bool mustSelect, uInt maxRow)
 Execute the select command (select/sort/projection/giving).
Table doFromQuery (Bool showTimings)
 Execute a query in a from clause resulting in a Table.
TableExprNode doSubQuery (Bool showTimings)
 Execute a subquery and create an appropriate node for the result.
TableExprNode doExists (Bool noexists, Bool showTimings)
 Test if a subquery has sufficient elements.
void show (ostream &os) const
 Show the expression tree.
void handleSelect (const TableExprNode &)
 Keep the selection expression.
void handleCalcComm (const TableExprNode &)
 Keep the expression of a calculate command.
void handleCreTab (const String &tableName, const Record &dmInfo)
 Keep the create table command.
void handleColSpec (const String &columnName, const String &dataType, const Record &spec, Bool isCOrder=False)
 Keep the column specification in a create table command.
void addUpdate (TableParseUpdate *upd)
 Add an update object.
void handleUpdate ()
 Keep the update expressions.
void handleInsert ()
 Make ready for the insert expression.
void handleInsert (TableParseSelect *sel)
void handleCount ()
 Make ready for a COUNT command.
void handleSort (const std::vector< TableParseSort > &sortList, Bool noDuplicates, Sort::Order defaultSortOrder)
 Keep the sort expressions.
void handleLimit (const TableExprNode &expr)
 Evaluate and keep the limit value.
void handleOffset (const TableExprNode &expr)
 Evaluate and keep the offset value.
void addTable (Int tabnr, const String &name, const Table &table, const String &shorthand, const vector< const Table * > tempTables, const vector< TableParseSelect * > &stack)
 Add a table nr, name, or object to the container.
void replaceTable (const Table &table)
 Replace the first table (used by CALC command).
TableExprNode handleKeyCol (const String &name)
 Find the keyword or column name and create a TableExprNode from it.
TableExprNode handleFunc (const String &name, const TableExprNodeSet &arguments, const TaQLStyle &)
 Handle a function.
void handleColumn (Int type, const String &name, const TableExprNode &expr, const String &newName, const String &newDtype)
 Add a column to the list of column names.
void handleColumnFinish (Bool distinct)
 Finish the addition of columns to the list of column names.
void handleGiving (const String &name, Int type)
 Handle the name and type given in a GIVING clause.
void handleGiving (const TableExprNodeSet &)
 Handle the set given in a GIVING clause.
const Block< String > & getColumnNames () const
 Get the projected column names.
const TablegetTable () const
 Get the resulting table.

Static Public Member Functions

static TableExprNode handleSlice (const TableExprNode &array, const TableExprNodeSet &indices, const TaQLStyle &)
 Handle a slice operator.
static TableExprNode makeFuncNode (const String &name, const TableExprNodeSet &arguments, const Vector< int > &ignoreFuncs, const Table &table, const TaQLStyle &)
 Make a function object node for the given function name and arguments.

Private Member Functions

void doUpdate (Bool showTimings, const Table &origTable, Table &updTable, const Vector< uInt > &rownrs)
 Do the update step.
Table doInsert (Bool showTimings, Table &table)
 Do the insert step and return a selection containing the new rows.
void doDelete (Bool showTimings, Table &table)
 Do the delete step.
Table doCount (Bool showTimings, const Table &)
 Do the count step returning a memory table containing the unique column values and the counts of the column values.
Table doProject (Bool showTimings, const Table &)
 Do the projection step returning a table containing the projection.
Table doProjectExpr ()
 Do the projection containing column expressions.
void doSort (Bool showTimings, const Table &origTable)
 Do the sort step.
void doLimOff (Bool showTimings)
 Do the limit/offset step.
Table doLimOff (Bool showTimings, const Table &table)
Table doDistinct (Bool showTimings, const Table &table)
 Do the 'select distinct' step.
Table doFinish (Bool showTimings, Table &table)
 Finish the table (rename, copy, and/or flush).
template<typename TCOL , typename TNODE >
void updateValue2 (uInt row, const TableExprId &rowid, Bool isScalarCol, const TableExprNode &node, TableColumn &col, const Slicer *slicerPtr, IPosition &blc, IPosition &trc, IPosition &inc)
 Update the values in the columns (helpers of doUpdate).
template<typename T >
void updateValue1 (uInt row, const TableExprId &rowid, Bool isScalarCol, const TableExprNode &node, TableColumn &col, const Slicer *slicerPtr, IPosition &blc, IPosition &trc, IPosition &inc)
DataType makeDataType (DataType dtype, const String &dtstr, const String &colName)
 Make a data type from the string.
Sort::Order getOrder (const TableParseSort &key) const
 Get the order for this key.
TableExprNode getColSet ()
 Make an array from the contents of a column in a subquery.
TableExprNode makeSubSet (const Table &origTable) const
 Make a set from the results of the subquery.
Int64 evalIntScaExpr (const TableExprNode &expr) const
 Evaluate an int scalar expression.
Bool splitName (String &shorthand, String &columnName, Vector< String > &fieldNames, const String &name, Bool checkError) const
 Split a name into its parts (shorthand, column and field names).
Table findTable (const String &shorthand) const
 Find a table for the given shorthand.
void handleWildColumn (Int stringType, const String &name)
 Handle the selection of a wildcarded column name.
void addColumnDesc (TableDesc &td, DataType dtype, const String &colName, Int options, Int ndim, const IPosition &shape, const String &dmType, const String &dmGroup, const String &comment, const String &unitName)
 Add the description of a column to the table description.
Block< StringgetStoredColumns (const Table &tab) const
 Find the names of all stored columns in a table.

Static Private Member Functions

static
TableExprFuncNode::FunctionType 
findFunc (const String &name, uInt narguments, const Vector< Int > &ignoreFuncs)
 Find the function code belonging to a function name.
static Table tableKey (const String &fullName, const String &shorthand, const String &columnName, const Vector< String > &fieldNames, const vector< TableParseSelect * > &stack)
 Try to find the keyword representing a table in one of the tables in any select block (from inner to outer).
static Table findTableKey (const Table &table, const String &columnName, const Vector< String > &keyNames)
 Try to find the keyword representing a table in the given table.

Private Attributes

CommandType commandType_p
TableDesc tableDesc_p
vector< TableParsefromTables_p
Block< StringcolumnNames_p
Block< TableExprNodecolumnExpr_p
Block< StringcolumnOldNames_p
Block< StringcolumnDtypes_p
uInt nrSelExprUsed_p
Bool distinct_p
String resultName_p
Int resultType_p
TableExprNodeSetresultSet_p
TableExprNode node_p
Int64 limit_p
Int64 offset_p
std::vector< TableParseUpdate * > update_p
TableParseSelectinsSel_p
std::vector< TableParseSortsort_p
Bool noDupl_p
Sort::Order order_p
Table table_p
Vector< uIntrownrs_p

Detailed Description

Select-class for flex/bison scanner/parser for TableParse.

Intended use:

Internal

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25

Prerequisite

Synopsis

This class is needed for the the actions in the flex scanner and bison parser. This stores the information by constructing TableParse objects as needed and storing them in a vector.

Motivation

It is necessary to be able to give a table select command in ASCII. This can be used in a CLI or in the table browser to get a subset of a table or to sort a table.

Definition at line 335 of file TableParse.h.


Member Enumeration Documentation

Enumerator:
PSELECT 
PUPDATE 
PINSERT 
PDELETE 
PCOUNT 
PCALC 
PCRETAB 

Definition at line 338 of file TableParse.h.


Constructor & Destructor Documentation

Construct.

Destructor.


Member Function Documentation

void casa::TableParseSelect::addColumnDesc ( TableDesc td,
DataType  dtype,
const String colName,
Int  options,
Int  ndim,
const IPosition shape,
const String dmType,
const String dmGroup,
const String comment,
const String unitName 
) [private]

Add the description of a column to the table description.

ndim < 0 means a scalar column.

void casa::TableParseSelect::addTable ( Int  tabnr,
const String name,
const Table table,
const String shorthand,
const vector< const Table * >  tempTables,
const vector< TableParseSelect * > &  stack 
)

Add a table nr, name, or object to the container.

Add an update object.

Definition at line 692 of file TableParse.h.

References update_p.

Return the command type.

Definition at line 355 of file TableParse.h.

References commandType_p.

Table casa::TableParseSelect::doCount ( Bool  showTimings,
const Table  
) [private]

Do the count step returning a memory table containing the unique column values and the counts of the column values.

void casa::TableParseSelect::doDelete ( Bool  showTimings,
Table table 
) [private]

Do the delete step.

Table casa::TableParseSelect::doDistinct ( Bool  showTimings,
const Table table 
) [private]

Do the 'select distinct' step.

TableExprNode casa::TableParseSelect::doExists ( Bool  noexists,
Bool  showTimings 
)

Test if a subquery has sufficient elements.

It uses default LIMIT=1, but that can be overidden in the subquery. The flag tells if NOT EXISTS or EXISTS was given.

Table casa::TableParseSelect::doFinish ( Bool  showTimings,
Table table 
) [private]

Finish the table (rename, copy, and/or flush).

Execute a query in a from clause resulting in a Table.

Table casa::TableParseSelect::doInsert ( Bool  showTimings,
Table table 
) [private]

Do the insert step and return a selection containing the new rows.

void casa::TableParseSelect::doLimOff ( Bool  showTimings) [private]

Do the limit/offset step.

Table casa::TableParseSelect::doLimOff ( Bool  showTimings,
const Table table 
) [private]
Table casa::TableParseSelect::doProject ( Bool  showTimings,
const Table  
) [private]

Do the projection step returning a table containing the projection.

Do the projection containing column expressions.

Projection is done for the selected rownrs.

void casa::TableParseSelect::doSort ( Bool  showTimings,
const Table origTable 
) [private]

Do the sort step.

Execute a subquery and create an appropriate node for the result.

void casa::TableParseSelect::doUpdate ( Bool  showTimings,
const Table origTable,
Table updTable,
const Vector< uInt > &  rownrs 
) [private]

Do the update step.

Rows 0,1,2,.. in UpdTable are updated from the expression result for the rows in the given rownrs vector.

Int64 casa::TableParseSelect::evalIntScaExpr ( const TableExprNode expr) const [private]

Evaluate an int scalar expression.

void casa::TableParseSelect::execute ( Bool  showTimings,
Bool  setInGiving,
Bool  mustSelect,
uInt  maxRow 
)

Execute the select command (select/sort/projection/giving).

The setInGiving flag tells if a set in the GIVING part is allowed. The mustSelect flag tells if a SELECT command must do something. Usually that is required, but not for a SELECT in an INSERT command. Optionally the maximum nr of rows to be selected can be given. It will be used as the default value for the LIMIT clause. 0 = no maximum.

static TableExprFuncNode::FunctionType casa::TableParseSelect::findFunc ( const String name,
uInt  narguments,
const Vector< Int > &  ignoreFuncs 
) [static, private]

Find the function code belonging to a function name.

Functions to be ignored can be given (as function type values). If the function name is unknown, NRFUNC is returned.

Table casa::TableParseSelect::findTable ( const String shorthand) const [private]

Find a table for the given shorthand.

If no shorthand is given, the first table is returned (if there). If not found, a null Table object is returned.

static Table casa::TableParseSelect::findTableKey ( const Table table,
const String columnName,
const Vector< String > &  keyNames 
) [static, private]

Try to find the keyword representing a table in the given table.

If the columnName is empty, the keyword is a table keyword. If not found, a null Table object is returned.

Make an array from the contents of a column in a subquery.

const Block< String > & casa::TableParseSelect::getColumnNames ( ) const [inline]

Get the projected column names.

Definition at line 686 of file TableParse.h.

References columnNames_p.

Return the expression node.

Definition at line 359 of file TableParse.h.

References node_p.

Sort::Order casa::TableParseSelect::getOrder ( const TableParseSort key) const [inline, private]

Get the order for this key.

Use the default order_p if not explicitly given with the key.

Definition at line 695 of file TableParse.h.

References casa::TableParseSort::order(), order_p, and casa::TableParseSort::orderGiven().

Block<String> casa::TableParseSelect::getStoredColumns ( const Table tab) const [private]

Find the names of all stored columns in a table.

const Table & casa::TableParseSelect::getTable ( ) const [inline]

Get the resulting table.

Definition at line 689 of file TableParse.h.

References table_p.

Keep the expression of a calculate command.

void casa::TableParseSelect::handleColSpec ( const String columnName,
const String dataType,
const Record spec,
Bool  isCOrder = False 
)

Keep the column specification in a create table command.

void casa::TableParseSelect::handleColumn ( Int  type,
const String name,
const TableExprNode expr,
const String newName,
const String newDtype 
)

Add a column to the list of column names.

Finish the addition of columns to the list of column names.

Make ready for a COUNT command.

It checks if all column expressions are scalar.

void casa::TableParseSelect::handleCreTab ( const String tableName,
const Record dmInfo 
)

Keep the create table command.

TableExprNode casa::TableParseSelect::handleFunc ( const String name,
const TableExprNodeSet arguments,
const TaQLStyle  
)

Handle a function.

void casa::TableParseSelect::handleGiving ( const String name,
Int  type 
)

Handle the name and type given in a GIVING clause.

Handle the set given in a GIVING clause.

Make ready for the insert expression.

The first one uses values (added via addUpdate), the second one a subquery.

Find the keyword or column name and create a TableExprNode from it.

Evaluate and keep the limit value.

Evaluate and keep the offset value.

Keep the selection expression.

static TableExprNode casa::TableParseSelect::handleSlice ( const TableExprNode array,
const TableExprNodeSet indices,
const TaQLStyle  
) [static]

Handle a slice operator.

void casa::TableParseSelect::handleSort ( const std::vector< TableParseSort > &  sortList,
Bool  noDuplicates,
Sort::Order  defaultSortOrder 
)

Keep the sort expressions.

Keep the update expressions.

void casa::TableParseSelect::handleWildColumn ( Int  stringType,
const String name 
) [private]

Handle the selection of a wildcarded column name.

DataType casa::TableParseSelect::makeDataType ( DataType  dtype,
const String dtstr,
const String colName 
) [private]

Make a data type from the string.

It checks if it is compatible with the given (expression) data type.

static TableExprNode casa::TableParseSelect::makeFuncNode ( const String name,
const TableExprNodeSet arguments,
const Vector< int > &  ignoreFuncs,
const Table table,
const TaQLStyle  
) [static]

Make a function object node for the given function name and arguments.

The ignoreFuncs vector contains invalid function codes.

TableExprNode casa::TableParseSelect::makeSubSet ( const Table origTable) const [private]

Make a set from the results of the subquery.

Replace the first table (used by CALC command).

void casa::TableParseSelect::show ( ostream &  os) const

Show the expression tree.

Bool casa::TableParseSelect::splitName ( String shorthand,
String columnName,
Vector< String > &  fieldNames,
const String name,
Bool  checkError 
) const [private]

Split a name into its parts (shorthand, column and field names).

True is returned when the name contained a keyword part. In that case fieldNames contains the keyword name and the possible subfields. The possible shorthand and the column name are filled in if it is a column keyword. If the name represents a column, fieldNames contains the subfields of the column (for the case where the column contains records). If the name is invalid, an exception is thrown if checkError=True. Otherwise the name is treated as a normal name without keyword.

static Table casa::TableParseSelect::tableKey ( const String fullName,
const String shorthand,
const String columnName,
const Vector< String > &  fieldNames,
const vector< TableParseSelect * > &  stack 
) [static, private]

Try to find the keyword representing a table in one of the tables in any select block (from inner to outer).

If not found, an exception is thrown.

template<typename T >
void casa::TableParseSelect::updateValue1 ( uInt  row,
const TableExprId rowid,
Bool  isScalarCol,
const TableExprNode node,
TableColumn col,
const Slicer slicerPtr,
IPosition blc,
IPosition trc,
IPosition inc 
) [private]
template<typename TCOL , typename TNODE >
void casa::TableParseSelect::updateValue2 ( uInt  row,
const TableExprId rowid,
Bool  isScalarCol,
const TableExprNode node,
TableColumn col,
const Slicer slicerPtr,
IPosition blc,
IPosition trc,
IPosition inc 
) [private]

Update the values in the columns (helpers of doUpdate).


Member Data Documentation

Definition at line 618 of file TableParse.h.

Definition at line 614 of file TableParse.h.

Definition at line 612 of file TableParse.h.

Referenced by getColumnNames().

Definition at line 616 of file TableParse.h.

Definition at line 604 of file TableParse.h.

Referenced by commandType().

Definition at line 622 of file TableParse.h.

Definition at line 610 of file TableParse.h.

Definition at line 637 of file TableParse.h.

Definition at line 631 of file TableParse.h.

Definition at line 629 of file TableParse.h.

Referenced by getNode().

Definition at line 641 of file TableParse.h.

Definition at line 620 of file TableParse.h.

Definition at line 633 of file TableParse.h.

Definition at line 643 of file TableParse.h.

Referenced by getOrder().

Definition at line 624 of file TableParse.h.

Definition at line 627 of file TableParse.h.

Definition at line 625 of file TableParse.h.

Definition at line 647 of file TableParse.h.

Definition at line 639 of file TableParse.h.

Definition at line 645 of file TableParse.h.

Referenced by getTable().

Definition at line 606 of file TableParse.h.

Definition at line 635 of file TableParse.h.

Referenced by addUpdate().


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