use of org.pentaho.di.core.row.ValueMetaInterface in project pentaho-kettle by pentaho.
the class JsonInputMeta method getFields.
@Override
public void getFields(RowMetaInterface rowMeta, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
if (inFields && removeSourceField && !Utils.isEmpty(valueField)) {
int index = rowMeta.indexOfValue(valueField);
if (index != -1) {
rowMeta.removeValueMeta(index);
}
}
for (JsonInputField field : getInputFields()) {
try {
rowMeta.addValueMeta(field.toValueMeta(name, space));
} catch (Exception e) {
throw new KettleStepException(e);
}
}
if (includeFilename) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(filenameField));
v.setLength(250);
v.setPrecision(-1);
v.setOrigin(name);
rowMeta.addValueMeta(v);
}
if (includeRowNumber) {
ValueMetaInterface v = new ValueMetaInteger(space.environmentSubstitute(rowNumberField));
v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
v.setOrigin(name);
rowMeta.addValueMeta(v);
}
// Add additional fields
additionalOutputFields.normalize();
additionalOutputFields.getFields(rowMeta, name, info, space, repository, metaStore);
}
use of org.pentaho.di.core.row.ValueMetaInterface in project pentaho-kettle by pentaho.
the class GPBulkDataOutput method writeLine.
public void writeLine(RowMetaInterface mi, Object[] row) throws KettleException {
if (first) {
first = false;
enclosure = meta.getEnclosure();
// Setup up the fields we need to take for each of the rows
// as this speeds up processing.
fieldNumbers = new int[meta.getFieldStream().length];
for (int i = 0; i < fieldNumbers.length; i++) {
fieldNumbers[i] = mi.indexOfValue(meta.getFieldStream()[i]);
if (fieldNumbers[i] < 0) {
throw new KettleException("Could not find field " + meta.getFieldStream()[i] + " in stream");
}
}
sdfDate = new SimpleDateFormat("yyyy-MM-dd");
sdfDateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
}
// Write the data to the output
ValueMetaInterface v = null;
int number = 0;
for (int i = 0; i < fieldNumbers.length; i++) {
if (i != 0) {
output.print(",");
}
number = fieldNumbers[i];
v = mi.getValueMeta(number);
if (row[number] == null) {
// TODO (SB): special check for null in case of Strings.
output.print(enclosure);
output.print(enclosure);
} else {
switch(v.getType()) {
case ValueMetaInterface.TYPE_STRING:
String s = mi.getString(row, number);
if (s.indexOf(enclosure) >= 0) {
s = createEscapedString(s, enclosure);
}
output.print(enclosure);
output.print(s);
output.print(enclosure);
break;
case ValueMetaInterface.TYPE_INTEGER:
Long l = mi.getInteger(row, number);
output.print(enclosure);
output.print(l);
output.print(enclosure);
break;
case ValueMetaInterface.TYPE_NUMBER:
Double d = mi.getNumber(row, number);
output.print(enclosure);
output.print(d);
output.print(enclosure);
break;
case ValueMetaInterface.TYPE_BIGNUMBER:
BigDecimal bd = mi.getBigNumber(row, number);
output.print(enclosure);
output.print(bd);
output.print(enclosure);
break;
case ValueMetaInterface.TYPE_DATE:
Date dt = mi.getDate(row, number);
output.print(enclosure);
String mask = meta.getDateMask()[i];
if (GPBulkLoaderMeta.DATE_MASK_DATETIME.equals(mask)) {
output.print(sdfDateTime.format(dt));
} else {
// Default is date format
output.print(sdfDate.format(dt));
}
output.print(enclosure);
break;
case ValueMetaInterface.TYPE_BOOLEAN:
Boolean b = mi.getBoolean(row, number);
output.print(enclosure);
if (b.booleanValue()) {
output.print("Y");
} else {
output.print("N");
}
output.print(enclosure);
break;
case ValueMetaInterface.TYPE_BINARY:
byte[] byt = mi.getBinary(row, number);
output.print("<startlob>");
output.print(byt);
output.print("<endlob>");
break;
default:
throw new KettleException("Unsupported type");
}
}
}
output.print(Const.CR);
}
use of org.pentaho.di.core.row.ValueMetaInterface in project pentaho-kettle by pentaho.
the class HL7InputMeta method getFields.
@Override
public void getFields(RowMetaInterface rowMeta, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
ValueMetaInterface valueMeta = new ValueMetaString("ParentGroup");
valueMeta.setOrigin(origin);
rowMeta.addValueMeta(valueMeta);
valueMeta = new ValueMetaString("Group");
valueMeta.setOrigin(origin);
rowMeta.addValueMeta(valueMeta);
valueMeta = new ValueMetaString("HL7Version");
valueMeta.setOrigin(origin);
rowMeta.addValueMeta(valueMeta);
valueMeta = new ValueMetaString("StructureName");
valueMeta.setOrigin(origin);
rowMeta.addValueMeta(valueMeta);
valueMeta = new ValueMetaString("StructureNumber");
valueMeta.setOrigin(origin);
rowMeta.addValueMeta(valueMeta);
valueMeta = new ValueMetaString("FieldName");
valueMeta.setOrigin(origin);
rowMeta.addValueMeta(valueMeta);
valueMeta = new ValueMetaString("Coordinates");
valueMeta.setOrigin(origin);
rowMeta.addValueMeta(valueMeta);
valueMeta = new ValueMetaString("HL7DataType");
valueMeta.setOrigin(origin);
rowMeta.addValueMeta(valueMeta);
valueMeta = new ValueMetaString("FieldDescription");
valueMeta.setOrigin(origin);
rowMeta.addValueMeta(valueMeta);
valueMeta = new ValueMetaString("Value");
valueMeta.setOrigin(origin);
rowMeta.addValueMeta(valueMeta);
}
use of org.pentaho.di.core.row.ValueMetaInterface in project pentaho-kettle by pentaho.
the class GPBulkLoaderMeta method getSQLStatements.
@Override
public SQLStatement getSQLStatements(TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, Repository repository, IMetaStore metaStore) throws KettleStepException {
// default: nothing to do!
SQLStatement retval = new SQLStatement(stepMeta.getName(), databaseMeta, null);
if (databaseMeta != null) {
if (prev != null && prev.size() > 0) {
// Copy the row
RowMetaInterface tableFields = new RowMeta();
// Now change the field names
for (int i = 0; i < fieldTable.length; i++) {
ValueMetaInterface v = prev.searchValueMeta(fieldStream[i]);
if (v != null) {
ValueMetaInterface tableField = v.clone();
tableField.setName(fieldTable[i]);
tableFields.addValueMeta(tableField);
} else {
throw new KettleStepException("Unable to find field [" + fieldStream[i] + "] in the input rows");
}
}
if (!Utils.isEmpty(tableName)) {
Database db = new Database(loggingObject, databaseMeta);
db.shareVariablesWith(transMeta);
try {
db.connect();
String schemaTable = databaseMeta.getQuotedSchemaTableCombination(transMeta.environmentSubstitute(schemaName), transMeta.environmentSubstitute(tableName));
String sql = db.getDDL(schemaTable, tableFields, null, false, null, true);
if (sql.length() == 0) {
retval.setSQL(null);
} else {
retval.setSQL(sql);
}
} catch (KettleException e) {
retval.setError(BaseMessages.getString(PKG, "GPBulkLoaderMeta.GetSQL.ErrorOccurred") + e.getMessage());
}
} else {
retval.setError(BaseMessages.getString(PKG, "GPBulkLoaderMeta.GetSQL.NoTableDefinedOnConnection"));
}
} else {
retval.setError(BaseMessages.getString(PKG, "GPBulkLoaderMeta.GetSQL.NotReceivingAnyFields"));
}
} else {
retval.setError(BaseMessages.getString(PKG, "GPBulkLoaderMeta.GetSQL.NoConnectionDefined"));
}
return retval;
}
use of org.pentaho.di.core.row.ValueMetaInterface in project pentaho-kettle by pentaho.
the class GPLoadMeta method getSQLStatements.
public SQLStatement getSQLStatements(TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, Repository repository, IMetaStore metaStore) throws KettleStepException {
// default: nothing to do!
SQLStatement retval = new SQLStatement(stepMeta.getName(), databaseMeta, null);
if (databaseMeta != null) {
if (prev != null && prev.size() > 0) {
// Copy the row
RowMetaInterface tableFields = new RowMeta();
// Now change the field names
for (int i = 0; i < fieldTable.length; i++) {
ValueMetaInterface v = prev.searchValueMeta(fieldStream[i]);
if (v != null) {
ValueMetaInterface tableField = v.clone();
tableField.setName(fieldTable[i]);
tableFields.addValueMeta(tableField);
} else {
throw new KettleStepException("Unable to find field [" + fieldStream[i] + "] in the input rows");
}
}
if (!Utils.isEmpty(tableName)) {
Database db = new Database(loggingObject, databaseMeta);
db.shareVariablesWith(transMeta);
try {
db.connect();
String schemaTable = databaseMeta.getQuotedSchemaTableCombination(transMeta.environmentSubstitute(schemaName), transMeta.environmentSubstitute(tableName));
String sql = db.getDDL(schemaTable, tableFields, null, false, null, true);
if (sql.length() == 0) {
retval.setSQL(null);
} else {
retval.setSQL(sql);
}
} catch (KettleException e) {
retval.setError(BaseMessages.getString(PKG, "GPLoadMeta.GetSQL.ErrorOccurred") + e.getMessage());
}
} else {
retval.setError(BaseMessages.getString(PKG, "GPLoadMeta.GetSQL.NoTableDefinedOnConnection"));
}
} else {
retval.setError(BaseMessages.getString(PKG, "GPLoadMeta.GetSQL.NotReceivingAnyFields"));
}
} else {
retval.setError(BaseMessages.getString(PKG, "GPLoadMeta.GetSQL.NoConnectionDefined"));
}
return retval;
}
Aggregations