Search in sources :

Example 41 with KettleStepException

use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.

the class InjectorMeta method getFields.

public void getFields(RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    for (int i = 0; i < this.fieldname.length; i++) {
        ValueMetaInterface v;
        try {
            v = ValueMetaFactory.createValueMeta(this.fieldname[i], type[i], length[i], precision[i]);
            inputRowMeta.addValueMeta(v);
        } catch (KettlePluginException e) {
            throw new KettleStepException(e);
        }
    }
}
Also used : KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 42 with KettleStepException

use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.

the class JaninoMeta method getFields.

@Override
public void getFields(RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    for (int i = 0; i < formula.length; i++) {
        JaninoMetaFunction fn = formula[i];
        if (Utils.isEmpty(fn.getReplaceField())) {
            // Not replacing a field.
            if (!Utils.isEmpty(fn.getFieldName())) {
                try {
                    ValueMetaInterface v = ValueMetaFactory.createValueMeta(fn.getFieldName(), fn.getValueType());
                    v.setLength(fn.getValueLength(), fn.getValuePrecision());
                    v.setOrigin(name);
                    row.addValueMeta(v);
                } catch (Exception e) {
                    throw new KettleStepException(e);
                }
            }
        } else {
            // Replacing a field
            int index = row.indexOfValue(fn.getReplaceField());
            if (index < 0) {
                throw new KettleStepException("Unknown field specified to replace with a formula result: [" + fn.getReplaceField() + "]");
            }
            // Change the data type etc.
            // 
            ValueMetaInterface v = row.getValueMeta(index).clone();
            v.setLength(fn.getValueLength(), fn.getValuePrecision());
            v.setOrigin(name);
            // replace it
            row.setValueMeta(index, v);
        }
    }
}
Also used : KettleStepException(org.pentaho.di.core.exception.KettleStepException) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 43 with KettleStepException

use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.

the class MappingInputMeta method getFields.

public void getFields(RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    // 
    if (inputRowMeta != null && !inputRowMeta.isEmpty()) {
        // First rename any fields...
        if (valueRenames != null) {
            for (MappingValueRename valueRename : valueRenames) {
                ValueMetaInterface valueMeta = inputRowMeta.searchValueMeta(valueRename.getSourceValueName());
                if (valueMeta == null) {
                    // ok, let's search once again, now using target name
                    valueMeta = inputRowMeta.searchValueMeta(valueRename.getTargetValueName());
                    if (valueMeta == null) {
                        throw new KettleStepException(BaseMessages.getString(PKG, "MappingInput.Exception.UnableToFindMappedValue", valueRename.getSourceValueName()));
                    }
                } else {
                    valueMeta.setName(valueRename.getTargetValueName());
                }
            }
        }
        if (selectingAndSortingUnspecifiedFields) {
            // Select the specified fields from the input, re-order everything and put the other fields at the back,
            // sorted...
            // 
            RowMetaInterface newRow = new RowMeta();
            for (int i = 0; i < fieldName.length; i++) {
                int index = inputRowMeta.indexOfValue(fieldName[i]);
                if (index < 0) {
                    throw new KettleStepException(BaseMessages.getString(PKG, "MappingInputMeta.Exception.UnknownField", fieldName[i]));
                }
                newRow.addValueMeta(inputRowMeta.getValueMeta(index));
            }
            // Now get the unspecified fields.
            // Sort the fields
            // Add them after the specified fields...
            // 
            List<String> extra = new ArrayList<String>();
            for (int i = 0; i < inputRowMeta.size(); i++) {
                String fieldName = inputRowMeta.getValueMeta(i).getName();
                if (newRow.indexOfValue(fieldName) < 0) {
                    extra.add(fieldName);
                }
            }
            Collections.sort(extra);
            for (String fieldName : extra) {
                ValueMetaInterface extraValue = inputRowMeta.searchValueMeta(fieldName);
                newRow.addValueMeta(extraValue);
            }
            // now merge the new row...
            // This is basically the input row meta data with the fields re-ordered.
            // 
            row.mergeRowMeta(newRow);
        } else {
            row.mergeRowMeta(inputRowMeta);
            // 
            if (!row.isEmpty()) {
                for (int i = 0; i < fieldName.length; i++) {
                    if (row.indexOfValue(fieldName[i]) < 0) {
                        throw new KettleStepException(BaseMessages.getString(PKG, "MappingInputMeta.Exception.UnknownField", fieldName[i]));
                    }
                }
            }
        }
    } else {
        if (row.isEmpty()) {
            // We'll have to work with the statically provided information
            for (int i = 0; i < fieldName.length; i++) {
                if (!Utils.isEmpty(fieldName[i])) {
                    int valueType = fieldType[i];
                    if (valueType == ValueMetaInterface.TYPE_NONE) {
                        valueType = ValueMetaInterface.TYPE_STRING;
                    }
                    ValueMetaInterface v;
                    try {
                        v = ValueMetaFactory.createValueMeta(fieldName[i], valueType);
                        v.setLength(fieldLength[i]);
                        v.setPrecision(fieldPrecision[i]);
                        v.setOrigin(origin);
                        row.addValueMeta(v);
                    } catch (KettlePluginException e) {
                        throw new KettleStepException(e);
                    }
                }
            }
        }
    // else: row is OK, keep it as it is.
    }
}
Also used : MappingValueRename(org.pentaho.di.trans.steps.mapping.MappingValueRename) KettleStepException(org.pentaho.di.core.exception.KettleStepException) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) RowMeta(org.pentaho.di.core.row.RowMeta) ArrayList(java.util.ArrayList) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 44 with KettleStepException

