net.sf.farrago.fennel.rel
Class FennelRelUtil

java.lang.Object
  extended by net.sf.farrago.fennel.rel.FennelRelUtil

public abstract class FennelRelUtil
extends Object

Static utilities for FennelRel implementations.

Version:
$Id: //open/dev/farrago/src/net/sf/farrago/fennel/rel/FennelRelUtil.java#3 $
Author:
John V. Sichi

Constructor Summary
FennelRelUtil()
           
 
Method Summary
static void addTupleAttrDescriptor(FarragoMetadataFactory repos, FemTupleDescriptor tupleDesc, RelDataType type)
          Adds a type to a tuple descriptor.
static FennelBufferRel bufferRight(RelNode left, RelNode right)
          Returns a FennelBufferRel in the case where it makes sense to buffer the RHS into the cartesian product join.
static RexNode convertCoordinate(RexBuilder rexBuilder, SargEndpoint endpoint)
          Converts a SargEndpoint into the rex coordinate representation expected by Fennel BTree searches.
static RexLiteral convertEndpoint(RexBuilder rexBuilder, SargEndpoint endpoint)
          Converts a SargEndpoint into the literal representation for a lower/upper bound directive expected by Fennel BTree searches.
static List<RexNode> convertIntervalListToTuple(RexBuilder rexBuilder, List<SargInterval> intervalList)
          Converts a list of SargInterval representing intervals on multiple columns into the directive tuple representation expected by Fennel BTree searches.
static RelNode convertIntervalTupleToRel(RelTraitSet callTraits, RelDataType keyRowType, RelOptCluster cluster, List<RexNode> tuple)
          Converts the tuple representation of a SargInterval into a relational expression.
static FennelTupleDescriptor convertRowTypeToFennelTupleDesc(RelDataType rowType)
          Creates a FennelTupleDescriptor for a RelDataType which is a row.
static RelNode convertSargExpr(RelTraitSet callTraits, RelDataType keyRowType, RelOptCluster cluster, List<SargIntervalSequence> sargSeqList)
          Converts a list of SargIntervalSequence into a relational expression which produces a representation for the sequence of resolved intervals expected by Fennel BTree searches.
static RelNode convertSargExpr(RelTraitSet callTraits, RelDataType keyRowType, RelOptCluster cluster, SargExpr sargExpr)
          Converts a SargExpr into a relational expression which produces a representation for the sequence of resolved intervals expected by Fennel BTree searches.
static String convertTuplesToBase64String(RelDataType rowType, List<List<RexLiteral>> tuples)
          Converts a list of a list of RexLiterals representing tuples into a base-64 encoded string.
static FemTupleDescriptor createTupleDescriptorFromRexNode(FarragoMetadataFactory repos, List<? extends RexNode> nodeList)
          Creates a FemTupleDescriptor from a list of RexNodes representing a row.
static FemTupleDescriptor createTupleDescriptorFromRowType(FarragoRepos repos, RelDataTypeFactory typeFactory, RelDataType rowType)
          Creates a FemTupleDescriptor for a RelDataType which is a row.
static FemTupleProjection createTupleProjection(FarragoMetadataFactory repos, Integer[] projection)
          Generates a FemTupleProjection from an array of Integers.
static FemTupleProjection createTupleProjection(FarragoMetadataFactory repos, List<Integer> projection)
          Generates a FemTupleProjection from a list of Integers.
static void defineAggStream(List<AggregateCall> aggCalls, int groupCount, FarragoRepos repos, FemAggStreamDef aggStream)
          Helper method which sets properties of a FemAggStreamDef.
static SargIntervalSequence evaluateSargExpr(SargExpr sargExpr)
          Converts a SargExpr into a SargIntervalSequence.
static Object explainProjection(Integer[] projection)
           
static boolean extractSimplePredicates(List<SargBinding> sargBindingList, List<RexInputRef> filterCols, List<RexNode> filterOperands, List<CompOperatorEnum> op)
          Extracts from a sargable predicate represented by a SargBinding list the column ordinals and operands in the individual sub-expressions, provided all but one of the filters is a equality predicate.
