Search in sources :

Example 1 with LogicalTable

use of org.pentaho.metadata.model.LogicalTable in project pentaho-kettle by pentaho.

the class JobGeneratorTest method testGenerateDimensionTransformations.

@Test
public void testGenerateDimensionTransformations() throws Exception {
    final LogicalModel logicalModel = mock(LogicalModel.class);
    when(jobGenerator.domain.getLogicalModels()).thenReturn(new LinkedList<LogicalModel>() {

        {
            add(logicalModel);
        }
    });
    final LogicalTable logicalTable = mock(LogicalTable.class);
    when(logicalTable.getProperty(eq(DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME))).thenReturn("test_table_name");
    when(logicalModel.getLogicalTables()).thenReturn(new LinkedList<LogicalTable>() {

        {
            add(logicalTable);
        }
    });
    when(logicalTable.getProperty(eq(DefaultPropertyID.TABLE_TYPE.getId()))).thenReturn(TableType.DIMENSION);
    when(logicalTable.getProperty(eq(DefaultIDs.LOGICAL_TABLE_DIMENSION_TYPE))).thenReturn(DimensionType.JUNK_DIMENSION.name());
    final List<TransMeta> transMetas = jobGenerator.generateDimensionTransformations();
    assertNotNull(transMetas);
    assertEquals(1, transMetas.size());
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) TransMeta(org.pentaho.di.trans.TransMeta) LogicalTable(org.pentaho.metadata.model.LogicalTable) Test(org.junit.Test)

Example 2 with LogicalTable

use of org.pentaho.metadata.model.LogicalTable in project pentaho-kettle by pentaho.

the class MetadataGenerator method generatePhysicalMetadataModel.

public Domain generatePhysicalMetadataModel() throws KettleException {
    // First do some checking and lookups...
    // 
    String targetDatabaseName = ConceptUtil.getString(logicalDomain, DefaultIDs.DOMAIN_TARGET_DATABASE);
    if (Utils.isEmpty(targetDatabaseName)) {
        throw new KettleException("Please specify a target database!");
    }
    DatabaseMeta targetDatabaseMeta = DatabaseMeta.findDatabase(databases, targetDatabaseName);
    if (targetDatabaseMeta == null) {
        throw new KettleException("Target database with name '" + targetDatabaseName + "' can't be found!");
    }
    // Now start creation of a new domain with physical underpinning.
    // 
    Domain domain = new Domain();
    // Copy the domain information...
    // 
    domain.setId(createId("DOMAIN", null, domain));
    domain.setName(logicalDomain.getName());
    domain.setDescription(logicalDomain.getDescription());
    // 
    for (LogicalModel logicalModel : logicalDomain.getLogicalModels()) {
        // Copy model information...
        // 
        LogicalModel model = new LogicalModel();
        model.setId(createId("MODEL", domain, model));
        model.setName(logicalModel.getName());
        model.setDescription(logicalModel.getDescription());
        // Create a physical model...
        // 
        SqlPhysicalModel sqlModel = new SqlPhysicalModel();
        sqlModel.setDatasource(createSqlDataSource(targetDatabaseMeta));
        model.setPhysicalModel(sqlModel);
        for (LogicalTable logicalTable : logicalModel.getLogicalTables()) {
            LogicalTable table = new LogicalTable();
            table.setId(createId("LOGICAL_TABLE", logicalModel, logicalTable));
            table.setName(logicalTable.getName());
            table.setDescription(logicalTable.getDescription());
            String targetTable = ConceptUtil.getString(logicalTable, DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME);
            SqlPhysicalTable sqlTable = new SqlPhysicalTable(sqlModel);
            table.setPhysicalTable(sqlTable);
            // Copy name & description from physical level...
            // 
            sqlTable.setId(createId("PHYSICAL_TABLE", logicalModel, logicalTable));
            sqlTable.setName(logicalTable.getName());
            sqlTable.setDescription(logicalTable.getDescription());
            sqlTable.setTableType(ConceptUtil.getTableType(logicalTable));
            sqlTable.setTargetSchema(targetDatabaseMeta.getPreferredSchemaName());
            sqlTable.setTargetTable(targetTable);
        }
    }
    return domain;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) LogicalModel(org.pentaho.metadata.model.LogicalModel) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) LogicalTable(org.pentaho.metadata.model.LogicalTable) Domain(org.pentaho.metadata.model.Domain) SqlPhysicalModel(org.pentaho.metadata.model.SqlPhysicalModel) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) SqlPhysicalTable(org.pentaho.metadata.model.SqlPhysicalTable)

Example 3 with LogicalTable

use of org.pentaho.metadata.model.LogicalTable in project pentaho-kettle by pentaho.

the class ConceptUtilTest method testFindLogicalTables.

