Search in sources :

Example 11 with LogicalTable

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

the class JobGeneratorTest method testGetUniqueLogicalTables.

@Test
public void testGetUniqueLogicalTables() 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);
        }
    });
    final List<LogicalTable> uniqueLogicalTables = jobGenerator.getUniqueLogicalTables();
    assertNotNull(uniqueLogicalTables);
    assertEquals(1, uniqueLogicalTables.size());
    assertEquals(logicalTable, uniqueLogicalTables.get(0));
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) LogicalTable(org.pentaho.metadata.model.LogicalTable) Test(org.junit.Test)

Example 12 with LogicalTable

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

the class JobGeneratorTest method testGenerateCombinationLookupStepFromLogicalTable.

@Test
public void testGenerateCombinationLookupStepFromLogicalTable() throws Exception {
    final LogicalTable logicalTable = mock(LogicalTable.class);
    final DatabaseMeta databaseMeta = mock(DatabaseMeta.class);
    final StepMeta stepMeta = jobGenerator.generateCombinationLookupStepFromLogicalTable(databaseMeta, logicalTable);
    assertNotNull(stepMeta);
}
Also used : LogicalTable(org.pentaho.metadata.model.LogicalTable) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) Test(org.junit.Test)

Example 13 with LogicalTable

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

the class StarModelDialog method addDimensionKeys.

protected void addDimensionKeys() {
    // Import the technical keys from all the dimensions in the fact table...
    // 
    List<LogicalColumn> keyColumns = new ArrayList<LogicalColumn>();
    List<LogicalTable> dimensionTables = ConceptUtil.findLogicalTables(logicalModel, TableType.DIMENSION);
    for (LogicalTable dimensionTable : dimensionTables) {
        // Find the technical or smart key
        // 
        keyColumns.addAll(ConceptUtil.findLogicalColumns(dimensionTable, AttributeType.SMART_TECHNICAL_KEY));
        keyColumns.addAll(ConceptUtil.findLogicalColumns(dimensionTable, AttributeType.TECHNICAL_KEY));
    }
    for (LogicalColumn keyColumn : keyColumns) {
        LogicalColumn column = new LogicalColumn();
        String dimensionName = ConceptUtil.getName(keyColumn.getLogicalTable(), locale);
        column.setName(new LocalizedString(locale, dimensionName + " TK"));
        column.setDescription(new LocalizedString(locale, ConceptUtil.getDescription(keyColumn, locale)));
        column.setProperty(DefaultIDs.LOGICAL_COLUMN_PHYSICAL_COLUMN_NAME, dimensionName.toLowerCase().replace(' ', '_') + "_tk");
        column.setProperty(DefaultIDs.LOGICAL_COLUMN_ATTRIBUTE_TYPE, AttributeType.TECHNICAL_KEY.name());
        column.setDataType(keyColumn.getDataType());
        column.setProperty(DefaultIDs.LOGICAL_COLUMN_DIMENSION_NAME, dimensionName);
        column.setProperty(DefaultIDs.LOGICAL_COLUMN_LENGTH, ConceptUtil.getString(keyColumn, DefaultIDs.LOGICAL_COLUMN_LENGTH));
        column.setProperty(DefaultIDs.LOGICAL_COLUMN_LENGTH, ConceptUtil.getString(keyColumn, DefaultIDs.LOGICAL_COLUMN_LENGTH));
        column.setProperty(DefaultIDs.LOGICAL_COLUMN_CONVERSION_REMARKS, "Key to dimension '" + dimensionName + "'");
        addLogicalColumnToFactAttributesList(column);
    }
    wFactAttributes.removeEmptyRows();
    wFactAttributes.setRowNums();
    wFactAttributes.optWidth(true);
    getRelationshipsFromFact();
}
Also used : LogicalColumn(org.pentaho.metadata.model.LogicalColumn) ArrayList(java.util.ArrayList) LogicalTable(org.pentaho.metadata.model.LogicalTable) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString)

Example 14 with LogicalTable

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

the class DataAccessServiceTestBase method getDomain.

