Skip to content

Commit

Permalink
[PDI-20085] - KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL produces opposite…
Browse files Browse the repository at this point in the history
… display for NULLS
  • Loading branch information
andreramos89 committed May 16, 2024
1 parent 9856562 commit 40dc35e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4039,18 +4039,16 @@ public Object convertDataFromString( String pol, ValueMetaInterface convertMeta,
boolean isStringValue = outValueType == Value.VALUE_TYPE_STRING;
Object emptyValue = isStringValue ? Const.NULL_STRING : null;

boolean isEmptyAndNullDiffer = !convertStringToBoolean(
boolean isEmptyAndNullDiffer = convertStringToBoolean(
Const.NVL( System.getProperty( Const.KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL, "N" ), "N" ) );

boolean normalizeNullStringToEmpty = convertStringToBoolean(
boolean normalizeNullStringToEmpty = !convertStringToBoolean(
Const.NVL( System.getProperty( Const.KETTLE_DO_NOT_NORMALIZE_NULL_STRING_TO_EMPTY, "N" ), "N" ) );

//the property KETTLE_DO_NOT_NORMALIZE_NULL_STRING_TO_EMPTY is only valid when KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL = Y.
//the isEmptyAndNullDiffer means that null and empty string should be different. normalizeNullStringToEmpty stops pentaho from making this transaction.
if ( isEmptyAndNullDiffer && pol == null && isStringValue ) {
if ( normalizeNullStringToEmpty ) {
pol = StringUtils.EMPTY;
}
if ( (isEmptyAndNullDiffer && pol == null && isStringValue && normalizeNullStringToEmpty) || (!isEmptyAndNullDiffer && pol == null && isStringValue ) ) {
pol = StringUtils.EMPTY;
}

if ( pol == null ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,14 +386,14 @@ public void testConvertDataFromStringToString() throws KettleValueException {
result =
outValueMetaString.convertDataFromString( inputValueNullString, inValueMetaString, nullIf, ifNull, trim_type );
assertEquals( "KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL = N: "
+ "Conversion from null string must return null", null, result );
+ "Conversion from null string must return empty String", StringUtils.EMPTY, result );

System.setProperty( Const.KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL, "Y" );
System.setProperty( Const.KETTLE_DO_NOT_NORMALIZE_NULL_STRING_TO_EMPTY, "N" );
result =
outValueMetaString.convertDataFromString( inputValueNullString, inValueMetaString, nullIf, ifNull, trim_type );
assertEquals( "KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL = Y and KETTLE_DO_NOT_NORMALIZE_NULL_STRING_TO_EMPTY = N: "
+ "Conversion from null string must return null ", null, result );
+ "Conversion from null string must return empty String ", StringUtils.EMPTY, result );

System.setProperty( Const.KETTLE_DO_NOT_NORMALIZE_NULL_STRING_TO_EMPTY, "Y" );
result =
Expand Down

0 comments on commit 40dc35e

Please sign in to comment.