Search in sources :

Example 1 with DimensionLookupMeta

use of org.pentaho.di.trans.steps.dimensionlookup.DimensionLookupMeta 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 2 with DimensionLookupMeta

use of org.pentaho.di.trans.steps.dimensionlookup.DimensionLookupMeta in project pentaho-kettle by pentaho.

the class DimensionLookupDialog method create.

// Generate code for create table...
// Conversions done by Database
// For Sybase ASE: don't keep everything in lowercase!
private void create() {
    try {
        DimensionLookupMeta info = new DimensionLookupMeta();
        getInfo(info);
        // new name might not yet be linked to other
        String name = stepname;
        // steps!
        StepMeta stepinfo = new StepMeta(BaseMessages.getString(PKG, "DimensionLookupDialog.Stepinfo.Title"), name, info);
        RowMetaInterface prev = transMeta.getPrevStepFields(stepname);
        String message = null;
        if (Utils.isEmpty(info.getKeyField())) {
            message = BaseMessages.getString(PKG, "DimensionLookupDialog.Error.NoTechnicalKeySpecified");
        }
        if (Utils.isEmpty(info.getTableName())) {
            message = BaseMessages.getString(PKG, "DimensionLookupDialog.Error.NoTableNameSpecified");
        }
        if (message == null) {
            SQLStatement sql = info.getSQLStatements(transMeta, stepinfo, prev, repository, metaStore);
            if (!sql.hasError()) {
                if (sql.hasSQL()) {
                    SQLEditor sqledit = new SQLEditor(transMeta, shell, SWT.NONE, info.getDatabaseMeta(), transMeta.getDbCache(), sql.getSQL());
                    sqledit.open();
                } else {
                    MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
                    mb.setMessage(BaseMessages.getString(PKG, "DimensionLookupDialog.NoSQLNeeds.DialogMessage"));
                    mb.setText(BaseMessages.getString(PKG, "DimensionLookupDialog.NoSQLNeeds.DialogTitle"));
                    mb.open();
                }
            } else {
                MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
                mb.setMessage(sql.getError());
                mb.setText(BaseMessages.getString(PKG, "DimensionLookupDialog.SQLError.DialogTitle"));
                mb.open();
            }
        } else {
            MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
            mb.setMessage(message);
            mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title"));
            mb.open();
        }
    } catch (KettleException ke) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "DimensionLookupDialog.UnableToBuildSQLError.DialogMessage"), BaseMessages.getString(PKG, "DimensionLookupDialog.UnableToBuildSQLError.DialogTitle"), ke);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) SQLEditor(org.pentaho.di.ui.core.database.dialog.SQLEditor) DimensionLookupMeta(org.pentaho.di.trans.steps.dimensionlookup.DimensionLookupMeta) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) SQLStatement(org.pentaho.di.core.SQLStatement) MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

StepMeta (org.pentaho.di.trans.step.StepMeta)2 DimensionLookupMeta (org.pentaho.di.trans.steps.dimensionlookup.DimensionLookupMeta)2 ArrayList (java.util.ArrayList)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1 SQLStatement (org.pentaho.di.core.SQLStatement)1 KettleException (org.pentaho.di.core.exception.KettleException)1 Point (org.pentaho.di.core.gui.Point)1 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)1 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)1 AttributeType (org.pentaho.di.starmodeler.AttributeType)1 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)1 SQLEditor (org.pentaho.di.ui.core.database.dialog.SQLEditor)1 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)1 LogicalColumn (org.pentaho.metadata.model.LogicalColumn)1