Search in sources :

Example 11 with KettlePluginException

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

the class MemoryGroupByMeta method getFields.

@Override
public void getFields(RowMetaInterface r, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) {
    // Check compatibility mode
    boolean compatibilityMode = ValueMetaBase.convertStringToBoolean(space.getVariable(Const.KETTLE_COMPATIBILITY_MEMORY_GROUP_BY_SUM_AVERAGE_RETURN_NUMBER_TYPE, "N"));
    // re-assemble a new row of metadata
    // 
    RowMetaInterface fields = new RowMeta();
    // 
    for (int i = 0; i < groupField.length; i++) {
        ValueMetaInterface valueMeta = r.searchValueMeta(groupField[i]);
        if (valueMeta != null) {
            valueMeta.setStorageType(ValueMetaInterface.STORAGE_TYPE_NORMAL);
            fields.addValueMeta(valueMeta);
        }
    }
    // 
    for (int i = 0; i < subjectField.length; i++) {
        ValueMetaInterface subj = r.searchValueMeta(subjectField[i]);
        if (subj != null || aggregateType[i] == TYPE_GROUP_COUNT_ANY) {
            String value_name = aggregateField[i];
            int value_type = ValueMetaInterface.TYPE_NONE;
            int length = -1;
            int precision = -1;
            switch(aggregateType[i]) {
                case TYPE_GROUP_FIRST:
                case TYPE_GROUP_LAST:
                case TYPE_GROUP_FIRST_INCL_NULL:
                case TYPE_GROUP_LAST_INCL_NULL:
                case TYPE_GROUP_MIN:
                case TYPE_GROUP_MAX:
                    value_type = subj.getType();
                    break;
                case TYPE_GROUP_COUNT_DISTINCT:
                case TYPE_GROUP_COUNT_ALL:
                case TYPE_GROUP_COUNT_ANY:
                    value_type = ValueMetaInterface.TYPE_INTEGER;
                    break;
                case TYPE_GROUP_CONCAT_COMMA:
                    value_type = ValueMetaInterface.TYPE_STRING;
                    break;
                case TYPE_GROUP_SUM:
                case TYPE_GROUP_AVERAGE:
                    if (!compatibilityMode && subj.isNumeric()) {
                        value_type = subj.getType();
                    } else {
                        value_type = ValueMetaInterface.TYPE_NUMBER;
                    }
                    break;
                case TYPE_GROUP_MEDIAN:
                case TYPE_GROUP_PERCENTILE:
                case TYPE_GROUP_STANDARD_DEVIATION:
                    value_type = ValueMetaInterface.TYPE_NUMBER;
                    break;
                case TYPE_GROUP_CONCAT_STRING:
                    value_type = ValueMetaInterface.TYPE_STRING;
                    break;
                default:
                    break;
            }
            if (aggregateType[i] == TYPE_GROUP_COUNT_ALL || aggregateType[i] == TYPE_GROUP_COUNT_DISTINCT || aggregateType[i] == TYPE_GROUP_COUNT_ANY) {
                length = ValueMetaInterface.DEFAULT_INTEGER_LENGTH;
                precision = 0;
            } else if (aggregateType[i] == TYPE_GROUP_SUM && value_type != ValueMetaInterface.TYPE_INTEGER && value_type != ValueMetaInterface.TYPE_NUMBER && value_type != ValueMetaInterface.TYPE_BIGNUMBER) {
                // If it ain't numeric, we change it to Number
                // 
                value_type = ValueMetaInterface.TYPE_NUMBER;
                precision = -1;
                length = -1;
            }
            if (value_type != ValueMetaInterface.TYPE_NONE) {
                ValueMetaInterface v;
                try {
                    v = ValueMetaFactory.createValueMeta(value_name, value_type);
                } catch (KettlePluginException e) {
                    log.logError(BaseMessages.getString(PKG, "MemoryGroupByMeta.Exception.UnknownValueMetaType"), value_type, e);
                    v = new ValueMetaNone(value_name);
                }
                v.setOrigin(origin);
                v.setLength(length, precision);
                if (subj != null) {
                    v.setConversionMask(subj.getConversionMask());
                }
                fields.addValueMeta(v);
            }
        }
    }
    // Now that we have all the fields we want, we should clear the original row and replace the values...
    // 
    r.clear();
    r.addRowMeta(fields);
}
Also used : KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) ValueMetaNone(org.pentaho.di.core.row.value.ValueMetaNone) RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 12 with KettlePluginException

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

