Search in sources :

Example 21 with KettlePluginException

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

the class RowMetaAndData method addValue.

public void addValue(String valueName, int valueType, Object valueData) {
    ValueMetaInterface v;
    try {
        v = ValueMetaFactory.createValueMeta(valueName, valueType);
    } catch (KettlePluginException e) {
        v = new ValueMetaNone(valueName);
    }
    addValue(v, valueData);
}
Also used : KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) ValueMetaNone(org.pentaho.di.core.row.value.ValueMetaNone) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 22 with KettlePluginException

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

the class TableInputMeta 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;
    }
    boolean param = false;
    Database db = getDatabase();
    // keep track of it for canceling purposes...
    super.databases = new Database[] { db };
    // First try without connecting to the database... (can be S L O W)
    String sNewSQL = sql;
    if (isVariableReplacementActive()) {
        sNewSQL = db.environmentSubstitute(sql);
        if (space != null) {
            sNewSQL = space.environmentSubstitute(sNewSQL);
        }
    }
    RowMetaInterface add = null;
    try {
        add = db.getQueryFields(sNewSQL, param);
    } catch (KettleDatabaseException dbe) {
        throw new KettleStepException("Unable to get queryfields for SQL: " + Const.CR + sNewSQL, dbe);
    }
    if (add != null) {
        for (int i = 0; i < add.size(); i++) {
            ValueMetaInterface v = add.getValueMeta(i);
            v.setOrigin(origin);
        }
        row.addRowMeta(add);
    } else {
        try {
            db.connect();
            RowMetaInterface paramRowMeta = null;
            Object[] paramData = null;
            StreamInterface infoStream = getStepIOMeta().getInfoStreams().get(0);
            if (!Utils.isEmpty(infoStream.getStepname())) {
                param = true;
                if (info.length >= 0 && info[0] != null) {
                    paramRowMeta = info[0];
                    paramData = RowDataUtil.allocateRowData(paramRowMeta.size());
                }
            }
            add = db.getQueryFields(sNewSQL, param, paramRowMeta, paramData);
            if (add == null) {
                return;
            }
            for (int i = 0; i < add.size(); i++) {
                ValueMetaInterface v = add.getValueMeta(i);
                v.setOrigin(origin);
            }
            row.addRowMeta(add);
        } catch (KettleException ke) {
            throw new KettleStepException("Unable to get queryfields for SQL: " + Const.CR + sNewSQL, ke);
        } finally {
            db.disconnect();
        }
    }
    if (isLazyConversionActive()) {
        for (int i = 0; i < row.size(); i++) {
            ValueMetaInterface v = row.getValueMeta(i);
            try {
                if (v.getType() == ValueMetaInterface.TYPE_STRING) {
                    ValueMetaInterface storageMeta = ValueMetaFactory.cloneValueMeta(v);
                    storageMeta.setStorageType(ValueMetaInterface.STORAGE_TYPE_NORMAL);
                    v.setStorageMetadata(storageMeta);
                    v.setStorageType(ValueMetaInterface.STORAGE_TYPE_BINARY_STRING);
                }
            } catch (KettlePluginException e) {
                throw new KettleStepException("Unable to clone meta for lazy conversion: " + Const.CR + v, e);
            }
        }
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Database(org.pentaho.di.core.database.Database) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface)

Example 23 with KettlePluginException

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

the class TransExecutorMeta method addFieldToRow.

