Class DimensionCache
- java.lang.Object
-
- org.pentaho.di.trans.steps.dimensionlookup.DimensionCache
-
- All Implemented Interfaces:
Comparator<Object[]>
public class DimensionCache extends Object implements Comparator<Object[]>
This class will act as a special purpose dimension Cache. The idea here is to not only cache the last version of a dimension entry, but all versions. So basically, the entry key is the natural key as well as the from-to date range. The way to achieve that result is to keep a sorted list in memory. Because we want as few conversion errors as possible, we'll use the same row as we get from the database.- Author:
- matt
-
-
Constructor Summary
Constructors Constructor Description DimensionCache(org.pentaho.di.core.row.RowMetaInterface rowMeta, int[] keyIndexes, int fromDateIndex, int toDateIndex)Create a new dimension cache object
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddRow(int index, Object[] row)Insert a row into the list on a certain indexvoidaddRow(Object[] row)Add a row to the back of the listintcompare(Object[] o1, Object[] o2)Compare 2 rows of data using the natural keys and indexes specified.intgetFromDateIndex()int[]getKeyIndexes()Object[]getRow(int index)Get a row from the cache on a certain indexList<Object[]>getRowCache()org.pentaho.di.core.row.RowMetaInterfacegetRowMeta()intgetToDateIndex()intlookupRow(Object[] lookupRowData)Looks up a row in the (sorted) cache.voidsetFromDateIndex(int fromDateIndex)voidsetKeyIndexes(int[] keyIndexes)voidsetRowCache(List<Object[]> rowCache)voidsetRowMeta(org.pentaho.di.core.row.RowMetaInterface rowMeta)voidsetToDateIndex(int toDateIndex)voidsortRows()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
-
-
-
Constructor Detail
-
DimensionCache
public DimensionCache(org.pentaho.di.core.row.RowMetaInterface rowMeta, int[] keyIndexes, int fromDateIndex, int toDateIndex)Create a new dimension cache object- Parameters:
rowMeta- the description of the rows to storekeyIndexes- the indexes of the natural key (in that order)fromDateIndex- the field index where the start of the date range can be foundtoDateIndex- the field index where the end of the date range can be found
-
-
Method Detail
-
addRow
public void addRow(Object[] row)
Add a row to the back of the list- Parameters:
row- the row to add
-
getRow
public Object[] getRow(int index)
Get a row from the cache on a certain index- Parameters:
index- the index to look for- Returns:
- the row on the specified index
-
addRow
public void addRow(int index, Object[] row)Insert a row into the list on a certain index- Parameters:
index- the index on which the row should be insertedrow- the row to add
-
lookupRow
public int lookupRow(Object[] lookupRowData) throws org.pentaho.di.core.exception.KettleException
Looks up a row in the (sorted) cache.- Parameters:
lookupRowData- The data of the lookup row. Make sure that on the index of the from date, you put the lookup date.- Throws:
a- KettleException in case there are conversion errors during the lookup of the roworg.pentaho.di.core.exception.KettleException
-
sortRows
public void sortRows()
-
compare
public int compare(Object[] o1, Object[] o2)
Compare 2 rows of data using the natural keys and indexes specified.- Specified by:
comparein interfaceComparator<Object[]>- Parameters:
o1-o2-- Returns:
-
getRowMeta
public org.pentaho.di.core.row.RowMetaInterface getRowMeta()
- Returns:
- the rowMeta
-
setRowMeta
public void setRowMeta(org.pentaho.di.core.row.RowMetaInterface rowMeta)
- Parameters:
rowMeta- the rowMeta to set
-
setRowCache
public void setRowCache(List<Object[]> rowCache)
- Parameters:
rowCache- the rowCache to set
-
getKeyIndexes
public int[] getKeyIndexes()
- Returns:
- the keyIndexes
-
setKeyIndexes
public void setKeyIndexes(int[] keyIndexes)
- Parameters:
keyIndexes- the keyIndexes to set
-
getFromDateIndex
public int getFromDateIndex()
- Returns:
- the fromDateIndex
-
setFromDateIndex
public void setFromDateIndex(int fromDateIndex)
- Parameters:
fromDateIndex- the fromDateIndex to set
-
getToDateIndex
public int getToDateIndex()
- Returns:
- the toDateIndex
-
setToDateIndex
public void setToDateIndex(int toDateIndex)
- Parameters:
toDateIndex- the toDateIndex to set
-
-