TableParse.h

Classes

TableParse -- Class to hold values from table grammar parser (full description)
TableParseVal -- Helper class for values in TableParse (full description)
TableParseSort -- Helper class for sort keys in TableParse (full description)
TableParseUpdate -- Helper class for updates in TableParse (full description)
TableParseSelect -- Select-class for flex/bison scanner/parser for TableParse (full description)

class TableParse

Interface

friend AipsIO& operator<< (AipsIO&, const TableParse&)
friend AipsIO& operator>> (AipsIO&, TableParse&)
friend Table tableCommand (const Table& command)
friend Table tableCommand (const Table& command, const Table& tempTable)
friend Table tableCommand (const Table& command, const String<const Table*>& tempTables)
friend Table tableCommand (const Table& command, String<Table>& columnNames)
friend Table tableCommand (const Table& command, String<Table>& columnNames, Table& commandType)
friend Table tableCommand (const Table& command, const String<const Table*>& tempTables, PtrBlock<Table>& columnNames)
friend Table tableCommand (const Table& command, const String<const Table*>& tempTables, PtrBlock<Table>& columnNames, Table& commandType)
Public Members
TableParse ()
TableParse (const TableParse&)
TableParse& operator= (const TableParse&)
TableParse (const Table& table, const String& shorthand)
Bool test (const String& shortHand) const
const String& shorthand() const
const Table& table() const

Description

Prerequisite

Etymology

TableParse is the class used to parse a table command.

Synopsis

TableParse is used by the parser of table select statements. The parser is written in Bison and Flex in files TableGram.y and .l. The statements in there use the routines in this file to act upon a reduced rule. Since multiple tables can be given (with a shorthand), the table names are stored in a list. The variable names can be qualified by the table name and will be looked up in the appropriate table.

A select command is similar to SQL and can look like: SELECT columns FROM tab1 sh1, tab2 sh2, tab3 WHERE sh1.field == 3*sh1.field2 ... ORDERBY columns GIVING table This is described in more detail in TableGram.l.

The class TableParse only contains information about a table used in the table command. Global variables (like a list and a vector) are used in TableParse.cc to hold further information.

Global functions are used to operate on the information. The main function is the global function tableCommand. It executes the given TaQL command and returns the resulting table. This is, in fact, the only function to be used by a user.

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.

Member Description

friend AipsIO& operator<< (AipsIO&, const TableParse&)
friend AipsIO& operator>> (AipsIO&, TableParse&)

Dummy AipsIO routines; they are needed for the List container.

friend Table tableCommand (const Table& command)
friend Table tableCommand (const Table& command, const Table& tempTable)
friend Table tableCommand (const Table& command, const String<const Table*>& tempTables)
friend Table tableCommand (const Table& command, String<Table>& columnNames)
friend Table tableCommand (const Table& command, String<Table>& columnNames, Table& commandType)
friend Table tableCommand (const Table& command, const String<const Table*>& tempTables, PtrBlock<Table>& columnNames)
friend Table tableCommand (const Table& command, const String<const Table*>& tempTables, PtrBlock<Table>& columnNames, Table& commandType)

Parse and execute the given command. It will open (and close) all tables needed. It returns the resulting table. The command type (select or update) and the selected or updated column names can be returned. Zero or more temporary tables can be used in the command using the $nnn syntax.

TableParse ()

Default constructor for List container class.

TableParse (const TableParse&)

Copy constructor (copy semantics).

TableParse& operator= (const TableParse&)

Assignment (copy semantics).

TableParse (const Table& table, const String& shorthand)

Associate the table and the shorthand.

Bool test (const String& shortHand) const

Test if shorthand matches.

const String& shorthand() const

Get the shorthand.

const Table& table() const

Get table object.


class TableParseVal

Interface

static TableParseVal* makeValue()

Description

Prerequisite

Etymology

TableParseVal holds a value found when analyzing a table command.

Synopsis

A table command is lexically analyzed via flex. An object of this class is used to hold a value (like a name or a literal) for later use in the parser code.

Member Description

static TableParseVal* makeValue()

Make a new TableParseVal object (for the flex actions).

class TableParseSort

Interface

