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);
}
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);
}
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;
}
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;
}
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);
}
Aggregations