use of org.pentaho.di.core.row.ValueMeta in project pentaho-kettle by pentaho.
the class XMLInputSaxMeta method getFields.
public void getFields(RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
for (int i = 0; i < inputFields.length; i++) {
XMLInputSaxField field = inputFields[i];
int type = field.getType();
if (type == ValueMeta.TYPE_NONE) {
type = ValueMeta.TYPE_STRING;
}
try {
ValueMetaInterface v = ValueMetaFactory.createValueMeta(field.getName(), type);
v.setLength(field.getLength());
v.setPrecision(field.getPrecision());
v.setConversionMask(field.getFormat());
v.setGroupingSymbol(field.getGroupSymbol());
v.setDecimalSymbol(field.getDecimalSymbol());
v.setCurrencySymbol(field.getCurrencySymbol());
v.setOrigin(name);
row.addValueMeta(v);
} catch (Exception e) {
throw new KettleStepException(e);
}
}
if (includeFilename) {
ValueMeta v = new ValueMeta(filenameField, ValueMeta.TYPE_STRING);
v.setLength(100, -1);
v.setOrigin(name);
row.addValueMeta(v);
}
if (includeRowNumber) {
ValueMeta v = new ValueMeta(rowNumberField, ValueMeta.TYPE_NUMBER);
v.setLength(7, 0);
v.setOrigin(name);
row.addValueMeta(v);
}
}
use of org.pentaho.di.core.row.ValueMeta in project pentaho-kettle by pentaho.
the class ShapeFileReaderMeta method getFields.
public void getFields(RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space) throws KettleStepException {
// The filename...
ValueMetaInterface filename = new ValueMeta("filename", ValueMetaInterface.TYPE_STRING);
filename.setOrigin(name);
filename.setLength(255);
row.addValueMeta(filename);
// The file type
ValueMetaInterface ft = new ValueMeta("filetype", ValueMetaInterface.TYPE_STRING);
ft.setLength(50);
ft.setOrigin(name);
row.addValueMeta(ft);
// The shape nr
ValueMetaInterface shnr = new ValueMeta("shapenr", ValueMetaInterface.TYPE_INTEGER);
shnr.setOrigin(name);
row.addValueMeta(shnr);
// The part nr
ValueMetaInterface pnr = new ValueMeta("partnr", ValueMetaInterface.TYPE_INTEGER);
pnr.setOrigin(name);
row.addValueMeta(pnr);
// The part nr
ValueMetaInterface nrp = new ValueMeta("nrparts", ValueMetaInterface.TYPE_INTEGER);
nrp.setOrigin(name);
row.addValueMeta(nrp);
// The point nr
ValueMetaInterface ptnr = new ValueMeta("pointnr", ValueMetaInterface.TYPE_INTEGER);
ptnr.setOrigin(name);
row.addValueMeta(ptnr);
// The nr of points
ValueMetaInterface nrpt = new ValueMeta("nrpointS", ValueMetaInterface.TYPE_INTEGER);
nrpt.setOrigin(name);
row.addValueMeta(nrpt);
// The X coordinate
ValueMetaInterface x = new ValueMeta("x", ValueMetaInterface.TYPE_NUMBER);
x.setOrigin(name);
row.addValueMeta(x);
// The Y coordinate
ValueMetaInterface y = new ValueMeta("y", ValueMetaInterface.TYPE_NUMBER);
y.setOrigin(name);
row.addValueMeta(y);
// The measure
ValueMetaInterface m = new ValueMeta("measure", ValueMetaInterface.TYPE_NUMBER);
m.setOrigin(name);
row.addValueMeta(m);
if (getDbfFilename() != null) {
XBase xbase = new XBase(getLog(), getDbfFilename());
try {
xbase.setDbfFile(getDbfFilename());
xbase.open();
RowMetaInterface fields = xbase.getFields();
for (int i = 0; i < fields.size(); i++) {
fields.getValueMeta(i).setOrigin(name);
row.addValueMeta(fields.getValueMeta(i));
}
} catch (Throwable e) {
throw new KettleStepException("Unable to read from DBF file", e);
} finally {
xbase.close();
}
} else {
throw new KettleStepException("Unable to read from DBF file: no filename specfied");
}
}
use of org.pentaho.di.core.row.ValueMeta in project pentaho-kettle by pentaho.
the class LucidDBBulkLoader method init.
public boolean init(StepMetaInterface smi, StepDataInterface sdi) {
meta = (LucidDBBulkLoaderMeta) smi;
data = (LucidDBBulkLoaderData) sdi;
if (super.init(smi, sdi)) {
data.quote = "\"".getBytes();
data.separator = ",".getBytes();
data.newline = Const.CR.getBytes();
data.bulkTimestampMeta = new ValueMeta("timestampMeta", ValueMetaInterface.TYPE_DATE);
data.bulkTimestampMeta.setConversionMask("yyyy-MM-dd HH:mm:ss");
data.bulkTimestampMeta.setStringEncoding(meta.getEncoding());
data.bulkDateMeta = new ValueMeta("dateMeta", ValueMetaInterface.TYPE_DATE);
data.bulkDateMeta.setConversionMask("yyyy-MM-dd");
data.bulkDateMeta.setStringEncoding(meta.getEncoding());
data.bulkNumberMeta = new ValueMeta("numberMeta", ValueMetaInterface.TYPE_NUMBER);
data.bulkNumberMeta.setConversionMask("#.#");
data.bulkNumberMeta.setGroupingSymbol(",");
data.bulkNumberMeta.setDecimalSymbol(".");
data.bulkNumberMeta.setStringEncoding(meta.getEncoding());
data.bufferSize = Const.toInt(environmentSubstitute(meta.getBufferSize()), 100000);
// Allocate the buffer
//
data.rowBuffer = new byte[data.bufferSize][];
data.bufferIndex = 0;
// Schema-table combination...
data.schemaTable = meta.getDatabaseMeta().getQuotedSchemaTableCombination(environmentSubstitute(meta.getSchemaName()), environmentSubstitute(meta.getTableName()));
return true;
}
return false;
}
use of org.pentaho.di.core.row.ValueMeta in project pentaho-kettle by pentaho.
the class Database method callProcedure.
public RowMetaAndData callProcedure(String[] arg, String[] argdir, int[] argtype, String resultname, int resulttype) throws KettleDatabaseException {
RowMetaAndData ret;
try {
boolean moreResults = cstmt.execute();
ret = new RowMetaAndData();
int pos = 1;
if (resultname != null && resultname.length() != 0) {
ValueMeta vMeta = new ValueMeta(resultname, resulttype);
Object v = null;
switch(resulttype) {
case ValueMetaInterface.TYPE_BOOLEAN:
v = Boolean.valueOf(cstmt.getBoolean(pos));
break;
case ValueMetaInterface.TYPE_NUMBER:
v = new Double(cstmt.getDouble(pos));
break;
case ValueMetaInterface.TYPE_BIGNUMBER:
v = cstmt.getBigDecimal(pos);
break;
case ValueMetaInterface.TYPE_INTEGER:
v = Long.valueOf(cstmt.getLong(pos));
break;
case ValueMetaInterface.TYPE_STRING:
v = cstmt.getString(pos);
break;
case ValueMetaInterface.TYPE_BINARY:
if (databaseMeta.supportsGetBlob()) {
Blob blob = cstmt.getBlob(pos);
if (blob != null) {
v = blob.getBytes(1L, (int) blob.length());
} else {
v = null;
}
} else {
v = cstmt.getBytes(pos);
}
break;
case ValueMetaInterface.TYPE_DATE:
if (databaseMeta.supportsTimeStampToDateConversion()) {
v = cstmt.getTimestamp(pos);
} else {
v = cstmt.getDate(pos);
}
break;
default:
break;
}
ret.addValue(vMeta, v);
pos++;
}
for (int i = 0; i < arg.length; i++) {
if (argdir[i].equalsIgnoreCase("OUT") || argdir[i].equalsIgnoreCase("INOUT")) {
ValueMetaInterface vMeta = ValueMetaFactory.createValueMeta(arg[i], argtype[i]);
Object v = null;
switch(argtype[i]) {
case ValueMetaInterface.TYPE_BOOLEAN:
v = Boolean.valueOf(cstmt.getBoolean(pos + i));
break;
case ValueMetaInterface.TYPE_NUMBER:
v = new Double(cstmt.getDouble(pos + i));
break;
case ValueMetaInterface.TYPE_BIGNUMBER:
v = cstmt.getBigDecimal(pos + i);
break;
case ValueMetaInterface.TYPE_INTEGER:
v = Long.valueOf(cstmt.getLong(pos + i));
break;
case ValueMetaInterface.TYPE_STRING:
v = cstmt.getString(pos + i);
break;
case ValueMetaInterface.TYPE_BINARY:
if (databaseMeta.supportsGetBlob()) {
Blob blob = cstmt.getBlob(pos + i);
if (blob != null) {
v = blob.getBytes(1L, (int) blob.length());
} else {
v = null;
}
} else {
v = cstmt.getBytes(pos + i);
}
break;
case ValueMetaInterface.TYPE_DATE:
if (databaseMeta.supportsTimeStampToDateConversion()) {
v = cstmt.getTimestamp(pos + i);
} else {
v = cstmt.getDate(pos + i);
}
break;
default:
break;
}
ret.addValue(vMeta, v);
}
}
ResultSet rs = null;
int updateCount = -1;
do {
rs = null;
try {
// Save the result set
if (moreResults) {
rs = cstmt.getResultSet();
} else {
// Save the update count if it is available (> -1)
updateCount = cstmt.getUpdateCount();
}
moreResults = cstmt.getMoreResults();
} finally {
if (rs != null) {
rs.close();
rs = null;
}
}
} while (moreResults || (updateCount > -1));
return ret;
} catch (Exception ex) {
throw new KettleDatabaseException("Unable to call procedure", ex);
}
}
use of org.pentaho.di.core.row.ValueMeta in project pentaho-kettle by pentaho.
the class RulesExecutorMetaMapper method saveMeta.
/**
* Save data from the MetaMapper into the RulesMeta
*
* @param meta
*/
@SuppressWarnings("deprecation")
public void saveMeta(RulesExecutorMeta meta) {
if (ruleSource != null && ruleSource.equalsIgnoreCase("file")) {
if (meta.getRuleFile() != null && !meta.getRuleFile().equals(getRuleFile()) || (meta.getRuleFile() != getRuleFile()) || meta.getRuleDefinition() != null) {
meta.setRuleFile(getRuleFile());
meta.setRuleDefinition(null);
meta.setChanged();
}
} else if (ruleSource != null && ruleSource.equalsIgnoreCase("definition")) {
if (meta.getRuleDefinition() != null && !meta.getRuleDefinition().equals(getRuleDefinition()) || (meta.getRuleDefinition() != getRuleDefinition()) || meta.getRuleFile() != null) {
meta.setRuleDefinition(getRuleDefinition());
meta.setRuleFile(null);
meta.setChanged();
}
}
ValueMetaInterface vm = null;
Column c = null;
for (int i = 0; i < getColumnList().size(); i++) {
vm = i < meta.getRuleResultColumns().size() ? meta.getRuleResultColumns().get(i) : null;
c = getColumnList().get(i);
if (c != null) {
if (c.getName() != null) {
// The column has a name and is valid for insertion
if (vm == null) {
vm = new ValueMeta();
meta.getRuleResultColumns().add(vm);
meta.setChanged();
}
if (!c.getName().equals(vm.getName())) {
vm.setName(c.getName());
meta.setChanged();
}
if (c.getType() != null && !c.getType().equals(vm.getTypeDesc()) || (c.getType() != vm.getTypeDesc())) {
vm.setType(ValueMeta.getType(c.getType()));
meta.setChanged();
}
} else {
// The column does not have a name and should be removed or skipped over
if (vm != null) {
// This item exists in the meta; remove it
if (i < meta.getRuleResultColumns().size()) {
meta.getRuleResultColumns().remove(i);
}
}
// Remove the item from column list table
getColumnList().remove(i);
// All items have shifted after the removal; Process this position again
i--;
}
}
}
}
Aggregations