explicit TableParseSort (const TableExprNode&)
TableParseSort (const TableExprNode&, Sort::Order)
~TableParseSort()
const TableExprNode& node() const
Sort::Order order() const
Bool orderGiven() const

Description

Prerequisite

Etymology

TableParseSort holds a sort expression and order.

Synopsis

A table command is parsed. An object of this class is used to hold the sort expression and sort order.

Member Description

explicit TableParseSort (const TableExprNode&)

Construct from a given expression. The order is not given.

TableParseSort (const TableExprNode&, Sort::Order)

Construct from a given expression and for the given order.

~TableParseSort()

const TableExprNode& node() const

Get the expression node.

Sort::Order order() const

Get the sort order.

Bool orderGiven() const

Is the order given?


class TableParseUpdate

Interface

TableParseUpdate (const String& columnName, const TableExprNode&)
TableParseUpdate (const String& columnName, const TableExprNodeSet& indices, const TableExprNode&)
~TableParseUpdate()
void setColumnName (const String& name)
const String& columnName() const
TableExprNodeIndex* indexPtr() const
const TableExprNode& indexNode() const
const TableExprNode& node() const

Description

Prerequisite

Etymology

TableParseUpdate holds a column name, optional indices, and an update expression.

Synopsis

A table command is parsed. An object of this class is used to hold the column name, optional indices, and value expression for the UPDATE command.

Member Description

TableParseUpdate (const String& columnName, const TableExprNode&)

Construct from a column name and expression.

TableParseUpdate (const String& columnName, const TableExprNodeSet& indices, const TableExprNode&)

Construct from a column name, subscripts, and expression.

~TableParseUpdate()

void setColumnName (const String& name)

Set the column name.

const String& columnName() const

Get the column name.

TableExprNodeIndex* indexPtr() const

Get the pointer to the indices.

const TableExprNode& indexNode() const

Get the index expression node.

const TableExprNode& node() const

Get the expression node.


class TableParseSelect

Interface

TableParseSelect (Int commandType)
~TableParseSelect()
void execute (Bool setInGiving, String& commandType, Bool mustSelect=True, uInt maxRow=0)
TableParseVal* doFromQuery()
TableExprNode doSubQuery()
TableExprNode doExists (Bool noexists)
void show (ostream& os) const
void setDistinctCol()
void handleSelect (TableExprNode*& node)
void handleUpdate (PtrBlock<TableParseUpdate*>*& upd)
void handleInsert (PtrBlock<TableParseUpdate*>*& ins)
void handleInsert (TableParseSelect*& sel)
void handleSort (PtrBlock<TableParseSort*>*& sortList, Bool noDuplicates, Sort::Order defaultSortOrder)
void handleLimit (const TableExprNode& expr)
void handleOffset (const TableExprNode& expr)
void addTable (const TableParseVal* name, const String& shorthand)
TableExprNode handleKeyCol (const String& name)
static TableExprNode handleSlice (const TableExprNode& array, const TableExprNodeSet& indices)
TableExprNode handleFunc (const String& name, const TableExprNodeSet& arguments)
static TableExprNode makeFuncNode (const String& name, const TableExprNodeSet& arguments, const Vector<int>& ignoreFuncs, const Vector& table)
static TableExprFuncNode::FunctionType findFunc (const String& name, uInt narguments, const String<Int>& ignoreFuncs)
static TableExprNode handleLiteral (TableParseVal*)
void handleSelectColumn (const String& name)
void handleGiving (const String& name)
void handleGiving (const TableExprNodeSet&)
const Block<String>& getColumnNames() const
const Table& getTable() const
static void newSelect (Int commandType)
static TableParseSelect* popSelect()
static TableParseSelect* currentSelect()
static void clearSelect()
Private Members
void doUpdate (Table& table)
Table doInsert (Table& table)
void doDelete (Table& table, const Table& sel)
Table doSort (const Table& table)
Table doLimOff (const Table& table)
Table doDistinct (const Table& table)
Sort::Order getOrder (const TableParseSort& key) const
TableExprNode makeSubSet() const
Double evalDSExpr (const TableExprNode& expr) const
Bool splitName (String& shorthand, String& columnName, Vector<String>& fieldNames, const String& name, Bool checkError) const
Table findTable (const String& shorthand) const
Block<String> getStoredColumns (const Table& tab) const
static Table tableKey (const String& shorthand, const String& columnName, const Vector<String>& fieldNames)
static Table findTableKey (const Table& table, const String& columnName, const Vector<String>& keyNames)

