Quadcap Embeddable Database

com.quadcap.sql.SelectExpression Class Reference

Inheritance diagram for com.quadcap.sql.SelectExpression:

com.quadcap.sql.TableExpression Externalizable com.quadcap.sql.Expression List of all members.

Detailed Description

A table expression representing a SELECT clause.

Author:
Stan Bailes

Definition at line 63 of file SelectExpression.java.

Public Member Functions

 SelectExpression ()
 Default constructor.

 SelectExpression (String tableName, Expression where)
 The typical 'select from table where' stuff.

Vector getFrom ()
 Get the FROM list.

void setDistinct (boolean b)
 Set the DISTINCT flag.

void setItems (Vector v)
 Set the select items (i.e., the colums returned from this select).

void setFrom (Vector v)
 Set the from list (a list of tables is implicitly joined).

void setGroupBy (Vector v)
 Set the GROUP BY clause as a list of names.

void setHaving (Expression e)
 Set the HAVING expression.

int rank ()
 We're a table.

boolean isUpdatable ()
 Well, a bunch of things can prevent us from being updateable.

Cursor getCursor (Session session, Cursor cur) throws SQLException
 This is the main entry point to this madness.

Value getValue (Session session, Cursor cur) throws SQLException
 Return the expression as a scalar value.

void getBaseTables (Vector v)
 Get the base tables that participate in this select expression.

void visitSubExpressions (ExpressionVisitor ev)
 Expression implementation...

void invert ()
 Nope, I'm not a boolean.

void readExternal (ObjectInput in) throws IOException, ClassNotFoundException
 Read me from a stream.

void writeExternal (ObjectOutput out) throws IOException
 Write me to a stream.

String toString ()
 Return a string representation for debugging purposes.

String name ()

Static Public Member Functions

final void showCursor (Cursor c)
 Display a cursor (under trace control).

void showCursor (Cursor c, boolean really)
 Display c cursor (or not).


Package Functions

TableExpression scheduleJoin () throws SQLException
 Cross-join multiple tables in 'from' clause.

boolean isAggregate (Session session, Vector items) throws SQLException
 Check the list of select items to see if any of them are aggregate expressions.

Cursor staticCursor (Session session, Cursor c, Vector items, Value v) throws SQLException
 Helper to create a cursor containing a single constant value.

Cursor optimizeAggregate (Session session, Cursor c, Vector items) throws SQLException
 Identify cases of MIN(column) or MAX(column) on indexed columns.


Package Attributes

boolean distinct = false
Vector items = null
Vector from = null
Vector groupBy = null
Expression having = null
Vector aggregates = null


Constructor & Destructor Documentation

com.quadcap.sql.SelectExpression.SelectExpression  ) 
 

Default constructor.

Definition at line 76 of file SelectExpression.java.

com.quadcap.sql.SelectExpression.SelectExpression String  tableName,
Expression  where
 

The typical 'select from table where' stuff.

Definition at line 81 of file SelectExpression.java.


Member Function Documentation

void com.quadcap.sql.SelectExpression.getBaseTables Vector  v  )  [virtual]
 

Get the base tables that participate in this select expression.

Implements com.quadcap.sql.TableExpression.

Definition at line 398 of file SelectExpression.java.

References com.quadcap.sql.SelectExpression.from, and com.quadcap.sql.SelectExpression.getBaseTables().

Referenced by com.quadcap.sql.SelectExpression.getBaseTables(), and com.quadcap.sql.StmtInsert.IsSelfInsert.visit().

Cursor com.quadcap.sql.SelectExpression.getCursor Session  session,
Cursor  cur
throws SQLException [virtual]
 

This is the main entry point to this madness.

Our handling of selects is fairly literal, and pretty brute force. Things work much better if there are appropriate indexes to use based on the query.....

Implements com.quadcap.sql.TableExpression.

Definition at line 170 of file SelectExpression.java.