/**
 * Provide a mock domain
 *
 * @return
 */
private Domain getDomain() {
    LogicalColumn logicalColumn1;
    LogicalColumn logicalColumn2;
    String locale = LocaleHelper.getLocale().toString();
    SqlPhysicalModel model = new SqlPhysicalModel();
    SqlDataSource dataSource = new SqlDataSource();
    dataSource.setDatabaseName("SampleData");
    model.setDatasource(dataSource);
    SqlPhysicalTable table = new SqlPhysicalTable(model);
    model.getPhysicalTables().add(table);
    table.setTargetTableType(TargetTableType.INLINE_SQL);
    table.setTargetTable("select * from customers");
    table.setId("customers");
    SqlPhysicalColumn column = new SqlPhysicalColumn(table);
    column.setTargetColumn("customername");
    column.setName(new LocalizedString(locale, "Customer Name"));
    column.setDescription(new LocalizedString(locale, "Customer Name Desc"));
    column.setDataType(DataType.STRING);
    column.setId("cutomer_customername");
    table.getPhysicalColumns().add(column);
    LogicalModel logicalModel = new LogicalModel();
    model.setId("MODEL");
    model.setName(new LocalizedString(locale, "My Model"));
    model.setDescription(new LocalizedString(locale, "A Description of the Model"));
    LogicalTable logicalTable = new LogicalTable();
    logicalTable.setId("BT_CUSTOMERS");
    logicalTable.setPhysicalTable(table);
    logicalModel.getLogicalTables().add(logicalTable);
    logicalModel.setName(new LocalizedString(locale, "My Model"));
    logicalColumn1 = new LogicalColumn();
    logicalColumn1.setId("LC_CUSTOMERNAME");
    logicalColumn1.setPhysicalColumn(column);
    logicalColumn1.setAggregationType(AggregationType.COUNT);
    logicalColumn1.setLogicalTable(logicalTable);
    logicalColumn1.setDataType(DataType.STRING);
    logicalColumn2 = new LogicalColumn();
    logicalColumn2.setId("LC_CUSTOMERNUMBER");
    logicalColumn2.setAggregationType(AggregationType.COUNT);
    logicalColumn2.setPhysicalColumn(column);
    logicalColumn2.setLogicalTable(logicalTable);
    logicalColumn2.setDataType(DataType.NUMERIC);
    logicalTable.addLogicalColumn(logicalColumn1);
    logicalTable.addLogicalColumn(logicalColumn2);
    Domain thisDomain = new Domain();
    thisDomain.addPhysicalModel(model);
    thisDomain.addLogicalModel(logicalModel);
    return thisDomain;
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) LogicalColumn(org.pentaho.metadata.model.LogicalColumn) SqlDataSource(org.pentaho.metadata.model.SqlDataSource) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) SqlPhysicalColumn(org.pentaho.metadata.model.SqlPhysicalColumn) LogicalTable(org.pentaho.metadata.model.LogicalTable) SqlPhysicalModel(org.pentaho.metadata.model.SqlPhysicalModel) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) Domain(org.pentaho.metadata.model.Domain) SqlPhysicalTable(org.pentaho.metadata.model.SqlPhysicalTable)

Example 15 with LogicalTable

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

the class DatasourceModelTest method contructRelationalModel.

