public static Object sum( ValueMetaInterface metaA, Object dataA, ValueMetaInterface metaB, Object dataB ) throws KettleValueException { if ( dataA == null && dataB == null ) { return null; } if ( dataA == null && dataB != null ) { Object value = metaA.convertData( metaB, dataB ); metaA.setStorageType( ValueMetaInterface.STORAGE_TYPE_NORMAL ); return value; } if ( dataA != null && dataB == null ) { return dataA; } return plus( metaA, dataA, metaB, dataB ); }
return ValueDataUtil.plus( valueMetaA, dataA, valueMetaB, dataB );
calcData[index] = ValueDataUtil.plus( metaA, dataA, metaB, dataB ); if ( metaA.isString() || metaB.isString() ) { resultType = ValueMetaInterface.TYPE_STRING;
private void addCumulativeSums( Object[] row ) throws KettleValueException { // We need to adjust this row with cumulative averages? // for ( int i = 0; i < data.cumulativeSumSourceIndexes.size(); i++ ) { int sourceIndex = data.cumulativeSumSourceIndexes.get( i ); Object previousTarget = data.previousSums[ i ]; Object sourceValue = row[ sourceIndex ]; int targetIndex = data.cumulativeSumTargetIndexes.get( i ); ValueMetaInterface sourceMeta = data.inputRowMeta.getValueMeta( sourceIndex ); ValueMetaInterface targetMeta = data.outputRowMeta.getValueMeta( targetIndex ); // If the first values where null, or this is the first time around, just take the source value... // if ( targetMeta.isNull( previousTarget ) ) { row[ targetIndex ] = sourceMeta.convertToNormalStorageType( sourceValue ); } else { // If the source value is null, just take the previous target value // if ( sourceMeta.isNull( sourceValue ) ) { row[ targetIndex ] = previousTarget; } else { row[ targetIndex ] = ValueDataUtil.plus( targetMeta, data.previousSums[ i ], sourceMeta, row[ sourceIndex ] ); } } data.previousSums[ i ] = row[ targetIndex ]; } }
@Test public void testPlus() throws KettleValueException { long longValue = 1; assertEquals( longValue, ValueDataUtil.plus( new ValueMetaInteger(), longValue, new ValueMetaString(), StringUtils.EMPTY ) ); }
data.sum[idx] = targetData; } else { data.sum[idx] = ValueDataUtil.plus( targetMeta, data.sum[idx], targetMeta, targetData );