Hi,
I got a requirement where I need to store values into Oracle DB from Postgres .
I do not know the number of columns as well as their types.
The table names are fetched dynamically.
The problem is whit the Boolean values , Since Oracle does not support Boolean types , the transformation fails.
I wrote a User defined Java class to convert Boolean to Int Conversion is done , but the problem exists while transferring this data to outputrow. Please help me here. Following error is thrown :
"d Boolean : There was a data type error: the data type of java.lang.Integer object [1] does not correspond to value meta [Boolean]"
Here is my Code :
static long rownum = 0;
static RowMetaInterface inputRowMeta;
static long numFields;
static String[] fieldNames;
static String field_name;
int int_value;
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException
{
// get the current row
Object[] r = getRow();
// If the row object is null, we are done processing.
if (r == null) {
setOutputDone();
return false;
}
// If this is the first row, cache some metadata.
// We will reuse this metadata in processing the rest of the rows.
if (first) {
inputRowMeta = getInputRowMeta();
fieldNames = inputRowMeta.getFieldNames();
numFields = fieldNames.length;
}
// Generate a new id number for the current row.
// Generate one output row for each field in the input stream.
int fieldnum;
Object[] outputRowData = createOutputRow(r, data.outputRowMeta.size());
for (fieldnum = 0; fieldnum < getInputRowMeta().size(); fieldnum++)
{
if(inputRowMeta.getValueMeta(fieldnum).isBoolean())
{
Boolean bool_value=inputRowMeta.getBoolean(r,fieldnum);
ValueMeta newmeta = new org.pentaho.di.core.row.ValueMeta(inputRowMeta.getValueMeta(fieldnum).getName(), org.pentaho.di.core.row.ValueMeta.TYPE_INTEGER);
inputRowMeta.setValueMeta(fieldnum, newmeta);
field_name=inputRowMeta.getValueMeta(fieldnum).getName();
if(bool_value)
{
int_value=1;
//r=inputRowMeta.getNumber(r, fieldnum);
outputRowData[fieldnum]=int_value;
//get(Fields.Out,field_name).setValue(r,int_value);
logBasic("bool_value is true "+bool_value);
logBasic("outputRowData["+fieldnum+"]"+outputRowData[fieldnum]);
}
else
{
int_value=0;
//r=inputRowMeta.getNumber(r, fieldnum);
outputRowData[fieldnum]=int_value;
//get(Fields.Out,field_name).setValue(r,int_value);
logBasic("bool_value is false "+bool_value);
logBasic("outputRowData["+fieldnum+"]"+outputRowData[fieldnum]);
}
putRow(data.outputRowMeta,outputRowData);
}
else
{
logBasic("Not a bool_value");
logBasic("field num "+fieldnum);
//logBasic("type is "+type);
putRow(data.outputRowMeta, r);
}
}
return true;
}
I got a requirement where I need to store values into Oracle DB from Postgres .
I do not know the number of columns as well as their types.
The table names are fetched dynamically.
The problem is whit the Boolean values , Since Oracle does not support Boolean types , the transformation fails.
I wrote a User defined Java class to convert Boolean to Int Conversion is done , but the problem exists while transferring this data to outputrow. Please help me here. Following error is thrown :
"d Boolean : There was a data type error: the data type of java.lang.Integer object [1] does not correspond to value meta [Boolean]"
Here is my Code :
static long rownum = 0;
static RowMetaInterface inputRowMeta;
static long numFields;
static String[] fieldNames;
static String field_name;
int int_value;
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException
{
// get the current row
Object[] r = getRow();
// If the row object is null, we are done processing.
if (r == null) {
setOutputDone();
return false;
}
// If this is the first row, cache some metadata.
// We will reuse this metadata in processing the rest of the rows.
if (first) {
inputRowMeta = getInputRowMeta();
fieldNames = inputRowMeta.getFieldNames();
numFields = fieldNames.length;
}
// Generate a new id number for the current row.
// Generate one output row for each field in the input stream.
int fieldnum;
Object[] outputRowData = createOutputRow(r, data.outputRowMeta.size());
for (fieldnum = 0; fieldnum < getInputRowMeta().size(); fieldnum++)
{
if(inputRowMeta.getValueMeta(fieldnum).isBoolean())
{
Boolean bool_value=inputRowMeta.getBoolean(r,fieldnum);
ValueMeta newmeta = new org.pentaho.di.core.row.ValueMeta(inputRowMeta.getValueMeta(fieldnum).getName(), org.pentaho.di.core.row.ValueMeta.TYPE_INTEGER);
inputRowMeta.setValueMeta(fieldnum, newmeta);
field_name=inputRowMeta.getValueMeta(fieldnum).getName();
if(bool_value)
{
int_value=1;
//r=inputRowMeta.getNumber(r, fieldnum);
outputRowData[fieldnum]=int_value;
//get(Fields.Out,field_name).setValue(r,int_value);
logBasic("bool_value is true "+bool_value);
logBasic("outputRowData["+fieldnum+"]"+outputRowData[fieldnum]);
}
else
{
int_value=0;
//r=inputRowMeta.getNumber(r, fieldnum);
outputRowData[fieldnum]=int_value;
//get(Fields.Out,field_name).setValue(r,int_value);
logBasic("bool_value is false "+bool_value);
logBasic("outputRowData["+fieldnum+"]"+outputRowData[fieldnum]);
}
putRow(data.outputRowMeta,outputRowData);
}
else
{
logBasic("Not a bool_value");
logBasic("field num "+fieldnum);
//logBasic("type is "+type);
putRow(data.outputRowMeta, r);
}
}
return true;
}