net.sf.farrago.namespace.ftrs
Class FtrsIndexGuide

java.lang.Object
  extended by net.sf.farrago.namespace.ftrs.FtrsIndexGuide

 class FtrsIndexGuide
extends Object

FtrsIndexGuide provides information about the mapping from catalog definitions for tables and indexes to their Fennel representation.

Examples in the comments refer to the test tables EMPS and DEPTS defined in farrago/initsql/createSalesSchema.sql. For an overview and terminology, please see the design docs.

Version:
$Id: //open/dev/farrago/src/net/sf/farrago/namespace/ftrs/FtrsIndexGuide.java#22 $
Author:
John V. Sichi

Field Summary
private  RelDataType flattenedRowType
           
private  int[] flatteningMap
           
private  FarragoRepos repos
           
private  CwmColumnSet table
           
private  FarragoTypeFactory typeFactory
           
private  RelDataType unflattenedRowType
           
 
Constructor Summary
FtrsIndexGuide(FarragoTypeFactory typeFactory, CwmColumnSet table)
           
 
Method Summary
private  void appendClusteredDistinctKey(FemLocalIndex clusteredIndex, List<FemAbstractColumn> indexColumnList)
           
private  void appendConstraintColumns(List<FemAbstractColumn> list, FemAbstractUniqueConstraint constraint)
           
private  void appendDefinedKey(List<FemAbstractColumn> list, FemLocalIndex index)
           
(package private)  FemTupleProjection createTupleProjectionFromColumnList(List<FemAbstractColumn> indexColumnList)
          Generates a FemTupleProjection from a list of CWM columns.
private  int flattenOrdinal(int columnOrdinal)
          Converts from unflattened 0-based logical column ordinal to 0-based flattened tuple ordinal (as known by Fennel).
private  FemTupleDescriptor getClusteredCoverageTupleDescriptor()
           
(package private)  Integer[] getClusteredDistinctKeyArray(FemLocalIndex index)
          Gets the distinct key of a clustered index.
(package private)  Integer[] getCollationKeyArray(FemLocalIndex index)
          Gets the collation key of an index.
(package private)  FemTupleProjection getCoverageProjection(FemLocalIndex index)
          Creates a FemTupleProjection which specifies how to extract the index coverage tuple from a full table tuple.
(package private)  FemTupleDescriptor getCoverageTupleDescriptor(FemLocalIndex index)
          Creates a FemTupleDescriptor for the coverage tuple of an index.
(package private)  List<? extends Object> getDistinctKeyColList(FemLocalIndex index)
           
(package private)  FemTupleProjection getDistinctKeyProjection(FemLocalIndex index)
          Gets a FemTupleProjection which specifies how to extract the distinct key from the result of getCoverageTupleDescriptor.
 RelDataType getFlattenedRowType()
           
(package private)  Integer[] getUnclusteredCoverageArray(FemLocalIndex index)
          Same as getUnclusteredCoverageColList, but returns flattened column ordinals instead.
(package private)  List<FemAbstractColumn> getUnclusteredCoverageColList(FemLocalIndex index)
          Gets a list of columns covered by an unclustered index.
private  FemTupleDescriptor getUnclusteredCoverageTupleDescriptor(FemLocalIndex index)
           
 FemIndexWriterDef newIndexWriter(FennelRel rel, FemLocalIndex index)
          Creates a new physical writer definition for a particular index, initializing any invariant information.
 int unFlattenOrdinal(int fieldOrdinal)
          Returns the unflattened column ordinal corresponding to a flattened field ordinal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

typeFactory

private FarragoTypeFactory typeFactory

repos

private FarragoRepos repos

table

private CwmColumnSet table

unflattenedRowType

private RelDataType unflattenedRowType

flattenedRowType

private RelDataType flattenedRowType

flatteningMap

private int[] flatteningMap
Constructor Detail

FtrsIndexGuide

FtrsIndexGuide(FarragoTypeFactory typeFactory,
               CwmColumnSet table)
Method Detail

getFlattenedRowType

public RelDataType getFlattenedRowType()
Returns:
the flattened row type for the indexed table

getUnclusteredCoverageColList

List<FemAbstractColumn> getUnclusteredCoverageColList(FemLocalIndex index)
Gets a list of columns covered by an unclustered index.

Example: for index EMPS_UX, the result is [ NAME, DEPTNO, EMPNO ]

Parameters:
index - index for which to compute column list
Returns:
List (of CwmColumn) making up an unclustered index's tuple

getUnclusteredCoverageArray

Integer[] getUnclusteredCoverageArray(FemLocalIndex index)
Same as getUnclusteredCoverageColList, but returns flattened column ordinals instead.

Example: for index EMPS_UX, the result is [ 1, 2, 0 ]

