com.endeca.navigation.analytics
Class Statement

java.lang.Object
  extended by com.endeca.navigation.analytics.Statement
All Implemented Interfaces:
QueryNode

public class Statement
extends Object
implements QueryNode

A Statement represents a pass over a set of input records (those of the FROM table) to generate a set of output records. Input records and output records may be filtered; output records are populated with derived values, and with values by which the records are GROUPed. The output record set may be sorted and paged.

A Statement has the form:

RETURN {table-name} AS // required: or DEFINE: see setShown()
SELECT // required
{expr1} AS {field1}, // required: at least one assignment.
{expr2} AS {field2},
...
FROM {input-table-name} // optional
WHERE {filter} // optional
GROUP // optional: or GROUP BY {field}, {field},...
HAVING {filter} // optional
ORDER BY {field},{field}... // optional
PAGE({start}, {end}) // optional
Note that NavStateRecords and AllBaseRecords are reserved table names. NavStateRecords is the default if the FROM clause is omitted.


Constructor Summary
Statement()
          Constructs a new, empty Statement, which in its initial state will act as a simple pass-through of records.
 
Method Summary
 int getFirstPage()
          If the Statement is paged, returns the first row-number requested.
 String getFromStatementName()
          Gets the name of the FROM statement.
 GroupByList getGroupByList()
          Gets the GroupByList for this Statement.
 Filter getHavingFilter()
          Gets the "HAVING clause" Filter for this Statement.
 String getName()
          Gets the name of the current Statement.
 OrderByList getOrderByList()
          Gets the OrderByList for this Statement.
 int getPagesRequested()
          If the Statement is paged, returns the number of rows requested.
 SelectList getSelectList()
          Gets the list of Select operations for this Statement.
 Filter getWhereFilter()
          Gets the "WHERE clause" Filter for this Statement.
 boolean isPaged()
          Tests whether this Statement is paged.
 boolean isShown()
          Tests whether the Statement is a Return or Define Statement.
 void setFromStatementName(String name)
          Specifies the name of the statement whose records are scanned as input to the current Statement.
 void setGroupByList(GroupByList groupByList)
          Sets the GroupByList for this Statement.
 void setHavingFilter(Filter filter)
          Adds a "HAVING clause" to this Statement.
 void setName(String _name)
          Sets the name of the current Statement.
 void setOrderByList(OrderByList orderByList)
          Sets the OrderByList for this Statement.
 void setReturnRows(int first, int num)
          Sets the paging parameters for the Statement.
 void setSelectList(SelectList selectList)
          Sets the list of Select expressions for this Statement.
 void setShown(boolean show)
          Specifies whether the Statement is Return or Define.
 void setWhereFilter(Filter filter)
          Adds the "WHERE clause" for this Statement.
 String toString()
          Returns the string form of this Statement.
 String toWire()
          Prints the wire format of this Statement.
 void validateSyntax()
          Validates the syntax of this Statement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Statement

public Statement()
Constructs a new, empty Statement, which in its initial state will act as a simple pass-through of records.

Method Detail

setReturnRows

public void setReturnRows(int first,
                          int num)
Sets the paging parameters for the Statement. After ordering, records with index less than first or greater or equal to first + num will be discarded. Calling this method sets the paged setting of the Statement to true.

Parameters:
first - the first row-number requested.
num - the number of rows requested.

isPaged

public boolean isPaged()
Tests whether this Statement is paged. A Statement is paged if the application only wants a subset of the records that the Statement computes.

By default, the paged setting is false. Calling setReturnRows sets paged to true.

Returns:
true if this Statement is paged, false otherwise.

getFirstPage

public int getFirstPage()
If the Statement is paged, returns the first row-number requested.

Returns:
An integer representing the first row-number requested. If the Statement is not paged, 0 is returned.

getPagesRequested

public int getPagesRequested()
If the Statement is paged, returns the number of rows requested.

Returns:
An integer representing the number of rows requested. Returns 0 if the Statement is not paged.

setFromStatementName

public void setFromStatementName(String name)
Specifies the name of the statement whose records are scanned as input to the current Statement.

Parameters:
name - a String representing the name of the statement

getFromStatementName

public String getFromStatementName()
Gets the name of the FROM statement. The FROM statement is the statement whose records are the input for this Statement. Note that the return value may be null; when the Statement is computed, a missing FROM clause is interpreted as "FROM NavStateRecords".

Returns:
A String representing the FROM statement whose records are the input for this Statement, or null if no name exists.

setName

public void setName(String _name)
Sets the name of the current Statement. Once the query is sent to the MDEX Engine and a response is returned, this name must be used as the parameter to the Navigation.getAnalyticsStatementResult(String) method to obtain an AnalyticsStatementResult containing the records associated with the Statement.

