org.teiid.query.sql.symbol
Class AggregateSymbol

java.lang.Object
  extended by org.teiid.query.sql.symbol.Symbol
      extended by org.teiid.query.sql.symbol.SelectSymbol
          extended by org.teiid.query.sql.symbol.SingleElementSymbol
              extended by org.teiid.query.sql.symbol.ExpressionSymbol
                  extended by org.teiid.query.sql.symbol.AggregateSymbol
All Implemented Interfaces:
java.lang.Cloneable, LanguageObject, Expression

public class AggregateSymbol
extends ExpressionSymbol

An aggregate symbol represents an aggregate function in the SELECT or HAVING clauses. It extends ExpressionSymbol as they have many things in common. The aggregate symbol is typically something like SUM(stock.quantity * 2). There are five supported aggregate functions: COUNT, SUM, AVG, MIN, and MAX. Aggregate functions contain an expression - this data is managed by the super class, ExpressionSymbol. Aggregate functions may also specify a DISTINCT flag to indicate that duplicates should be ignored. The DISTINCT flag may be set for all five aggregate functions but is ignored for the computation of MIN and MAX. One special use of an aggregate symbol is for the symbol COUNT(*). The * expression is encoded by setting the expression to null. This may ONLY be used with the COUNT function.

The type of an aggregate symbol depends on the function and the type of the underlying expression. The type of a COUNT function is ALWAYS integer. MIN and MAX functions take the type of their contained expression. AVG and SUM vary depending on the type of the expression. If the expression is of a type other than biginteger, the aggregate function returns type long. For the case of biginteger, the aggregate function returns type biginteger. Similarly, all floating point expressions not of type bigdecimal return type double and bigdecimal maps to bigdecimal.


Nested Class Summary
static class AggregateSymbol.Type
           
 
Nested classes/interfaces inherited from interface org.teiid.query.sql.LanguageObject
LanguageObject.Util
 
Field Summary
 
Fields inherited from class org.teiid.query.sql.symbol.SingleElementSymbol
SEPARATOR
 
Constructor Summary
protected AggregateSymbol(java.lang.String name, java.lang.String canonicalName, AggregateSymbol.Type aggregateFunction, boolean isDistinct, Expression expression)
          Constructor used for cloning
  AggregateSymbol(java.lang.String name, java.lang.String aggregateFunction, boolean isDistinct, Expression expression)
          Construct an aggregate symbol with all given data.
 
Method Summary
 void acceptVisitor(LanguageVisitor visitor)
          Method for accepting a visitor.
 java.lang.Object clone()
          Return a deep copy of this object
 boolean equals(java.lang.Object obj)
          ExpressionSymbol matching is not based upon the name
 AggregateSymbol.Type getAggregateFunction()
          Get the aggregate function type - this will map to one of the reserved words for the aggregate functions.
 OrderBy getOrderBy()
           
 java.lang.Class<?> getType()
          Get the type of the symbol, which depends on the aggregate function and the type of the contained expression
 int hashCode()
          Return a hash code for this symbol.
 boolean isBoolean()
           
 boolean isDistinct()
          Get the distinct flag.
 boolean isEnhancedNumeric()
           
 void setAggregateFunction(AggregateSymbol.Type aggregateFunction)
          Set the aggregate function.
 void setOrderBy(OrderBy orderBy)
           
 
Methods inherited from class org.teiid.query.sql.symbol.ExpressionSymbol
getExpression, isDerivedExpression, isResolved, setDerivedExpression, setExpression
 
Methods inherited from class org.teiid.query.sql.symbol.SingleElementSymbol
getShortCanonicalName, getShortName, getShortName
 
Methods inherited from class org.teiid.query.sql.symbol.Symbol
getCanonical, getCanonicalName, getName, getOutputName, setName, setOutputName, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AggregateSymbol

protected AggregateSymbol(java.lang.String name,
                          java.lang.String canonicalName,
                          AggregateSymbol.Type aggregateFunction,
                          boolean isDistinct,
                          Expression expression)
Constructor used for cloning

Parameters:
name -
canonicalName -
Since:
4.3

AggregateSymbol

public AggregateSymbol(java.lang.String name,
                       java.lang.String aggregateFunction,
                       boolean isDistinct,
                       Expression expression)
Construct an aggregate symbol with all given data.

Parameters:
name - Name of the function
aggregateFunction - Aggregate function type (SQLConstants.NonReserved.COUNT, etc)
isDistinct - True if DISTINCT flag is set
expression - Contained expression
Method Detail

setAggregateFunction

public void setAggregateFunction(AggregateSymbol.Type aggregateFunction)
Set the aggregate function. If the aggregate function is an invalid value, an IllegalArgumentException is thrown.

Parameters:
aggregateFunction - Aggregate function type
See Also:
SQLConstants.NonReserved.COUNT, SQLConstants.NonReserved.SUM, SQLConstants.NonReserved.AVG, SQLConstants.NonReserved.MIN, SQLConstants.NonReserved.MAX

getAggregateFunction

public AggregateSymbol.Type getAggregateFunction()
Get the aggregate function type - this will map to one of the reserved words for the aggregate functions.

Returns:
Aggregate function type

isDistinct

public boolean isDistinct()
Get the distinct flag. If true, aggregate symbol will remove duplicates during computation.

Returns:
True if duplicates should be removed during computation

getType

public java.lang.Class<?> getType()
Get the type of the symbol, which depends on the aggregate function and the type of the contained expression

Specified by:
getType in interface Expression
Overrides:
getType in class ExpressionSymbol
Returns:
Type of the symbol

isBoolean

public boolean isBoolean()

isEnhancedNumeric

public boolean isEnhancedNumeric()

acceptVisitor

public void acceptVisitor(LanguageVisitor visitor)
Description copied from interface: LanguageObject
Method for accepting a visitor. It is the responsibility of the language object to call back on the visitor.

Specified by:
acceptVisitor in interface LanguageObject
Overrides:
acceptVisitor in class ExpressionSymbol
Parameters:
visitor - Visitor being used

getOrderBy

public OrderBy getOrderBy()

setOrderBy

public void setOrderBy(OrderBy orderBy)

clone

public java.lang.Object clone()
Return a deep copy of this object

Specified by:
clone in interface LanguageObject
Overrides:
clone in class ExpressionSymbol
Returns:
Deep copy of this object

hashCode

public int hashCode()
Description copied from class: Symbol
Return a hash code for this symbol.

Overrides:
hashCode in class ExpressionSymbol
Returns:
Hash code
See Also:
ExpressionSymbol.hashCode()

equals

public boolean equals(java.lang.Object obj)
Description copied from class: ExpressionSymbol
ExpressionSymbol matching is not based upon the name

Overrides:
equals in class ExpressionSymbol
Parameters:
obj - Other object
Returns:
True if other obj is a Symbol (or subclass) and name is equal
See Also:
ExpressionSymbol.equals(java.lang.Object)


Copyright © 2010. All Rights Reserved.