the class DatabaseJoinMeta method getTableFields.

@Override
public RowMetaInterface getTableFields() {
    // Build a dummy parameter row...
    // 
    RowMetaInterface param = new RowMeta();
    for (int i = 0; i < parameterField.length; i++) {
        ValueMetaInterface v;
        try {
            v = ValueMetaFactory.createValueMeta(parameterField[i], parameterType[i]);
        } catch (KettlePluginException e) {
            v = new ValueMetaNone(parameterField[i]);
        }
        param.addValueMeta(v);
    }
    RowMetaInterface fields = null;
    if (databaseMeta != null) {
        Database db = new Database(loggingObject, databaseMeta);
        // Keep track of this one for cancelQuery
        databases = new Database[] { db };
        try {
            db.connect();
            fields = db.getQueryFields(databaseMeta.environmentSubstitute(sql), true, param, new Object[param.size()]);
        } catch (KettleDatabaseException dbe) {
            logError(BaseMessages.getString(PKG, "DatabaseJoinMeta.Log.DatabaseErrorOccurred") + dbe.getMessage());
        } finally {
            db.disconnect();
        }
    }
    return fields;
}
Also used : KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) ValueMetaNone(org.pentaho.di.core.row.value.ValueMetaNone) RowMeta(org.pentaho.di.core.row.RowMeta) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) Database(org.pentaho.di.core.database.Database) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 13 with KettlePluginException

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

the class GetVariableMeta method getFields.

@Override
public void getFields(RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    // Determine the maximum length...
    // 
    int length = -1;
    for (int i = 0; i < fieldDefinitions.length; i++) {
        String variableString = fieldDefinitions[i].getVariableString();
        if (variableString != null) {
            String string = space.environmentSubstitute(variableString);
            if (string.length() > length) {
                length = string.length();
            }
        }
    }
    RowMetaInterface row = new RowMeta();
    for (int i = 0; i < fieldDefinitions.length; i++) {
        ValueMetaInterface v;
        try {
            v = ValueMetaFactory.createValueMeta(fieldDefinitions[i].getFieldName(), fieldDefinitions[i].getFieldType());
        } catch (KettlePluginException e) {
            throw new KettleStepException(e);
        }
        int fieldLength = fieldDefinitions[i].getFieldLength();
        if (fieldLength < 0) {
            v.setLength(length);
        } else {
            v.setLength(fieldLength);
        }
        int fieldPrecision = fieldDefinitions[i].getFieldPrecision();
        if (fieldPrecision >= 0) {
            v.setPrecision(fieldPrecision);
        }
        v.setConversionMask(fieldDefinitions[i].getFieldFormat());
        v.setGroupingSymbol(fieldDefinitions[i].getGroup());
        v.setDecimalSymbol(fieldDefinitions[i].getDecimal());
        v.setCurrencySymbol(fieldDefinitions[i].getCurrency());
        v.setTrimType(fieldDefinitions[i].getTrimType());
        v.setOrigin(name);
        row.addValueMeta(v);
    }
    inputRowMeta.mergeRowMeta(row, name);
}
Also used : KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 14 with KettlePluginException

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

the class GroupBy method newAggregate.

/**
 * used for junits in GroupByAggregationNullsTest
 *
 * @param r
 */
