use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class CubeInputMeta method getFields.
public void getFields(RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
GZIPInputStream fis = null;
DataInputStream dis = null;
try {
InputStream is = KettleVFS.getInputStream(space.environmentSubstitute(filename), space);
fis = new GZIPInputStream(is);
dis = new DataInputStream(fis);
RowMetaInterface add = new RowMeta(dis);
for (int i = 0; i < add.size(); i++) {
add.getValueMeta(i).setOrigin(name);
}
r.mergeRowMeta(add);
} catch (KettleFileException kfe) {
throw new KettleStepException(BaseMessages.getString(PKG, "CubeInputMeta.Exception.UnableToReadMetaData"), kfe);
} catch (IOException e) {
throw new KettleStepException(BaseMessages.getString(PKG, "CubeInputMeta.Exception.ErrorOpeningOrReadingCubeFile"), e);
} finally {
try {
if (fis != null) {
fis.close();
}
if (dis != null) {
dis.close();
}
} catch (IOException ioe) {
throw new KettleStepException(BaseMessages.getString(PKG, "CubeInputMeta.Exception.UnableToCloseCubeFile"), ioe);
}
}
}
use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class DatabaseJoin method lookupValues.
private synchronized void lookupValues(RowMetaInterface rowMeta, Object[] rowData) throws KettleException {
if (first) {
first = false;
data.outputRowMeta = rowMeta.clone();
meta.getFields(data.outputRowMeta, getStepname(), new RowMetaInterface[] { meta.getTableFields() }, null, this, repository, metaStore);
data.lookupRowMeta = new RowMeta();
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "DatabaseJoin.Log.CheckingRow") + rowMeta.getString(rowData));
}
data.keynrs = new int[meta.getParameterField().length];
for (int i = 0; i < meta.getParameterField().length; i++) {
data.keynrs[i] = rowMeta.indexOfValue(meta.getParameterField()[i]);
if (data.keynrs[i] < 0) {
throw new KettleStepException(BaseMessages.getString(PKG, "DatabaseJoin.Exception.FieldNotFound", meta.getParameterField()[i]));
}
data.lookupRowMeta.addValueMeta(rowMeta.getValueMeta(data.keynrs[i]).clone());
}
}
// Construct the parameters row...
Object[] lookupRowData = new Object[data.lookupRowMeta.size()];
for (int i = 0; i < data.keynrs.length; i++) {
lookupRowData[i] = rowData[data.keynrs[i]];
}
// Set the values on the prepared statement (for faster exec.)
ResultSet rs = data.db.openQuery(data.pstmt, data.lookupRowMeta, lookupRowData);
// Get a row from the database...
//
Object[] add = data.db.getRow(rs);
RowMetaInterface addMeta = data.db.getReturnRowMeta();
incrementLinesInput();
int counter = 0;
while (add != null && (meta.getRowLimit() == 0 || counter < meta.getRowLimit())) {
counter++;
Object[] newRow = RowDataUtil.resizeArray(rowData, data.outputRowMeta.size());
int newIndex = rowMeta.size();
for (int i = 0; i < addMeta.size(); i++) {
newRow[newIndex++] = add[i];
}
// we have to clone, otherwise we only get the last new value
putRow(data.outputRowMeta, data.outputRowMeta.cloneRow(newRow));
if (log.isRowLevel()) {
logRowlevel(BaseMessages.getString(PKG, "DatabaseJoin.Log.PutoutRow") + data.outputRowMeta.getString(newRow));
}
// Get a new row
if (meta.getRowLimit() == 0 || counter < meta.getRowLimit()) {
add = data.db.getRow(rs);
incrementLinesInput();
}
}
// Nothing found? Perhaps we have to put something out after all?
if (counter == 0 && meta.isOuterJoin()) {
if (data.notfound == null) {
// Just return null values for all values...
//
data.notfound = new Object[data.db.getReturnRowMeta().size()];
}
Object[] newRow = RowDataUtil.resizeArray(rowData, data.outputRowMeta.size());
int newIndex = rowMeta.size();
for (int i = 0; i < data.notfound.length; i++) {
newRow[newIndex++] = data.notfound[i];
}
putRow(data.outputRowMeta, newRow);
}
data.db.closeQuery(rs);
}
use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class DatabaseLookupMeta method getFields.
@Override
public void getFields(RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
if (Utils.isEmpty(info) || info[0] == null) {
// null or length 0 : no info from database
for (int i = 0; i < getReturnValueNewName().length; i++) {
try {
ValueMetaInterface v = ValueMetaFactory.createValueMeta(getReturnValueNewName()[i], getReturnValueDefaultType()[i]);
v.setOrigin(name);
row.addValueMeta(v);
} catch (Exception e) {
throw new KettleStepException(e);
}
}
} else {
for (int i = 0; i < returnValueNewName.length; i++) {
ValueMetaInterface v = info[0].searchValueMeta(returnValueField[i]);
if (v != null) {
// avoid renaming other value meta - PDI-9844
ValueMetaInterface copy = v.clone();
copy.setName(returnValueNewName[i]);
copy.setOrigin(name);
row.addValueMeta(copy);
}
}
}
}
use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class DataGridMeta method getFields.
@Override
public void getFields(RowMetaInterface rowMeta, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
for (int i = 0; i < fieldName.length; i++) {
try {
if (!Utils.isEmpty(fieldName[i])) {
int type = ValueMetaFactory.getIdForValueMeta(fieldType[i]);
if (type == ValueMetaInterface.TYPE_NONE) {
type = ValueMetaInterface.TYPE_STRING;
}
ValueMetaInterface v = ValueMetaFactory.createValueMeta(fieldName[i], type);
v.setLength(fieldLength[i]);
v.setPrecision(fieldPrecision[i]);
v.setOrigin(name);
v.setConversionMask(fieldFormat[i]);
v.setCurrencySymbol(currency[i]);
v.setGroupingSymbol(group[i]);
v.setDecimalSymbol(decimal[i]);
rowMeta.addValueMeta(v);
}
} catch (Exception e) {
throw new KettleStepException("Unable to create value of type " + fieldType[i], e);
}
}
}
use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class DBProc method runProc.
private Object[] runProc(RowMetaInterface rowMeta, Object[] rowData) throws KettleException {
if (first) {
first = false;
// get the RowMeta for the output
//
data.outputMeta = data.inputRowMeta.clone();
meta.getFields(data.outputMeta, getStepname(), null, null, this, repository, metaStore);
data.argnrs = new int[meta.getArgument().length];
for (int i = 0; i < meta.getArgument().length; i++) {
if (!meta.getArgumentDirection()[i].equalsIgnoreCase("OUT")) {
// IN or INOUT
data.argnrs[i] = rowMeta.indexOfValue(meta.getArgument()[i]);
if (data.argnrs[i] < 0) {
logError(BaseMessages.getString(PKG, "DBProc.Log.ErrorFindingField") + meta.getArgument()[i] + "]");
throw new KettleStepException(BaseMessages.getString(PKG, "DBProc.Exception.CouldnotFindField", meta.getArgument()[i]));
}
} else {
data.argnrs[i] = -1;
}
}
data.db.setProcLookup(environmentSubstitute(meta.getProcedure()), meta.getArgument(), meta.getArgumentDirection(), meta.getArgumentType(), meta.getResultName(), meta.getResultType());
}
Object[] outputRowData = RowDataUtil.resizeArray(rowData, data.outputMeta.size());
int outputIndex = rowMeta.size();
data.db.setProcValues(rowMeta, rowData, data.argnrs, meta.getArgumentDirection(), !Utils.isEmpty(meta.getResultName()));
RowMetaAndData add = data.db.callProcedure(meta.getArgument(), meta.getArgumentDirection(), meta.getArgumentType(), meta.getResultName(), meta.getResultType());
int addIndex = 0;
// Function return?
if (!Utils.isEmpty(meta.getResultName())) {
// first is the function return
outputRowData[outputIndex++] = add.getData()[addIndex++];
}
//
for (int i = 0; i < data.argnrs.length; i++) {
if (meta.getArgumentDirection()[i].equalsIgnoreCase("OUT")) {
// add
outputRowData[outputIndex++] = add.getData()[addIndex++];
} else if (meta.getArgumentDirection()[i].equalsIgnoreCase("INOUT")) {
// replace
outputRowData[data.argnrs[i]] = add.getData()[addIndex];
addIndex++;
}
// IN not taken
}
return outputRowData;
}
Aggregations