Search in sources :

Example 1 with AttributeType

use of org.pentaho.di.starmodeler.AttributeType 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)

Aggregations

ArrayList (java.util.ArrayList)1 Point (org.pentaho.di.core.gui.Point)1 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)1 AttributeType (org.pentaho.di.starmodeler.AttributeType)1 StepMeta (org.pentaho.di.trans.step.StepMeta)1 DimensionLookupMeta (org.pentaho.di.trans.steps.dimensionlookup.DimensionLookupMeta)1 LogicalColumn (org.pentaho.metadata.model.LogicalColumn)1