Search in sources :

Example 81 with ValueMetaString

use of org.pentaho.di.core.row.value.ValueMetaString in project pentaho-kettle by pentaho.

the class FuzzyMatchMeta method getFields.

public void getFields(RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    // Add match field
    ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getOutputMatchField()));
    v.setOrigin(name);
    v.setStorageType(ValueMetaInterface.STORAGE_TYPE_NORMAL);
    inputRowMeta.addValueMeta(v);
    String mainField = space.environmentSubstitute(getOutputValueField());
    if (!Utils.isEmpty(mainField) && isGetCloserValue()) {
        switch(getAlgorithmType()) {
            case FuzzyMatchMeta.OPERATION_TYPE_DAMERAU_LEVENSHTEIN:
            case FuzzyMatchMeta.OPERATION_TYPE_LEVENSHTEIN:
                v = new ValueMetaInteger(mainField);
                v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH);
                break;
            case FuzzyMatchMeta.OPERATION_TYPE_JARO:
            case FuzzyMatchMeta.OPERATION_TYPE_JARO_WINKLER:
            case FuzzyMatchMeta.OPERATION_TYPE_PAIR_SIMILARITY:
                v = new ValueMetaNumber(mainField);
                break;
            default:
                // Phonetic algorithms
                v = new ValueMetaString(mainField);
                break;
        }
        v.setStorageType(ValueMetaInterface.STORAGE_TYPE_NORMAL);
        v.setOrigin(name);
        inputRowMeta.addValueMeta(v);
    }
    boolean activateAdditionalFields = isGetCloserValue() || (getAlgorithmType() == FuzzyMatchMeta.OPERATION_TYPE_DOUBLE_METAPHONE) || (getAlgorithmType() == FuzzyMatchMeta.OPERATION_TYPE_SOUNDEX) || (getAlgorithmType() == FuzzyMatchMeta.OPERATION_TYPE_REFINED_SOUNDEX) || (getAlgorithmType() == FuzzyMatchMeta.OPERATION_TYPE_METAPHONE);
    if (activateAdditionalFields) {
        if (info != null && info.length == 1 && info[0] != null) {
            for (int i = 0; i < valueName.length; i++) {
                v = info[0].searchValueMeta(value[i]);
                if (v != null) {
                    // Configuration error/missing resources...
                    v.setName(valueName[i]);
                    v.setOrigin(name);
                    // Only normal storage goes into the cache
                    v.setStorageType(ValueMetaInterface.STORAGE_TYPE_NORMAL);
                    inputRowMeta.addValueMeta(v);
                } else {
                    throw new KettleStepException(BaseMessages.getString(PKG, "FuzzyMatchMeta.Exception.ReturnValueCanNotBeFound", value[i]));
                }
            }
        } else {
            for (int i = 0; i < valueName.length; i++) {
                v = new ValueMetaString(valueName[i]);
                v.setOrigin(name);
                inputRowMeta.addValueMeta(v);
            }
        }
    }
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettleStepException(org.pentaho.di.core.exception.KettleStepException) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 82 with ValueMetaString

use of org.pentaho.di.core.row.value.ValueMetaString 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 83 with ValueMetaString

use of org.pentaho.di.core.row.value.ValueMetaString in project pentaho-kettle by pentaho.

the class HL7InputMeta method getFields.