static FemTupleAccessor getAccessorForTupleDescriptor(FarragoMetadataFactory repos, FennelDbHandle fennelDbHandle, FemTupleDescriptor tupleDesc)
          Generates a FemTupleAccessor from a FemTupleDescriptor.
static FarragoPreparingStmt getPreparingStmt(RelNode rel)
           
static FarragoPreparingStmt getPreparingStmt(RelOptCluster cluster)
           
static FennelRelImplementor getRelImplementor(RelNode rel)
          Returns the fennel implementor for a given relational expression.
static FarragoRepos getRepos(FennelRel rel)
           
static AggFunction lookupAggFunction(AggregateCall call)
          Finds the definition of the aggregate function used by a given call.
static Integer[] newBiasedIotaProjection(int n, int base)
          Generates a projection of attribute indices in sequence from (base) to (base + n-1).
static Integer[] newIotaProjection(int n)
          Generates a projection of attribute indices in sequence from 0 to n-1.
private static List<List<SargInterval>> pivotSargSeqList(List<SargIntervalSequence> sargSeqList)
          Pivots a list of (@link SargIntervalSequence}, with each list element representing the sequence of value intervals corresponding to a column; to a list of SargInterval lists, with each element (a list) representing the value intervals covering all the columns.
private static FemTupleAccessor tupleDescriptorToAccessor(FarragoMetadataFactory repos, FemTupleDescriptor tupleDesc)
          Converts a FemTupleDescriptor into a FemTupleAccessor without invoking native methods.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FennelRelUtil

public FennelRelUtil()
Method Detail

getAccessorForTupleDescriptor

public static FemTupleAccessor getAccessorForTupleDescriptor(FarragoMetadataFactory repos,
                                                             FennelDbHandle fennelDbHandle,
                                                             FemTupleDescriptor tupleDesc)
Generates a FemTupleAccessor from a FemTupleDescriptor.

Parameters:
repos - repos for storing transient objects
fennelDbHandle - handle to Fennel database being accessed
tupleDesc - source FemTupleDescriptor
Returns:
FemTupleAccessor for accessing tuples conforming to tupleDesc

tupleDescriptorToAccessor

private static FemTupleAccessor tupleDescriptorToAccessor(FarragoMetadataFactory repos,
                                                          FemTupleDescriptor tupleDesc)
Converts a FemTupleDescriptor into a FemTupleAccessor without invoking native methods.


createTupleDescriptorFromRowType

public static FemTupleDescriptor createTupleDescriptorFromRowType(FarragoRepos repos,
                                                                  RelDataTypeFactory typeFactory,
                                                                  RelDataType rowType)
Creates a FemTupleDescriptor for a RelDataType which is a row.

Parameters:
repos - repos storing object definitions
rowType - row type descriptor
Returns:
generated tuple descriptor

createTupleDescriptorFromRexNode

public static FemTupleDescriptor createTupleDescriptorFromRexNode(FarragoMetadataFactory repos,
                                                                  List<? extends RexNode> nodeList)
Creates a FemTupleDescriptor from a list of RexNodes representing a row.

Parameters:
repos - repos storing object definitions
nodeList - List of RexNodes
Returns:
generated tuple descriptor

createTupleProjection

public static FemTupleProjection createTupleProjection(FarragoMetadataFactory repos,
                                                       Integer[] projection)
Generates a FemTupleProjection from an array of Integers.

Parameters:
repos - the repos for storing transient objects
projection - the projection to generate
Returns:
generated FemTupleProjection

createTupleProjection

public static FemTupleProjection createTupleProjection(FarragoMetadataFactory repos,
                                                       List<Integer> projection)
Generates a FemTupleProjection from a list of Integers.

Parameters:
repos - the repos for storing transient objects
projection - the projection to generate
Returns:
generated FemTupleProjection

newIotaProjection

public static Integer[] newIotaProjection(int n)
Generates a projection of attribute indices in sequence from 0 to n-1.