References com.quadcap.sql.TupleImpl.addColumn(), com.quadcap.sql.SelectExpression.aggregates, com.quadcap.sql.SelectExpression.distinct, com.quadcap.sql.SelectExpression.from, com.quadcap.sql.SelectItem.getAsName(), com.quadcap.sql.TableExpression.getCursor(), com.quadcap.sql.SelectExpression.getCursor(), com.quadcap.sql.SelectItem.getExpression(), com.quadcap.sql.types.Value.getType(), com.quadcap.sql.Expression.getValue(), com.quadcap.sql.SelectExpression.groupBy, com.quadcap.sql.SelectExpression.having, com.quadcap.sql.SelectExpression.isAggregate(), com.quadcap.sql.SelectExpression.items, com.quadcap.sql.SelectExpression.name(), com.quadcap.sql.SelectExpression.optimizeAggregate(), com.quadcap.sql.SelectExpression.scheduleJoin(), com.quadcap.sql.Row.set(), com.quadcap.sql.Cursor.setOuterCursor(), com.quadcap.sql.TableExpression.setWhere(), and com.quadcap.sql.SelectExpression.showCursor().

Referenced by com.quadcap.sql.StmtDelete.execute(), and com.quadcap.sql.SelectExpression.getCursor().

Vector com.quadcap.sql.SelectExpression.getFrom  ) 
 

Get the FROM list.

Definition at line 91 of file SelectExpression.java.

References com.quadcap.sql.SelectExpression.from.

Value com.quadcap.sql.SelectExpression.getValue Session  session,
Cursor  cur
throws SQLException
 

Return the expression as a scalar value.

We try. If there's only a single column in the result, we just return the column's value for the first row of the result. Otherwise, return ValueNull.

Reimplemented from com.quadcap.sql.Expression.

Definition at line 376 of file SelectExpression.java.

References com.quadcap.sql.Cursor.close(), com.quadcap.sql.Cursor.getRow(), com.quadcap.sql.SelectExpression.getValue(), com.quadcap.sql.Row.item(), com.quadcap.sql.Cursor.next(), and com.quadcap.sql.Row.size().

Referenced by com.quadcap.sql.SelectExpression.getValue().

void com.quadcap.sql.SelectExpression.invert  ) 
 

Nope, I'm not a boolean.

Exceptions:
RuntimeException is thrown

Reimplemented from com.quadcap.sql.Expression.

Definition at line 438 of file SelectExpression.java.

boolean com.quadcap.sql.SelectExpression.isAggregate Session  session,
Vector  items
throws SQLException [package]
 

Check the list of select items to see if any of them are aggregate expressions.

(Side effect: set 'aggregates' variable.)

Definition at line 295 of file SelectExpression.java.

References com.quadcap.sql.SelectExpression.IsAggregate.aggregates, com.quadcap.sql.SelectItem.getExpression(), com.quadcap.sql.SelectExpression.groupBy, com.quadcap.sql.SelectExpression.isAggregate(), com.quadcap.sql.SelectExpression.items, com.quadcap.sql.SelectExpression.IsAggregate.reset(), com.quadcap.sql.SelectExpression.IsAggregate.seenAggregate, com.quadcap.sql.SelectExpression.IsAggregate.seenName, and com.quadcap.sql.SelectExpression.IsAggregate.visit().

Referenced by com.quadcap.sql.SelectExpression.getCursor(), and com.quadcap.sql.SelectExpression.isAggregate().

boolean com.quadcap.sql.SelectExpression.isUpdatable  )  [virtual]
 

Well, a bunch of things can prevent us from being updateable.

Here are the ones we know about:

Implements com.quadcap.sql.TableExpression.

Definition at line 129 of file SelectExpression.java.

References com.quadcap.sql.SelectExpression.aggregates, com.quadcap.sql.SelectExpression.distinct, com.quadcap.sql.SelectExpression.from, com.quadcap.sql.SelectExpression.groupBy, com.quadcap.sql.SelectExpression.having, and com.quadcap.sql.TableExpression.isUpdatable().

String com.quadcap.sql.SelectExpression.name  )  [virtual]
 

Implements com.quadcap.sql.TableExpression.

Definition at line 534 of file SelectExpression.java.

References com.quadcap.sql.SelectExpression.toString().

Referenced by com.quadcap.sql.SelectExpression.getCursor().

Cursor com.quadcap.sql.SelectExpression.optimizeAggregate Session  session,
Cursor  c,
Vector  items
throws SQLException [package]
 

Identify cases of MIN(column) or MAX(column) on indexed columns.

Compute the value directly and replace the index cursor with a static cursor containing the value.

Definition at line 332 of file SelectExpression.java.