private GuiStateModel contructRelationalModel(GuiStateModel guiStateModel) {
    IDatabaseConnection connection = new DatabaseConnection();
    connection.setAccessType(DatabaseAccessType.NATIVE);
    // connection.setDriverClass("org.hsqldb.jdbcDriver");
    connection.setName("SampleData");
    connection.setPassword("password");
    // connection.setUrl("jdbc:hsqldb:file:target/test-classes/solution1/system/data/sampledata");
    connection.setUsername("pentaho_user");
    List<IDatabaseConnection> connectionList = new ArrayList<IDatabaseConnection>();
    connectionList.add(connection);
    guiStateModel.setConnections(connectionList);
    guiStateModel.setPreviewLimit("10");
    guiStateModel.validateRelational();
    LogicalColumn logColumn = new LogicalColumn();
    logColumn.setDataType(DataType.NUMERIC);
    List<AggregationType> aggTypeList = new ArrayList<AggregationType>();
    aggTypeList.add(AggregationType.AVERAGE);
    logColumn.setAggregationList(aggTypeList);
    logColumn.setName(new LocalizedString("En", "Column1"));
    BusinessData businessData = new BusinessData();
    List<List<String>> dataSample = new ArrayList<List<String>>();
    List<String> rowData = new ArrayList<String>();
    rowData.add("Data1");
    rowData.add("Data2");
    rowData.add("Data3");
    rowData.add("Data4");
    dataSample.add(rowData);
    String locale = LocaleHelper.getLocale().toString();
    SqlPhysicalModel model = new SqlPhysicalModel();
    SqlDataSource dataSource = new SqlDataSource();
    dataSource.setDatabaseName("SampleData");
    model.setDatasource(dataSource);
    SqlPhysicalTable table = new SqlPhysicalTable(model);
    model.getPhysicalTables().add(table);
    table.setTargetTableType(TargetTableType.INLINE_SQL);
    table.setTargetTable("select * from customers");
    SqlPhysicalColumn column = new SqlPhysicalColumn(table);
    column.setTargetColumn("customername");
    column.setName(new LocalizedString(locale, "Customer Name"));
    column.setDescription(new LocalizedString(locale, "Customer Name Desc"));
    column.setDataType(DataType.STRING);
    table.getPhysicalColumns().add(column);
    LogicalModel logicalModel = new LogicalModel();
    model.setId("MODEL");
    model.setName(new LocalizedString(locale, "My Model"));
    model.setDescription(new LocalizedString(locale, "A Description of the Model"));
    LogicalTable logicalTable = new LogicalTable();
    logicalTable.setPhysicalTable(table);
    logicalModel.getLogicalTables().add(logicalTable);
    LogicalColumn logicalColumn = new LogicalColumn();
    logicalColumn.setId("LC_CUSTOMERNAME");
    logicalColumn.setPhysicalColumn(column);
    logicalTable.addLogicalColumn(logicalColumn);
    Category mainCategory = new Category();
    mainCategory.setId("CATEGORY");
    mainCategory.setName(new LocalizedString(locale, "Category"));
    mainCategory.addLogicalColumn(logicalColumn);
    logicalModel.getCategories().add(mainCategory);
    Domain domain = new Domain();
    domain.addPhysicalModel(model);
    domain.addLogicalModel(logicalModel);
    List<LocaleType> localeTypeList = new ArrayList<LocaleType>();
    localeTypeList.add(new LocaleType("Code", "Locale Description"));
    domain.setLocales(localeTypeList);
    businessData.setData(dataSample);
    businessData.setDomain(domain);
    guiStateModel.setLocaleCode("en");
    guiStateModel.setLogicalModels(domain.getLogicalModels());
    guiStateModel.validateRelational();
    return guiStateModel;
}
Also used : BusinessData(org.pentaho.platform.dataaccess.datasource.beans.BusinessData) LogicalColumn(org.pentaho.metadata.model.LogicalColumn) Category(org.pentaho.metadata.model.Category) ArrayList(java.util.ArrayList) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) SqlPhysicalColumn(org.pentaho.metadata.model.SqlPhysicalColumn) LogicalTable(org.pentaho.metadata.model.LogicalTable) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) SqlPhysicalModel(org.pentaho.metadata.model.SqlPhysicalModel) AggregationType(org.pentaho.metadata.model.concept.types.AggregationType) SqlPhysicalTable(org.pentaho.metadata.model.SqlPhysicalTable) LogicalModel(org.pentaho.metadata.model.LogicalModel) SqlDataSource(org.pentaho.metadata.model.SqlDataSource) LocaleType(org.pentaho.metadata.model.concept.types.LocaleType) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) ArrayList(java.util.ArrayList) List(java.util.List) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Domain(org.pentaho.metadata.model.Domain)

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