Parameters:
n - length of array to generate
Returns:
generated array

newBiasedIotaProjection

public static Integer[] newBiasedIotaProjection(int n,
                                                int base)
Generates a projection of attribute indices in sequence from (base) to (base + n-1).

Parameters:
n - length of array to generate
base - first value to generate
Returns:
generated array

addTupleAttrDescriptor

public static void addTupleAttrDescriptor(FarragoMetadataFactory repos,
                                          FemTupleDescriptor tupleDesc,
                                          RelDataType type)
Adds a type to a tuple descriptor.

Parameters:
repos - Repository/metadata factory
tupleDesc - Tuple descriptor
type - Type to be aded

convertRowTypeToFennelTupleDesc

public static FennelTupleDescriptor convertRowTypeToFennelTupleDesc(RelDataType rowType)
Creates a FennelTupleDescriptor for a RelDataType which is a row.

Parameters:
rowType - row type descriptor
Returns:
generated tuple descriptor

explainProjection

public static Object explainProjection(Integer[] projection)
Returns:
an object suitable for display in a plan explanation

getPreparingStmt

public static FarragoPreparingStmt getPreparingStmt(RelNode rel)
Parameters:
rel - the relational expression
Returns:
the preparing stmt that a relational expression belongs to

getPreparingStmt

public static FarragoPreparingStmt getPreparingStmt(RelOptCluster cluster)
Parameters:
cluster - the cluster
Returns:
the preparing stmt a cluster belongs to

getRepos

public static FarragoRepos getRepos(FennelRel rel)
Returns:
the repository that a relational expression belongs to

evaluateSargExpr

public static SargIntervalSequence evaluateSargExpr(SargExpr sargExpr)
Converts a SargExpr into a SargIntervalSequence.

Parameters:
sargExpr - expression to be oncverted
Returns:
corresponding SargIntervalSequence

pivotSargSeqList

private static List<List<SargInterval>> pivotSargSeqList(List<SargIntervalSequence> sargSeqList)
Pivots a list of (@link SargIntervalSequence}, with each list element representing the sequence of value intervals corresponding to a column; to a list of SargInterval lists, with each element (a list) representing the value intervals covering all the columns. e.g. for the following predicates

  a = 2
  b = 3
  1 < c <= 4, c > 10
