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 8, 2024
1 parent 113d11c commit eb57e11
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

package org.pentaho.di.core.row.value;

import org.apache.commons.lang.StringUtils;
import org.pentaho.di.compatibility.Value;
import org.pentaho.di.core.Const;
import org.pentaho.di.core.database.DatabaseInterface;
Expand Down Expand Up @@ -4038,15 +4039,17 @@ 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" ) );

if ( normalizeNullStringToEmpty ) {
if ( pol == null && isStringValue && isEmptyAndNullDiffer ) {
pol = Const.NULL_STRING;
//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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,15 +389,17 @@ public void testConvertDataFromStringToString() throws KettleValueException {
+ "Conversion from null string must return null", null, 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( inputValueEmptyString, inValueMetaString, nullIf, ifNull, trim_type );
assertEquals( "KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL = Y: "
+ "Conversion from empty string to string must return empty string", StringUtils.EMPTY, 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 empty string", StringUtils.EMPTY, result );

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

// test KETTLE_DO_NOT_NORMALIZE_SPACES_ONLY_STRING_TO_EMPTY
System.setProperty( Const.KETTLE_DO_NOT_NORMALIZE_SPACES_ONLY_STRING_TO_EMPTY, "Y" );
Expand Down

0 comments on commit eb57e11

Please sign in to comment.