Classes | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Friends
ibis::selectClause Class Reference

A class to represent the select clause. More...

#include <selectClause.h>

List of all members.

Classes

class  variable
 A specialization of ibis::math::variable. More...

Public Member Functions

void clear ()
bool empty () const
 Returns true if this select clause is empty.
int find (const char *) const
 Locate the position of the string.
void getNullMask (const ibis::part &, ibis::bitvector &) const
const char * getString (void) const
 Return a pointer to the string form of the select clause.
const char * operator* (void) const
 Dereferences to the string form of the select clause.
selectClauseoperator= (const selectClause &rhs)
 Assignment operator.
int parse (const char *cl)
 Parse a new string.
void print (std::ostream &) const
 Write a string version of the select clause to the specified output stream.
void printDetails (std::ostream &) const
 selectClause (const char *cl=0)
 Parse a new string as a select clause.
 selectClause (const ibis::table::stringList &)
 Parse a list of strings.
 selectClause (const selectClause &)
 Copy constructor. Deep copy.
void swap (selectClause &rhs)
 Swap the content of two select clauses.
int verify (const ibis::part &) const
 Verify the select clause is valid against the given data partition.
int verifySome (const std::vector< uint32_t > &, const ibis::part &) const
 Verify the selected terms.

Static Public Member Functions

static int verifyTerm (const ibis::math::term &, const ibis::part &, const ibis::selectClause *=0)
 Verify the specified term has valid column names.

Protected Types

typedef std::map< const char
*, ibis::selectClause::variable
*, ibis::lessi
varMap

Protected Member Functions

ibis::math::variableaddAgregado (ibis::selectClause::AGREGADO, ibis::math::term *)
 Record an aggregation function.
ibis::math::termaddRecursive (ibis::math::term *&)
void addTerm (ibis::math::term *, const std::string *)
 Add a top-level term.
uint64_t decodeAName (const char *) const
 Determine if the name refers to a term in the list of aggregation functions.
void fillNames ()
 Fill array names_ and xnames_.
void gatherVariables (varMap &vmap, ibis::math::term *t) const
bool hasAggregation (const ibis::math::term *tm) const
 Does the math expression contain any aggregation operations?

Protected Attributes

std::vector< AGREGADOaggr_
 Aggregators.
mathTerms atms_
 Arithmetic expressions used by aggregators.
std::string clause_
 String version of the select clause.
ibis::selectLexerlexer
 A pointer for the parser.
std::vector< std::string > names_
 Names of the variables inside the aggregation functions.
StringToInt ordered_
 A ordered version of names_.
StringToInt xalias_
 Aliases.
std::vector< std::string > xnames_
 Names of the top-level terms.
mathTerms xtms_
 Top-level terms. Externally visible arithmetic expressions.

Friends

class ibis::selectParser
class variable
typedef std::vector
< ibis::math::term * > 
mathTerms
 Functions related to extenally visible portion of the select clause.
typedef std::map< const char
*, const char *, ibis::lessi
nameMap
 Functions related to extenally visible portion of the select clause.
const mathTermsgetTerms () const
 Retrieve all top-level arithmetic expressions.
const ibis::math::termtermExpr (unsigned i) const
 Fetch the ith term visible to the outside. No array bound checking.
uint32_t numTerms () const
 Number of terms visible to the outside.
const char * termName (unsigned i) const
 Name given to the top-level function.
std::string termDescription (unsigned i) const
 Produce a string for the jth term of the select clause.
int getAliases (nameMap &) const
 Map internal column names to external column names.
uint32_t numGroupbyKeys () const
 Number of terms without aggregation functions.
int getGroupbyKeys (std::vector< std::string > &keys) const
 Gather the implicit group-by keys into a vector.
enum  AGREGADO {
  NIL_AGGR, AVG, CNT, MAX,
  MIN, SUM, DISTINCT, VARPOP,
  VARSAMP, STDPOP, STDSAMP, MEDIAN
}
 Aggregation functions. More...
typedef std::map< std::string,
unsigned > 
StringToInt
 Aggregation functions.
uint32_t aggSize () const
 Functions related to internal aggregation operations.