Parameters:
index - index for which to compute projection
Returns:
projection as array of 0-based flattened column ordinals

getClusteredDistinctKeyArray

Integer[] getClusteredDistinctKeyArray(FemLocalIndex index)
Gets the distinct key of a clustered index.

Example: for the clustered index on table EMPS, the result is [ 2, 0 ]. But if the clustered index were defined as non-unique on column city instead, then the result would be [ 4, 2, 0 ]. For a non-unique clustered index on empno, the result would be [ 0, 2 ].

Parameters:
index - the FemLocalIndex for which the key is to be projected
Returns:
array of 0-based flattened column ordinals

getDistinctKeyColList

List<? extends Object> getDistinctKeyColList(FemLocalIndex index)

getCollationKeyArray

Integer[] getCollationKeyArray(FemLocalIndex index)
Gets the collation key of an index.

Example: for index DEPTS_UNIQUE_NAME, the result is [ 1, 0 ]

Parameters:
index - index for which to compute projection
Returns:
projection as array of 0-based flattened column ordinals

getDistinctKeyProjection

FemTupleProjection getDistinctKeyProjection(FemLocalIndex index)
Gets a FemTupleProjection which specifies how to extract the distinct key from the result of getCoverageTupleDescriptor. The projected ordinals are relative to the index coverage tuple, not the table.

Example: for the clustered index of table EMPS, the result is [ 2, 0 ]. For index DEPTS_UNIQUE_NAME, the result is [ 0 ]. For index EMPS_UX, the result is [ 0, 1, 2 ].

Parameters:
index - the FemLocalIndex for which the key is to be projected
Returns:
new FemTupleProjection

getCoverageTupleDescriptor

FemTupleDescriptor getCoverageTupleDescriptor(FemLocalIndex index)
Creates a FemTupleDescriptor for the coverage tuple of an index.

Parameters:
index - the FemLocalIndex to be described
Returns:
new FemTupleDescriptor

getCoverageProjection

FemTupleProjection getCoverageProjection(FemLocalIndex index)
Creates a FemTupleProjection which specifies how to extract the index coverage tuple from a full table tuple.

Example: for the clustered index of table EMPS, the result is [ 0, 1, 2, 3, 4, 5 ]. For index DEPTS_UNIQUE_NAME, the result is [ 1, 0 ].

Parameters:
index - the FemLocalIndex for which the tuple is to be projected
Returns:
new FemTupleProjection

createTupleProjectionFromColumnList

FemTupleProjection createTupleProjectionFromColumnList(List<FemAbstractColumn> indexColumnList)
Generates a FemTupleProjection from a list of CWM columns.

Parameters:
indexColumnList - list of columns
Returns:
generated FemTupleProjection

newIndexWriter

public FemIndexWriterDef newIndexWriter(FennelRel rel,
                                        FemLocalIndex index)
Creates a new physical writer definition for a particular index, initializing any invariant information.

Parameters:
rel - relational expression modifying the index
index - the index of interest
Returns:
new writer

appendConstraintColumns

private void appendConstraintColumns(List<FemAbstractColumn> list,
                                     FemAbstractUniqueConstraint constraint)

appendDefinedKey

private void appendDefinedKey(List<FemAbstractColumn> list,
                              FemLocalIndex index)

appendClusteredDistinctKey

private void appendClusteredDistinctKey(FemLocalIndex clusteredIndex,
                                        List<FemAbstractColumn> indexColumnList)

getClusteredCoverageTupleDescriptor

private FemTupleDescriptor getClusteredCoverageTupleDescriptor()

getUnclusteredCoverageTupleDescriptor

private FemTupleDescriptor getUnclusteredCoverageTupleDescriptor(FemLocalIndex index)

flattenOrdinal

private int flattenOrdinal(int columnOrdinal)
Converts from unflattened 0-based logical column ordinal to 0-based flattened tuple ordinal (as known by Fennel). These differ in the presence of user-defined types. For example, consider DDL like


 create type pencil (
     outer_radius_mm double,
     lead_radius_mm double,
     length_mm double,
     has_eraser boolean
 );

 create table pencil_case(
     id int not null primary key,
     p pencil not null,
     crayon_count int);

The corresponding flattened ordinals would be 0 for id, 1 for p, 5 for crayon_count. The gap corresponds to the fact that the pencil column has four fields, after which comes crayon_count.

Parameters:
columnOrdinal - logical column ordinal; e.g. 0 for id, 1 for p, 2 for crayon_count
Returns:
flattened column ordinal

unFlattenOrdinal

public int unFlattenOrdinal(int fieldOrdinal)
Returns the unflattened column ordinal corresponding to a flattened field ordinal

Parameters:
fieldOrdinal - flattened ordinal
Returns:
unflattened ordinal