@Test
public void testFindLogicalTables() throws Exception {
    final LogicalModel logicalModel = mock(LogicalModel.class);
    final TableType dimension = TableType.DIMENSION;
    final LogicalTable logicalTable1 = mock(LogicalTable.class);
    when(logicalTable1.getProperty(eq(DefaultPropertyID.TABLE_TYPE.getId()))).thenReturn(dimension);
    final LogicalTable logicalTable2 = mock(LogicalTable.class);
    when(logicalTable2.getProperty(eq(DefaultPropertyID.TABLE_TYPE.getId()))).thenReturn(TableType.FACT);
    final LogicalTable logicalTable3 = mock(LogicalTable.class);
    when(logicalTable3.getProperty(eq(DefaultPropertyID.TABLE_TYPE.getId()))).thenReturn(dimension);
    when(logicalModel.getLogicalTables()).thenReturn(new LinkedList<LogicalTable>() {

        {
            add(logicalTable1);
            add(logicalTable2);
            add(logicalTable3);
        }
    });
    final List<LogicalTable> logicalTables = ConceptUtil.findLogicalTables(logicalModel, dimension);
    assertEquals(2, logicalTables.size());
    assertEquals(logicalTable1, logicalTables.get(0));
    assertEquals(logicalTable3, logicalTables.get(1));
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) TableType(org.pentaho.metadata.model.concept.types.TableType) LogicalTable(org.pentaho.metadata.model.LogicalTable) Test(org.junit.Test)

Example 4 with LogicalTable

use of org.pentaho.metadata.model.LogicalTable in project pentaho-kettle by pentaho.

the class ConceptUtilTest method testFindDimensionWithName.

@Test
public void testFindDimensionWithName() throws Exception {
    final LogicalModel logicalModel = mock(LogicalModel.class);
    final String dn = "dn";
    final LogicalTable logicalTable1 = mock(LogicalTable.class);
    when(logicalTable1.getProperty(eq(DefaultPropertyID.TABLE_TYPE.getId()))).thenReturn(TableType.DIMENSION);
    when(logicalTable1.getProperty(eq(Concept.NAME_PROPERTY))).thenReturn(new LocalizedString(locale, "wrong name"));
    final LogicalTable logicalTable2 = mock(LogicalTable.class);
    when(logicalTable2.getProperty(eq(DefaultPropertyID.TABLE_TYPE.getId()))).thenReturn(TableType.FACT);
    final LogicalTable logicalTable3 = mock(LogicalTable.class);
    when(logicalTable3.getProperty(eq(DefaultPropertyID.TABLE_TYPE.getId()))).thenReturn(TableType.DIMENSION);
    when(logicalTable3.getProperty(eq(Concept.NAME_PROPERTY))).thenReturn(new LocalizedString(locale, dn));
    when(logicalModel.getLogicalTables()).thenReturn(new LinkedList<LogicalTable>() {

        {
            add(logicalTable1);
            add(logicalTable2);
            add(logicalTable3);
        }
    });
    assertNull(ConceptUtil.findDimensionWithName(logicalModel, dn, "other_locale"));
    assertNull(ConceptUtil.findDimensionWithName(logicalModel, "dn2", locale));
    final LogicalTable dimensionWithName = ConceptUtil.findDimensionWithName(logicalModel, dn, locale);
    assertEquals(logicalTable3, dimensionWithName);
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) Matchers.anyString(org.mockito.Matchers.anyString) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) LogicalTable(org.pentaho.metadata.model.LogicalTable) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) Test(org.junit.Test)

Example 5 with LogicalTable

use of org.pentaho.metadata.model.LogicalTable in project pentaho-kettle by pentaho.

the class ConceptUtilTest method testIndexOfFactTable.

@Test
public void testIndexOfFactTable() throws Exception {
    final LogicalModel logicalModel = mock(LogicalModel.class);
    final LogicalTable logicalTable1 = mock(LogicalTable.class);
    when(logicalTable1.getProperty(eq(DefaultPropertyID.TABLE_TYPE.getId()))).thenReturn(TableType.DIMENSION);
    final LogicalTable logicalTable2 = mock(LogicalTable.class);
    when(logicalTable2.getProperty(eq(DefaultPropertyID.TABLE_TYPE.getId()))).thenReturn(TableType.FACT);
    final LogicalTable logicalTable3 = mock(LogicalTable.class);
    when(logicalTable3.getProperty(eq(DefaultPropertyID.TABLE_TYPE.getId()))).thenReturn(TableType.DIMENSION);
    when(logicalModel.getLogicalTables()).thenReturn(new LinkedList<LogicalTable>() {

        {
            add(logicalTable1);
            add(logicalTable2);
            add(logicalTable3);
        }
    });
    final int indexOfFactTable = ConceptUtil.indexOfFactTable(logicalModel);
    assertEquals(1, indexOfFactTable);
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) LogicalTable(org.pentaho.metadata.model.LogicalTable) Test(org.junit.Test)

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