Search in sources :

Example 16 with LogicalColumn

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

the class StarModelDialog method copyTable.

protected boolean copyTable(Shell shell, LogicalModel logicalModel, String tableName) {
    LogicalTable originalTable = findLogicalTable(tableName);
    if (originalTable != null) {
        // Copy
        // 
        LogicalTable logicalTable = new LogicalTable();
        logicalTable.setId(UUID.randomUUID().toString());
        logicalTable.setName(new LocalizedString(locale, ConceptUtil.getName(originalTable, locale) + " (Copy)"));
        logicalTable.setDescription(new LocalizedString(locale, ConceptUtil.getDescription(originalTable, locale) + " (Copy)"));
        logicalTable.setProperty(DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME, originalTable.getProperty(DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME));
        logicalTable.setProperty(DefaultPropertyID.TABLE_TYPE.getId(), originalTable.getProperty(DefaultPropertyID.TABLE_TYPE.getId()));
        for (LogicalColumn column : originalTable.getLogicalColumns()) {
            logicalTable.getLogicalColumns().add((LogicalColumn) column.clone());
        }
        DimensionTableDialog dialog = new DimensionTableDialog(shell, logicalTable, locale);
        if (dialog.open() != null) {
            logicalModel.addLogicalTable(logicalTable);
            return true;
        }
    }
    return false;
}
Also used : LogicalColumn(org.pentaho.metadata.model.LogicalColumn) LogicalTable(org.pentaho.metadata.model.LogicalTable) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString)

Example 17 with LogicalColumn

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

the class StarModelDialog method getRelationshipsFromFact.

protected void getRelationshipsFromFact() {
    logicalRelationships = new ArrayList<LogicalRelationship>();
    getFactColumns();
    for (LogicalColumn column : factTable.getLogicalColumns()) {
        String dimensionName = ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_DIMENSION_NAME);
        if (!Utils.isEmpty(dimensionName)) {
            LogicalTable dimensionTable = ConceptUtil.findDimensionWithName(logicalModel, dimensionName, locale);
            if (dimensionTable != null) {
                LogicalColumn tk = ConceptUtil.findLogicalColumn(dimensionTable, AttributeType.TECHNICAL_KEY);
                if (tk == null) {
                    tk = ConceptUtil.findLogicalColumn(dimensionTable, AttributeType.SMART_TECHNICAL_KEY);
                }
                if (tk != null) {
                    LogicalTable fromTable = factTable;
                    LogicalColumn fromColumn = column;
                    LogicalTable toTable = dimensionTable;
                    LogicalColumn toColumn = tk;
                    LogicalRelationship relationship = new LogicalRelationship(logicalModel, fromTable, toTable, fromColumn, toColumn);
                    logicalRelationships.add(relationship);
                }
            }
        }
    }
}
Also used : LogicalColumn(org.pentaho.metadata.model.LogicalColumn) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) LogicalTable(org.pentaho.metadata.model.LogicalTable) LogicalRelationship(org.pentaho.metadata.model.LogicalRelationship)

Example 18 with LogicalColumn

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

the class JobGenerator method generateDimensionLookupStepFromLogicalTable.

