Skip to content

Commit

Permalink
[BACKLOG-10068] When Lazy Conversion is enabled aggregations cannot b…
Browse files Browse the repository at this point in the history
…e calculated since the aggregrated value is converted to a numeric even though the meta type is still set to Binary String. Converting the aggregation meta type from binary string to normal when a convert call is made.
  • Loading branch information
DFieldFL committed Sep 1, 2016
1 parent 0ddde3d commit 53e3fe1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/src/org/pentaho/di/core/row/ValueDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,9 @@ public static Object sum( ValueMetaInterface metaA, Object dataA, ValueMetaInter
return null;
}
if ( dataA == null && dataB != null ) {
return metaA.convertData( metaB, dataB );
Object value = metaA.convertData( metaB, dataB );
metaA.setStorageType( ValueMetaInterface.STORAGE_TYPE_NORMAL );
return value;
}
if ( dataA != null && dataB == null ) {
return dataA;
Expand Down
38 changes: 38 additions & 0 deletions engine/test-src/org/pentaho/di/core/row/ValueDataUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.*;

import java.math.BigDecimal;
import java.text.ParseException;
Expand All @@ -36,6 +37,8 @@
import org.apache.commons.lang.StringUtils;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.pentaho.di.core.Const;
import org.pentaho.di.core.KettleEnvironment;
import org.pentaho.di.core.exception.KettleException;
Expand Down Expand Up @@ -724,6 +727,41 @@ public void testRemainder() throws Exception {
calculate( "-144.144", "16.12", ValueMetaInterface.TYPE_BIGNUMBER, CalculatorMetaFunction.CALC_REMAINDER ) );
}

@Test
public void testSumWithNullValues() throws Exception {
ValueMetaInterface metaA = new ValueMetaInteger();
metaA.setStorageType( ValueMetaInterface.STORAGE_TYPE_NORMAL );
ValueMetaInterface metaB = new ValueMetaInteger();
metaA.setStorageType( ValueMetaInterface.STORAGE_TYPE_NORMAL );

assertNull( ValueDataUtil.sum( metaA, null, metaB, null ) );

Long valueB = new Long( 2 );
ValueDataUtil.sum( metaA, null, metaB, valueB );
}

@Test
public void testSumConvertingStorageTypeToNormal() throws Exception {
ValueMetaInterface metaA = mock( ValueMetaInteger.class );
metaA.setStorageType( ValueMetaInterface.STORAGE_TYPE_BINARY_STRING );

ValueMetaInterface metaB = new ValueMetaInteger();
metaB.setStorageType( ValueMetaInterface.STORAGE_TYPE_BINARY_STRING );
Object valueB = "2";

when( metaA.convertData( metaB, valueB ) ).thenAnswer( new Answer<Long>() {
@Override
public Long answer( InvocationOnMock invocation ) throws Throwable {
return new Long( 2 );
}
} );

Object returnValue = ValueDataUtil.sum( metaA, null, metaB, valueB );
verify( metaA ).convertData( metaB, valueB );
assertEquals( 2L, returnValue );
assertEquals( metaA.getStorageType(), ValueMetaInterface.STORAGE_TYPE_NORMAL );
}

private Object calculate( String string_dataA, int valueMetaInterfaceType, int calculatorMetaFunction ) {
return calculate( string_dataA, null, null, valueMetaInterfaceType, calculatorMetaFunction );
}
Expand Down

0 comments on commit 53e3fe1

Please sign in to comment.