Search in sources :

Example 11 with ValueMeta

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

the class XMLInputSaxMeta method getFields.

public void getFields(RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    for (int i = 0; i < inputFields.length; i++) {
        XMLInputSaxField field = inputFields[i];
        int type = field.getType();
        if (type == ValueMeta.TYPE_NONE) {
            type = ValueMeta.TYPE_STRING;
        }
        try {
            ValueMetaInterface v = ValueMetaFactory.createValueMeta(field.getName(), type);
            v.setLength(field.getLength());
            v.setPrecision(field.getPrecision());
            v.setConversionMask(field.getFormat());
            v.setGroupingSymbol(field.getGroupSymbol());
            v.setDecimalSymbol(field.getDecimalSymbol());
            v.setCurrencySymbol(field.getCurrencySymbol());
            v.setOrigin(name);
            row.addValueMeta(v);
        } catch (Exception e) {
            throw new KettleStepException(e);
        }
    }
    if (includeFilename) {
        ValueMeta v = new ValueMeta(filenameField, ValueMeta.TYPE_STRING);
        v.setLength(100, -1);
        v.setOrigin(name);
        row.addValueMeta(v);
    }
    if (includeRowNumber) {
        ValueMeta v = new ValueMeta(rowNumberField, ValueMeta.TYPE_NUMBER);
        v.setLength(7, 0);
        v.setOrigin(name);
        row.addValueMeta(v);
    }
}
Also used : KettleStepException(org.pentaho.di.core.exception.KettleStepException) ValueMeta(org.pentaho.di.core.row.ValueMeta) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 12 with ValueMeta

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

the class ShapeFileReaderMeta method getFields.

public void getFields(RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space) throws KettleStepException {
    // The filename...
    ValueMetaInterface filename = new ValueMeta("filename", ValueMetaInterface.TYPE_STRING);
    filename.setOrigin(name);
    filename.setLength(255);
    row.addValueMeta(filename);
    // The file type
    ValueMetaInterface ft = new ValueMeta("filetype", ValueMetaInterface.TYPE_STRING);
    ft.setLength(50);
    ft.setOrigin(name);
    row.addValueMeta(ft);
    // The shape nr
    ValueMetaInterface shnr = new ValueMeta("shapenr", ValueMetaInterface.TYPE_INTEGER);
    shnr.setOrigin(name);
    row.addValueMeta(shnr);
    // The part nr
    ValueMetaInterface pnr = new ValueMeta("partnr", ValueMetaInterface.TYPE_INTEGER);
    pnr.setOrigin(name);
    row.addValueMeta(pnr);
    // The part nr
    ValueMetaInterface nrp = new ValueMeta("nrparts", ValueMetaInterface.TYPE_INTEGER);
    nrp.setOrigin(name);
    row.addValueMeta(nrp);
    // The point nr
    ValueMetaInterface ptnr = new ValueMeta("pointnr", ValueMetaInterface.TYPE_INTEGER);
    ptnr.setOrigin(name);
    row.addValueMeta(ptnr);
    // The nr of points
    ValueMetaInterface nrpt = new ValueMeta("nrpointS", ValueMetaInterface.TYPE_INTEGER);
    nrpt.setOrigin(name);
    row.addValueMeta(nrpt);
    // The X coordinate
    ValueMetaInterface x = new ValueMeta("x", ValueMetaInterface.TYPE_NUMBER);
    x.setOrigin(name);
    row.addValueMeta(x);
    // The Y coordinate
    ValueMetaInterface y = new ValueMeta("y", ValueMetaInterface.TYPE_NUMBER);
    y.setOrigin(name);
    row.addValueMeta(y);
    // The measure
    ValueMetaInterface m = new ValueMeta("measure", ValueMetaInterface.TYPE_NUMBER);
    m.setOrigin(name);
    row.addValueMeta(m);
    if (getDbfFilename() != null) {
        XBase xbase = new XBase(getLog(), getDbfFilename());
        try {
            xbase.setDbfFile(getDbfFilename());
            xbase.open();
            RowMetaInterface fields = xbase.getFields();
            for (int i = 0; i < fields.size(); i++) {
                fields.getValueMeta(i).setOrigin(name);
                row.addValueMeta(fields.getValueMeta(i));
            }
        } catch (Throwable e) {
            throw new KettleStepException("Unable to read from DBF file", e);
        } finally {
            xbase.close();
        }
    } else {
        throw new KettleStepException("Unable to read from DBF file: no filename specfied");
    }
}
Also used : KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMeta(org.pentaho.di.core.row.ValueMeta) XBase(org.pentaho.di.trans.steps.xbaseinput.XBase) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 13 with ValueMeta

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