protected StepMeta generateDimensionLookupStepFromLogicalTable(DatabaseMeta databaseMeta, LogicalTable logicalTable) {
    String name = ConceptUtil.getName(logicalTable, locale);
    String description = ConceptUtil.getDescription(logicalTable, locale);
    String phTable = ConceptUtil.getString(logicalTable, DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME);
    String schemaTable = databaseMeta.getQuotedSchemaTableCombination(null, Const.NVL(phTable, name));
    DimensionLookupMeta meta = new DimensionLookupMeta();
    meta.setDatabaseMeta(databaseMeta);
    // TODO
    meta.setSchemaName(null);
    meta.setTableName(schemaTable);
    meta.setAutoIncrement(databaseMeta.supportsAutoinc());
    meta.setCacheSize(5000);
    meta.setCommitSize(500);
    meta.setUpdate(true);
    // Find the technical key (if any defined)
    // 
    LogicalColumn keyColumn = ConceptUtil.findLogicalColumn(logicalTable, AttributeType.TECHNICAL_KEY);
    if (keyColumn != null) {
        ValueMetaInterface keyValue = getValueForLogicalColumn(databaseMeta, keyColumn);
        meta.setKeyField(keyValue.getName());
    }
    // Simply add all the NATURAL_KEY columns...
    // 
    List<LogicalColumn> naturalKeys = ConceptUtil.findLogicalColumns(logicalTable, AttributeType.NATURAL_KEY);
    meta.setKeyLookup(new String[naturalKeys.size()]);
    meta.setKeyStream(new String[naturalKeys.size()]);
    for (int i = 0; i < naturalKeys.size(); i++) {
        LogicalColumn logicalColumn = naturalKeys.get(i);
        ValueMetaInterface valueMeta = getValueForLogicalColumn(databaseMeta, logicalColumn);
        meta.getKeyLookup()[i] = valueMeta.getName();
        meta.getKeyStream()[i] = valueMeta.getName();
    }
    // All other attribute columns go in the fields tab
    // 
    List<LogicalColumn> attributes = new ArrayList<LogicalColumn>();
    for (LogicalColumn logicalColumn : logicalTable.getLogicalColumns()) {
        AttributeType attributeType = ConceptUtil.getAttributeType(logicalColumn);
        if (attributeType.isAttribute()) {
            attributes.add(logicalColumn);
        }
    }
    meta.setFieldLookup(new String[attributes.size()]);
    meta.setFieldStream(new String[attributes.size()]);
    meta.setFieldUpdate(new int[attributes.size()]);
    for (int i = 0; i < attributes.size(); i++) {
        LogicalColumn logicalColumn = attributes.get(i);
        AttributeType attributeType = ConceptUtil.getAttributeType(logicalColumn);
        ValueMetaInterface valueMeta = getValueForLogicalColumn(databaseMeta, logicalColumn);
        meta.getFieldLookup()[i] = valueMeta.getName();
        meta.getFieldStream()[i] = valueMeta.getName();
        if (attributeType == AttributeType.ATTRIBUTE_OVERWRITE) {
            meta.getFieldUpdate()[i] = DimensionLookupMeta.TYPE_UPDATE_DIM_PUNCHTHROUGH;
        } else {
            // Historical or default: keep versions of the dimension records...
            // 
            meta.getFieldUpdate()[i] = DimensionLookupMeta.TYPE_UPDATE_DIM_INSERT;
        }
    }
    // The version field...
    // 
    LogicalColumn versionColumn = ConceptUtil.findLogicalColumn(logicalTable, AttributeType.VERSION_FIELD);
    if (versionColumn != null) {
        String phName = ConceptUtil.getString(versionColumn, DefaultIDs.LOGICAL_COLUMN_PHYSICAL_COLUMN_NAME);
        meta.setVersionField(phName);
    }
    // Start of the date range
    // 
    LogicalColumn startRangeColumn = ConceptUtil.findLogicalColumn(logicalTable, AttributeType.DATE_START);
    if (startRangeColumn != null) {
        String phName = ConceptUtil.getString(startRangeColumn, DefaultIDs.LOGICAL_COLUMN_PHYSICAL_COLUMN_NAME);
        meta.setDateFrom(phName);
    }
    // End of the date range
    // 
    LogicalColumn endRangeColumn = ConceptUtil.findLogicalColumn(logicalTable, AttributeType.DATE_END);
    if (endRangeColumn != null) {
        String phName = ConceptUtil.getString(endRangeColumn, DefaultIDs.LOGICAL_COLUMN_PHYSICAL_COLUMN_NAME);
        meta.setDateTo(phName);
    }
    StepMeta stepMeta = new StepMeta(name, meta);
    stepMeta.drawStep();
    stepMeta.setDescription(description);
    return stepMeta;
}
Also used : LogicalColumn(org.pentaho.metadata.model.LogicalColumn) DimensionLookupMeta(org.pentaho.di.trans.steps.dimensionlookup.DimensionLookupMeta) AttributeType(org.pentaho.di.starmodeler.AttributeType) ArrayList(java.util.ArrayList) StepMeta(org.pentaho.di.trans.step.StepMeta) Point(org.pentaho.di.core.gui.Point) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 19 with LogicalColumn

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

the class JobGenerator method generateCombinationLookupStepFromLogicalTable.