@Override
public void getFields(RowMetaInterface rowMeta, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    ValueMetaInterface valueMeta = new ValueMetaString("ParentGroup");
    valueMeta.setOrigin(origin);
    rowMeta.addValueMeta(valueMeta);
    valueMeta = new ValueMetaString("Group");
    valueMeta.setOrigin(origin);
    rowMeta.addValueMeta(valueMeta);
    valueMeta = new ValueMetaString("HL7Version");
    valueMeta.setOrigin(origin);
    rowMeta.addValueMeta(valueMeta);
    valueMeta = new ValueMetaString("StructureName");
    valueMeta.setOrigin(origin);
    rowMeta.addValueMeta(valueMeta);
    valueMeta = new ValueMetaString("StructureNumber");
    valueMeta.setOrigin(origin);
    rowMeta.addValueMeta(valueMeta);
    valueMeta = new ValueMetaString("FieldName");
    valueMeta.setOrigin(origin);
    rowMeta.addValueMeta(valueMeta);
    valueMeta = new ValueMetaString("Coordinates");
    valueMeta.setOrigin(origin);
    rowMeta.addValueMeta(valueMeta);
    valueMeta = new ValueMetaString("HL7DataType");
    valueMeta.setOrigin(origin);
    rowMeta.addValueMeta(valueMeta);
    valueMeta = new ValueMetaString("FieldDescription");
    valueMeta.setOrigin(origin);
    rowMeta.addValueMeta(valueMeta);
    valueMeta = new ValueMetaString("Value");
    valueMeta.setOrigin(origin);
    rowMeta.addValueMeta(valueMeta);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 84 with ValueMetaString

use of org.pentaho.di.core.row.value.ValueMetaString in project pentaho-kettle by pentaho.

the class JsonInputMeta method getFields.

@Override
public void getFields(RowMetaInterface rowMeta, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    if (inFields && removeSourceField && !Utils.isEmpty(valueField)) {
        int index = rowMeta.indexOfValue(valueField);
        if (index != -1) {
            rowMeta.removeValueMeta(index);
        }
    }
    for (JsonInputField field : getInputFields()) {
        try {
            rowMeta.addValueMeta(field.toValueMeta(name, space));
        } catch (Exception e) {
            throw new KettleStepException(e);
        }
    }
    if (includeFilename) {
        ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(filenameField));
        v.setLength(250);
        v.setPrecision(-1);
        v.setOrigin(name);
        rowMeta.addValueMeta(v);
    }
    if (includeRowNumber) {
        ValueMetaInterface v = new ValueMetaInteger(space.environmentSubstitute(rowNumberField));
        v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
        v.setOrigin(name);
        rowMeta.addValueMeta(v);
    }
    // Add additional fields
    additionalOutputFields.normalize();
    additionalOutputFields.getFields(rowMeta, name, info, space, repository, metaStore);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettleStepException(org.pentaho.di.core.exception.KettleStepException) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) 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 85 with ValueMetaString

use of org.pentaho.di.core.row.value.ValueMetaString in project pentaho-kettle by pentaho.

the class JsonInputMetaInjectionTest method test.

