com.akiban.sql.compiler
Class TypeCompiler

java.lang.Object
  extended by com.akiban.sql.compiler.TypeCompiler
Direct Known Subclasses:
BitTypeCompiler, BooleanTypeCompiler, CharTypeCompiler, CLOBTypeCompiler, DateTypeCompiler, IntervalTypeCompiler, LOBTypeCompiler, NumericTypeCompiler, RefTypeCompiler, TimestampTypeCompiler, TimeTypeCompiler, UserDefinedTypeCompiler, XMLTypeCompiler

public abstract class TypeCompiler
extends Object

This interface defines methods associated with a TypeId that are used by the compiler.


Field Summary
static String AVG_OP
           
static int BOOLEAN_MAXWIDTH_AS_CHAR
           
static String DIV_OP
           
static String DIVIDE_OP
           
static int DOUBLE_MAXWIDTH_AS_CHAR
           
static int INT_MAXWIDTH_AS_CHAR
           
static int LONGINT_MAXWIDTH_AS_CHAR
          Various fixed numbers related to datatypes.
static String MINUS_OP
           
static String MOD_OP
           
static String PLUS_OP
           
static int REAL_MAXWIDTH_AS_CHAR
           
static int SMALLINT_MAXWIDTH_AS_CHAR
           
static String SUM_OP
           
static String TIMES_OP
           
static int TINYINT_MAXWIDTH_AS_CHAR
           
 
Constructor Summary
protected TypeCompiler(TypeId typeId)
           
 
Method Summary
abstract  boolean compatible(TypeId otherType)
          Determine if this type is compatible to some other type (e.g.
abstract  boolean convertible(TypeId otherType, boolean forDataTypeFunction)
          Determine if this type can be CONVERTed to some other type
abstract  int getCastToCharWidth(DataTypeDescriptor dtd)
          Return the maximum width for this data type when cast to a char type.
abstract  String getCorrespondingPrimitiveTypeName()
          Get the name of the corresponding Java type.
abstract  String getPrimitiveMethodName()
          Get the method name for getting out the corresponding primitive Java type from a DataValueDescriptor.
protected  int getStoredFormatIdFromTypeId()
          Get the format id from the corresponding TypeId.
static TypeCompiler getTypeCompiler(TypeId typeId)
          Get the TypeCompiler that corresponds to the given TypeId.
 TypeId getTypeId()
           
protected  boolean numberConvertible(TypeId otherType, boolean forDataTypeFunction)
          Tell whether this numeric type can be converted to the given type.
 DataTypeDescriptor resolveArithmeticOperation(DataTypeDescriptor leftType, DataTypeDescriptor rightType, String operator)
          Type resolution methods on binary operators
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LONGINT_MAXWIDTH_AS_CHAR

public static final int LONGINT_MAXWIDTH_AS_CHAR
Various fixed numbers related to datatypes.

See Also:
Constant Field Values

INT_MAXWIDTH_AS_CHAR

public static final int INT_MAXWIDTH_AS_CHAR
See Also:
Constant Field Values

SMALLINT_MAXWIDTH_AS_CHAR

public static final int SMALLINT_MAXWIDTH_AS_CHAR
See Also:
Constant Field Values

TINYINT_MAXWIDTH_AS_CHAR

public static final int TINYINT_MAXWIDTH_AS_CHAR
See Also:
Constant Field Values

DOUBLE_MAXWIDTH_AS_CHAR

public static final int DOUBLE_MAXWIDTH_AS_CHAR
See Also:
Constant Field Values

REAL_MAXWIDTH_AS_CHAR

public static final int REAL_MAXWIDTH_AS_CHAR
See Also:
Constant Field Values

BOOLEAN_MAXWIDTH_AS_CHAR

public static final int BOOLEAN_MAXWIDTH_AS_CHAR
See Also:
Constant Field Values

PLUS_OP

public static final String PLUS_OP
See Also:
Constant Field Values

DIVIDE_OP

public static final String DIVIDE_OP
See Also:
Constant Field Values

DIV_OP

public static final String DIV_OP
See Also:
Constant Field Values

MINUS_OP

public static final String MINUS_OP
See Also:
Constant Field Values

TIMES_OP

public static final String TIMES_OP
See Also:
Constant Field Values

SUM_OP

public static final String SUM_OP
See Also:
Constant Field Values

AVG_OP

public static final String AVG_OP
See Also:
Constant Field Values

MOD_OP

public static final String MOD_OP
See Also:
Constant Field Values
Constructor Detail

TypeCompiler

protected TypeCompiler(TypeId typeId)
Method Detail

getTypeId

public TypeId getTypeId()

resolveArithmeticOperation

public DataTypeDescriptor resolveArithmeticOperation(DataTypeDescriptor leftType,
                                                     DataTypeDescriptor rightType,
                                                     String operator)
                                              throws StandardException
Type resolution methods on binary operators

Parameters:
leftType - The type of the left parameter
rightType - The type of the right parameter
operator - The name of the operator (e.g. "+").
Returns:
The type of the result
Throws:
StandardException - Thrown on error

convertible

public abstract boolean convertible(TypeId otherType,
                                    boolean forDataTypeFunction)
Determine if this type can be CONVERTed to some other type

Parameters:
otherType - The CompilationType of the other type to compare this type to
forDataTypeFunction - true if this is a type function that requires more liberal behavior (e.g DOUBLE can convert a char but you cannot cast a CHAR to double.
Returns:
true if the types can be converted, false if conversion is not allowed

numberConvertible

protected boolean numberConvertible(TypeId otherType,
                                    boolean forDataTypeFunction)
Tell whether this numeric type can be converted to the given type.

Parameters:
otherType - The TypeId of the other type.
forDataTypeFunction - was this called from a scalarFunction like CHAR() or DOUBLE()

compatible

public abstract boolean compatible(TypeId otherType)
Determine if this type is compatible to some other type (e.g. COALESCE(thistype, othertype)).

Parameters:
otherType - The CompilationType of the other type to compare this type to
Returns:
true if the types are compatible, false if not compatible

getCorrespondingPrimitiveTypeName

public abstract String getCorrespondingPrimitiveTypeName()
Get the name of the corresponding Java type. For numerics and booleans we will get the corresponding Java primitive type. e Each SQL type has a corresponding Java type. When a SQL value is passed to a Java method, it is translated to its corresponding Java type. For example, a SQL Integer will be mapped to a Java int, but a SQL date will be mapped to a java.sql.Date.

Returns:
The name of the corresponding Java primitive type.

getPrimitiveMethodName

public abstract String getPrimitiveMethodName()
Get the method name for getting out the corresponding primitive Java type from a DataValueDescriptor.

Returns:
String The method call name for getting the corresponding primitive Java type.

getCastToCharWidth

public abstract int getCastToCharWidth(DataTypeDescriptor dtd)
Return the maximum width for this data type when cast to a char type.

Parameters:
dtd - The associated DataTypeDescriptor for this TypeId.
Returns:
int The maximum width for this data type when cast to a char type.

getStoredFormatIdFromTypeId

protected int getStoredFormatIdFromTypeId()
Get the format id from the corresponding TypeId.

Returns:
The format from the corresponding TypeId.
See Also:
TypeId.FormatIds

getTypeCompiler

public static TypeCompiler getTypeCompiler(TypeId typeId)
Get the TypeCompiler that corresponds to the given TypeId.



Copyright © 2013 Akiban Technologies, Inc. All rights reserved.