Skip to content

Commit

Permalink
[CDA-175] - Exporting Union query that has a uses a query with a calc…
Browse files Browse the repository at this point in the history
…ulated column gives error
  • Loading branch information
Elio Freitas committed Mar 30, 2016
1 parent abb389a commit b1f4411
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 33 deletions.
12 changes: 12 additions & 0 deletions core/src/main/java/pt/webdetails/cda/utils/TableModelUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,12 @@ public static TableModel appendTableModel( final TableModel tableModelA, final T
final TypedTableModel typedTableModel = new TypedTableModel( colNames, colTypes, rowCount );
for ( int r = 0; r < tableModelA.getRowCount(); r++ ) {
for ( int c = 0; c < colTypes.length; c++ ) {
if ( c < typedTableModel.getColumnCount() && c < tableModelA.getColumnCount() ) {
if ( !typedTableModel.getColumnClass( c ).equals( tableModelA.getColumnClass( c ) ) ) {
logger.error( "type mismatch, appending " + tableModelA.getColumnClass( c ).toString() + " to "
+ typedTableModel.getColumnClass( c ).toString() );
}
}
typedTableModel.setValueAt( tableModelA.getValueAt( r, c ), r, c );
}
}
Expand All @@ -479,6 +485,12 @@ public static TableModel appendTableModel( final TableModel tableModelA, final T
int rowCountOffset = tableModelA.getRowCount();
for ( int r = 0; r < tableModelB.getRowCount(); r++ ) {
for ( int c = 0; c < colTypes.length; c++ ) {
if ( c < typedTableModel.getColumnCount() && c < tableModelB.getColumnCount() ) {
if ( !typedTableModel.getColumnClass( c ).equals( tableModelB.getColumnClass( c ) ) ) {
logger.error( "type mismatch, appending " + tableModelB.getColumnClass( c ).toString() + " to "
+ typedTableModel.getColumnClass( c ).toString() );
}
}
typedTableModel.setValueAt( tableModelB.getValueAt( r, c ), r + rowCountOffset, c );
}
}
Expand Down
75 changes: 42 additions & 33 deletions core/src/main/java/pt/webdetails/robochef/TableModelInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import javax.swing.table.TableModel;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.pentaho.di.core.row.RowMeta;
import org.pentaho.di.core.row.RowMetaInterface;
import org.pentaho.di.core.row.ValueMetaInterface;
Expand All @@ -28,6 +30,7 @@
import org.pentaho.di.core.row.value.ValueMetaString;

public class TableModelInput extends RowProducerBridge {
private static final Log logger = LogFactory.getLog( TableModelInput.class );
public synchronized Callable<Boolean> getCallableRowProducer( final TableModel tableModel,
final boolean markFinished ) {
final Callable<Boolean> callable = new Callable<Boolean>() {
Expand Down Expand Up @@ -60,42 +63,48 @@ private Object getDataObjectForColumn( final ValueMetaInterface valueMeta, final
}

Object newValue;
switch( valueMeta.getType() ) {
case ValueMetaInterface.TYPE_STRING:
newValue = String.valueOf( value );
break;
case ValueMetaInterface.TYPE_NUMBER:
if ( value instanceof Double ) {
newValue = value;
} else {
newValue = Double.valueOf( value.toString() );
}
break;
case ValueMetaInterface.TYPE_INTEGER:
if ( value instanceof Long ) {
try {
switch ( valueMeta.getType() ) {
case ValueMetaInterface.TYPE_STRING:
newValue = String.valueOf( value );
break;
case ValueMetaInterface.TYPE_NUMBER:
if ( value instanceof Double ) {
newValue = value;
} else {
newValue = Double.valueOf( value.toString() );
}
break;
case ValueMetaInterface.TYPE_INTEGER:
if ( value instanceof Long ) {
newValue = value;
} else {
newValue = Long.valueOf( value.toString() );
}
break;
case ValueMetaInterface.TYPE_DATE:
newValue = value;
} else {
newValue = Long.valueOf( value.toString() );
}
break;
case ValueMetaInterface.TYPE_DATE:
newValue = value;
break;
case ValueMetaInterface.TYPE_BIGNUMBER:
if ( value instanceof java.math.BigDecimal ) {
break;
case ValueMetaInterface.TYPE_BIGNUMBER:
if ( value instanceof java.math.BigDecimal ) {
newValue = value;
} else {
newValue = java.math.BigDecimal.valueOf( ( (java.math.BigInteger) value ).doubleValue() );
}
break;
case ValueMetaInterface.TYPE_BOOLEAN:
newValue = value;
} else {
newValue = java.math.BigDecimal.valueOf( ( (java.math.BigInteger) value ).doubleValue() );
}
break;
case ValueMetaInterface.TYPE_BOOLEAN:
newValue = value;
break;
default:
throw new IllegalArgumentException(
String.format( "ValueMeta mismatch %s (%s)", valueMeta.toString(), value ) );
break;
default:
throw new IllegalArgumentException(
String.format( "ValueMeta mismatch %s (%s)", valueMeta.toString(), value ) );
}
return newValue;
} catch ( NumberFormatException e ) {
logger.error( "type mismatch in column " + valueMeta.getName() + " expecting " + valueMeta.getTypeDesc()
+ " received " + value.getClass() );
throw e;
}
return newValue;
}

private RowMetaInterface getRowMetaForTableModel( final TableModel tableModel ) throws IllegalArgumentException {
Expand Down

0 comments on commit b1f4411

Please sign in to comment.