const ibis::math::termaggExpr (unsigned i) const
 Fetch the ith term of inside the select clause. No array bound checking.
const char * aggName (unsigned i) const
 Name inside the aggregation function.
std::string aggDescription (unsigned i) const
 Write the string form of the ith (internal) term.
AGREGADO getAggregator (uint32_t i) const
 Return the aggregation function used for the ith term.
const StringToIntgetOrdered () const
 Aggregation functions.

Detailed Description

A class to represent the select clause.

It parses a string into a list of arithmetic expressions and aggregation functions.

The terms in a select clause are to be separated by comas ',' and each term may be an arithmetic expression or an aggregation function over an arithmetic expression, e.g., "age, avg(income)" and "temperature, sqrt(vx*vx+vy*vy+vz*vz) as speed, max(duration * speed)". An arithmetic expression may contain any valid combination of numbers and column names connected with operators +, -, *, /, %, ^, ** and standard functions with one and two arguements (defined in math.h). The supported aggregation functions are:

Each term may optionally be followed by an alias for the term. The alias must be a valid SQL name. The alias may optionally be preceded by the keyword 'AS'. The aliases can be used in the other part of the query.

Note:
All select operations excludes null values! In most SQL implementations, the function 'count(*)' includes the null values. However, in FastBit, null values are always excluded. For example, the return value for 'count(*)' in the following two select statements may be different if there are any null values in column A,
 select count(*) from ...;
 select avg(A), count(*) from ...;
In the first case, the number reported is purely determined by the where clause. However, in the second case, because the select clause also involves the column A, all of null values of A are excluded, therefore 'count(*)' in the second example may be smaller than that of the first example.

Member Typedef Documentation

Functions related to extenally visible portion of the select clause.

A vector of arithematic expressions.

typedef std::map<const char*, const char*, ibis::lessi> ibis::selectClause::nameMap

Functions related to extenally visible portion of the select clause.

A vector of arithematic expressions.

typedef std::map<std::string, unsigned> ibis::selectClause::StringToInt

Aggregation functions.

Note:
"Agregado" is Spanish for aggregate.

Member Enumeration Documentation

Aggregation functions.

Note:
"Agregado" is Spanish for aggregate.

Member Function Documentation

ibis::math::variable * ibis::selectClause::addAgregado ( ibis::selectClause::AGREGADO  agr,
ibis::math::term expr 
) [protected]

Record an aggregation function.

Return a math term of the type variable to caller so the caller can continue to build up a larger expression. For simplicity, the variable name is simply "__hhh", where "hhh" is the size of aggr_ in hexadecimal.

References ibis::math::variable::dup(), and ibis::gVerbose.

void ibis::selectClause::addTerm ( ibis::math::term tm,
const std::string *  al 
) [protected]

Add a top-level term.

It invokes ibis::selectClause::addRecursive to do the actual work. The final expression returned by addRecursive is added to xtms_.

References ibis::gVerbose.

std::string ibis::selectClause::aggDescription ( unsigned  i) const

Write the string form of the ith (internal) term.

The result is placed in the second argument str.

Referenced by ibis::bord::evaluateTerms(), and ibis::bord::groupby().

const char* ibis::selectClause::aggName ( unsigned  i) const [inline]

Name inside the aggregation function.

To be used together with aggSize() and aggExpr().

Referenced by ibis::bundle1::bundle1(), ibis::bundles::bundles(), ibis::bord::evaluateTerms(), ibis::bord::groupby(), and verifyTerm().

uint32_t ibis::selectClause::aggSize ( ) const [inline]

Functions related to internal aggregation operations.

The number of arithmetic expressions inside the select clause.

Referenced by ibis::part::addColumn(), ibis::bundle1::bundle1(), ibis::bundles::bundles(), ibis::bundle::create(), ibis::bord::evaluateTerms(), ibis::filter::filt(), ibis::bord::groupby(), ibis::table::select(), ibis::whereClause::verifyExpr(), and verifyTerm().

uint64_t ibis::selectClause::decodeAName ( const char *  nm) const [protected]

Determine if the name refers to a term in the list of aggregation functions.