protected StepMeta generateCombinationLookupStepFromLogicalTable(DatabaseMeta databaseMeta, LogicalTable logicalTable) {
    String name = ConceptUtil.getName(logicalTable, locale);
    String description = ConceptUtil.getDescription(logicalTable, locale);
    String phTable = ConceptUtil.getString(logicalTable, DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME);
    String schemaTable = databaseMeta.getQuotedSchemaTableCombination(null, Const.NVL(phTable, name));
    CombinationLookupMeta meta = new CombinationLookupMeta();
    meta.setDatabaseMeta(databaseMeta);
    // TODO
    meta.setSchemaName(null);
    meta.setTablename(schemaTable);
    meta.setUseAutoinc(databaseMeta.supportsAutoinc());
    meta.setCacheSize(5000);
    meta.setCommitSize(500);
    // replace attribute fields with a TK
    meta.setReplaceFields(true);
    // Find the technical key (if any defined)
    // 
    LogicalColumn keyColumn = ConceptUtil.findLogicalColumn(logicalTable, AttributeType.TECHNICAL_KEY);
    if (keyColumn != null) {
        ValueMetaInterface keyValue = getValueForLogicalColumn(databaseMeta, keyColumn);
        meta.setTechnicalKeyField(keyValue.getName());
    }
    // Simply add all the attributes as key columns...
    // 
    List<LogicalColumn> attributes = ConceptUtil.findLogicalColumns(logicalTable, AttributeType.ATTRIBUTE);
    meta.setKeyLookup(new String[attributes.size()]);
    meta.setKeyField(new String[attributes.size()]);
    for (int i = 0; i < attributes.size(); i++) {
        LogicalColumn logicalColumn = attributes.get(i);
        ValueMetaInterface valueMeta = getValueForLogicalColumn(databaseMeta, logicalColumn);
        meta.getKeyLookup()[i] = valueMeta.getName();
        meta.getKeyField()[i] = valueMeta.getName();
    }
    StepMeta stepMeta = new StepMeta(name, meta);
    stepMeta.drawStep();
    stepMeta.setDescription(description);
    return stepMeta;
}
Also used : LogicalColumn(org.pentaho.metadata.model.LogicalColumn) CombinationLookupMeta(org.pentaho.di.trans.steps.combinationlookup.CombinationLookupMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) Point(org.pentaho.di.core.gui.Point) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 20 with LogicalColumn

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

the class JobGenerator method getRowForLogicalTable.

private RowMetaInterface getRowForLogicalTable(DatabaseMeta databaseMeta, LogicalTable logicalTable) {
    RowMetaInterface fields = new RowMeta();
    for (LogicalColumn column : logicalTable.getLogicalColumns()) {
        ValueMetaInterface valueMeta = getValueForLogicalColumn(databaseMeta, column);
        fields.addValueMeta(valueMeta);
    }
    return fields;
}
Also used : LogicalColumn(org.pentaho.metadata.model.LogicalColumn) RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Aggregations

LogicalColumn (org.pentaho.metadata.model.LogicalColumn)30 LocalizedString (org.pentaho.metadata.model.concept.types.LocalizedString)16 LogicalTable (org.pentaho.metadata.model.LogicalTable)12 ArrayList (java.util.ArrayList)10 LogicalModel (org.pentaho.metadata.model.LogicalModel)9 Domain (org.pentaho.metadata.model.Domain)8 Category (org.pentaho.metadata.model.Category)7 Test (org.junit.Test)5 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)4 SqlDataSource (org.pentaho.metadata.model.SqlDataSource)4 SqlPhysicalColumn (org.pentaho.metadata.model.SqlPhysicalColumn)4 SqlPhysicalModel (org.pentaho.metadata.model.SqlPhysicalModel)4 SqlPhysicalTable (org.pentaho.metadata.model.SqlPhysicalTable)4 AggregationType (org.pentaho.metadata.model.concept.types.AggregationType)4 Point (org.pentaho.di.core.gui.Point)3 StepMeta (org.pentaho.di.trans.step.StepMeta)3 List (java.util.List)2 Document (org.dom4j.Document)2 Element (org.dom4j.Element)2 TableItem (org.eclipse.swt.widgets.TableItem)2