Search in sources :

Example 51 with RowMeta

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

the class S3CsvInputMeta_GetFields_Test method getFields_DeprecatedAlsoPicksFields.

@Test
public void getFields_DeprecatedAlsoPicksFields() throws Exception {
    RowMeta rowMeta = new RowMeta();
    createSampleMeta().getFields(rowMeta, "", null, null, null);
    assertFieldsArePopulated(rowMeta);
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) Test(org.junit.Test)

Example 52 with RowMeta

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

the class S3CsvInputMeta_GetFields_Test method getFields_PicksFields.

@Test
public void getFields_PicksFields() throws Exception {
    RowMeta rowMeta = new RowMeta();
    createSampleMeta().getFields(rowMeta, "", null, null, null, null, null);
    assertFieldsArePopulated(rowMeta);
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) Test(org.junit.Test)

Example 53 with RowMeta

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

the class XMLInput method processRow.

public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
    if (first) {
        // we just got started
        first = false;
        data.outputRowMeta = new RowMeta();
        meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore);
        // For String to <type> conversions, we allocate a conversion meta data row as well...
        // 
        data.convertRowMeta = data.outputRowMeta.cloneToType(ValueMetaInterface.TYPE_STRING);
    }
    Object[] outputRowData = getRowFromXML();
    if (outputRowData == null) {
        // signal end to receiver(s)
        setOutputDone();
        // This is the end of this step.
        return false;
    }
    if (log.isRowLevel()) {
        logRowlevel(BaseMessages.getString(PKG, "XMLInput.Log.ReadRow", outputRowData.toString()));
    }
    incrementLinesInput();
    putRow(data.outputRowMeta, outputRowData);
    // limit has been reached, stop now.
    if (meta.getRowLimit() > 0 && data.rownr >= meta.getRowLimit()) {
        setOutputDone();
        return false;
    }
    return true;
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta)

Example 54 with RowMeta

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

the class GetXMLData method ReadNextString.