References com.quadcap.sql.AggregateExpression.all, com.quadcap.sql.Cursor.close(), com.quadcap.sql.Constraint.getColumn(), com.quadcap.sql.IndexCursor.getConstraint(), com.quadcap.sql.SelectItem.getExpression(), com.quadcap.sql.AggregateExpression.getInnerExpression(), com.quadcap.sql.Column.getName(), com.quadcap.sql.NameExpression.getName(), com.quadcap.sql.AggregateExpression.isCount(), com.quadcap.sql.AggregateExpression.isMax(), com.quadcap.sql.AggregateExpression.isMin(), com.quadcap.sql.Row.item(), com.quadcap.sql.SelectExpression.items, and com.quadcap.sql.SelectExpression.optimizeAggregate().

Referenced by com.quadcap.sql.SelectExpression.getCursor(), and com.quadcap.sql.SelectExpression.optimizeAggregate().

int com.quadcap.sql.SelectExpression.rank  )  [virtual]
 

We're a table.

Implements com.quadcap.sql.TableExpression.

Definition at line 123 of file SelectExpression.java.

void com.quadcap.sql.SelectExpression.readExternal ObjectInput  in  )  throws IOException, ClassNotFoundException
 

Read me from a stream.

Definition at line 446 of file SelectExpression.java.

References com.quadcap.sql.SelectExpression.readExternal().

Referenced by com.quadcap.sql.SelectExpression.readExternal().

TableExpression com.quadcap.sql.SelectExpression.scheduleJoin  )  throws SQLException [package]
 

Cross-join multiple tables in 'from' clause.

TODO: First, tables which have selection constraintsfind pairs of tables that have candidate join columns and greedily join them. Next, pick tables which have matching non-key join columns and join them Finally, join all the rest.

Definition at line 151 of file SelectExpression.java.

References com.quadcap.sql.SelectExpression.from.

Referenced by com.quadcap.sql.SelectExpression.getCursor().

void com.quadcap.sql.SelectExpression.setDistinct boolean  b  ) 
 

Set the DISTINCT flag.

Definition at line 98 of file SelectExpression.java.

References com.quadcap.sql.SelectExpression.setDistinct().

Referenced by com.quadcap.sql.SQLParser.querySpecification(), and com.quadcap.sql.SelectExpression.setDistinct().

void com.quadcap.sql.SelectExpression.setFrom Vector  v  ) 
 

Set the from list (a list of tables is implicitly joined).

Definition at line 108 of file SelectExpression.java.

References com.quadcap.sql.SelectExpression.setFrom().

Referenced by com.quadcap.sql.SQLParser.querySpecification(), and com.quadcap.sql.SelectExpression.setFrom().

void com.quadcap.sql.SelectExpression.setGroupBy Vector  v  ) 
 

Set the GROUP BY clause as a list of names.

Definition at line 113 of file SelectExpression.java.

References com.quadcap.sql.SelectExpression.setGroupBy().

Referenced by com.quadcap.sql.SQLParser.querySpecification(), and com.quadcap.sql.SelectExpression.setGroupBy().

void com.quadcap.sql.SelectExpression.setHaving Expression  e  ) 
 

Set the HAVING expression.

Definition at line 118 of file SelectExpression.java.

References com.quadcap.sql.SelectExpression.setHaving().

Referenced by com.quadcap.sql.SQLParser.querySpecification(), and com.quadcap.sql.SelectExpression.setHaving().

void com.quadcap.sql.SelectExpression.setItems Vector  v  ) 
 

Set the select items (i.e., the colums returned from this select).

Definition at line 103 of file SelectExpression.java.

References com.quadcap.sql.SelectExpression.setItems().

Referenced by com.quadcap.sql.SQLParser.querySpecification(), and com.quadcap.sql.SelectExpression.setItems().

void com.quadcap.sql.SelectExpression.showCursor Cursor  c,
boolean  really
[static]
 

Display c cursor (or not).

Definition at line 524 of file SelectExpression.java.

final void com.quadcap.sql.SelectExpression.showCursor Cursor  c  )  [static]
 

Display a cursor (under trace control).

Definition at line 511 of file SelectExpression.java.

References com.quadcap.sql.SelectExpression.showCursor().

Referenced by com.quadcap.sql.SelectExpression.getCursor(), and com.quadcap.sql.SelectExpression.showCursor().

Cursor com.quadcap.sql.SelectExpression.staticCursor Session  session,
Cursor  c,
Vector  items,
Value  v
throws SQLException [package]
 

