Search in sources :

Example 41 with ValueMeta

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

the class WebServiceDialog method getInWebServiceFields.

private RowMetaInterface getInWebServiceFields() {
    RowMetaInterface r = null;
    if (inWsdlParamContainer != null) {
        r = new RowMeta();
        String[] params = inWsdlParamContainer.getParamNames();
        // If we have already saved fields mapping, we only show these mappings
        for (int cpt = 0; cpt < params.length; cpt++) {
            ValueMetaInterface value = new ValueMeta(params[cpt], XsdType.xsdTypeToKettleType(inWsdlParamContainer.getParamType(params[cpt])));
            r.addValueMeta(value);
        }
    }
    return r;
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMeta(org.pentaho.di.core.row.ValueMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 42 with ValueMeta

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

the class JobGenerator method getValueForLogicalColumn.

private ValueMetaInterface getValueForLogicalColumn(DatabaseMeta databaseMeta, LogicalColumn column) {
    String columnName = ConceptUtil.getName(column, locale);
    String phColumnName = ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_PHYSICAL_COLUMN_NAME);
    DataType columnType = column.getDataType();
    String lengthString = ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_LENGTH);
    int length = Const.toInt(lengthString, -1);
    String precisionString = ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_PRECISION);
    int precision = Const.toInt(precisionString, -1);
    int type = ValueMetaInterface.TYPE_STRING;
    switch(columnType) {
        case UNKNOWN:
        case URL:
        case STRING:
            precision = -1;
            break;
        case IMAGE:
        case BINARY:
            type = ValueMetaInterface.TYPE_BINARY;
            precision = -1;
            break;
        case BOOLEAN:
            type = ValueMetaInterface.TYPE_BOOLEAN;
            length = -1;
            precision = -1;
            break;
        case DATE:
            type = ValueMetaInterface.TYPE_DATE;
            length = -1;
            precision = -1;
            break;
        case NUMERIC:
            if (precision <= 0 && length < 15) {
                type = ValueMetaInterface.TYPE_INTEGER;
            } else {
                if (length >= 15) {
                    type = ValueMetaInterface.TYPE_BIGNUMBER;
                } else {
                    type = ValueMetaInterface.TYPE_NUMBER;
                }
            }
            break;
        default:
            break;
    }
    ValueMetaInterface value = new ValueMeta(databaseMeta.quoteField(Const.NVL(phColumnName, columnName)), type);
    value.setLength(length, precision);
    return value;
}
Also used : DataType(org.pentaho.metadata.model.concept.types.DataType) ValueMeta(org.pentaho.di.core.row.ValueMeta) Point(org.pentaho.di.core.gui.Point) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 43 with ValueMeta

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

the class RulesAccumulatorMetaMapper method saveMeta.

/**
 * Save data from the MetaMapper into the RulesMeta
 *
 * @param meta
 */
