use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class InjectorMeta method getFields.
public void getFields(RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
for (int i = 0; i < this.fieldname.length; i++) {
ValueMetaInterface v;
try {
v = ValueMetaFactory.createValueMeta(this.fieldname[i], type[i], length[i], precision[i]);
inputRowMeta.addValueMeta(v);
} catch (KettlePluginException e) {
throw new KettleStepException(e);
}
}
}
use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class JaninoMeta method getFields.
@Override
public void getFields(RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
for (int i = 0; i < formula.length; i++) {
JaninoMetaFunction fn = formula[i];
if (Utils.isEmpty(fn.getReplaceField())) {
// Not replacing a field.
if (!Utils.isEmpty(fn.getFieldName())) {
try {
ValueMetaInterface v = ValueMetaFactory.createValueMeta(fn.getFieldName(), fn.getValueType());
v.setLength(fn.getValueLength(), fn.getValuePrecision());
v.setOrigin(name);
row.addValueMeta(v);
} catch (Exception e) {
throw new KettleStepException(e);
}
}
} else {
// Replacing a field
int index = row.indexOfValue(fn.getReplaceField());
if (index < 0) {
throw new KettleStepException("Unknown field specified to replace with a formula result: [" + fn.getReplaceField() + "]");
}
// Change the data type etc.
//
ValueMetaInterface v = row.getValueMeta(index).clone();
v.setLength(fn.getValueLength(), fn.getValuePrecision());
v.setOrigin(name);
// replace it
row.setValueMeta(index, v);
}
}
}
use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class MappingInputMeta method getFields.
public void getFields(RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
//
if (inputRowMeta != null && !inputRowMeta.isEmpty()) {
// First rename any fields...
if (valueRenames != null) {
for (MappingValueRename valueRename : valueRenames) {
ValueMetaInterface valueMeta = inputRowMeta.searchValueMeta(valueRename.getSourceValueName());
if (valueMeta == null) {
// ok, let's search once again, now using target name
valueMeta = inputRowMeta.searchValueMeta(valueRename.getTargetValueName());
if (valueMeta == null) {
throw new KettleStepException(BaseMessages.getString(PKG, "MappingInput.Exception.UnableToFindMappedValue", valueRename.getSourceValueName()));
}
} else {
valueMeta.setName(valueRename.getTargetValueName());
}
}
}
if (selectingAndSortingUnspecifiedFields) {
// Select the specified fields from the input, re-order everything and put the other fields at the back,
// sorted...
//
RowMetaInterface newRow = new RowMeta();
for (int i = 0; i < fieldName.length; i++) {
int index = inputRowMeta.indexOfValue(fieldName[i]);
if (index < 0) {
throw new KettleStepException(BaseMessages.getString(PKG, "MappingInputMeta.Exception.UnknownField", fieldName[i]));
}
newRow.addValueMeta(inputRowMeta.getValueMeta(index));
}
// Now get the unspecified fields.
// Sort the fields
// Add them after the specified fields...
//
List<String> extra = new ArrayList<String>();
for (int i = 0; i < inputRowMeta.size(); i++) {
String fieldName = inputRowMeta.getValueMeta(i).getName();
if (newRow.indexOfValue(fieldName) < 0) {
extra.add(fieldName);
}
}
Collections.sort(extra);
for (String fieldName : extra) {
ValueMetaInterface extraValue = inputRowMeta.searchValueMeta(fieldName);
newRow.addValueMeta(extraValue);
}
// now merge the new row...
// This is basically the input row meta data with the fields re-ordered.
//
row.mergeRowMeta(newRow);
} else {
row.mergeRowMeta(inputRowMeta);
//
if (!row.isEmpty()) {
for (int i = 0; i < fieldName.length; i++) {
if (row.indexOfValue(fieldName[i]) < 0) {
throw new KettleStepException(BaseMessages.getString(PKG, "MappingInputMeta.Exception.UnknownField", fieldName[i]));
}
}
}
}
} else {
if (row.isEmpty()) {
// We'll have to work with the statically provided information
for (int i = 0; i < fieldName.length; i++) {
if (!Utils.isEmpty(fieldName[i])) {
int valueType = fieldType[i];
if (valueType == ValueMetaInterface.TYPE_NONE) {
valueType = ValueMetaInterface.TYPE_STRING;
}
ValueMetaInterface v;
try {
v = ValueMetaFactory.createValueMeta(fieldName[i], valueType);
v.setLength(fieldLength[i]);
v.setPrecision(fieldPrecision[i]);
v.setOrigin(origin);
row.addValueMeta(v);
} catch (KettlePluginException e) {
throw new KettleStepException(e);
}
}
}
}
// else: row is OK, keep it as it is.
}
}
use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class MergeRowsMeta method getFields.
@Override
public void getFields(RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
//
if (info != null) {
boolean found = false;
for (int i = 0; i < info.length && !found; i++) {
if (info[i] != null) {
r.mergeRowMeta(info[i], name);
found = true;
}
}
}
if (Utils.isEmpty(flagField)) {
throw new KettleStepException(BaseMessages.getString(PKG, "MergeRowsMeta.Exception.FlagFieldNotSpecified"));
}
ValueMetaInterface flagFieldValue = new ValueMetaString(flagField);
flagFieldValue.setOrigin(name);
r.addValueMeta(flagFieldValue);
}
use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class MondrianInputMeta method getFields.
public void getFields(RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
if (databaseMeta == null) {
// TODO: throw an exception here
return;
}
RowMetaInterface add = null;
try {
String mdx = getSQL();
if (isVariableReplacementActive()) {
mdx = space.environmentSubstitute(mdx);
}
MondrianHelper helper = new MondrianHelper(databaseMeta, catalog, mdx, space);
add = helper.getCachedRowMeta();
if (add == null) {
helper.openQuery();
helper.createRectangularOutput();
add = helper.getOutputRowMeta();
}
} catch (KettleDatabaseException dbe) {
throw new KettleStepException("Unable to get query result for MDX query: " + Const.CR + sql, dbe);
}
//
for (int i = 0; i < add.size(); i++) {
ValueMetaInterface v = add.getValueMeta(i);
v.setOrigin(origin);
}
row.addRowMeta(add);
}
Aggregations