A representation of the where clause. More...
#include <whereClause.h>
Public Member Functions | |
void | addConditions (const char *) |
Append a set of conditions to the existing where clause. More... | |
void | addExpr (const ibis::qExpr *) |
Append a set of conditions to the existing where clause. More... | |
void | clear () throw () |
Clear the existing content. | |
bool | empty () const |
The where clause is considered empty if the expr_ is a nil pointer. | |
const ibis::qExpr * | getExpr (void) const |
Return a pointer to the root of the expression tree for the where clause. More... | |
ibis::qExpr * | getExpr (void) |
Return a pointer to the root of the expression tree for the where clause. More... | |
void | getNullMask (const ibis::part &, ibis::bitvector &) const |
const char * | getString (void) const |
Return a pointer to the string form of the where clause. | |
ibis::qExpr * | operator-> () |
Member access operator redefined to point to ibis::qExpr. | |
const ibis::qExpr * | operator-> () const |
Member access operator redefined to point to const ibis::qExpr. | |
whereClause & | operator= (const whereClause &) |
Assignment operator. | |
int | parse (const char *cl) |
Parse a new string. | |
void | resetString () |
Regenerate the string version of the query conditions. | |
void | setExpr (const ibis::qExpr *ex) |
Assign a new set of conditions directly. More... | |
void | simplify () |
Simplify the query expression. | |
void | swap (whereClause &rhs) throw () |
Swap the contents of two where clauses. | |
int | verify (const ibis::part &p0, const ibis::selectClause *sel=0) const |
Verify that the names exist in the data partition. More... | |
whereClause (const char *cl=0) | |
Construct a where clause from a string. | |
whereClause (const whereClause &) | |
Construct a where clause from another where clause. | |
~whereClause () | |
Destructor. | |
Static Public Member Functions | |
static int | removeAlias (ibis::qContinuousRange *&, const ibis::column *) |
Create a simple range expression as the replacement of the incoming oldr. More... | |
static int | verifyExpr (const ibis::qExpr *, const ibis::part &, const ibis::selectClause *) |
static int | verifyExpr (ibis::qExpr *&, const ibis::part &, const ibis::selectClause *) |
A function to verify an single query expression. More... | |
Protected Member Functions | |
void | amplify (const ibis::part &) |
!< The expression tree. More... | |
Protected Attributes | |
std::string | clause_ |
ibis::qExpr * | expr_ |
!< String version of the where clause. | |
Friends | |
class | ibis::whereParser |
A representation of the where clause.
It parses a string into an ibis::qExpr object. One may access the functions defined for ibis::qExpr through the operator->.
A where clause is a set of range conditions joined together with logical operators. The supported logical operators are
The supported range conditions are equality conditions, discrete ranges, one-sided range conditions and two-sided range conditions.
An arithematic expression may contain operators +, -, *, /, %, ^, and **, as well as common one-argument and two-argument functions defined in the header file math.h. Both operators ^ and ** denote the exponential operation.
The following operations on text fields are also supported. For the purpose of query composition, they can be tought of as alternative form of discrete ranges.
Operator LIKE, e.g.,
Note that the regular expression can only contain wild characters % and _ per SQL standard. Internally, this is referred to as pattern matching and treats a string as a single atomic unit of data.
Operator CONTAINS, e.g.,
When multiple keywords are given, this operator is meant to look for rows containing all of the given keywords. Internally, this is referred to as keyword matching and treats a string field as a list of words. Typically, the column is of type TEXT and a KEYWORD index has been built on the column. Note that the KEYWORD index could take a user provided parser to extract the keywords.
This operator can work with set-valued data, in which case, each row of this column is a set but expressed as a string. The user provides a parser during the construction of the KEYWORD index to make sure the string is parsd into the correct elements of the sets. This expression is used to identify sets with the speicified list of elements.
Operator NOT NULL The only way to mention NULL values in a query expression is through this operator.
Note that there is no support for NULL as an operator. The way to select only NULL values is through (NOT column_name NOT NULL).
Time handling functions An integer valued column could be used to store Unix time stamps (i.e., seconds since beginning of 1970), in which case, it might be useful to perform comparison on day of the week or hours of a day in a where clause. To support such operations, four functions are provided.
– from_unixtime_local(timestamp, "format"): extract a number from the time stamp. The timestamp should be the name of column to be interpreted as Unix time stamps. The format string follows the convention of function strftime
from libc
. Note that this function actuall uses strftime
to extract the information in string form first and then interpret the leading portion of the string as a floating-point number. The tailing portion of the string that could not be interpreted as part of a floating-point number is ignored. If this process results no number at all, for example, strftime
prints the first date and time with an alphabet as the first character, then this function returns a NaN (Not-a-number).
This function assumes the time stamps are in the local time zone.
Note that the format string must be quoted.
– from_unixtime_gmt(timestamp, "format"): same functionality as from_unixtime_local, but assumes the time stamps are in time zone GMT/UTC.
Note that the format string must be quoted.
– to_unixtime_local("date-time-string", "format"): This function attempts to be the inverse of from_unixtime_local. It is a constant function at this time and only transform one specific time value to unix time stamp. Therefore this is only useful for generating a constant for bounding a unix time stamp.
– to_unixtime_gmt("date-time-string", "format"): the inverse of from_unixtime_gmt, but only works with a simple time constant.
void ibis::whereClause::addConditions | ( | const char * | cl | ) |
Append a set of conditions to the existing where clause.
The new conditions are joined together with the existing ones with the AND operator.
Referenced by ibis::query::addConditions().
void ibis::whereClause::addExpr | ( | const ibis::qExpr * | ex | ) |
Append a set of conditions to the existing where clause.
The new conditions are joined together with the existing ones with the AND operator.
References ibis::qExpr::dup().
Referenced by ibis::query::addConditions().
|
protected |
!< The expression tree.
Add conditions implied by self-join conditions.
References ibis::math::term::eval(), ibis::qExpr::findRange(), ibis::column::getActualMax(), ibis::column::getActualMin(), ibis::part::getColumn(), ibis::qExpr::getLeft(), ibis::qExpr::getRight(), ibis::qRange::leftBound(), ibis::qRange::restrictRange(), ibis::qRange::rightBound(), and ibis::qExpr::simplify().
|
inline |
Return a pointer to the root of the expression tree for the where clause.
References expr_.
Referenced by ibis::query::addConditions(), ibis::query::contractQuery(), ibis::query::countHits(), ibis::quaere::create(), ibis::query::estimate(), ibis::query::evaluate(), ibis::query::expandQuery(), ibis::query::getNumHits(), ibis::query::query(), ibis::query::setPartition(), ibis::query::setSelectClause(), ibis::countQuery::setWhereClause(), ibis::query::setWhereClause(), ibis::filter::sift(), ibis::filter::sift1(), ibis::filter::sift1S(), ibis::filter::sift2(), and ibis::filter::sift2S().
|
inline |
Return a pointer to the root of the expression tree for the where clause.
References expr_.
|
static |
Create a simple range expression as the replacement of the incoming oldr.
It replaces the name of the column if the incoming expression uses an alias. It replaces the negative query boundaries with 0 for unsigned integer columns.
References ibis::column::isUnsignedInteger(), ibis::qContinuousRange::leftBound(), ibis::column::name(), and ibis::qContinuousRange::rightBound().
|
inline |
Assign a new set of conditions directly.
The new set of conditions is copied here.
References ibis::qExpr::dup(), and expr_.
Referenced by ibis::table::select(), ibis::countQuery::setWhereClause(), and ibis::query::setWhereClause().
int ibis::whereClause::verify | ( | const ibis::part & | part0, |
const ibis::selectClause * | sel = 0 |
||
) | const |
Verify that the names exist in the data partition.
This function also simplifies the arithmetic expression if ibis::term::preserveInputExpression is not set and augment the expressions with implied conditions.
Referenced by ibis::query::addConditions(), ibis::countQuery::setPartition(), ibis::query::setPartition(), ibis::countQuery::setWhereClause(), and ibis::query::setWhereClause().
|
static |
A function to verify an single query expression.
This function checks each variable name specified in the query expression to make sure they all appear as column names of the given data partition. It returns the number of names NOT in the data partition.
It also removes the aliases and simplifies certain query expressions. For example, it converts expressions of the form "string1 = string2" to string lookups when one of the strings is a name of a string-valued column.
References ibis::selectClause::aggExpr(), ibis::selectClause::aggSize(), ibis::CATEGORY, ibis::qContinuousRange::colName(), ibis::qDiscreteRange::colName(), ibis::qAnyString::colName(), ibis::qLike::colName(), ibis::math::term::dup(), ibis::math::variable::dup(), ibis::selectClause::find(), ibis::FLOAT, ibis::selectClause::getAggregator(), ibis::part::getColumn(), ibis::column::getDictionary(), ibis::qExpr::getLeft(), ibis::qExpr::getRight(), ibis::qExpr::getType(), ibis::qDiscreteRange::getValues(), ibis::column::isFloat(), ibis::column::isInteger(), ibis::qContinuousRange::leftBound(), ibis::part::name(), ibis::column::name(), ibis::util::readDouble(), ibis::util::readInt(), ibis::qContinuousRange::rightBound(), ibis::TEXT, ibis::column::type(), ibis::TYPESTRING, ibis::UBYTE, and ibis::UINT.