use of org.pentaho.metadata.model.LogicalTable in project pentaho-kettle by pentaho.
the class ConceptUtilTest method testFindFirstKeyColumn.
@Test
public void testFindFirstKeyColumn() throws Exception {
final LogicalTable logicalTable = mock(LogicalTable.class);
assertNull(ConceptUtil.findFirstKeyColumn(logicalTable));
final LogicalColumn logicalColumn = mock(LogicalColumn.class);
final LogicalColumn logicalColumnKey1 = mock(LogicalColumn.class);
final LogicalColumn logicalColumnKey2 = mock(LogicalColumn.class);
when(logicalColumnKey1.getFieldType()).thenReturn(FieldType.KEY);
when(logicalColumnKey2.getFieldType()).thenReturn(FieldType.KEY);
when(logicalTable.getLogicalColumns()).thenReturn(new LinkedList<LogicalColumn>() {
{
add(logicalColumn);
add(logicalColumnKey1);
add(logicalColumnKey2);
}
});
final LogicalColumn firstKeyColumn = ConceptUtil.findFirstKeyColumn(logicalTable);
assertEquals(logicalColumnKey1, firstKeyColumn);
}
use of org.pentaho.metadata.model.LogicalTable in project pentaho-kettle by pentaho.
the class ConceptUtilTest method testFindLogicalColumns.
@Test
public void testFindLogicalColumns() throws Exception {
final LogicalTable logicalTable = mock(LogicalTable.class);
final AttributeType attribute = AttributeType.ATTRIBUTE;
final LogicalColumn logicalColumn1 = mock(LogicalColumn.class);
when(logicalColumn1.getProperty(DefaultIDs.LOGICAL_COLUMN_ATTRIBUTE_TYPE)).thenReturn(attribute.name());
final LogicalColumn logicalColumn2 = mock(LogicalColumn.class);
when(logicalColumn2.getProperty(DefaultIDs.LOGICAL_COLUMN_ATTRIBUTE_TYPE)).thenReturn(attribute.name());
when(logicalTable.getLogicalColumns()).thenReturn(new LinkedList<LogicalColumn>() {
{
add(logicalColumn1);
add(logicalColumn2);
}
});
assertTrue(ConceptUtil.findLogicalColumns(logicalTable, AttributeType.ATTRIBUTE_HISTORICAL).isEmpty());
final List<LogicalColumn> logicalColumns = ConceptUtil.findLogicalColumns(logicalTable, attribute);
assertEquals(2, logicalColumns.size());
assertEquals(logicalColumn1, logicalColumns.get(0));
assertEquals(logicalColumn2, logicalColumns.get(1));
}
use of org.pentaho.metadata.model.LogicalTable in project pentaho-kettle by pentaho.
the class SharedDimensionMetaStoreUtilTest method testSaveSharedDimension.
@Test
public void testSaveSharedDimension() throws Exception {
final String locale = Locale.US.toString();
final IMetaStore metaStore = mock(IMetaStore.class);
final IMetaStoreElementType metaStoreElementType = mock(IMetaStoreElementType.class);
when(metaStore.newElementType(anyString())).thenReturn(metaStoreElementType);
final IMetaStoreElement metaStoreElement = mock(IMetaStoreElement.class);
final String sdId = "sdId";
when(metaStore.getElement(anyString(), eq(metaStoreElementType), eq(sdId))).thenReturn(metaStoreElement);
final LogicalTable sharedDimension = mock(LogicalTable.class);
final String sdName = "sdName";
when(sharedDimension.getName(eq(locale))).thenReturn(sdName);
when(sharedDimension.getId()).thenReturn(sdId);
SharedDimensionMetaStoreUtil.saveSharedDimension(metaStore, sharedDimension, locale);
verify(metaStoreElement, times(1)).setElementType(eq(metaStoreElementType));
verify(metaStoreElement, times(1)).setName(eq(sdName));
verify(metaStoreElement, times(2)).addChild(any(IMetaStoreAttribute.class));
verify(metaStore, times(1)).updateElement(anyString(), eq(metaStoreElementType), eq(sdId), eq(metaStoreElement));
verify(sharedDimension, times(1)).setId(anyString());
}
use of org.pentaho.metadata.model.LogicalTable in project pentaho-kettle by pentaho.
the class ConceptUtil method indexOfFactTable.
public static int indexOfFactTable(LogicalModel logicalModel) {
for (int i = 0; i < logicalModel.getLogicalTables().size(); i++) {
LogicalTable logicalTable = logicalModel.getLogicalTables().get(i);
TableType type = getTableType(logicalTable);
if (type == TableType.FACT) {
return i;
}
}
return -1;
}
use of org.pentaho.metadata.model.LogicalTable in project pentaho-kettle by pentaho.
the class JobGenerator method generateDimensionTransformations.
/**
* This method generates a list of transformations: one for each dimension.
*
* @return the list of generated transformations
*/
public List<TransMeta> generateDimensionTransformations() throws KettleException {
DatabaseMeta databaseMeta = findTargetDatabaseMeta();
List<TransMeta> transMetas = new ArrayList<TransMeta>();
List<LogicalTable> logicalTables = getUniqueLogicalTables();
for (LogicalTable logicalTable : logicalTables) {
TableType tableType = ConceptUtil.getTableType(logicalTable);
DimensionType dimensionType = ConceptUtil.getDimensionType(logicalTable);
if (tableType == TableType.DIMENSION) {
switch(dimensionType) {
case SLOWLY_CHANGING_DIMENSION:
case JUNK_DIMENSION:
{
TransMeta transMeta = generateDimensionTransformation(databaseMeta, logicalTable);
transMetas.add(transMeta);
}
break;
case // TODO: generate a standard date transformation
DATE:
{
TransMeta transMeta = generateDateTransformation(databaseMeta, logicalTable);
transMetas.add(transMeta);
}
break;
case // TODO: generate a standard time transformation
TIME:
{
TransMeta transMeta = generateTimeTransformation(databaseMeta, logicalTable);
transMetas.add(transMeta);
}
break;
default:
break;
}
}
}
return transMetas;
}
Aggregations