@Test
public void test() throws Exception {
    check("FILE_NAME_OUTPUT", new BooleanGetter() {

        public boolean get() {
            return meta.includeFilename();
        }
    });
    check("FILE_NAME_FIELDNAME", new StringGetter() {

        public String get() {
            return meta.getFilenameField();
        }
    });
    check("ROW_NUMBER_OUTPUT", new BooleanGetter() {

        public boolean get() {
            return meta.includeRowNumber();
        }
    });
    check("ROW_NUMBER_FIELDNAME", new StringGetter() {

        public String get() {
            return meta.getRowNumberField();
        }
    });
    check("ROW_LIMIT", new LongGetter() {

        public long get() {
            return meta.getRowLimit();
        }
    });
    check("ADD_RESULT_FILE", new BooleanGetter() {

        public boolean get() {
            return meta.addResultFile();
        }
    });
    check("IGNORE_EMPTY_FILE", new BooleanGetter() {

        public boolean get() {
            return meta.isIgnoreEmptyFile();
        }
    });
    check("DO_NOT_FAIL_IF_NO_FILE", new BooleanGetter() {

        public boolean get() {
            return meta.isDoNotFailIfNoFile();
        }
    });
    check("IGNORE_MISSING_PATH", new BooleanGetter() {

        public boolean get() {
            return meta.isIgnoreMissingPath();
        }
    });
    check("READ_SOURCE_AS_URL", new BooleanGetter() {

        public boolean get() {
            return meta.isReadUrl();
        }
    });
    check("REMOVE_SOURCE_FIELDS", new BooleanGetter() {

        public boolean get() {
            return meta.isRemoveSourceField();
        }
    });
    check("FILE_SHORT_FILE_FIELDNAME", new StringGetter() {

        public String get() {
            return meta.additionalOutputFields.shortFilenameField;
        }
    });
    check("FILE_EXTENSION_FIELDNAME", new StringGetter() {

        public String get() {
            return meta.additionalOutputFields.extensionField;
        }
    });
    check("FILE_PATH_FIELDNAME", new StringGetter() {

        public String get() {
            return meta.additionalOutputFields.pathField;
        }
    });
    check("FILE_SIZE_FIELDNAME", new StringGetter() {

        public String get() {
            return meta.additionalOutputFields.sizeField;
        }
    });
    check("FILE_HIDDEN_FIELDNAME", new StringGetter() {

        public String get() {
            return meta.additionalOutputFields.hiddenField;
        }
    });
    check("FILE_LAST_MODIFICATION_FIELDNAME", new StringGetter() {

        public String get() {
            return meta.additionalOutputFields.lastModificationField;
        }
    });
    check("FILE_URI_FIELDNAME", new StringGetter() {

        public String get() {
            return meta.additionalOutputFields.uriField;
        }
    });
    check("FILE_ROOT_URI_FIELDNAME", new StringGetter() {

        public String get() {
            return meta.additionalOutputFields.rootUriField;
        }
    });
    check("FILENAME", new StringGetter() {

        public String get() {
            return meta.inputFiles.fileName[0];
        }
    });
    check("FILEMASK", new StringGetter() {

        public String get() {
            return meta.inputFiles.fileMask[0];
        }
    });
    check("EXCLUDE_FILEMASK", new StringGetter() {

        public String get() {
            return meta.inputFiles.excludeFileMask[0];
        }
    });
    check("FILE_REQUIRED", new StringGetter() {

        public String get() {
            return meta.inputFiles.fileRequired[0];
        }
    });
    check("INCLUDE_SUBFOLDERS", new StringGetter() {

        public String get() {
            return meta.inputFiles.includeSubFolders[0];
        }
    });
    check("FIELD_NAME", new StringGetter() {

        public String get() {
            return meta.inputFields[0].getName();
        }
    });
    check("FIELD_PATH", new StringGetter() {

        public String get() {
            return meta.inputFields[0].getPath();
        }
    });
    check("FIELD_LENGTH", new IntGetter() {

        public int get() {
            return meta.inputFields[0].getLength();
        }
    });
    check("FIELD_FORMAT", new StringGetter() {

        public String get() {
            return meta.inputFields[0].getFormat();
        }
    });
    check("FIELD_PRECISION", new IntGetter() {

        public int get() {
            return meta.inputFields[0].getPrecision();
        }
    });
    check("FIELD_CURRENCY", new StringGetter() {

        public String get() {
            return meta.inputFields[0].getCurrencySymbol();
        }
    });
    check("FIELD_DECIMAL", new StringGetter() {

        public String get() {
            return meta.inputFields[0].getDecimalSymbol();
        }
    });
    check("FIELD_GROUP", new StringGetter() {

        public String get() {
            return meta.inputFields[0].getGroupSymbol();
        }
    });
    check("FIELD_REPEAT", new BooleanGetter() {

        public boolean get() {
            return meta.inputFields[0].isRepeated();
        }
    });
    check("SOURCE_FIELD_NAME", new StringGetter() {

        public String get() {
            return meta.getFieldValue();
        }
    });
    check("SOURCE_IN_FIELD", new BooleanGetter() {

        public boolean get() {
            return meta.isInFields();
        }
    });
    check("SOURCE_FIELD_IS_FILENAME", new BooleanGetter() {

        public boolean get() {
            return meta.getIsAFile();
        }
    });
    ValueMetaInterface mftt = new ValueMetaString("f");
    injector.setProperty(meta, "FIELD_TRIM_TYPE", setValue(mftt, "left"), "f");
    assertEquals(1, meta.inputFields[0].getTrimType());
    injector.setProperty(meta, "FIELD_TRIM_TYPE", setValue(mftt, "right"), "f");
    assertEquals(2, meta.inputFields[0].getTrimType());
    skipPropertyTest("FIELD_TRIM_TYPE");
    skipPropertyTest("FIELD_TYPE");
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) BaseMetadataInjectionTest(org.pentaho.di.core.injection.BaseMetadataInjectionTest) Test(org.junit.Test)

Aggregations

ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)447 RowMeta (org.pentaho.di.core.row.RowMeta)219 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)181 Test (org.junit.Test)179 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)176 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)141 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)86 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)67 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)66 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)57 KettleException (org.pentaho.di.core.exception.KettleException)40 ArrayList (java.util.ArrayList)33 LongObjectId (org.pentaho.di.repository.LongObjectId)29 ValueMetaBigNumber (org.pentaho.di.core.row.value.ValueMetaBigNumber)27 ValueMetaBinary (org.pentaho.di.core.row.value.ValueMetaBinary)26 ObjectId (org.pentaho.di.repository.ObjectId)26 ValueMetaTimestamp (org.pentaho.di.core.row.value.ValueMetaTimestamp)21 RowSet (org.pentaho.di.core.RowSet)18 Date (java.util.Date)17 ValueMetaBase (org.pentaho.di.core.row.value.ValueMetaBase)16