Search in sources :

Example 6 with LogicalTable

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);
}
Also used : LogicalColumn(org.pentaho.metadata.model.LogicalColumn) LogicalTable(org.pentaho.metadata.model.LogicalTable) Test(org.junit.Test)

Example 7 with LogicalTable

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));
}
Also used : LogicalColumn(org.pentaho.metadata.model.LogicalColumn) LogicalTable(org.pentaho.metadata.model.LogicalTable) Test(org.junit.Test)

Example 8 with LogicalTable

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());
}
Also used : IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) IMetaStoreAttribute(org.pentaho.metastore.api.IMetaStoreAttribute) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) Matchers.anyString(org.mockito.Matchers.anyString) LogicalTable(org.pentaho.metadata.model.LogicalTable) IMetaStore(org.pentaho.metastore.api.IMetaStore) Test(org.junit.Test)

Example 9 with LogicalTable

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;
}
Also used : TableType(org.pentaho.metadata.model.concept.types.TableType) LogicalTable(org.pentaho.metadata.model.LogicalTable)

Example 10 with LogicalTable

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;
}
Also used : DimensionType(org.pentaho.di.starmodeler.DimensionType) TableType(org.pentaho.metadata.model.concept.types.TableType) TransMeta(org.pentaho.di.trans.TransMeta) ArrayList(java.util.ArrayList) LogicalTable(org.pentaho.metadata.model.LogicalTable) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta)

Aggregations

LogicalTable (org.pentaho.metadata.model.LogicalTable)34 Test (org.junit.Test)14 LocalizedString (org.pentaho.metadata.model.concept.types.LocalizedString)13 LogicalColumn (org.pentaho.metadata.model.LogicalColumn)12 LogicalModel (org.pentaho.metadata.model.LogicalModel)11 ArrayList (java.util.ArrayList)7 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)6 Domain (org.pentaho.metadata.model.Domain)5 SqlPhysicalModel (org.pentaho.metadata.model.SqlPhysicalModel)5 SqlPhysicalTable (org.pentaho.metadata.model.SqlPhysicalTable)5 TableType (org.pentaho.metadata.model.concept.types.TableType)5 SqlDataSource (org.pentaho.metadata.model.SqlDataSource)4 SqlPhysicalColumn (org.pentaho.metadata.model.SqlPhysicalColumn)4 KettleException (org.pentaho.di.core.exception.KettleException)3 TransMeta (org.pentaho.di.trans.TransMeta)3 Category (org.pentaho.metadata.model.Category)3 LogicalRelationship (org.pentaho.metadata.model.LogicalRelationship)3 List (java.util.List)2 TableItem (org.eclipse.swt.widgets.TableItem)2 Matchers.anyString (org.mockito.Matchers.anyString)2