@SuppressWarnings("deprecation")
public void saveMeta(RulesAccumulatorMeta meta) {
    if (ruleSource != null && ruleSource.equalsIgnoreCase("file")) {
        if (meta.getRuleFile() != null && !meta.getRuleFile().equals(getRuleFile()) || (meta.getRuleFile() != getRuleFile()) || meta.getRuleDefinition() != null) {
            meta.setRuleFile(getRuleFile());
            meta.setRuleDefinition(null);
            meta.setChanged();
        }
    } else if (ruleSource != null && ruleSource.equalsIgnoreCase("definition")) {
        if (meta.getRuleDefinition() != null && !meta.getRuleDefinition().equals(getRuleDefinition()) || (meta.getRuleDefinition() != getRuleDefinition()) || meta.getRuleFile() != null) {
            meta.setRuleDefinition(getRuleDefinition());
            meta.setRuleFile(null);
            meta.setChanged();
        }
    }
    ValueMetaInterface vm = null;
    Column c = null;
    for (int i = 0; i < getColumnList().size(); i++) {
        vm = i < meta.getRuleResultColumns().size() ? meta.getRuleResultColumns().get(i) : null;
        c = getColumnList().get(i);
        if (c != null) {
            if (c.getName() != null) {
                // The column has a name and is valid for insertion
                if (vm == null) {
                    vm = new ValueMeta();
                    meta.getRuleResultColumns().add(vm);
                    meta.setChanged();
                }
                if (!c.getName().equals(vm.getName())) {
                    vm.setName(c.getName());
                    meta.setChanged();
                }
                if (c.getType() != null && !c.getType().equals(vm.getTypeDesc()) || (c.getType() != vm.getTypeDesc())) {
                    vm.setType(ValueMeta.getType(c.getType()));
                    meta.setChanged();
                }
            } else {
                // The column does not have a name and should be removed or skipped over
                if (vm != null) {
                    // This item exists in the meta; remove it
                    if (i < meta.getRuleResultColumns().size()) {
                        meta.getRuleResultColumns().remove(i);
                    }
                }
                // Remove the item from column list table
                getColumnList().remove(i);
                // All items have shifted after the removal; Process this position again
                i--;
            }
        }
    }
}
Also used : ValueMeta(org.pentaho.di.core.row.ValueMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 44 with ValueMeta

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

the class ElasticSearchBulkMeta method getFields.

/* This function adds meta data to the rows being pushed out */
public void getFields(RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    if (StringUtils.isNotBlank(this.getIdOutField())) {
        ValueMetaInterface valueMeta = new ValueMeta(space.environmentSubstitute(this.getIdOutField()), ValueMetaInterface.TYPE_STRING);
        valueMeta.setOrigin(name);
        // add if doesn't exist
        if (!r.exists(valueMeta)) {
            r.addValueMeta(valueMeta);
        }
    }
}
Also used : ValueMeta(org.pentaho.di.core.row.ValueMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 45 with ValueMeta

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

the class S3CsvInputMeta method getFields.

@Override
public void getFields(RowMetaInterface rowMeta, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    // Start with a clean slate, eats the input
    rowMeta.clear();
    for (int i = 0; i < inputFields.length; i++) {
        TextFileInputField field = inputFields[i];
        ValueMetaInterface valueMeta = new ValueMeta(field.getName(), field.getType());
        valueMeta.setConversionMask(field.getFormat());
        valueMeta.setLength(field.getLength());
        valueMeta.setPrecision(field.getPrecision());
        valueMeta.setConversionMask(field.getFormat());
        valueMeta.setDecimalSymbol(field.getDecimalSymbol());
        valueMeta.setGroupingSymbol(field.getGroupSymbol());
        valueMeta.setCurrencySymbol(field.getCurrencySymbol());
        valueMeta.setTrimType(field.getTrimType());
        if (lazyConversionActive) {
            valueMeta.setStorageType(ValueMetaInterface.STORAGE_TYPE_BINARY_STRING);
        }
        // In case we want to convert Strings...
        // Using a copy of the valueMeta object means that the inner and outer representation format is the same.
        // Preview will show the data the same way as we read it.
        // This layout is then taken further down the road by the metadata through the transformation.
        // 
        ValueMetaInterface storageMetadata = valueMeta.clone();
        storageMetadata.setType(ValueMetaInterface.TYPE_STRING);
        storageMetadata.setStorageType(ValueMetaInterface.STORAGE_TYPE_NORMAL);
        // we don't really know the lengths of the strings read in advance.
        storageMetadata.setLength(-1, -1);
        valueMeta.setStorageMetadata(storageMetadata);
        valueMeta.setOrigin(origin);
        rowMeta.addValueMeta(valueMeta);
    }
    if (!Utils.isEmpty(filenameField) && includingFilename) {
        ValueMetaInterface filenameMeta = new ValueMetaString(filenameField);
        filenameMeta.setOrigin(origin);
        if (lazyConversionActive) {
            filenameMeta.setStorageType(ValueMetaInterface.STORAGE_TYPE_BINARY_STRING);
            filenameMeta.setStorageMetadata(new ValueMetaString(filenameField));
        }
        rowMeta.addValueMeta(filenameMeta);
    }
    if (!Utils.isEmpty(rowNumField)) {
        ValueMetaInterface rowNumMeta = new ValueMetaInteger(rowNumField);
        rowNumMeta.setLength(10);
        rowNumMeta.setOrigin(origin);
        rowMeta.addValueMeta(rowNumMeta);
    }
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) TextFileInputField(org.pentaho.di.trans.steps.textfileinput.TextFileInputField) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMeta(org.pentaho.di.core.row.ValueMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Aggregations

ValueMeta (org.pentaho.di.core.row.ValueMeta)47 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)39 Test (org.junit.Test)18 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)14 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)13 RowMeta (org.pentaho.di.core.row.RowMeta)12 IAnalysisContext (org.pentaho.metaverse.api.IAnalysisContext)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 KettleValueException (org.pentaho.di.core.exception.KettleValueException)5 MetaverseTransientNode (org.pentaho.dictionary.MetaverseTransientNode)5 IComponentDescriptor (org.pentaho.metaverse.api.IComponentDescriptor)5 KettleException (org.pentaho.di.core.exception.KettleException)4 KettleStepException (org.pentaho.di.core.exception.KettleStepException)4 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)3 Matchers.anyString (org.mockito.Matchers.anyString)2 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)2 BatchUpdateException (java.sql.BatchUpdateException)1 Blob (java.sql.Blob)1 ResultSet (java.sql.ResultSet)1