The input looks like

   {([, 2, ], 2)}
   {([, 3, ], 3)}
   {((, 1, ], 4), ((, 10, +, null)}
The output will be

   {([, 2, ], 2), ([, 3, ], 3), ((,  1, ], 4)}
   {([, 2, ], 2), ([, 3, ], 3), ((, 10, ), +)}
NOTE
  1. the prefix columns can only have point intervals.
  2. This function is added to better support the unbounded multi-column key case, which is currently disabled in BTree code.

Parameters:
sargSeqList - list of SargIntervalSequence representing the expression to be converted
Returns:
the list of SargInterval lists.

convertSargExpr

public static RelNode convertSargExpr(RelTraitSet callTraits,
                                      RelDataType keyRowType,
                                      RelOptCluster cluster,
                                      List<SargIntervalSequence> sargSeqList)
Converts a list of SargIntervalSequence into a relational expression which produces a representation for the sequence of resolved intervals expected by Fennel BTree searches.

Parameters:
callTraits - traits to apply to new rels generated
keyRowType - input row type expected by BTree search
cluster - query cluster
sargSeqList - list of SargIntervalSequence representing the expression to be converted
Returns:
corresponding relational expression

convertSargExpr

public static RelNode convertSargExpr(RelTraitSet callTraits,
                                      RelDataType keyRowType,
                                      RelOptCluster cluster,
                                      SargExpr sargExpr)
Converts a SargExpr into a relational expression which produces a representation for the sequence of resolved intervals expected by Fennel BTree searches.

Parameters:
callTraits - traits to apply to new rels generated
keyRowType - input row type expected by BTree search
cluster - query cluster
sargExpr - expression to be converted
Returns:
corresponding relational expression

convertIntervalListToTuple

public static List<RexNode> convertIntervalListToTuple(RexBuilder rexBuilder,
                                                       List<SargInterval> intervalList)
Converts a list of SargInterval representing intervals on multiple columns into the directive tuple representation expected by Fennel BTree searches.

Parameters:
rexBuilder - builder for tuple values
intervalList - intervalList to be converted
Returns:
corresponding tuple

convertIntervalTupleToRel

public static RelNode convertIntervalTupleToRel(RelTraitSet callTraits,
                                                RelDataType keyRowType,
                                                RelOptCluster cluster,
                                                List<RexNode> tuple)
Converts the tuple representation of a SargInterval into a relational expression.

Parameters:
callTraits - traits to apply to new rels generated
keyRowType - input row type expected by BTree search
cluster - query cluster
tuple - tuple to be converted
Returns:
corresponding relational expression

convertEndpoint

public static RexLiteral convertEndpoint(RexBuilder rexBuilder,
                                         SargEndpoint endpoint)
Converts a SargEndpoint into the literal representation for a lower/upper bound directive expected by Fennel BTree searches.

Parameters:
rexBuilder - builder for rex expressions
endpoint - endpoint to be converted
Returns:
literal representation

convertCoordinate

public static RexNode convertCoordinate(RexBuilder rexBuilder,
                                        SargEndpoint endpoint)
Converts a SargEndpoint into the rex coordinate representation expected by Fennel BTree searches.

Parameters:
rexBuilder - builder for rex expressions
endpoint - endpoint to be converted
Returns:
rex representation

getRelImplementor

public static FennelRelImplementor getRelImplementor(RelNode rel)
Returns the fennel implementor for a given relational expression.

Parameters:
rel - Relational expression
Returns:
Fennel implementor

convertTuplesToBase64String

public static String convertTuplesToBase64String(RelDataType rowType,
                                                 List<List<RexLiteral>> tuples)
Converts a list of a list of RexLiterals representing tuples into a base-64 encoded string.

Parameters:
rowType - the row type of the tuples
tuples - the tuples
Returns:
base-64 string representing the tuples

extractSimplePredicates

public static boolean extractSimplePredicates(List<SargBinding> sargBindingList,
                                              List<RexInputRef> filterCols,
                                              List<RexNode> filterOperands,
                                              List<CompOperatorEnum> op)
Extracts from a sargable predicate represented by a SargBinding list the column ordinals and operands in the individual sub-expressions, provided all but one of the filters is a equality predicate. The one non-equality predicate must be a single range predicate.

Parameters:
sargBindingList - filter represented as a SargBinding list
filterCols - returns the list of filter columns in the expression
filterOperands - returns the list of expressions that the filter columns are compared to
op - returns COMP_EQ if the predicates are all equality; otherwise, returns the value of the one non-equality predicate
Returns:
true if all but one of the predicates is an equality predicate with the one non-equality predicate being a single range predicate

bufferRight

public static FennelBufferRel bufferRight(RelNode left,
                                          RelNode right)
Returns a FennelBufferRel in the case where it makes sense to buffer the RHS into the cartesian product join. This is done by comparing the cost between the buffered and non-buffered cases.

Parameters:
left - left hand input into the cartesian join
right - right hand input into the cartesian join
Returns:
created FennelBufferRel if it makes sense to buffer the RHS

defineAggStream

public static void defineAggStream(List<AggregateCall> aggCalls,
                                   int groupCount,
                                   FarragoRepos repos,
                                   FemAggStreamDef aggStream)
Helper method which sets properties of a FemAggStreamDef.

Parameters:
aggCalls - List of calls to aggregate functions
groupCount - Number of grouping columns =
repos - Repository
aggStream - Agg stream to configure

lookupAggFunction

public static AggFunction lookupAggFunction(AggregateCall call)
Finds the definition of the aggregate function used by a given call.

Parameters:
call - Call
Returns:
Definition of aggregate function
Throws:
IllegalArgumentException - if aggregate is not one of the builtins supported by Fennel