protected void addFieldToRow(RowMetaInterface row, String fieldName, int type, int length, int precision) throws KettleStepException {
    if (!Utils.isEmpty(fieldName)) {
        try {
            ValueMetaInterface value = ValueMetaFactory.createValueMeta(fieldName, type, length, precision);
            value.setOrigin(getParentStepMeta().getName());
            row.addValueMeta(value);
        } catch (KettlePluginException e) {
            throw new KettleStepException(BaseMessages.getString(PKG, "TransExecutorMeta.ValueMetaInterfaceCreation", fieldName), 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 24 with KettlePluginException

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

the class YamlInputMeta method getFields.

@Override
public void getFields(RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    int i;
    for (i = 0; i < inputFields.length; i++) {
        YamlInputField field = inputFields[i];
        int type = field.getType();
        if (type == ValueMetaInterface.TYPE_NONE) {
            type = ValueMetaInterface.TYPE_STRING;
        }
        String valueName = space.environmentSubstitute(field.getName());
        ValueMetaInterface v;
        try {
            v = ValueMetaFactory.createValueMeta(valueName, type);
        } catch (KettlePluginException e) {
            v = new ValueMetaString(valueName);
        }
        v.setLength(field.getLength());
        v.setPrecision(field.getPrecision());
        v.setOrigin(name);
        v.setConversionMask(field.getFormat());
        v.setDecimalSymbol(field.getDecimalSymbol());
        v.setGroupingSymbol(field.getGroupSymbol());
        v.setCurrencySymbol(field.getCurrencySymbol());
        r.addValueMeta(v);
    }
    if (includeFilename) {
        ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(filenameField));
        v.setLength(250);
        v.setPrecision(-1);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (includeRowNumber) {
        ValueMetaInterface v = new ValueMetaInteger(space.environmentSubstitute(rowNumberField));
        v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 25 with KettlePluginException

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

the class YamlReader method getFields.

@SuppressWarnings({ "rawtypes", "unchecked" })
public RowMeta getFields() {
    RowMeta rowMeta = new RowMeta();
    Iterator<Object> ito = documents.iterator();
    while (ito.hasNext()) {
        Object data = ito.next();
        if (data instanceof Map) {
            // First check if we deals with a map
            Map<Object, Object> map = (Map<Object, Object>) data;
            Iterator it = map.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry pairs = (Map.Entry) it.next();
                String valueName = pairs.getKey().toString();
                ValueMetaInterface valueMeta;
                try {
                    valueMeta = ValueMetaFactory.createValueMeta(valueName, getType(pairs.getValue()));
                } catch (KettlePluginException e) {
                    valueMeta = new ValueMetaNone(valueName);
                }
                rowMeta.addValueMeta(valueMeta);
            }
        } else if (data instanceof List) {
            rowMeta = new RowMeta();
            // Maybe we deals with List
            List<Object> list = (List<Object>) data;
            Iterator<Object> it = list.iterator();
            Object value = it.next();
            if (list.size() == 1) {
                Map<Object, Object> map = (Map<Object, Object>) value;
                Iterator its = map.entrySet().iterator();
                while (its.hasNext()) {
                    Map.Entry pairs = (Map.Entry) its.next();
                    String valueName = pairs.getKey().toString();
                    ValueMetaInterface valueMeta;
                    try {
                        valueMeta = ValueMetaFactory.createValueMeta(valueName, getType(pairs.getValue()));
                    } catch (KettlePluginException e) {
                        valueMeta = new ValueMetaNone(valueName);
                    }
                    rowMeta.addValueMeta(valueMeta);
                }
            } else {
                ValueMetaInterface valueMeta;
                try {
                    valueMeta = ValueMetaFactory.createValueMeta(DEFAULT_LIST_VALUE_NAME, getType(value));
                } catch (KettlePluginException e) {
                    valueMeta = new ValueMetaNone(DEFAULT_LIST_VALUE_NAME);
                }
                rowMeta.addValueMeta(valueMeta);
            }
        }
    }
    return rowMeta;
}
Also used : KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) ValueMetaNone(org.pentaho.di.core.row.value.ValueMetaNone) Iterator(java.util.Iterator) FileObject(org.apache.commons.vfs2.FileObject) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Aggregations

KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)47 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)23 FileObject (org.apache.commons.vfs2.FileObject)12 Node (org.w3c.dom.Node)11 RowMeta (org.pentaho.di.core.row.RowMeta)10 ValueMetaNone (org.pentaho.di.core.row.value.ValueMetaNone)10 Document (org.w3c.dom.Document)10 ArrayList (java.util.ArrayList)9 KettleStepException (org.pentaho.di.core.exception.KettleStepException)9 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)9 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)9 PluginInterface (org.pentaho.di.core.plugins.PluginInterface)7 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)6 Map (java.util.Map)4 KettleException (org.pentaho.di.core.exception.KettleException)4 PluginFolderInterface (org.pentaho.di.core.plugins.PluginFolderInterface)4 IOException (java.io.IOException)3 Annotation (java.lang.annotation.Annotation)3 URLClassLoader (java.net.URLClassLoader)3 HashMap (java.util.HashMap)3