the class LucidDBBulkLoader method init.

public boolean init(StepMetaInterface smi, StepDataInterface sdi) {
    meta = (LucidDBBulkLoaderMeta) smi;
    data = (LucidDBBulkLoaderData) sdi;
    if (super.init(smi, sdi)) {
        data.quote = "\"".getBytes();
        data.separator = ",".getBytes();
        data.newline = Const.CR.getBytes();
        data.bulkTimestampMeta = new ValueMeta("timestampMeta", ValueMetaInterface.TYPE_DATE);
        data.bulkTimestampMeta.setConversionMask("yyyy-MM-dd HH:mm:ss");
        data.bulkTimestampMeta.setStringEncoding(meta.getEncoding());
        data.bulkDateMeta = new ValueMeta("dateMeta", ValueMetaInterface.TYPE_DATE);
        data.bulkDateMeta.setConversionMask("yyyy-MM-dd");
        data.bulkDateMeta.setStringEncoding(meta.getEncoding());
        data.bulkNumberMeta = new ValueMeta("numberMeta", ValueMetaInterface.TYPE_NUMBER);
        data.bulkNumberMeta.setConversionMask("#.#");
        data.bulkNumberMeta.setGroupingSymbol(",");
        data.bulkNumberMeta.setDecimalSymbol(".");
        data.bulkNumberMeta.setStringEncoding(meta.getEncoding());
        data.bufferSize = Const.toInt(environmentSubstitute(meta.getBufferSize()), 100000);
        // Allocate the buffer
        // 
        data.rowBuffer = new byte[data.bufferSize][];
        data.bufferIndex = 0;
        // Schema-table combination...
        data.schemaTable = meta.getDatabaseMeta().getQuotedSchemaTableCombination(environmentSubstitute(meta.getSchemaName()), environmentSubstitute(meta.getTableName()));
        return true;
    }
    return false;
}
Also used : ValueMeta(org.pentaho.di.core.row.ValueMeta)

Example 14 with ValueMeta

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

the class Database method callProcedure.