Description

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 List.

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.

Member Description

TableParseSelect (Int commandType)

Construct for the given command type.

~TableParseSelect()

Destructor.

void execute (Bool setInGiving, String& commandType, Bool mustSelect=True, uInt maxRow=0)

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. The commandType (select or update) is filled in. 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.

TableParseVal* doFromQuery()

Execute a query in a from clause and create an appropriate value for the result.

TableExprNode doSubQuery()

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

TableExprNode doExists (Bool noexists)

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.

void show (ostream& os) const

Show the expression tree.

void setDistinctCol()

Set the distinct flag for column projection.

void handleSelect (TableExprNode*& node)

Keep the selection expression. It takes over the pointer (and clears the input pointer).

void handleUpdate (PtrBlock<TableParseUpdate*>*& upd)

Keep the update expressions. It takes over the pointer (and clears the input pointer).

void handleInsert (PtrBlock<TableParseUpdate*>*& ins)
void handleInsert (TableParseSelect*& sel)

Keep the insert expressions or table selection. It takes over the pointer (and clears the input pointer).

void handleSort (PtrBlock<TableParseSort*>*& sortList, Bool noDuplicates, Sort::Order defaultSortOrder)

Keep the sort expressions. It takes over the pointer (and clears the input pointer).

void handleLimit (const TableExprNode& expr)

Evaluate and keep the limit value.

void handleOffset (const TableExprNode& expr)

Evaluate and keep the offset value.

void addTable (const TableParseVal* name, const String& shorthand)

Add a table name to the linked list.

TableExprNode handleKeyCol (const String& name)

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

static TableExprNode handleSlice (const TableExprNode& array, const TableExprNodeSet& indices)

Handle a slice operator.

TableExprNode handleFunc (const String& name, const TableExprNodeSet& arguments)

Handle a function.

static TableExprNode makeFuncNode (const String& name, const TableExprNodeSet& arguments, const Vector<int>& ignoreFuncs, const Vector& table)

Make a function object node for the given function name and arguments. The ignoreFuncs vector contains invalid function codes.

static TableExprFuncNode::FunctionType findFunc (const String& name, uInt narguments, const String<Int>& ignoreFuncs)

Find the function code belonging to a function name. Functions to be ignored can be given (as function type values).

static TableExprNode handleLiteral (TableParseVal*)

Create a TableExprNode from a literal.

void handleSelectColumn (const String& name)

Add a column to the list of selected column names.

void handleGiving (const String& name)

Handle the name 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 Table& getTable() const

Get the resulting table.

static void newSelect (Int commandType)

Create a new TableParseSelect-object for the given command type and put it on the stack (block)

static TableParseSelect* popSelect()

Get and remove the last element from the "select stack". Note that this does not delete the object pointed to. It only clears the pointer and decrements the stack size.

static TableParseSelect* currentSelect()

Get current TableParseSelect object.

static void clearSelect()

Clear the select stack. Normally this won't do anything, but in case of exceptions something may be left.

void doUpdate (Table& table)

Do the update step.

Table doInsert (Table& table)

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

void doDelete (Table& table, const Table& sel)

Do the delete step.

Table doSort (const Table& table)

Do the sort step.

Table doLimOff (const Table& table)

Do the limit/offset step.

Table doDistinct (const Table& table)

Do the 'select distinct' step.

Sort::Order getOrder (const TableParseSort& key) const

Get the order for this key. Use the default order_p if not explicitly given with the key.

TableExprNode makeSubSet() const

Make a set from the results of the subquery.

Double evalDSExpr (const TableExprNode& expr) const

Evaluate a double 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). 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.

Table findTable (const String& shorthand) const

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.

Block<String> getStoredColumns (const Table& tab) const

Find the names of all stored columns in a table.

static Table tableKey (const String& shorthand, const String& columnName, const Vector<String>& fieldNames)

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.

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. If the columnName is empty, the keyword is a table keyword. If not found, a null Table object is returned.