Parameters:
_name - a String representing the name of the current Statement

getName

public String getName()
Gets the name of the current Statement. The name must be non-null in order for the Statement to be syntactically valid.

Returns:
A String representing the name of the current Statement, or null if no name has been set.

setShown

public void setShown(boolean show)
Specifies whether the Statement is Return or Define. Return means that the results should be returned to the client, while Define means that it will only be used to compute other results.

Parameters:
show - true to specify a Return statement or false to specify a Define statement

isShown

public boolean isShown()
Tests whether the Statement is a Return or Define Statement.

Returns:
true if the current Statement is a Return statement (indicates that the application wants to see its result records), or false if it is a Define statement (indicates that it is only used as an intermediate calculation).

setSelectList

public void setSelectList(SelectList selectList)
Sets the list of Select expressions for this Statement. Each Select associates a derived value with each result aggregated record produced by this Statement.

Parameters:
selectList - a SelectList containing the Select expressions for this Statement

getSelectList

public SelectList getSelectList()
Gets the list of Select operations for this Statement. Each Select associates a derived value with each result aggregated record produced by this Statement.

Returns:
A SelectList containing the Select expressions for this Statement.

setWhereFilter

public void setWhereFilter(Filter filter)
Adds the "WHERE clause" for this Statement. A "WHERE clause" acts as a filter on input records that will be grouped into result aggregates. In other words, this method specifies a pre-filter for this Statement.

Parameters:
filter - a Filter containing the "WHERE clause" for this Statement

getWhereFilter

public Filter getWhereFilter()
Gets the "WHERE clause" Filter for this Statement. The "WHERE clause" acts as a filter on input records that will be grouped into result aggregates. In other words, it specifies a pre-filter for this Statement.

Returns:
A Filter containing the "WHERE clause" for this Statement.

setHavingFilter

public void setHavingFilter(Filter filter)
Adds a "HAVING clause" to this Statement. A "HAVING clause" acts as a filter on output aggregated records. In other words, this method specifies a post-filter for this Statement.

Parameters:
filter - a Filter containing the "HAVING clause" for this Statement

getHavingFilter

public Filter getHavingFilter()
Gets the "HAVING clause" Filter for this Statement. The "HAVING clause" acts as a filter on result aggregated records. In other words, it specifies a post-filter for this Statement.

Returns:
A Filter containing the "HAVING clause" for this Statement.

setGroupByList

public void setGroupByList(GroupByList groupByList)
Sets the GroupByList for this Statement. The GroupByList determines the way that input records are grouped into result aggregated records. Basically, each GroupBy in the specified GroupByList represents a grouping property or dimension, and input records are assigned to a resulting aggregate based on their values for these properties and dimensions. Note that if an empty GroupByList is attached to a Statement, it indicates that the input records will be GROUPed to a single record.

Parameters:
groupByList - a GroupByList that is either empty or contains GroupBy instances.

getGroupByList

public GroupByList getGroupByList()
Gets the GroupByList for this Statement. See the setGroupByList method for an explanation of the purpose of the GroupByList.

Returns:
A GroupByList that is either empty (code>null) or contains GroupBy instances.

setOrderByList

public void setOrderByList(OrderByList orderByList)
Sets the OrderByList for this Statement. The list of OrderBy specifications for the Statement determines the order in which result aggregated records will be returned, and determines the ranks of result aggregated records used by paging controls associated with GroupBy specifications.

Parameters:
orderByList - an OrderByList that contains one or more OrderBy instances. Note that the OrderByList cannot be empty.

getOrderByList

public OrderByList getOrderByList()
Gets the OrderByList for this Statement. The list of OrderBy specifications for the Statement determines the order in which result aggregated records will be returned, and determines the ranks of result aggregated records used by paging controls associated with GroupBy specifications.

Returns:
An OrderByList that contains one or more OrderBy instances.

toString

public String toString()
Returns the string form of this Statement. See the class comments for the format of the Statement.

Specified by:
toString in interface QueryNode
Overrides:
toString in class Object
Returns:
A string representation of the Statement in the specified format.

toWire

public String toWire()
Prints the wire format of this Statement. This method is not intended for public use because the wire format is subject to change.

Specified by:
toWire in interface QueryNode

validateSyntax

public void validateSyntax()
                    throws SyntaxException
Validates the syntax of this Statement. A Statement is valid if (1) the table-name is non-null and non-empty, (2) the SelectList is non-null and valid, and (3) if any of whereFilter, havingFilter, groupByList, and orderByList are non-null, they must be valid.

Specified by:
validateSyntax in interface QueryNode
Throws:
SyntaxException - if the syntax requirements are not satisfied.


2010 Endeca Technologies, Inc.
Endeca Confidential