private boolean ReadNextString() {
    try {
        // Grab another row ...
        data.readrow = getRow();
        if (data.readrow == null) {
            if (log.isDetailed()) {
                logDetailed(BaseMessages.getString(PKG, "GetXMLData.Log.FinishedProcessing"));
            }
            return false;
        }
        if (first) {
            first = false;
            data.nrReadRow = getInputRowMeta().size();
            data.inputRowMeta = getInputRowMeta();
            data.outputRowMeta = data.inputRowMeta.clone();
            meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore);
            // Get total previous fields
            data.totalpreviousfields = data.inputRowMeta.size();
            // Create convert meta-data objects that will contain Date & Number formatters
            data.convertRowMeta = new RowMeta();
            for (ValueMetaInterface valueMeta : data.convertRowMeta.getValueMetaList()) {
                data.convertRowMeta.addValueMeta(ValueMetaFactory.cloneValueMeta(valueMeta, ValueMetaInterface.TYPE_STRING));
            }
            // For String to <type> conversions, we allocate a conversion meta data row as well...
            // 
            data.convertRowMeta = data.outputRowMeta.cloneToType(ValueMetaInterface.TYPE_STRING);
            // Check is XML field is provided
            if (Utils.isEmpty(meta.getXMLField())) {
                logError(BaseMessages.getString(PKG, "GetXMLData.Log.NoField"));
                throw new KettleException(BaseMessages.getString(PKG, "GetXMLData.Log.NoField"));
            }
            // cache the position of the field
            if (data.indexOfXmlField < 0) {
                data.indexOfXmlField = getInputRowMeta().indexOfValue(meta.getXMLField());
                if (data.indexOfXmlField < 0) {
                    // The field is unreachable !
                    logError(BaseMessages.getString(PKG, "GetXMLData.Log.ErrorFindingField", meta.getXMLField()));
                    throw new KettleException(BaseMessages.getString(PKG, "GetXMLData.Exception.CouldnotFindField", meta.getXMLField()));
                }
            }
        }
        if (meta.isInFields()) {
            // get XML field value
            String Fieldvalue = getInputRowMeta().getString(data.readrow, data.indexOfXmlField);
            if (log.isDetailed()) {
                logDetailed(BaseMessages.getString(PKG, "GetXMLData.Log.XMLStream", meta.getXMLField(), Fieldvalue));
            }
            if (meta.getIsAFile()) {
                FileObject file = null;
                try {
                    // XML source is a file.
                    file = KettleVFS.getFileObject(Fieldvalue, getTransMeta());
                    if (meta.isIgnoreEmptyFile() && file.getContent().getSize() == 0) {
                        logBasic(BaseMessages.getString(PKG, "GetXMLData.Error.FileSizeZero", "" + file.getName()));
                        return ReadNextString();
                    }
                    // Open the XML document
                    if (!setDocument(null, file, false, false)) {
                        throw new KettleException(BaseMessages.getString(PKG, "GetXMLData.Log.UnableCreateDocument"));
                    }
                    if (!applyXPath()) {
                        throw new KettleException(BaseMessages.getString(PKG, "GetXMLData.Log.UnableApplyXPath"));
                    }
                    addFileToResultFilesname(file);
                    if (log.isDetailed()) {
                        logDetailed(BaseMessages.getString(PKG, "GetXMLData.Log.LoopFileOccurences", "" + data.nodesize, file.getName().getBaseName()));
                    }
                } catch (Exception e) {
                    throw new KettleException(e);
                } finally {
                    try {
                        if (file != null) {
                            file.close();
                        }
                    } catch (Exception e) {
                    // Ignore close errors
                    }
                }
            } else {
                boolean url = false;
                boolean xmltring = true;
                if (meta.isReadUrl()) {
                    url = true;
                    xmltring = false;
                }
                // Open the XML document
                if (!setDocument(Fieldvalue, null, xmltring, url)) {
                    throw new KettleException(BaseMessages.getString(PKG, "GetXMLData.Log.UnableCreateDocument"));
                }
                // Apply XPath and set node list
                if (!applyXPath()) {
                    throw new KettleException(BaseMessages.getString(PKG, "GetXMLData.Log.UnableApplyXPath"));
                }
                if (log.isDetailed()) {
                    logDetailed(BaseMessages.getString(PKG, "GetXMLData.Log.LoopFileOccurences", "" + data.nodesize));
                }
            }
        }
    } catch (Exception e) {
        logError(BaseMessages.getString(PKG, "GetXMLData.Log.UnexpectedError", e.toString()));
        stopAll();
        logError(Const.getStackTracker(e));
        setErrors(1);
        return false;
    }
    return true;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RowMeta(org.pentaho.di.core.row.RowMeta) FileObject(org.apache.commons.vfs2.FileObject) KettleException(org.pentaho.di.core.exception.KettleException) FileSystemException(org.apache.commons.vfs2.FileSystemException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 55 with RowMeta

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

the class GetXMLData method processRow.

public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
    if (first && !meta.isInFields()) {
        first = false;
        data.files = meta.getFiles(this);
        if (!meta.isdoNotFailIfNoFile() && data.files.nrOfFiles() == 0) {
            throw new KettleException(BaseMessages.getString(PKG, "GetXMLData.Log.NoFiles"));
        }
        handleMissingFiles();
        // Create the output row meta-data
        data.outputRowMeta = new RowMeta();
        meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore);
        // Create convert meta-data objects that will contain Date & Number formatters
        // For String to <type> conversions, we allocate a conversion meta data row as well...
        // 
        data.convertRowMeta = data.outputRowMeta.cloneToType(ValueMetaInterface.TYPE_STRING);
    }
    // Grab a row
    Object[] r = getXMLRow();
    if (data.errorInRowButContinue) {
        // continue without putting the row out
        return true;
    }
    if (r == null) {
        // signal end to receiver(s)
        setOutputDone();
        // end of data or error.
        return false;
    }
    return putRowOut(r);
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RowMeta(org.pentaho.di.core.row.RowMeta) FileObject(org.apache.commons.vfs2.FileObject)

Aggregations

RowMeta (org.pentaho.di.core.row.RowMeta)540 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)280 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)249 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)209 Test (org.junit.Test)174 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)135 KettleException (org.pentaho.di.core.exception.KettleException)112 ArrayList (java.util.ArrayList)68 KettleStepException (org.pentaho.di.core.exception.KettleStepException)56 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)52 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)44 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)41 RowSet (org.pentaho.di.core.RowSet)34 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)27 ValueMetaBase (org.pentaho.di.core.row.value.ValueMetaBase)26 SQLException (java.sql.SQLException)24 FileObject (org.apache.commons.vfs2.FileObject)24 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)23 StepMeta (org.pentaho.di.trans.step.StepMeta)23 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)23