public RowMetaAndData callProcedure(String[] arg, String[] argdir, int[] argtype, String resultname, int resulttype) throws KettleDatabaseException {
    RowMetaAndData ret;
    try {
        boolean moreResults = cstmt.execute();
        ret = new RowMetaAndData();
        int pos = 1;
        if (resultname != null && resultname.length() != 0) {
            ValueMeta vMeta = new ValueMeta(resultname, resulttype);
            Object v = null;
            switch(resulttype) {
                case ValueMetaInterface.TYPE_BOOLEAN:
                    v = Boolean.valueOf(cstmt.getBoolean(pos));
                    break;
                case ValueMetaInterface.TYPE_NUMBER:
                    v = new Double(cstmt.getDouble(pos));
                    break;
                case ValueMetaInterface.TYPE_BIGNUMBER:
                    v = cstmt.getBigDecimal(pos);
                    break;
                case ValueMetaInterface.TYPE_INTEGER:
                    v = Long.valueOf(cstmt.getLong(pos));
                    break;
                case ValueMetaInterface.TYPE_STRING:
                    v = cstmt.getString(pos);
                    break;
                case ValueMetaInterface.TYPE_BINARY:
                    if (databaseMeta.supportsGetBlob()) {
                        Blob blob = cstmt.getBlob(pos);
                        if (blob != null) {
                            v = blob.getBytes(1L, (int) blob.length());
                        } else {
                            v = null;
                        }
                    } else {
                        v = cstmt.getBytes(pos);
                    }
                    break;
                case ValueMetaInterface.TYPE_DATE:
                    if (databaseMeta.supportsTimeStampToDateConversion()) {
                        v = cstmt.getTimestamp(pos);
                    } else {
                        v = cstmt.getDate(pos);
                    }
                    break;
                default:
                    break;
            }
            ret.addValue(vMeta, v);
            pos++;
        }
        for (int i = 0; i < arg.length; i++) {
            if (argdir[i].equalsIgnoreCase("OUT") || argdir[i].equalsIgnoreCase("INOUT")) {
                ValueMetaInterface vMeta = ValueMetaFactory.createValueMeta(arg[i], argtype[i]);
                Object v = null;
                switch(argtype[i]) {
                    case ValueMetaInterface.TYPE_BOOLEAN:
                        v = Boolean.valueOf(cstmt.getBoolean(pos + i));
                        break;
                    case ValueMetaInterface.TYPE_NUMBER:
                        v = new Double(cstmt.getDouble(pos + i));
                        break;
                    case ValueMetaInterface.TYPE_BIGNUMBER:
                        v = cstmt.getBigDecimal(pos + i);
                        break;
                    case ValueMetaInterface.TYPE_INTEGER:
                        v = Long.valueOf(cstmt.getLong(pos + i));
                        break;
                    case ValueMetaInterface.TYPE_STRING:
                        v = cstmt.getString(pos + i);
                        break;
                    case ValueMetaInterface.TYPE_BINARY:
                        if (databaseMeta.supportsGetBlob()) {
                            Blob blob = cstmt.getBlob(pos + i);
                            if (blob != null) {
                                v = blob.getBytes(1L, (int) blob.length());
                            } else {
                                v = null;
                            }
                        } else {
                            v = cstmt.getBytes(pos + i);
                        }
                        break;
                    case ValueMetaInterface.TYPE_DATE:
                        if (databaseMeta.supportsTimeStampToDateConversion()) {
                            v = cstmt.getTimestamp(pos + i);
                        } else {
                            v = cstmt.getDate(pos + i);
                        }
                        break;
                    default:
                        break;
                }
                ret.addValue(vMeta, v);
            }
        }
        ResultSet rs = null;
        int updateCount = -1;
        do {
            rs = null;
            try {
                // Save the result set
                if (moreResults) {
                    rs = cstmt.getResultSet();
                } else {
                    // Save the update count if it is available (> -1)
                    updateCount = cstmt.getUpdateCount();
                }
                moreResults = cstmt.getMoreResults();
            } finally {
                if (rs != null) {
                    rs.close();
                    rs = null;
                }
            }
        } while (moreResults || (updateCount > -1));
        return ret;
    } catch (Exception ex) {
        throw new KettleDatabaseException("Unable to call procedure", ex);
    }
}
Also used : Blob(java.sql.Blob) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) ResultSet(java.sql.ResultSet) FileObject(org.apache.commons.vfs2.FileObject) ValueMeta(org.pentaho.di.core.row.ValueMeta) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) Savepoint(java.sql.Savepoint) KettleValueException(org.pentaho.di.core.exception.KettleValueException) BatchUpdateException(java.sql.BatchUpdateException) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) SQLException(java.sql.SQLException) KettleDatabaseBatchException(org.pentaho.di.core.exception.KettleDatabaseBatchException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 15 with ValueMeta

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

the class RulesExecutorMetaMapper method saveMeta.

/**
 * Save data from the MetaMapper into the RulesMeta
 *
 * @param meta
 */
@SuppressWarnings("deprecation")
public void saveMeta(RulesExecutorMeta 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)

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