void newAggregate(Object[] r) {
    // Put all the counters at 0
    for (int i = 0; i < data.counts.length; i++) {
        data.counts[i] = 0;
    }
    data.distinctObjs = null;
    data.agg = new Object[data.subjectnrs.length];
    // sets all doubles to 0.0
    data.mean = new double[data.subjectnrs.length];
    data.aggMeta = new RowMeta();
    for (int i = 0; i < data.subjectnrs.length; i++) {
        ValueMetaInterface subjMeta = data.inputRowMeta.getValueMeta(data.subjectnrs[i]);
        Object v = null;
        ValueMetaInterface vMeta = null;
        int aggType = meta.getAggregateType()[i];
        switch(aggType) {
            case GroupByMeta.TYPE_GROUP_SUM:
            case GroupByMeta.TYPE_GROUP_AVERAGE:
            case GroupByMeta.TYPE_GROUP_CUMULATIVE_SUM:
            case GroupByMeta.TYPE_GROUP_CUMULATIVE_AVERAGE:
                if (subjMeta.isNumeric()) {
                    try {
                        vMeta = ValueMetaFactory.createValueMeta(meta.getAggregateField()[i], subjMeta.getType());
                    } catch (KettlePluginException e) {
                        vMeta = new ValueMetaNone(meta.getAggregateField()[i]);
                    }
                } else {
                    vMeta = new ValueMetaNumber(meta.getAggregateField()[i]);
                }
                break;
            case GroupByMeta.TYPE_GROUP_MEDIAN:
            case GroupByMeta.TYPE_GROUP_PERCENTILE:
                vMeta = new ValueMetaNumber(meta.getAggregateField()[i]);
                v = new ArrayList<Double>();
                break;
            case GroupByMeta.TYPE_GROUP_STANDARD_DEVIATION:
                vMeta = new ValueMetaNumber(meta.getAggregateField()[i]);
                break;
            case GroupByMeta.TYPE_GROUP_COUNT_DISTINCT:
            case GroupByMeta.TYPE_GROUP_COUNT_ANY:
            case GroupByMeta.TYPE_GROUP_COUNT_ALL:
                vMeta = new ValueMetaInteger(meta.getAggregateField()[i]);
                break;
            case GroupByMeta.TYPE_GROUP_FIRST:
            case GroupByMeta.TYPE_GROUP_LAST:
            case GroupByMeta.TYPE_GROUP_FIRST_INCL_NULL:
            case GroupByMeta.TYPE_GROUP_LAST_INCL_NULL:
            case GroupByMeta.TYPE_GROUP_MIN:
            case GroupByMeta.TYPE_GROUP_MAX:
                vMeta = subjMeta.clone();
                vMeta.setName(meta.getAggregateField()[i]);
                v = r == null ? null : r[data.subjectnrs[i]];
                break;
            case GroupByMeta.TYPE_GROUP_CONCAT_COMMA:
                vMeta = new ValueMetaString(meta.getAggregateField()[i]);
                v = new StringBuilder();
                break;
            case GroupByMeta.TYPE_GROUP_CONCAT_STRING:
                vMeta = new ValueMetaString(meta.getAggregateField()[i]);
                v = new StringBuilder();
                break;
            default:
                // TODO raise an error here because we cannot continue successfully maybe the UI should validate this
                break;
        }
        if ((subjMeta != null) && (aggType != GroupByMeta.TYPE_GROUP_COUNT_ALL && aggType != GroupByMeta.TYPE_GROUP_COUNT_DISTINCT && aggType != GroupByMeta.TYPE_GROUP_COUNT_ANY)) {
            vMeta.setLength(subjMeta.getLength(), subjMeta.getPrecision());
        }
        data.agg[i] = v;
        data.aggMeta.addValueMeta(vMeta);
    }
    // 
    for (int i = 0; i < data.previousSums.length; i++) {
        data.previousSums[i] = null;
    }
    for (int i = 0; i < data.previousAvgCount.length; i++) {
        data.previousAvgCount[i] = 0L;
        data.previousAvgSum[i] = null;
    }
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) ValueMetaNone(org.pentaho.di.core.row.value.ValueMetaNone) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) FileObject(org.apache.commons.vfs2.FileObject) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 15 with KettlePluginException

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

the class TwoWayPasswordEncoderPluginType method registerXmlPlugins.

@Override
protected void registerXmlPlugins() throws KettlePluginException {
    for (PluginFolderInterface folder : pluginFolders) {
        if (folder.isPluginXmlFolder()) {
            List<FileObject> pluginXmlFiles = findPluginXmlFiles(folder.getFolder());
            for (FileObject file : pluginXmlFiles) {
                try {
                    Document document = XMLHandler.loadXMLFile(file);
                    Node pluginNode = XMLHandler.getSubNode(document, "plugin");
                    if (pluginNode != null) {
                        registerPluginFromXmlResource(pluginNode, KettleVFS.getFilename(file.getParent()), this.getClass(), false, file.getParent().getURL());
                    }
                } catch (Exception e) {
                    // We want to report this plugin.xml error, perhaps an XML typo or something like that...
                    // 
                    log.logError("Error found while reading password encoder plugin.xml file: " + file.getName().toString(), e);
                }
            }
        }
    }
}
Also used : PluginFolderInterface(org.pentaho.di.core.plugins.PluginFolderInterface) Node(org.w3c.dom.Node) FileObject(org.apache.commons.vfs2.FileObject) Document(org.w3c.dom.Document) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException)

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