A name to a aggregation function will be named by ibis::selctClause::addAgregado. If the return value is less than the size of atms_, then the name is considered referring to a aggregation function, otherwise, it is a literal name from the user.

void ibis::selectClause::fillNames ( ) [protected]

Fill array names_ and xnames_.

An alias for an aggregation operation is used as the external name for the whole term. This function resolves all external names first to establish all aliases, and then resolve the names of the arguments to the aggregation functions. The arithmetic expressions without external names are given names of the form "__hhh", where "hhh" is a hexadecimal number.

References ibis::gVerbose.

int ibis::selectClause::find ( const char *  key) const

Locate the position of the string.

Upon successful completion, it returns the position of the term with the matching name, otherwise, it returns -1. The incoming argument may be an alias, a column name, or the exact form of the arithmetic expression. In case it is an arithmetic expression, it must be exactly the same as the original term passed to the constructor of this class including spaces. The comparison is done with case-insensitive string comparison.

Referenced by ibis::whereClause::verifyExpr(), and verifyTerm().

int ibis::selectClause::getAliases ( nameMap nmap) const

Map internal column names to external column names.

The key of the map is the internal column names, i.e., the column names used by the ibis::bord object generated with a selct clause. If that ibis::bord object does not go through any aggregation operation, then the columns need to be renamed using this information.

It returns the number of changes needed. A negative number is used to indicate error.

int ibis::selectClause::getGroupbyKeys ( std::vector< std::string > &  keys) const

Gather the implicit group-by keys into a vector.

Note:
Uses std::vector<std::string> because the string values may not existing inside the select clause, such as the string representation for arithmetic experssions.
const StringToInt& ibis::selectClause::getOrdered ( ) const [inline]

Aggregation functions.

Note:
"Agregado" is Spanish for aggregate.

References ordered_.

Referenced by ibis::bord::bord().

uint32_t ibis::selectClause::numGroupbyKeys ( ) const [inline]

Number of terms without aggregation functions.

They are implicitly used as sort keys for group by operations. However, if the select clause does not contain any aggregation function, the sorting operation might be skipped.

References aggr_, and atms_.

Referenced by ibis::filter::filt(), and ibis::table::select().

std::string ibis::selectClause::termDescription ( unsigned  j) const

Produce a string for the jth term of the select clause.

The string shows the actual expression, not the alias. To see the final name to be used, call ibis::selectClause::termName(j).

const char* ibis::selectClause::termName ( unsigned  i) const [inline]

Name given to the top-level function.

This is the external name assigned to termExpr(i) (which is also getTerms()[i]). To produce a string version of the term use termDescription.

Referenced by ibis::filter::filt(), ibis::bord::groupby(), and ibis::table::select().

int ibis::selectClause::verify ( const ibis::part part0) const

Verify the select clause is valid against the given data partition.

Returns the number of variables that are not in the data partition. This function also simplifies the arithmetic expression if ibis::math::preserveInputExpression is not set.

Note:
Simplifying the arithmetic expressions typically reduces the time needed for evaluations, but may introduce a different set of round-off erros in the evaluation process than the original expression. Set the variable ibis::math::preserveInputExpression to true to avoid this change in error round-off property.

References ibis::gVerbose, ibis::math::preserveInputExpressions, and ibis::math::term::reduce().

Referenced by ibis::filter::filt(), ibis::table::select(), ibis::query::setPartition(), and ibis::query::setSelectClause().

int ibis::selectClause::verifySome ( const std::vector< uint32_t > &  touse,
const ibis::part part0 
) const

Verify the selected terms.

Return the number of terms containing unknown names.

References ibis::gVerbose, ibis::math::preserveInputExpressions, and ibis::math::term::reduce().

int ibis::selectClause::verifyTerm ( const ibis::math::term xp0,
const ibis::part part0,
const ibis::selectClause sel0 = 0 
) [static]

Verify the specified term has valid column names.

It returns the number of terms not in the given data partition.

References aggName(), aggSize(), find(), ibis::part::getColumn(), ibis::qExpr::getLeft(), ibis::qExpr::getRight(), ibis::gVerbose, and ibis::part::name().


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

Make It A Bit Faster
Contact us
Disclaimers
FastBit source code
FastBit mailing list archive