use of org.pentaho.di.core.exception.KettlePluginException in project pentaho-kettle by pentaho.
the class RowMetaAndData method addValue.
public void addValue(String valueName, int valueType, Object valueData) {
ValueMetaInterface v;
try {
v = ValueMetaFactory.createValueMeta(valueName, valueType);
} catch (KettlePluginException e) {
v = new ValueMetaNone(valueName);
}
addValue(v, valueData);
}
use of org.pentaho.di.core.exception.KettlePluginException in project pentaho-kettle by pentaho.
the class TableInputMeta 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;
}
boolean param = false;
Database db = getDatabase();
// keep track of it for canceling purposes...
super.databases = new Database[] { db };
// First try without connecting to the database... (can be S L O W)
String sNewSQL = sql;
if (isVariableReplacementActive()) {
sNewSQL = db.environmentSubstitute(sql);
if (space != null) {
sNewSQL = space.environmentSubstitute(sNewSQL);
}
}
RowMetaInterface add = null;
try {
add = db.getQueryFields(sNewSQL, param);
} catch (KettleDatabaseException dbe) {
throw new KettleStepException("Unable to get queryfields for SQL: " + Const.CR + sNewSQL, dbe);
}
if (add != null) {
for (int i = 0; i < add.size(); i++) {
ValueMetaInterface v = add.getValueMeta(i);
v.setOrigin(origin);
}
row.addRowMeta(add);
} else {
try {
db.connect();
RowMetaInterface paramRowMeta = null;
Object[] paramData = null;
StreamInterface infoStream = getStepIOMeta().getInfoStreams().get(0);
if (!Utils.isEmpty(infoStream.getStepname())) {
param = true;
if (info.length >= 0 && info[0] != null) {
paramRowMeta = info[0];
paramData = RowDataUtil.allocateRowData(paramRowMeta.size());
}
}
add = db.getQueryFields(sNewSQL, param, paramRowMeta, paramData);
if (add == null) {
return;
}
for (int i = 0; i < add.size(); i++) {
ValueMetaInterface v = add.getValueMeta(i);
v.setOrigin(origin);
}
row.addRowMeta(add);
} catch (KettleException ke) {
throw new KettleStepException("Unable to get queryfields for SQL: " + Const.CR + sNewSQL, ke);
} finally {
db.disconnect();
}
}
if (isLazyConversionActive()) {
for (int i = 0; i < row.size(); i++) {
ValueMetaInterface v = row.getValueMeta(i);
try {
if (v.getType() == ValueMetaInterface.TYPE_STRING) {
ValueMetaInterface storageMeta = ValueMetaFactory.cloneValueMeta(v);
storageMeta.setStorageType(ValueMetaInterface.STORAGE_TYPE_NORMAL);
v.setStorageMetadata(storageMeta);
v.setStorageType(ValueMetaInterface.STORAGE_TYPE_BINARY_STRING);
}
} catch (KettlePluginException e) {
throw new KettleStepException("Unable to clone meta for lazy conversion: " + Const.CR + v, e);
}
}
}
}
use of org.pentaho.di.core.exception.KettlePluginException in project pentaho-kettle by pentaho.
the class TransExecutorMeta method addFieldToRow.
protected void addFieldToRow(RowMetaInterface row, String fieldName, int type, int length, int precision) throws KettleStepException {
if (!Utils.isEmpty(fieldName)) {
try {
ValueMetaInterface value = ValueMetaFactory.createValueMeta(fieldName, type, length, precision);
value.setOrigin(getParentStepMeta().getName());
row.addValueMeta(value);
} catch (KettlePluginException e) {
throw new KettleStepException(BaseMessages.getString(PKG, "TransExecutorMeta.ValueMetaInterfaceCreation", fieldName), e);
}
}
}
use of org.pentaho.di.core.exception.KettlePluginException in project pentaho-kettle by pentaho.
the class YamlInputMeta method getFields.
@Override
public void getFields(RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
int i;
for (i = 0; i < inputFields.length; i++) {
YamlInputField field = inputFields[i];
int type = field.getType();
if (type == ValueMetaInterface.TYPE_NONE) {
type = ValueMetaInterface.TYPE_STRING;
}
String valueName = space.environmentSubstitute(field.getName());
ValueMetaInterface v;
try {
v = ValueMetaFactory.createValueMeta(valueName, type);
} catch (KettlePluginException e) {
v = new ValueMetaString(valueName);
}
v.setLength(field.getLength());
v.setPrecision(field.getPrecision());
v.setOrigin(name);
v.setConversionMask(field.getFormat());
v.setDecimalSymbol(field.getDecimalSymbol());
v.setGroupingSymbol(field.getGroupSymbol());
v.setCurrencySymbol(field.getCurrencySymbol());
r.addValueMeta(v);
}
if (includeFilename) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(filenameField));
v.setLength(250);
v.setPrecision(-1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (includeRowNumber) {
ValueMetaInterface v = new ValueMetaInteger(space.environmentSubstitute(rowNumberField));
v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
v.setOrigin(name);
r.addValueMeta(v);
}
}
use of org.pentaho.di.core.exception.KettlePluginException in project pentaho-kettle by pentaho.
the class YamlReader method getFields.
@SuppressWarnings({ "rawtypes", "unchecked" })
public RowMeta getFields() {
RowMeta rowMeta = new RowMeta();
Iterator<Object> ito = documents.iterator();
while (ito.hasNext()) {
Object data = ito.next();
if (data instanceof Map) {
// First check if we deals with a map
Map<Object, Object> map = (Map<Object, Object>) data;
Iterator it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry) it.next();
String valueName = pairs.getKey().toString();
ValueMetaInterface valueMeta;
try {
valueMeta = ValueMetaFactory.createValueMeta(valueName, getType(pairs.getValue()));
} catch (KettlePluginException e) {
valueMeta = new ValueMetaNone(valueName);
}
rowMeta.addValueMeta(valueMeta);
}
} else if (data instanceof List) {
rowMeta = new RowMeta();
// Maybe we deals with List
List<Object> list = (List<Object>) data;
Iterator<Object> it = list.iterator();
Object value = it.next();
if (list.size() == 1) {
Map<Object, Object> map = (Map<Object, Object>) value;
Iterator its = map.entrySet().iterator();
while (its.hasNext()) {
Map.Entry pairs = (Map.Entry) its.next();
String valueName = pairs.getKey().toString();
ValueMetaInterface valueMeta;
try {
valueMeta = ValueMetaFactory.createValueMeta(valueName, getType(pairs.getValue()));
} catch (KettlePluginException e) {
valueMeta = new ValueMetaNone(valueName);
}
rowMeta.addValueMeta(valueMeta);
}
} else {
ValueMetaInterface valueMeta;
try {
valueMeta = ValueMetaFactory.createValueMeta(DEFAULT_LIST_VALUE_NAME, getType(value));
} catch (KettlePluginException e) {
valueMeta = new ValueMetaNone(DEFAULT_LIST_VALUE_NAME);
}
rowMeta.addValueMeta(valueMeta);
}
}
}
return rowMeta;
}
Aggregations