Helper to create a cursor containing a single constant value.

Definition at line 318 of file SelectExpression.java.

References com.quadcap.sql.SelectExpression.items, com.quadcap.sql.Row.set(), and com.quadcap.sql.SelectExpression.staticCursor().

Referenced by com.quadcap.sql.SelectExpression.staticCursor().

String com.quadcap.sql.SelectExpression.toString  )  [virtual]
 

Return a string representation for debugging purposes.

Implements com.quadcap.sql.Expression.

Definition at line 472 of file SelectExpression.java.

References com.quadcap.sql.SelectExpression.from, com.quadcap.sql.SelectExpression.groupBy, com.quadcap.sql.SelectExpression.having, com.quadcap.sql.SelectExpression.items, and com.quadcap.sql.Expression.toString().

Referenced by com.quadcap.sql.SelectExpression.name().

void com.quadcap.sql.SelectExpression.visitSubExpressions ExpressionVisitor  ev  ) 
 

Expression implementation...

Reimplemented from com.quadcap.sql.Expression.

Definition at line 407 of file SelectExpression.java.

References com.quadcap.sql.ExpressionVisitor.visit(), and com.quadcap.sql.SelectExpression.visitSubExpressions().

Referenced by com.quadcap.sql.SelectExpression.visitSubExpressions().

void com.quadcap.sql.SelectExpression.writeExternal ObjectOutput  out  )  throws IOException
 

Write me to a stream.

Definition at line 460 of file SelectExpression.java.

References com.quadcap.sql.SelectExpression.distinct, com.quadcap.sql.SelectExpression.from, com.quadcap.sql.SelectExpression.groupBy, com.quadcap.sql.SelectExpression.having, com.quadcap.sql.SelectExpression.items, and com.quadcap.sql.SelectExpression.writeExternal().

Referenced by com.quadcap.sql.SelectExpression.writeExternal().


Member Data Documentation

Vector com.quadcap.sql.SelectExpression.aggregates = null [package]
 

Definition at line 71 of file SelectExpression.java.

Referenced by com.quadcap.sql.SelectExpression.getCursor(), and com.quadcap.sql.SelectExpression.isUpdatable().

boolean com.quadcap.sql.SelectExpression.distinct = false [package]
 

Definition at line 66 of file SelectExpression.java.

Referenced by com.quadcap.sql.SelectExpression.getCursor(), com.quadcap.sql.SelectExpression.isUpdatable(), and com.quadcap.sql.SelectExpression.writeExternal().

Vector com.quadcap.sql.SelectExpression.from = null [package]
 

Definition at line 68 of file SelectExpression.java.

Referenced by com.quadcap.sql.SelectExpression.getBaseTables(), com.quadcap.sql.SelectExpression.getCursor(), com.quadcap.sql.SelectExpression.getFrom(), com.quadcap.sql.SelectExpression.isUpdatable(), com.quadcap.sql.SelectExpression.scheduleJoin(), com.quadcap.sql.SelectExpression.toString(), and com.quadcap.sql.SelectExpression.writeExternal().

Vector com.quadcap.sql.SelectExpression.groupBy = null [package]
 

Definition at line 69 of file SelectExpression.java.

Referenced by com.quadcap.sql.SelectExpression.getCursor(), com.quadcap.sql.SelectExpression.isAggregate(), com.quadcap.sql.SelectExpression.isUpdatable(), com.quadcap.sql.SelectExpression.toString(), and com.quadcap.sql.SelectExpression.writeExternal().

Expression com.quadcap.sql.SelectExpression.having = null [package]
 

Definition at line 70 of file SelectExpression.java.

Referenced by com.quadcap.sql.SelectExpression.getCursor(), com.quadcap.sql.SelectExpression.isUpdatable(), com.quadcap.sql.SelectExpression.toString(), and com.quadcap.sql.SelectExpression.writeExternal().

Vector com.quadcap.sql.SelectExpression.items = null [package]
 

Definition at line 67 of file SelectExpression.java.

Referenced by com.quadcap.sql.SelectExpression.getCursor(), com.quadcap.sql.SelectExpression.isAggregate(), com.quadcap.sql.SelectExpression.optimizeAggregate(), com.quadcap.sql.SelectExpression.staticCursor(), com.quadcap.sql.SelectExpression.toString(), and com.quadcap.sql.SelectExpression.writeExternal().