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());
}
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;
}
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));
}
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);
}
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);
}
Aggregations