TableParse.h

Classes

TableParse -- Class to hold values from table grammar parser (full description)
Global Functions -- (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

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

Review Status

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

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

TableParse()

Default constructor for 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.


Global Functions (source)

Interface

Private Members
TaQLResult tableCommand (const String& command)
TaQLResult tableCommand (const String& command, const Table& tempTable)
TaQLResult tableCommand (const String& command, const std::vector<const vector*>& tempTables)
TaQLResult tableCommand (const String& command, Vector<String>& columnNames)
TaQLResult tableCommand (const String& command, Vector<String>& columnNames, String& commandType)
TaQLResult tableCommand (const String& command, const std::vector<const vector*>& tempTables, Table<String>& columnNames)
TaQLResult tableCommand (const String& command, const std::vector<const vector*>& tempTables, Table<String>& columnNames, String& commandType)

Description

Synopsis

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.

Member Description

TaQLResult tableCommand (const String& command)

TaQLResult tableCommand (const String& command, const Table& tempTable)

TaQLResult tableCommand (const String& command, const std::vector<const vector*>& tempTables)

TaQLResult tableCommand (const String& command, Vector<String>& columnNames)

TaQLResult tableCommand (const String& command, Vector<String>& columnNames, String& commandType)

TaQLResult tableCommand (const String& command, const std::vector<const vector*>& tempTables, Table<String>& columnNames)

TaQLResult tableCommand (const String& command, const std::vector<const vector*>& tempTables, Table<String>& columnNames, String& commandType)


class TableParseSort

Interface

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

Description

Review Status

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

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

TableParseSort()

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

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() : indexPtr_p(0)
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

Review Status

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

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() : indexPtr_p(0)

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

Types

enum CommandType

PSELECT
PUPDATE
PINSERT
PDELETE
PCALC
PCRETAB

Interface

TableParseSelect (CommandType type)
~TableParseSelect()
CommandType commandType() const
TableExprNode getNode() const
void execute (Bool setInGiving, Bool mustSelect=True, uInt maxRow=0)
Table doFromQuery()
TableExprNode doSubQuery()
TableExprNode doExists (Bool noexists)
void show (ostream& os) const
void setDistinctCol()
void handleSelect (const TableExprNode&)
void handleCalcComm (const TableExprNode&)
void handleCreTab (const String& tableName, const Record& dmInfo)
void handleColSpec (const String& columnName, const String& dataType, const Record& spec)
void addUpdate (TableParseUpdate* upd)
void handleUpdate()
void handleInsert()
void handleInsert (TableParseSelect* sel)
void handleSort (const std::vector<vector>& sortList, Bool noDuplicates, TableParseSort::Order defaultSortOrder)
void handleLimit (const TableExprNode& expr)
void handleOffset (const TableExprNode& expr)
void addTable (Int tabnr, const String& name, const Table& table, const String& shorthand, const vector<const Table*> tempTables, const vector<TableParseSelect*>& stack)
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)
void handleColumn (const String& name, const TableExprNode& expr, const String& newName, const String& newDtype)
void handleGiving (const String& name, Int type)
void handleGiving (const TableExprNodeSet&)
const Block<String>& getColumnNames() const
const Table& getTable() const
Private Members
void doUpdate (Table& updTable, const Table& inTable)
Table doInsert (Table& table)
void doDelete (Table& table, const Table& sel)
Table doProject (const Table&)
Table doProjectExpr (const Table&)
Table doSort (const Table& table)
Table doLimOff (const Table& table)
Table doDistinct (const Table& table)
Table doFinish (Table& table)
DataType makeDataType (DataType dtype, const String& dtstr, const String& colName)
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
void addColumnDesc (TableDesc& td, DataType dtype, const String& colName, Int options, Int ndim, const String& shape, const String& dmType, const String& dmGroup, const String& comment)
Block<String> getStoredColumns (const Table& tab) const
static Table tableKey (const String& shorthand, const String& columnName, const Vector<String>& fieldNames, const vector<TableParseSelect*>& stack)
static Table findTableKey (const Table& table, const String& columnName, const Vector<String>& keyNames)

Description

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.

Member Description

enum CommandType

TableParseSelect (CommandType type)

Construct.

~TableParseSelect()

Destructor.

CommandType commandType() const

Return the command type.

TableExprNode getNode() const

Return the expression node.

void execute (Bool setInGiving, 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. 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.

Table doFromQuery()

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

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 (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)

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()
void handleInsert (TableParseSelect* sel)

Make ready for the insert expression. The first one uses values (added via addUpdate), the second one a subquery.

void handleSort (const std::vector<vector>& sortList, Bool noDuplicates, TableParseSort::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.

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

void handleColumn (const String& name, const TableExprNode& expr, const String& newName, const String& newDtype)

Add a column 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 Table& getTable() const

Get the resulting table.

void doUpdate (Table& updTable, const Table& inTable)

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 doProject (const Table&)

Do the projection step returning a table containing the projection.

Table doProjectExpr (const Table&)

Do the projection containing column expressions.

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.

Table doFinish (Table& table)

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

DataType makeDataType (DataType dtype, const String& dtstr, const String& colName)

Make a data type from the string. It checks if it is compatible with the given (expression) data type.

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.

void addColumnDesc (TableDesc& td, DataType dtype, const String& colName, Int options, Int ndim, const String& shape, const String& dmType, const String& dmGroup, const String& comment)

Add the description of a column to the table description. ndim < 0 means a scalar column.

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, 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). 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.