use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.

the class MergeRowsMeta method getFields.

@Override
public void getFields(RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    // 
    if (info != null) {
        boolean found = false;
        for (int i = 0; i < info.length && !found; i++) {
            if (info[i] != null) {
                r.mergeRowMeta(info[i], name);
                found = true;
            }
        }
    }
    if (Utils.isEmpty(flagField)) {
        throw new KettleStepException(BaseMessages.getString(PKG, "MergeRowsMeta.Exception.FlagFieldNotSpecified"));
    }
    ValueMetaInterface flagFieldValue = new ValueMetaString(flagField);
    flagFieldValue.setOrigin(name);
    r.addValueMeta(flagFieldValue);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettleStepException(org.pentaho.di.core.exception.KettleStepException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 45 with KettleStepException

use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.

the class MondrianInputMeta method getFields.

public void getFields(RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    if (databaseMeta == null) {
        // TODO: throw an exception here
        return;
    }
    RowMetaInterface add = null;
    try {
        String mdx = getSQL();
        if (isVariableReplacementActive()) {
            mdx = space.environmentSubstitute(mdx);
        }
        MondrianHelper helper = new MondrianHelper(databaseMeta, catalog, mdx, space);
        add = helper.getCachedRowMeta();
        if (add == null) {
            helper.openQuery();
            helper.createRectangularOutput();
            add = helper.getOutputRowMeta();
        }
    } catch (KettleDatabaseException dbe) {
        throw new KettleStepException("Unable to get query result for MDX query: " + Const.CR + sql, dbe);
    }
    // 
    for (int i = 0; i < add.size(); i++) {
        ValueMetaInterface v = add.getValueMeta(i);
        v.setOrigin(origin);
    }
    row.addRowMeta(add);
}
Also used : KettleStepException(org.pentaho.di.core.exception.KettleStepException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Aggregations

KettleStepException (org.pentaho.di.core.exception.KettleStepException)235 KettleException (org.pentaho.di.core.exception.KettleException)139 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)103 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)97 RowMeta (org.pentaho.di.core.row.RowMeta)51 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)44 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)27 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)27 KettleValueException (org.pentaho.di.core.exception.KettleValueException)26 IOException (java.io.IOException)23 RowAdapter (org.pentaho.di.trans.step.RowAdapter)21 ArrayList (java.util.ArrayList)20 StepMeta (org.pentaho.di.trans.step.StepMeta)19 RowSet (org.pentaho.di.core.RowSet)18 Database (org.pentaho.di.core.database.Database)15 KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)13 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)13 FormAttachment (org.eclipse.swt.layout.FormAttachment)12 FormData (org.eclipse.swt.layout.FormData)12 Button (org.eclipse.swt.widgets.Button)12