net.sf.saffron.rex
Class RexBuilder

java.lang.Object
  |
  +--net.sf.saffron.rex.RexBuilder
Direct Known Subclasses:
JavaRexBuilder

public class RexBuilder
extends Object

Factory for row expressions.

Some common literal values (NULL, TRUE, FALSE, 0, 1, '') are cached.

Since:
Nov 23, 2003
Version:
$Id: $
Author:
jhyde

Field Summary
private  RexLiteral booleanFalse
           
private  RexLiteral booleanTrue
           
private  RexLiteral constantNull
           
private  RexLiteral integerOne
           
private  RexLiteral integerZero
           
 SqlOperatorTable operatorTable
           
protected  SaffronTypeFactory typeFactory
           
private  RexLiteral varcharEmpty
           
 
Constructor Summary
protected RexBuilder(SaffronTypeFactory typeFactory)
           
 
Method Summary
 RexLiteral constantNull()
          Creates a constant for the SQL NULL value.
 SqlOperator getOperator(RexKind kind, RexNode[] args)
          Chooses an appropriate operator to implement a RexKind, given a specific number and types of arguments.
 SaffronTypeFactory getTypeFactory()
           
private  SaffronType[] getTypes(RexNode[] exprs)
           
 RexNode makeCall(RexKind kind, RexNode arg0)
          Creates a call with 1 argument, converting a RexKind to an appropriate SqlOperator.
 RexNode makeCall(RexKind kind, RexNode[] args)
          Creates a call with an array of arguments, converting a RexKind to an appropriate SqlOperator.
 RexNode makeCall(RexKind kind, RexNode arg0, RexNode arg1)
          Creates a call with 2 arguments, converting a RexKind to an appropriate SqlOperator.
 RexNode makeCall(SqlOperator op, RexNode[] exprs)
          Creates a call with an array of arguments.
 RexNode makeCall(SqlOperator op, RexNode expr0, RexNode expr1)
          Creates a call with 2 arguments.
 RexNode makeCast(SaffronType type, RexNode exp)
           
 RexNode makeCorrel(SaffronType type, String name)
           
 RexNode makeFieldAccess(RexNode expr, int i)
           
 RexNode makeFieldAccess(RexNode expr, String fieldName)
           
private  RexNode makeFieldAccessInternal(RexNode expr, SaffronField field)
           
 RexNode makeInputRef(SaffronType type, int i)
           
 RexLiteral makeLiteral(boolean b)
          Creates a boolean literal.
 RexLiteral makeLiteral(Date date)
          Creates a Date literal.
 RexLiteral makeLiteral(double d)
          Creates a double-precision literal.
 RexLiteral makeLiteral(long i)
          Creates an integer literal.
protected  RexLiteral makeLiteral(Object o, SaffronType type)
           
 RexLiteral makeLiteral(String s)
          Creates a varchar literal.
 RexLiteral makeLiteral(Time time)
          Creates a Time literal.
 RexLiteral makeLiteral(Timestamp timestamp)
          Creates a Timestamp literal.
 RexNode makeRangeReference(SaffronType rowType)
          Creates a reference to all the fields in the row.
 RexNode makeRangeReference(SaffronType type, int i)
          Creates a reference to all the fields in the row.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

typeFactory

protected final SaffronTypeFactory typeFactory

booleanTrue

private final RexLiteral booleanTrue

booleanFalse

private final RexLiteral booleanFalse

integerZero

private final RexLiteral integerZero

integerOne

private final RexLiteral integerOne

varcharEmpty

private final RexLiteral varcharEmpty

constantNull

private final RexLiteral constantNull

operatorTable

public final SqlOperatorTable operatorTable
Constructor Detail

RexBuilder

protected RexBuilder(SaffronTypeFactory typeFactory)
Method Detail

getTypeFactory

public SaffronTypeFactory getTypeFactory()

makeFieldAccess

public RexNode makeFieldAccess(RexNode expr,
                               String fieldName)

makeFieldAccess

public RexNode makeFieldAccess(RexNode expr,
                               int i)

makeFieldAccessInternal

private RexNode makeFieldAccessInternal(RexNode expr,
                                        SaffronField field)

makeCall

public RexNode makeCall(RexKind kind,
                        RexNode arg0)
Creates a call with 1 argument, converting a RexKind to an appropriate SqlOperator.


makeCall

public RexNode makeCall(RexKind kind,
                        RexNode[] args)
Creates a call with an array of arguments, converting a RexKind to an appropriate SqlOperator.


makeCall

public RexNode makeCall(RexKind kind,
                        RexNode arg0,
                        RexNode arg1)
Creates a call with 2 arguments, converting a RexKind to an appropriate SqlOperator.


makeCall

public RexNode makeCall(SqlOperator op,
                        RexNode expr0,
                        RexNode expr1)
Creates a call with 2 arguments.


makeCall

public RexNode makeCall(SqlOperator op,
                        RexNode[] exprs)
Creates a call with an array of arguments.

This is the fundamental method called by all of the other makeCall methods. If you derive a class from RexBuilder, this is the only method you need to override.


getTypes

private SaffronType[] getTypes(RexNode[] exprs)

getOperator

public SqlOperator getOperator(RexKind kind,
                               RexNode[] args)
Chooses an appropriate operator to implement a RexKind, given a specific number and types of arguments.


constantNull

public RexLiteral constantNull()
Creates a constant for the SQL NULL value.


makeCorrel

public RexNode makeCorrel(SaffronType type,
                          String name)

makeCast

public RexNode makeCast(SaffronType type,
                        RexNode exp)

makeRangeReference

public RexNode makeRangeReference(SaffronType rowType)
Creates a reference to all the fields in the row. That is, the whole row as a single record object.

Parameters:
rowType - Type of the input row

makeRangeReference

public RexNode makeRangeReference(SaffronType type,
                                  int i)
Creates a reference to all the fields in the row. For example, if the input row has type T{f0,f1,f2,f3,f4} then makeRangeReference(T{f0,f1,f2,f3,f4}, S{f3,f4}, 3) is an expression which yields the last 2 fields.

Parameters:
type - Type of the resulting range record.
i - Index of first field

makeInputRef

public RexNode makeInputRef(SaffronType type,
                            int i)

makeLiteral

protected RexLiteral makeLiteral(Object o,
                                 SaffronType type)

makeLiteral

public RexLiteral makeLiteral(boolean b)
Creates a boolean literal.


makeLiteral

public RexLiteral makeLiteral(long i)
Creates an integer literal.


makeLiteral

public RexLiteral makeLiteral(double d)
Creates a double-precision literal.


makeLiteral

public RexLiteral makeLiteral(String s)
Creates a varchar literal.

Pre-condition:
s != null

makeLiteral

public RexLiteral makeLiteral(Date date)
Creates a Date literal.

Pre-condition:
date != null

makeLiteral

public RexLiteral makeLiteral(Time time)
Creates a Time literal.

Pre-condition:
time != null

makeLiteral

public RexLiteral makeLiteral(Timestamp timestamp)
Creates a Timestamp literal.

Pre-condition:
timestamp != null

SourceForge.net_Logo